diff --git a/ext/custom-addons/dp_custom/models/account.py b/ext/custom-addons/dp_custom/models/account.py index e58ea93a..c37960d6 100644 --- a/ext/custom-addons/dp_custom/models/account.py +++ b/ext/custom-addons/dp_custom/models/account.py @@ -54,12 +54,14 @@ class AccountInvoiceLine(models.Model): def write(self, vals): res = super(AccountInvoiceLine, self).write(vals) - if vals.get('intrastat_id', False) and vals.get('lot_id', False): - self.env['stock.production.lot'].browse([vals.get('lot_id', False)]).write({ - 'intrastat_id': vals.get('intrastat_id') - }) - elif vals.get('intrastat_id', False) and not vals.get('lot_id', False): - raise UserError(_('Der Intrastrat Code kann nur gesetzt werden wenn ein Lot angegeben wurde.')) + for record in self: + lot_id = record.lot_id if 'lot_id' not in vals else vals.get('lot_id', False) + if vals.get('intrastat_id', False) and lot_id: + self.env['stock.production.lot'].browse([vals.get('lot_id', False)]).write({ + 'intrastat_id': vals.get('intrastat_id') + }) + elif vals.get('intrastat_id', False) and not lot_id: + raise UserError(_('Der Intrastrat Code kann nur gesetzt werden wenn ein Lot angegeben wurde.')) return res