Skip to Content
Menu
This question has been flagged
2 Replies
1635 Views

i added a custom field (x_discount_rate) in purchase_order module and in def _amount_all(self) discount field minus(-) with amount_untaxed += line.price_subtotal - x_discount_rate like this but in odoo when i create a purchase order it shows this error

NameError: global name 'x_discount_rate' is not defined

please help me to resolve this issue

Thanks.


Avatar
Discard
Author Best Answer

what should i do for minus(-) x_discount_rate from amount_total

class PurchaseOrder(models.Model): 
_name = "purchase.order"
_inherit = ['mail.thread', 'ir.needaction_mixin']
_description = "Purchase Order"
_order = 'date_order desc, id desc'


@api.depends('order_line.price_total')
def _amount_all(self):
for order in self:
amount_untaxed = amount_tax = 0.0
for line in order.order_line:
amount_untaxed += line.price_subtotal
# FORWARDPORT UP TO 10.0
if order.company_id.tax_calculation_rounding_method == 'round_globally':
taxes = line.taxes_id.compute_all(line.price_unit, line.order_id.currency_id, line.product_qty, product=line.product_id, partner=line.order_id.partner_id)
amount_tax += sum(t.get('amount', 0.0) for t in taxes.get('taxes', []))
else:
amount_tax += line.price_tax
order.update({
'amount_untaxed': order.currency_id.round(amount_untaxed),
'amount_tax': order.currency_id.round(amount_tax),
'amount_total': amount_untaxed + amount_tax
})

Avatar
Discard
Best Answer

Hi,

You have to call the field like self.field_name or as per the context. If you simply give x_discount_rate it will be considered as a variable and system will look for defined variable. So just update the code with self.x_discount_rate and see.

Not sure it has to be given self. you can check the rest of the function and see how the other fields are called and do accordingly

Thanks

Avatar
Discard