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_doneclass 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,
})