diff --git a/product_multi_uom/__manifest__.py b/product_multi_uom/__manifest__.py index 285006ec7..8639c19ef 100644 --- a/product_multi_uom/__manifest__.py +++ b/product_multi_uom/__manifest__.py @@ -21,7 +21,7 @@ ############################################################################# { 'name': "Product Multi UoM", - 'version': '16.0.1.0.0', + 'version': '16.0.1.1.1', 'category': 'Sales', 'summary': 'This module help to sell a product with multiple Uom category', 'description': "This versatile module empowers your sales strategy by " @@ -40,6 +40,7 @@ 'views/product_template_views.xml', 'views/sale_order_line_views.xml', 'views/secondary_uom_line_views.xml', + 'views/product_product_views.xml', ], 'images': ['static/description/banner.png'], 'license': 'AGPL-3', diff --git a/product_multi_uom/doc/RELEASE_NOTES.md b/product_multi_uom/doc/RELEASE_NOTES.md index 784846f5c..09575dd18 100644 --- a/product_multi_uom/doc/RELEASE_NOTES.md +++ b/product_multi_uom/doc/RELEASE_NOTES.md @@ -4,3 +4,8 @@ #### Version 16.0.1.0.0 #### ADD - Initial Commit for Product Multi UoM + +#### 09.07.2025 +#### Version 16.0.1.1.1 +#### UPDT +- Added the feature for product model and variant model to ensure smooth functioning for products without any variants, updated view and updated the function. diff --git a/product_multi_uom/models/product_product.py b/product_multi_uom/models/product_product.py new file mode 100644 index 000000000..a76546b1f --- /dev/null +++ b/product_multi_uom/models/product_product.py @@ -0,0 +1,63 @@ +# -*- coding: utf-8 -*- +############################################################################# +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2024-TODAY Cybrosys Technologies() +# Author: Saneen K () +# +# You can modify it under the terms of the GNU AFFERO +# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. +# +# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE +# (AGPL v3) along with this program. +# If not, see . +# +############################################################################# +from odoo import api, fields, models + + +class ProductProduct(models.Model): + """Inherits the 'product.template' for adding the secondary uom""" + _inherit = "product.product" + + is_need_secondary_uom = fields.Boolean(string="Need Secondary UoM's", + help="Enable this field for " + "using the secondary uom") + secondary_uom_ids = fields.One2many('secondary.uom.line', 'product_id', + string="Secondary UoM's", + help='Select the secondary UoM and ' + 'their ratio', store=True) + + @api.onchange('is_need_secondary_uom', 'uom_id') + def _onchange_is_need_secondary_uom(self): + """Function that write the default Uom and their ratio to the + secondary uom""" + base_uom = self.env['uom.uom'].sudo().search( + [('category_id', '=', self.uom_id.category_id.id)]) + if not self.secondary_uom_ids or self.uom_id.id not in self.secondary_uom_ids.mapped('secondary_uom_id').ids: + self.secondary_uom_ids = [fields.Command.clear()] + for uom in base_uom: + self.write({ + 'secondary_uom_ids': [(0, 0, { + 'secondary_uom_id': uom.id, + 'secondary_uom_ratio': float(uom.factor_inv), + 'example_ratio': f" 1 {uom.name} = {uom.factor_inv}" + f" {self.uom_id.name}", + })] + }) + + @api.model_create_multi + def create(self, vals_list): + """ Assign the default value to the secondary uom's """ + res = super().create(vals_list) + for rec in res: + if rec.product_tmpl_id.is_need_secondary_uom: + rec.is_need_secondary_uom = True + rec._onchange_is_need_secondary_uom() + return res diff --git a/product_multi_uom/models/product_template.py b/product_multi_uom/models/product_template.py index c9e57e486..cae99a47c 100644 --- a/product_multi_uom/models/product_template.py +++ b/product_multi_uom/models/product_template.py @@ -29,18 +29,19 @@ class ProductTemplate(models.Model): is_need_secondary_uom = fields.Boolean(string="Need Secondary UoM's", help="Enable this field for " "using the secondary uom") - secondary_uom_ids = fields.One2many('secondary.uom.line', 'product_id', + secondary_uom_ids = fields.One2many('secondary.uom.line', 'product_template_id', string="Secondary UoM's", help='Select the secondary UoM and ' 'their ratio', store=True) - @api.onchange('is_need_secondary_uom') + @api.onchange('is_need_secondary_uom', 'uom_id') def _onchange_is_need_secondary_uom(self): """Function that write the default Uom and their ratio to the secondary uom""" base_uom = self.env['uom.uom'].sudo().search( - [('category_id', '=', self.uom_id.category_id.id)]) - if not self.secondary_uom_ids: + [('category_id', '=', self.uom_id.category_id.id)]) + if not self.secondary_uom_ids or self.uom_id.id not in self.secondary_uom_ids.mapped('secondary_uom_id').ids: + self.secondary_uom_ids = [fields.Command.clear()] for uom in base_uom: self.write({ 'secondary_uom_ids': [(0, 0, { @@ -50,3 +51,12 @@ class ProductTemplate(models.Model): f" {self.uom_id.name}", })] }) + + @api.model_create_multi + def create(self, vals_list): + """Assign default value to the product variants""" + res = super().create(vals_list) + for product in res: + if product.is_need_secondary_uom: + product.product_variant_ids.is_need_secondary_uom = True + return res diff --git a/product_multi_uom/models/sale_order_line.py b/product_multi_uom/models/sale_order_line.py index 350d279ac..0f1bb41f3 100644 --- a/product_multi_uom/models/sale_order_line.py +++ b/product_multi_uom/models/sale_order_line.py @@ -19,7 +19,7 @@ # If not, see . # ############################################################################# -from odoo import api, fields, models, _ +from odoo import api, fields, models class SaleOrderLine(models.Model): @@ -50,24 +50,32 @@ class SaleOrderLine(models.Model): """Function that update the product_uom_qty as the value in the secondary uom quantity""" all_uom = [] - if self.product_template_id.is_need_secondary_uom: + domain = [('secondary_uom_id', '=', self.secondary_product_uom_id.id)] + if self.product_template_id.attribute_line_ids and self.product_id.is_need_secondary_uom: self.is_secondary_readonly = True + domain.append(('product_id', '=', self.product_id.id)) + for uom in self.product_id.secondary_uom_ids: + all_uom.append(uom.secondary_uom_id.id) + elif self.product_template_id.is_need_secondary_uom: + self.is_secondary_readonly = True + domain.append(('product_template_id', '=', self.product_template_id.id)) for uom in self.product_template_id.secondary_uom_ids: all_uom.append(uom.secondary_uom_id.id) if self.is_secondary_readonly: self.product_uom_readonly = True if self.secondary_product_uom_id.id in all_uom: - primary_uom_ratio = self.env['secondary.uom.line'].search( - [('secondary_uom_id', '=', self.secondary_product_uom_id.id), - ('product_id', '=', self.product_template_id.id)]).mapped( + primary_uom_ratio = self.env['secondary.uom.line'].search(domain).mapped( 'secondary_uom_ratio') + print(self.env['secondary.uom.line'].search([]).read()) + print(domain, self.env['secondary.uom.line'].search([])) + print(primary_uom_ratio) converted_uom_qty = primary_uom_ratio[ 0] * self.secondary_product_uom_qty self.product_uom_qty = converted_uom_qty @api.depends('product_id') def _compute_secondary_product_uom(self): - """Compute the default secondary uom""" + """Compute the s secondary uom""" for rec in self: if (not rec.product_uom or rec.product_id.uom_id.id != rec.secondary_product_uom_id.id): diff --git a/product_multi_uom/models/secondary_uom_line.py b/product_multi_uom/models/secondary_uom_line.py index 270f5b4c1..b9e1abb55 100644 --- a/product_multi_uom/models/secondary_uom_line.py +++ b/product_multi_uom/models/secondary_uom_line.py @@ -37,6 +37,9 @@ class SecondaryUomLine(models.Model): product_id = fields.Many2one('product.template', readonly=True, string="Product", help="Product having the Secondary UOM") + product_template_id = fields.Many2one('product.template', readonly=True, + string="Product", + help="Product having the Secondary UOM") secondary_uom_ratio = fields.Float(string='Secondary UoM Ratio', help="Choose the ratio with the base" " Unit of Measure.") diff --git a/product_multi_uom/views/product_product_views.xml b/product_multi_uom/views/product_product_views.xml new file mode 100644 index 000000000..4a897a00c --- /dev/null +++ b/product_multi_uom/views/product_product_views.xml @@ -0,0 +1,21 @@ + + + + + product.product.view.form.inherit.product.multi.uom + product.product + + + + + + + + + + + + + + +