From 6633e88469e00789daa30fbb0695188180a9d660 Mon Sep 17 00:00:00 2001 From: hugues de keyzer Date: Wed, 22 Nov 2023 14:24:17 +0100 Subject: [PATCH] [FIX] display error in case of no available shares display an error message instead of failing when trying to create a subscription request from a partner and no share products are available. --- cooperator/readme/newsfragments/86.bugfix.17.rst | 2 ++ cooperator/wizard/partner_create_subscription.py | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 cooperator/readme/newsfragments/86.bugfix.17.rst diff --git a/cooperator/readme/newsfragments/86.bugfix.17.rst b/cooperator/readme/newsfragments/86.bugfix.17.rst new file mode 100644 index 000000000..f79e41a43 --- /dev/null +++ b/cooperator/readme/newsfragments/86.bugfix.17.rst @@ -0,0 +1,2 @@ +Display an error message instead of failing when trying to create a +subscription request from a partner and no share products are available. diff --git a/cooperator/wizard/partner_create_subscription.py b/cooperator/wizard/partner_create_subscription.py index 18d09081d..ea3135b37 100644 --- a/cooperator/wizard/partner_create_subscription.py +++ b/cooperator/wizard/partner_create_subscription.py @@ -29,8 +29,12 @@ def _default_product_id(self): domain.append(("by_company", "=", True)) else: domain.append(("by_individual", "=", True)) - - return self.env["product.product"].search(domain)[0] + products = self.env["product.product"].search(domain) + if not products: + raise UserError( + _("No default share product found for this type of partner.") + ) + return products[0] def _get_representative(self): partner = self._get_partner()