Skip to Content
Menu
This question has been flagged
1888 Views

Ho All,

I am trying to add some extra fields to (stock.picking, stock_move, stock.move.line) models

Code is IS running good, but it does not save data to database

I cannot add photos 

code IS:


from odoo import models,fields, api
from odoo.addons import decimal_precision as dp
from num2words import num2words


class StockMove(models.Model):
_inherit = "stock.move"

br_currency_id = fields.Many2one(related='picking_id.currency_id',
store=True,
string='Currency',
readonly=True)
br_price_unit = fields.Float(string='U. Price',
required=True,
digits=dp.get_precision('Product Price'),
store=True)
br_price_total = fields.Float(string='Total', store=True)

"""
@api.onchange('product_id','br_price_unit','quantity_done')
def _compute_amount(self):
self.br_price_unit = self.product_id.standard_price
self.br_price_total=self.product_id.standard_price * self.quantity_done
"""


class StockMoveLines(models.Model):
_inherit = "stock.move.line"

br_currency_id = fields.Many2one(related='picking_id.currency_id',
store=True, string='Currency', readonly=True)
br_price_unit = fields.Float(string='U. Price',
required=True,
digits=dp.get_precision('Product Price'),
store=True)
br_price_total = fields.Float(string='Total', store=True)

@api.onchange('product_id', 'br_price_unit', 'qty_done')
def _compute_amount(self):
self.br_price_unit = self.product_id.standard_price
self.br_price_total = self.product_id.standard_price * self.qty_done


class StockPicking(models.Model):
_inherit = "stock.picking"

br_vendor_ref = fields.Char(string="Vendor Reference")
currency_id = fields.Many2one('res.currency', 'Currency',
readonly=True,
default=lambda self: self.env.user.company_id.currency_id.id)
br_amount_total = fields.Monetary(string='Total',
store=True,
readonly=True,
compute='_amount_all')
br_total_amount_in_words = fields.Char(string="Amount in Words",
store=True,
compute='_amount_all')

"""
def _amount_all(self):
for p in self:
p.amount_total=0.0
p.total_amount_in_words='a'
"""
@api.depends('move_line_ids.br_price_total')
def _amount_all(self):
for picking in self:
amount_total = 0.0
for line in picking.move_line_ids:
amount_total += line.br_price_total

lang = picking.partner_id and picking.partner_id.lang[:2]
try:
test = num2words(42, lang=lang)
except NotImplementedError:
lang = 'en'
numword = num2words(amount_total, lang=lang)

picking.update({
'br_amount_total': amount_total,
'br_total_amount_in_words': numword,
})

 

Avatar
Discard
Related Posts Replies Views Activity
3
Sep 22
5768
1
Aug 22
3491
3
Mar 21
1165
5
Feb 20
10623
2
Feb 19
2114