我正在尝试为(stock.picking,stock_move,stock.move.line)模型添加一些额外的字段
代码运行良好,但是没有将数据保存到数据库中
代码IS:
from odoo import models,fields, api
从odoo.addons 导入小数精度为dp 从num2words导入num2words
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 “”“
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
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,
})