diff --git a/product_category_global_info/__init__.py b/product_category_global_info/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/product_category_global_info/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/product_category_global_info/__manifest__.py b/product_category_global_info/__manifest__.py new file mode 100644 index 00000000000..ba3d72f66c5 --- /dev/null +++ b/product_category_global_info/__manifest__.py @@ -0,0 +1,18 @@ +{ + 'name': "Product Category Global Info", + 'version': '1.0', + 'summary': 'Extends product category with global info fields and a new tab grouping attributes by category.', + 'description': """ + This module extends the product category form by: + - Adding a boolean field "Show on Global Info" + - Adding a many2many field to map required attributes + It also adds a new tab called "Global Info" that displays category and attribute information grouped by product category. + """, + 'category': 'Productivity', + 'depends': ['stock', 'sale_management'], + 'data': [ + 'views/product_category_global_info.xml', + 'views/sale_order_view_inherit.xml', + ], + 'license': 'AGPL-3' +} diff --git a/product_category_global_info/models/__init__.py b/product_category_global_info/models/__init__.py new file mode 100644 index 00000000000..b35988a9830 --- /dev/null +++ b/product_category_global_info/models/__init__.py @@ -0,0 +1,2 @@ +from . import product_category +from . import sale_order_line diff --git a/product_category_global_info/models/product_category.py b/product_category_global_info/models/product_category.py new file mode 100644 index 00000000000..d31d348e150 --- /dev/null +++ b/product_category_global_info/models/product_category.py @@ -0,0 +1,18 @@ +from odoo import fields, models + + +class ProductCategory(models.Model): + _inherit = 'product.category' + + show_on_global_info = fields.Boolean( + string="Show on Global info", + help="If checked, this category will appear in the 'Global Info' tab of Sale Orders.", + default=False, + store=True + ) + + required_attribute_ids = fields.Many2many( + comodel_name="product.attribute", + string="Required Attribute", + help="Attributes that must be specified for products in this category." + ) diff --git a/product_category_global_info/models/sale_order_line.py b/product_category_global_info/models/sale_order_line.py new file mode 100644 index 00000000000..99084a7e05d --- /dev/null +++ b/product_category_global_info/models/sale_order_line.py @@ -0,0 +1,44 @@ +from odoo import api, fields, models + + +class SaleOrderLine(models.Model): + _inherit = 'sale.order.line' + + product_category_id = fields.Many2one( + comodel_name='product.category', + string="Product Category", + compute="_compute_product_category", + store=True + ) + + attribute_ids = fields.Many2many( + comodel_name='product.attribute', + string="Attributes" + ) + + attribute_value_ids = fields.Many2many( + comodel_name='product.attribute.value', + string="Attribute Value" + ) + + @api.depends('product_id') + def _compute_product_category(self): + for line in self: + if line.product_id and line.product_id.categ_id.show_on_global_info: + line.product_category_id = line.product_id.categ_id + else: + line.product_category_id = False + + @api.onchange('product_category_id') + def _onchange_product_category(self): + if self.product_category_id: + required_attributes = self.product_category_id.required_attribute_ids + default_attribute_values = [] + default_attributes = [] + + for attribute in required_attributes: + selected_value = self.product_template_attribute_value_ids.filtered(lambda v: v.attribute_id == attribute) + default_attributes.append(attribute.id) + default_attribute_values.append(selected_value.product_attribute_value_id.id) + self.attribute_ids = [(6, 0, default_attributes)] + self.attribute_value_ids = [(6, 0, default_attribute_values)] diff --git a/product_category_global_info/views/product_category_global_info.xml b/product_category_global_info/views/product_category_global_info.xml new file mode 100644 index 00000000000..8e5c0270b32 --- /dev/null +++ b/product_category_global_info/views/product_category_global_info.xml @@ -0,0 +1,13 @@ + + + product.category.form.inherit + product.category + + + + + + + + + diff --git a/product_category_global_info/views/sale_order_view_inherit.xml b/product_category_global_info/views/sale_order_view_inherit.xml new file mode 100644 index 00000000000..b24949ad182 --- /dev/null +++ b/product_category_global_info/views/sale_order_view_inherit.xml @@ -0,0 +1,46 @@ + + + + sale.order.line.list.global.info + sale.order.line + + + + + + + + + + + sale.order.global.info.form + sale.order + + + + + + + + + + + + sale.order.global.info.search + sale.order.line + + + + + + + + Global Info + sale.order.line + + + list + {'search_default_group_by_product_category': 1} + + +