我正在使用Odoo 11.0 C.E。
我尝试构建一个新模块以添加价格和price_total
我尝试添加三列(price_unit_br,price_total,currency_id)
仅(price_total,currency_id)添加到数据库
安装模块后,表单的设计如下
这是我的代码
class StockMove(models.Model):
_inherit = "stock.move"
currency_id = fields.Many2one(related='picking_id.currency_id', store=True, string='Currency', readonly=True)
price_unit_br = fields.Float(string='Unit Price Br', required=True, digits=dp.get_precision('Product Price'), store=True)
price_total = fields.Float(compute='_compute_amount', string='Total', store=True)
@api.depends('quantity_done', 'price_unit_br')
def _compute_amount(self):
for line in self:
total = 0.0
total = line.quantity_done * line.price_unit_br
line.update({
'price_total': total,
})
@api.onchange('product_id', 'quantity_done', 'product_uom')
def _onchange_quantity_br(self):
if not self.product_id:
return
price_unit = self.product_id.standard_price
self.price_unit_br = price_unit