Browse Source

[UPDT] Jul 9: Updted 'product_multi_uom'

18.0
AjmalCybro 5 days ago
parent
commit
7e65e05b65
  1. 3
      product_multi_uom/__manifest__.py
  2. 5
      product_multi_uom/doc/RELEASE_NOTES.md
  3. 1
      product_multi_uom/models/__init__.py
  4. 13
      product_multi_uom/models/product_product.py
  5. 62
      product_multi_uom/models/product_template.py
  6. 18
      product_multi_uom/models/sale_order_line.py
  7. 4
      product_multi_uom/models/secondary_uom_line.py
  8. 23
      product_multi_uom/views/product_template_views.xml

3
product_multi_uom/__manifest__.py

@ -21,7 +21,7 @@
#############################################################################
{
'name': "Product Multi UoM",
'version': '18.0.1.0.1',
'version': '18.0.1.1.2',
'category': 'Sales',
'summary': 'This module help to sell a product with multiple Uom category',
'description': "This versatile module empowers your sales strategy by "
@ -38,6 +38,7 @@
'data': [
'security/ir.model.access.csv',
'views/product_product_views.xml',
'views/product_template_views.xml',
'views/sale_order_line_views.xml',
],
'images': ['static/description/banner.png'],

5
product_multi_uom/doc/RELEASE_NOTES.md

@ -10,3 +10,8 @@
##### Update
- Updated the field position in the product_product model and the _onchange_secondary_uom_id function in the
secondary_uom_line model. Also updated the index images.
#### 08.07.2025
#### Version 18.0.1.1.2
##### Update
- Updated the module, add the feature for product model and variant model to ensure smooth functioning for products without any variants, updated view and updated the function.

1
product_multi_uom/models/__init__.py

@ -22,3 +22,4 @@
from . import product_product
from . import sale_order_line
from . import secondary_uom_line
from . import product_template

13
product_multi_uom/models/product_product.py

@ -34,13 +34,14 @@ class ProductProduct(models.Model):
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:
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,11 @@ class ProductProduct(models.Model):
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:
rec._onchange_is_need_secondary_uom()
return res

62
product_multi_uom/models/product_template.py

@ -0,0 +1,62 @@
# -*- coding: utf-8 -*-
#############################################################################
#
# Cybrosys Technologies Pvt. Ltd.
#
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>)
# Author: Ammu Raj (<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 ProductTemplate(models.Model):
"""Inherits the 'product.template' for adding the secondary uom"""
_inherit = "product.template"
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_template_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 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

18
product_multi_uom/models/sale_order_line.py

@ -45,21 +45,31 @@ class SaleOrderLine(models.Model):
" secondary and if yes then "
"make the field readonly")
@api.onchange('product_template_id', 'product_id')
def _onchange_is_secondary_readonly(self):
""" Function to assign value to field is_secondary_readonly """
self.is_secondary_readonly = self.product_id.is_need_secondary_uom or self.product_template_id.is_need_secondary_uom
@api.onchange('secondary_product_uom_id', 'secondary_product_uom_qty')
def _onchange_secondary_product_uom_id(self):
"""Function that update the product_uom_qty as the value in the
secondary uom quantity"""
all_uom = []
if self.product_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_id.id)]).mapped(
primary_uom_ratio = self.env['secondary.uom.line'].search(domain).mapped(
'secondary_uom_ratio')
converted_uom_qty = primary_uom_ratio[
0] * self.secondary_product_uom_qty

4
product_multi_uom/models/secondary_uom_line.py

@ -37,6 +37,9 @@ class SecondaryUomLine(models.Model):
product_id = fields.Many2one('product.product', 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.")
@ -61,3 +64,4 @@ class SecondaryUomLine(models.Model):
raise ValidationError(
_('This Unit of Measure is already exist in the secondary'
'uom list. Please select another uom for secondary uom'))

23
product_multi_uom/views/product_template_views.xml

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<!-- Added the fields in the product template form -->
<record id="product_template_only_form_view" model="ir.ui.view">
<field name="name">product.template.form.inherit.tooltip</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_only_form_view"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='product_tooltip']" position="after">
<field name="is_need_secondary_uom" groups="uom.group_uom"/>
<field name="secondary_uom_ids"
invisible="is_need_secondary_uom == False"
groups="uom.group_uom" force_save="1">
<list name="Secondary">
<field name="secondary_uom_id"/>
<field name="secondary_uom_ratio" column_invisible="1"/>
<field name="example_ratio" force_save="1"/>
</list>
</field>
</xpath>
</field>
</record>
</odoo>
Loading…
Cancel
Save