Hi. I want to get line numbers in the purchase order. But it raises error regarding NewID when lines got changed. How it can be implemented ?
Doing it like this:
class PurchaseOrderLine(models.Model):
_inherit = 'purchase.order.line'
line_number = fields.Integer(string='#', default=1)
class PurchaseOrder(models.Model):
_inherit = 'purchase.order'
@api.onchange('order_line')
def _compute_line_number(self):
sorted_lines = sorted(self.order_line, key=lambda d: (d['sequence'], d['id']), reverse=False)
cnt = 1
for l in sorted_lines:
l.line_number = cnt
cnt += 1