Browse Source

July 09: [FIX] Bug Fixed 'product_multi_uom'

16.0
Cybrosys Technologies 3 days ago
parent
commit
9cacba339c
  1. 3
      product_multi_uom/__manifest__.py
  2. 5
      product_multi_uom/doc/RELEASE_NOTES.md
  3. 63
      product_multi_uom/models/product_product.py
  4. 18
      product_multi_uom/models/product_template.py
  5. 20
      product_multi_uom/models/sale_order_line.py
  6. 3
      product_multi_uom/models/secondary_uom_line.py
  7. 21
      product_multi_uom/views/product_product_views.xml

3
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',

5
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.

63
product_multi_uom/models/product_product.py

@ -0,0 +1,63 @@
# -*- coding: utf-8 -*-
#############################################################################
#
# Cybrosys Technologies Pvt. Ltd.
#
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>)
# Author: Saneen K (<https://www.cybrosys.com>)
#
# 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 <http://www.gnu.org/licenses/>.
#
#############################################################################
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

18
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

20
product_multi_uom/models/sale_order_line.py

@ -19,7 +19,7 @@
# If not, see <http://www.gnu.org/licenses/>.
#
#############################################################################
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):

3
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.")

21
product_multi_uom/views/product_product_views.xml

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<!--Inherits the product variant view for adding the field for selecting the secondary Uom-->
<record id="product_normal_form_view" model="ir.ui.view">
<field name="name">product.product.view.form.inherit.product.multi.uom</field>
<field name="model">product.product</field>
<field name="inherit_id" ref="product.product_normal_form_view"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='uom_po_id']" position="after">
<field name="is_need_secondary_uom" groups="uom.group_uom"/>
<field name="secondary_uom_ids" attrs="{'invisible': [('is_need_secondary_uom', '==', False)]}" groups="uom.group_uom" force_save="1">
<tree name="Secondary">
<field name="secondary_uom_id"/>
<field name="secondary_uom_ratio" column_invisible="1" />
<field name="example_ratio" force_save="1"/>
</tree>
</field>
</xpath>
</field>
</record>
</odoo>
Loading…
Cancel
Save