Skip to content

Commit

Permalink
[FIX] product_label: Correctly define label_ids on product.template, …
Browse files Browse the repository at this point in the history
…like in odoo core
  • Loading branch information
legalsylvain committed Nov 24, 2024
1 parent e176e5f commit b387b28
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions product_label/models/product_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,34 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).


from odoo import fields, models
from odoo import api, fields, models


class ProductTemplate(models.Model):
_inherit = "product.template"

label_ids = fields.Many2many(
comodel_name="product.label",
related="product_variant_ids.label_ids",
compute="_compute_label_ids",
inverse="_inverse_label_ids",
string="Labels",
readonly=False,
)

@api.depends("product_variant_ids", "product_variant_ids.label_ids")
def _compute_label_ids(self):
for p in self:
if len(p.product_variant_ids) == 1:
p.label_ids = p.product_variant_ids.label_ids

Check warning on line 25 in product_label/models/product_template.py

View check run for this annotation

Codecov / codecov/patch

product_label/models/product_template.py#L25

Added line #L25 was not covered by tests
else:
p.label_ids = False

Check warning on line 27 in product_label/models/product_template.py

View check run for this annotation

Codecov / codecov/patch

product_label/models/product_template.py#L27

Added line #L27 was not covered by tests

def _inverse_label_ids(self):
for p in self:
if len(p.product_variant_ids) == 1:
p.product_variant_ids.label_ids = p.label_ids

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

View check run for this annotation

Codecov / codecov/patch

product_label/models/product_template.py#L32

Added line #L32 was not covered by tests

def _get_related_fields_variant_template(self):
res = super()._get_related_fields_variant_template()
res.append("label_ids")
return res

0 comments on commit b387b28

Please sign in to comment.