如何在报价单中的小计中添加另一个折扣?
How to add another discount to subtotal in Quotation Order?
报价单行中有一个 subtotal
(price_subtotal) 字段。
我添加了一个新字段extra_discount
。
我试过这段代码,但没有用。
@api.depends('product_uom_qty', 'price_unit', 'extra_discount')
def compute_all(self):
for record in self:
record.price_subtotal = (record.product_uom_qty * record.price_unit) - record.extra_discount
它对subtotal
没有任何作用。
那么,我该如何实现呢?
我会尝试覆盖字段 sale.order.line.price_subtotal
后面的 the computation method。
但我不确定 api.depends()
扩展(再添加一个重新计算触发字段)是否按预期工作。
但它看起来应该是这样的:
class SaleOrderLine(models.Model):
_inherit = "sale.order.line"
extra_discount = fields.Float()
@api.depends('product_uom_qty', 'discount', 'price_unit',
'tax_id', 'extra_discount')
def _compute_amount(self):
"""
Compute the amounts of the SO line.
Fully overridden to add field extra_discount to the
formula and triggers.
"""
for line in self:
price = line.price_unit * (1 - (line.discount or 0.0) / 100.0)
# new: substract extra_discount
price -= line.extra_discount
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'],
})
if self.env.context.get('import_file', False) and not self.env.user.user_has_groups('account.group_account_manager'):
line.tax_id.invalidate_cache(['invoice_repartition_line_ids'], [line.tax_id.id])
报价单行中有一个 subtotal
(price_subtotal) 字段。
我添加了一个新字段extra_discount
。
我试过这段代码,但没有用。
@api.depends('product_uom_qty', 'price_unit', 'extra_discount')
def compute_all(self):
for record in self:
record.price_subtotal = (record.product_uom_qty * record.price_unit) - record.extra_discount
它对subtotal
没有任何作用。
那么,我该如何实现呢?
我会尝试覆盖字段 sale.order.line.price_subtotal
后面的 the computation method。
但我不确定 api.depends()
扩展(再添加一个重新计算触发字段)是否按预期工作。
但它看起来应该是这样的:
class SaleOrderLine(models.Model):
_inherit = "sale.order.line"
extra_discount = fields.Float()
@api.depends('product_uom_qty', 'discount', 'price_unit',
'tax_id', 'extra_discount')
def _compute_amount(self):
"""
Compute the amounts of the SO line.
Fully overridden to add field extra_discount to the
formula and triggers.
"""
for line in self:
price = line.price_unit * (1 - (line.discount or 0.0) / 100.0)
# new: substract extra_discount
price -= line.extra_discount
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'],
})
if self.env.context.get('import_file', False) and not self.env.user.user_has_groups('account.group_account_manager'):
line.tax_id.invalidate_cache(['invoice_repartition_line_ids'], [line.tax_id.id])