From e7ef2dabbd480bdb772fa3903819af8d58b910e5 Mon Sep 17 00:00:00 2001 From: Yannick Tivisse Date: Fri, 9 Jul 2021 12:35:06 +0200 Subject: [PATCH] [IMP] lunch: Improve error message --- addons/lunch/models/lunch_product.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/addons/lunch/models/lunch_product.py b/addons/lunch/models/lunch_product.py index 7a8017da6d1..1cbb60519c6 100644 --- a/addons/lunch/models/lunch_product.py +++ b/addons/lunch/models/lunch_product.py @@ -102,10 +102,12 @@ class LunchProduct(models.Model): return self.filtered(lambda p: (p.category_id.active and p.supplier_id.active) != p.active).toggle_active() def toggle_active(self): - if self.filtered(lambda product: not product.active and not product.category_id.active): - raise UserError(_("The product category is archived. The user have to unarchive the category or change the category of the product.")) - if self.filtered(lambda product: not product.active and not product.supplier_id.active): - raise UserError(_("The product supplier is archived. The user have to unarchive the supplier or change the supplier of the product.")) + invalid_products = self.filtered(lambda product: not product.active and not product.category_id.active) + if invalid_products: + raise UserError(_("The following product categories are archived. You should either unarchive the categories or change the category of the product.\n%s", '\n'.join(invalid_products.category_id.mapped('name')))) + invalid_products = self.filtered(lambda product: not product.active and not product.supplier_id.active) + if invalid_products: + raise UserError(_("The following suppliers are archived. You should either unarchive the suppliers or change the supplier of the product.\n%s", '\n'.join(invalid_products.supplier_id.mapped('name')))) return super().toggle_active() def write(self, values):