Skip to content

Commit

Permalink
[IMP] improve code
Browse files Browse the repository at this point in the history
  • Loading branch information
sbejaoui committed Aug 21, 2023
1 parent 4ba0f7a commit 9333148
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)

Check warning on line 42 in product_attribute_set/models/product.py

View check run for this annotation

Codecov / codecov/patch

product_attribute_set/models/product.py#L40-L42

Added lines #L40 - L42 were not covered by tests

@api.onchange("categ_id")
def update_att_set_onchange_categ_id(self):
def _onchange_categ_id(self):
self.ensure_one()

Check warning on line 46 in product_attribute_set/models/product.py

View check run for this annotation

Codecov / codecov/patch

product_attribute_set/models/product.py#L46

Added line #L46 was not covered by tests
if self.categ_id and not self.attribute_set_id:
self.attribute_set_id = self.categ_id.attribute_set_id

Check warning on line 48 in product_attribute_set/models/product.py

View check run for this annotation

Codecov / codecov/patch

product_attribute_set/models/product.py#L48

Added line #L48 was not covered by tests
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)

Check warning on line 19 in product_attribute_set/models/product_category.py

View check run for this annotation

Codecov / codecov/patch

product_attribute_set/models/product_category.py#L19

Added line #L19 was not covered by tests
for record in self:
if vals.get("attribute_set_id"):
product_ids = self.env["product.template"].search(
templates = self.env["product.template"].search(

Check warning on line 22 in product_attribute_set/models/product_category.py

View check run for this annotation

Codecov / codecov/patch

product_attribute_set/models/product_category.py#L22

Added line #L22 was not covered by tests
[("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

Check warning on line 26 in product_attribute_set/models/product_category.py

View check run for this annotation

Codecov / codecov/patch

product_attribute_set/models/product_category.py#L25-L26

Added lines #L25 - L26 were not covered by tests

0 comments on commit 9333148

Please sign in to comment.