[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

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