[MIG] base_global_discount: Migration to 17.0

This commit is contained in:
miguel-S73
2024-08-14 17:10:35 +02:00
parent 323eaa6613
commit 22ec50848d
6 changed files with 26 additions and 15 deletions

View File

@@ -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",

View File

@@ -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

View File

@@ -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 @@ class ProductTemplate(models.Model):
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
)

View File

@@ -27,3 +27,12 @@ class TestGlobalDiscount(common.TransactionCase):
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])

View File

@@ -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>

View File

@@ -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>
@@ -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"
/>
<field
name="supplier_global_discount_ids"
@@ -35,7 +35,7 @@
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>