Skip to content

Commit

Permalink
[IMP]product_attribute_set: Improve write on category
Browse files Browse the repository at this point in the history
Adds the option of writing on many categories at the same time.
  • Loading branch information
GuillemCForgeFlow committed Nov 16, 2022
1 parent a8f80f3 commit 65b17f5
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions product_attribute_set/models/product_category.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@ class ProductCategory(models.Model):

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

return True
for category in self:
template_ids = self.env["product.template"].search(
[("categ_id", "=", category.id), ("attribute_set_id", "=", False)]
)
template_ids.write({"attribute_set_id": category.attribute_set_id.id})
return res

0 comments on commit 65b17f5

Please sign in to comment.