Skip to content

Commit

Permalink
Add name_with_tags_length field and computation logic
Browse files Browse the repository at this point in the history
Introduced a computed field `name_with_tags_length` to store the length of names with template tags replaced. Updated the product view to display this field for better insights into template-modified names.
  • Loading branch information
cbusillo committed Jan 2, 2025
1 parent ee7e4e1 commit 6066fd2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
7 changes: 7 additions & 0 deletions product_connect/models/product_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class ProductTemplate(models.Model):
)

is_ready_for_sale = fields.Boolean(tracking=True, index=True, default=True)
name_with_tags_length = fields.Integer(compute="_compute_name_with_tags_length")

motor = fields.Many2one("motor", ondelete="restrict", readonly=True, index=True)
motor_tests = fields.One2many("motor.test", related="motor.tests")
Expand Down Expand Up @@ -190,6 +191,12 @@ def write(self, vals: "odoo.values.product_template") -> bool:
product.motor.notify_changes()
return result

def _compute_name_with_tags_length(self) -> None:
for product in self:
name = product.replace_template_tags(product.name or "")
name = name.replace("{mpn}", product.first_mpn)
product.name_with_tags_length = len(name)

@api.depends("product_template_image_ids")
def _compute_image_1920(self) -> None:
for product in self:
Expand Down
1 change: 1 addition & 0 deletions product_connect/views/motor_product_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
<field name="bin" width="40px" optional="hide"/>
<button name="reset_name" type="object" icon="fa-refresh" class="sc_refresh_button_row"
title="Reset Name" invisible="motor_product_computed_name == name" width="18"/>
<field name="name_with_tags_length" string="Len" width="30"/>
<field name="name" decoration-warning="motor_product_computed_name != name"/>
<field name="dismantle_notes" optional="show"/>
<field name="website_description" optional="show" widget="text" string="Description"
Expand Down

0 comments on commit 6066fd2

Please sign in to comment.