diff --git a/base_global_discount/__manifest__.py b/base_global_discount/__manifest__.py
index 3c06c365b..83ee6a868 100644
--- a/base_global_discount/__manifest__.py
+++ b/base_global_discount/__manifest__.py
@@ -3,7 +3,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "Base Global Discount",
- "version": "16.0.1.1.0",
+ "version": "17.0.1.0.0",
"category": "Base",
"author": "Tecnativa, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/server-backend",
diff --git a/base_global_discount/models/global_discount.py b/base_global_discount/models/global_discount.py
index c50948d38..ee97b118b 100644
--- a/base_global_discount/models/global_discount.py
+++ b/base_global_discount/models/global_discount.py
@@ -14,7 +14,7 @@ class GlobalDiscount(models.Model):
discount_scope = fields.Selection(
selection=[("sale", "Sales"), ("purchase", "Purchases")],
default="sale",
- required="True",
+ required=True,
)
company_id = fields.Many2one(
comodel_name="res.company",
@@ -22,11 +22,9 @@ class GlobalDiscount(models.Model):
default=lambda self: self.env.company,
)
- def name_get(self):
- result = []
+ def _compute_display_name(self):
for one in self:
- result.append((one.id, f"{one.name} ({one.discount:.2f}%)"))
- return result
+ one.display_name = f"{one.name} ({one.discount:.2f}%)"
def _get_global_discount_vals(self, base, **kwargs):
"""Prepare the dict of values to create to obtain the discounted
diff --git a/base_global_discount/models/product_template.py b/base_global_discount/models/product_template.py
index 8b198594a..f98e2c18e 100644
--- a/base_global_discount/models/product_template.py
+++ b/base_global_discount/models/product_template.py
@@ -15,6 +15,7 @@ class ProductTemplate(models.Model):
),
compute="_compute_bypass_global_discount",
inverse="_inverse_bypass_global_discount",
+ search="_search_bypass_global_discount",
)
def _search_bypass_global_discount(self, operator, value):
@@ -31,9 +32,12 @@ def _compute_bypass_global_discount(self):
template.bypass_global_discount = (
template.product_variant_ids.bypass_global_discount
)
+ else:
+ template.bypass_global_discount = False
def _inverse_bypass_global_discount(self):
- if len(self.product_variant_ids) == 1:
- self.product_variant_ids.bypass_global_discount = (
- self.bypass_global_discount
- )
+ for template in self:
+ if len(template.product_variant_ids) == 1:
+ template.product_variant_ids.bypass_global_discount = (
+ template.bypass_global_discount
+ )
diff --git a/base_global_discount/tests/test_global_discount.py b/base_global_discount/tests/test_global_discount.py
index 41719dbc6..1b2986943 100644
--- a/base_global_discount/tests/test_global_discount.py
+++ b/base_global_discount/tests/test_global_discount.py
@@ -27,3 +27,12 @@ def test_01_global_discounts(self):
def test_02_display_name(self):
"""Test that the name is computed fine"""
self.assertTrue("%)" in self.global_discount_1.display_name)
+
+ def test_03_bypass_products(self):
+ template_obj = self.env["product.template"]
+ template = template_obj.create({"name": "Test Template"})
+ template.bypass_global_discount = True
+ self.assertTrue(template.bypass_global_discount)
+ search_result = template._search_bypass_global_discount("=", True)
+ self.assertEqual(len(search_result), 1)
+ self.assertEqual(template.id, search_result[0][2][0])
diff --git a/base_global_discount/views/product_views.xml b/base_global_discount/views/product_views.xml
index 65bc86c60..fabb5d6c3 100644
--- a/base_global_discount/views/product_views.xml
+++ b/base_global_discount/views/product_views.xml
@@ -23,7 +23,7 @@
diff --git a/base_global_discount/views/res_partner_views.xml b/base_global_discount/views/res_partner_views.xml
index 03fa2d710..54c73c3e3 100644
--- a/base_global_discount/views/res_partner_views.xml
+++ b/base_global_discount/views/res_partner_views.xml
@@ -11,14 +11,14 @@
name="customer_global_discount_ids"
widget="many2many_tags"
groups="base_global_discount.group_global_discount"
- attrs="{'invisible': [('is_company', '=', False), ('parent_id', '!=', False)]}"
+ invisible="not is_company and parent_id"
/>
@@ -27,7 +27,7 @@
name="supplier_global_discount_ids"
widget="many2many_tags"
groups="base_global_discount.group_global_discount"
- attrs="{'invisible': [('is_company', '=', False), ('parent_id', '!=', False)]}"
+ invisible="not is_company and parent_id"
/>