7 changed files with 122 additions and 11 deletions
@ -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 |
@ -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…
Reference in new issue