Skip to content

Commit

Permalink
[MIG] base_global_discount: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
miguel-S73 committed Aug 14, 2024
1 parent 323eaa6 commit 22ec508
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 15 deletions.
2 changes: 1 addition & 1 deletion base_global_discount/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 3 additions & 5 deletions base_global_discount/models/global_discount.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,17 @@ 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",
string="Company",
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
Expand Down
12 changes: 8 additions & 4 deletions base_global_discount/models/product_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -31,9 +32,12 @@ def _compute_bypass_global_discount(self):
template.bypass_global_discount = (

Check warning on line 32 in base_global_discount/models/product_template.py

View check run for this annotation

Codecov / codecov/patch

base_global_discount/models/product_template.py#L32

Added line #L32 was not covered by tests
template.product_variant_ids.bypass_global_discount
)
else:
template.bypass_global_discount = False

Check warning on line 36 in base_global_discount/models/product_template.py

View check run for this annotation

Codecov / codecov/patch

base_global_discount/models/product_template.py#L36

Added line #L36 was not covered by tests

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
)
9 changes: 9 additions & 0 deletions base_global_discount/tests/test_global_discount.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
2 changes: 1 addition & 1 deletion base_global_discount/views/product_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<xpath expr="//group[@name='group_standard_price']" position="inside">
<field
name="bypass_global_discount"
attrs="{'invisible': [('product_variant_count', '>', 1)]}"
invisible="product_variant_count > 1"
groups="base_global_discount.group_global_discount"
/>
</xpath>
Expand Down
8 changes: 4 additions & 4 deletions base_global_discount/views/res_partner_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
/>
<field
name="customer_global_discount_ids"
string="Sale Global Discounts"
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"
readonly="1"
/>
</group>
Expand All @@ -27,15 +27,15 @@
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"
/>
<field
name="supplier_global_discount_ids"
string="Purchase Global Discounts"
readonly="1"
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"
/>
</group>
</field>
Expand Down

0 comments on commit 22ec508

Please sign in to comment.