From 9333148c796c9fe7caf5cbe46f28127b970284cf Mon Sep 17 00:00:00 2001 From: sbejaoui Date: Tue, 15 Aug 2023 14:20:59 +0200 Subject: [PATCH] [IMP] improve code --- product_attribute_set/__manifest__.py | 2 +- product_attribute_set/models/product.py | 12 +++--------- product_attribute_set/models/product_category.py | 8 +++----- 3 files changed, 7 insertions(+), 15 deletions(-) diff --git a/product_attribute_set/__manifest__.py b/product_attribute_set/__manifest__.py index 98179607..06b79861 100644 --- a/product_attribute_set/__manifest__.py +++ b/product_attribute_set/__manifest__.py @@ -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", diff --git a/product_attribute_set/models/product.py b/product_attribute_set/models/product.py index c78aa365..540d4dcf 100644 --- a/product_attribute_set/models/product.py +++ b/product_attribute_set/models/product.py @@ -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" @@ -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 @@ -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 diff --git a/product_attribute_set/models/product_category.py b/product_attribute_set/models/product_category.py index 2a471c5a..ecc51adb 100644 --- a/product_attribute_set/models/product_category.py +++ b/product_attribute_set/models/product_category.py @@ -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