From 46fa7215ad0a70e4c5f6d5ee3befddfada574f83 Mon Sep 17 00:00:00 2001 From: Victor Feyens Date: Wed, 5 Aug 2020 14:49:43 +0000 Subject: [PATCH] [IMP] repair: improve constraint error message * Private method * Clearer and more complete error message, specifying all erroneous records Task Id: 2328664 COM PR: https://github.com/odoo/odoo/pull/55525 ENT PR: https://github.com/odoo/enterprise/pull/12250 --- addons/repair/models/repair.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/addons/repair/models/repair.py b/addons/repair/models/repair.py index 093678ef8e0..aee645ac0e1 100644 --- a/addons/repair/models/repair.py +++ b/addons/repair/models/repair.py @@ -652,9 +652,14 @@ class RepairLine(models.Model): help='The status of a repair line is set automatically to the one of the linked repair order.') @api.constrains('lot_id', 'product_id') - def constrain_lot_id(self): - for line in self.filtered(lambda x: x.product_id.tracking != 'none' and not x.lot_id): - raise ValidationError(_("Serial number is required for operation line with product '%s'") % (line.product_id.name)) + def _check_product_tracking(self): + invalid_lines = self.filtered(lambda x: x.product_id.tracking != 'none' and not x.lot_id) + if invalid_lines: + products = invalid_lines.product_id + raise ValidationError(_( + "Serial number is required for operation lines with products: %s", + ", ".join(products.mapped('name')), + )) @api.depends('price_unit', 'repair_id', 'product_uom_qty', 'product_id', 'repair_id.invoice_method') def _compute_price_subtotal(self):