Skip to content

Commit

Permalink
[IMP] improve code
Browse files Browse the repository at this point in the history
  • Loading branch information
sbejaoui authored and Vandan-OSI committed Aug 29, 2024
1 parent 388a765 commit 12e6a79
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 15 deletions.
2 changes: 1 addition & 1 deletion product_attribute_set/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"name": "Product Attribute Set",
"version": "16.0.1.0.0",
"category": "Generic Modules/Others",
"category": "PIM",
"license": "AGPL-3",
"author": "Akretion,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/odoo-pim",
Expand Down
12 changes: 3 additions & 9 deletions product_attribute_set/models/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@


class ProductTemplate(models.Model):
"""The mixin 'attribute.set.owner.mixin' override the model's fields_view_get()
method which will replace the 'attributes_placeholder' by a group made up of all
the product.template's Attributes.
Each Attribute will have a conditional invisibility depending on its Attriute Sets.
"""

_inherit = ["product.template", "attribute.set.owner.mixin"]
_name = "product.template"
Expand All @@ -23,12 +18,11 @@ class ProductTemplate(models.Model):
)

def _get_default_att_set(self):
"""Fill default Product's attribute_set with its Category's
default attribute_set."""
"""Get default product's attribute_set by category."""
default_categ_id_id = self._get_default_category_id()
if default_categ_id_id:
default_categ_id = self.env["product.category"].search(
[("id", "=", default_categ_id_id.id)]
[("id", "=", default_categ_id_id.id)], limit=1
)
return default_categ_id.attribute_set_id.id

Expand All @@ -48,7 +42,7 @@ def write(self, vals):
return super().write(vals)

@api.onchange("categ_id")
def update_att_set_onchange_categ_id(self):
def _onchange_categ_id(self):
self.ensure_one()
if self.categ_id and not self.attribute_set_id:
self.attribute_set_id = self.categ_id.attribute_set_id
Expand Down
8 changes: 3 additions & 5 deletions product_attribute_set/models/product_category.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@ class ProductCategory(models.Model):
)

def write(self, vals):
"""Fill Category's products with Category's default attribute_set_id if empty"""
# Fill Category's products with Category's default attribute_set_id if empty
super().write(vals)
for record in self:
if vals.get("attribute_set_id"):
product_ids = self.env["product.template"].search(
templates = self.env["product.template"].search(
[("categ_id", "=", record.id), ("attribute_set_id", "=", False)]
)
for product_id in product_ids:
product_id.attribute_set_id = record.attribute_set_id

templates.write({"attribute_set_id": record.attribute_set_id.id})
return True

0 comments on commit 12e6a79

Please sign in to comment.