Skip to content

Commit

Permalink
Merge PR #166 into 16.0
Browse files Browse the repository at this point in the history
Signed-off-by legalsylvain
  • Loading branch information
github-grap-bot committed Nov 24, 2024
2 parents e176e5f + b387b28 commit 9dc842f
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
else:
p.label_ids = False

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

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

0 comments on commit 9dc842f

Please sign in to comment.