I have this method:
@api.onchange('qty', 'consumed_qty')
def _remaining_func(self):
for qty in self.isbn:
if self.qty or self.consumed_qty:
self.remaining_qty = self.qty +(-self.consumed_qty)
But I need it to loop through records of my line (One2many field), right now, if I add just one record it works just fine, but if I add two or more, it throws the Expected singleton
error.
So, how can I loop with this method?
I have added the for qty in self.isbn
but with no success.
This is the class where this method is declared:
class bsi_production_order_lines(models.Model):
_name = 'bsi.production.order.lines'
production_order = fields.Many2one('bsi.production.order', string="Production Orders")
isbn = fields.Many2one('product.product', string="ISBN", domain="[('is_isbn', '=', True)]")
qty = fields.Float(string="Quantity")
consumed_qty = fields.Float(string="Consumed quantity")
remaining_qty = fields.Float(string="Remaining quantity", compute="_remaining_func")
Any ideas?