SO销售单和PO采购单,一定要在原始主类下添加字段,不能在继承类添加字段,不然xml识别不到字段。
SO销售单:
添加express_price字段后,找到def _compute_amount(self):方法,最后两行加入小计和合计的计算逻辑:
@api.depends('product_uom_qty', 'discount', 'price_unit', 'tax_id')
def _compute_amount(self):
"""
Compute the amounts of the SO line.
"""
for line in self:
price = line.price_unit * (1 - (line.discount or 0.0) / 100.0)
taxes = line.tax_id.compute_all(price, line.order_id.currency_id, line.product_uom_qty, product=line.product_id, partner=line.order_id.partner_shipping_id)
line.update({
'price_tax': sum(t.get('amount', 0.0) for t in taxes.get('taxes', [])),
'price_total': taxes['total_included'],
'price_subtotal': taxes['total_excluded'],
})
line.price_subtotal = line.product_uom_qty * line.price_unit + line.express_price
line.price_subtotal = line.product_uom_qty * line.price_unit + line.express_price
PO采购单:
由于PO采购单是SO销售单审核同步而来,所以运费字段取自SO销售单,同理,在主类创建计算字段,写入计算逻辑,最后再写入小计和合计逻辑。
express_price = fields.Float('运费', compute = '_coupute_express_price', store=True,inverse='_inverse_express_price')
# 如果是SO源单据的采购单,审核时会填入运费
@api.depends('order_id.order_line.product_id')
def _coupute_express_price(self):
if self.order_id.origin.startswith("SO"):
a=self.env['sale.order'].search([('name','=',self.order_id.origin)])
for b in a.order_line:
if self.product_id == b.product_id:
self.express_price = b.express_price
def _inverse_express_price(self):
pass
@api.depends('product_qty', 'price_unit', 'taxes_id')
def _compute_amount(self):
for line in self:
vals = line._prepare_compute_all_values()
taxes = line.taxes_id.compute_all(
vals['price_unit'],
vals['currency_id'],
vals['product_qty'],
vals['product'],
vals['partner'])
line.update({
'price_tax': sum(t.get('amount', 0.0) for t in taxes.get('taxes', [])),
'price_total': taxes['total_included'],
'price_subtotal': taxes['total_excluded'],
})
line.price_subtotal = line.product_qty * line.price_unit + line.express_price
line.price_subtotal = line.product_qty * line.price_unit + line.express_price