Skip to content

Commit

Permalink
[IMP] product_template_multi_link: Makes links bi-directional
Browse files Browse the repository at this point in the history
fixes OCA#307
  • Loading branch information
lmignon authored and David-Luis-Mora committed May 2, 2024
1 parent 0c5b399 commit d3eee69
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
1 change: 0 additions & 1 deletion product_template_multi_link/models/product_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ def _compute_product_template_link_count(self):

def show_product_template_links(self):
self.ensure_one()

return {
"name": _("Product links"),
"type": "ir.actions.act_window",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def _invalidate_links_on_product_template(self):
def _invalidate_links(self):
self.env["product.template"].invalidate_cache(["product_template_link_ids"])

@api.model
@api.model_create_multi
def create(self, vals_list):
with self._invalidate_links_on_product_template():
return super().create(vals_list)
Expand Down
21 changes: 20 additions & 1 deletion product_template_multi_link/models/product_template_link_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@ class ProductTemplateLinkType(models.Model):

name = fields.Char(required=True, translate=True)
inverse_name = fields.Char(
compute="_compute_inverse_name", readonly=False, store=True, translate=True
compute="_compute_inverse_name",
inverse="_inverse_inverse_name",
readonly=False,
store=True,
translate=True,
)
manual_inverse_name = fields.Char()
is_symmetric = fields.Boolean(
help="The relation meaning is the same from each side of the relation",
default=True,
Expand All @@ -25,11 +30,13 @@ class ProductTemplateLinkType(models.Model):
inverse_code = fields.Char(
"Technical code (inverse)",
compute="_compute_inverse_code",
inverse="_inverse_inverse_code",
readonly=False,
store=True,
help="This code allows to provide a technical code to external"
"systems identifying this link type",
)
manual_inverse_code = fields.Char()
_sql_constraints = [
("name_uniq", "unique (name)", "Link type name already exists !"),
(
Expand All @@ -51,6 +58,14 @@ class ProductTemplateLinkType(models.Model):

display_name = fields.Char(compute="_compute_display_name")

def _inverse_inverse_name(self):
for record in self:
record.manual_inverse_name = record.inverse_name

def _inverse_inverse_code(self):
for record in self:
record.manual_inverse_code = record.inverse_code

@api.depends("name", "inverse_name")
def _compute_display_name(self):
for record in self:
Expand All @@ -64,12 +79,16 @@ def _compute_inverse_name(self):
for record in self:
if record.is_symmetric:
record.inverse_name = record.name
else:
record.inverse_name = record.manual_inverse_name

@api.depends("code", "is_symmetric")
def _compute_inverse_code(self):
for record in self:
if record.is_symmetric:
record.inverse_code = record.code
else:
record.inverse_code = record.manual_inverse_code

def write(self, vals):
if not self:
Expand Down

0 comments on commit d3eee69

Please sign in to comment.