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

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

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

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)
Avatar
Discard
Best Answer
@api.depends('line_ids.x_line_total')
def _compute_x_grand_total(self):
for rec in self:
rec.ex_grand_total = sum(rec.line_ids.mapped('x_line_total'))
Avatar
Discard
Best Answer

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

@api.one
@api.depends('order_line')
def _compute_x_grand_total(self):
self.x_grand_total = sum(self.order_line.mapped('x_line_total'))


Avatar
Discard