Help

0

How to compute Purchase Order Line field and show in Purchase Order field

Avatar
Haris Masqati

i create a custom field x_line_total in Purchase order Line and create another custom field x_grand_total for show sum of x_line_total  field. How to compute x_line_total field into x_grand_totalfield?

This Code i written on .py file but this is not correct

class PurchaseOrder(models.Model):
_inherit = "purchase.order" 

@api.depends('order_line.x_line_total')
def _compute_x_grand_total(self): 

 for line in order.order_line: 
x_grand_total += line.x_line_total 

x_grand_total = fields.Float(compute='_compute_x_grand_total', string='Grand Total')

Avatar
Discard
1 Answer
2
Best Answer

Hi!

Change the code like this :

class PurchaseOrder(models.Model):
_inherit = "purchase.order"

x_grand_total = fields.Float(compute='_compute_x_grand_total', string='Grand Total')

@api.depends('order_line')
def _compute_x_grand_total(self):
self.x_grand_total = sum(line.x_line_total for line in self.order_line)

Best regards!

2 Comments
Avatar
Discard
Avatar
Haris Masqati
-

i tried your code but this error has been occurred

self.x_grand_total = sum(line.x_line_total for line in self.order_line)

AttributeError: 'purchase.order.line' object has no attribute 'x_line_total'

Avatar
Asad Asif
-

Hello,

Thanks it works :)