diff --git a/product_multi_uom_pos/__manifest__.py b/product_multi_uom_pos/__manifest__.py index 0ddc252ba..9eea08cd0 100644 --- a/product_multi_uom_pos/__manifest__.py +++ b/product_multi_uom_pos/__manifest__.py @@ -21,7 +21,7 @@ ############################################################################# { 'name': "POS Product Multiple UOM", - 'version': '17.0.1.0.4', + 'version': '17.0.1.0.5', 'category': 'Point of Sale', 'summary': """A module to manage multiple UoM in POS""", 'description': """Using this app, you can change unit of measure of @@ -32,7 +32,9 @@ 'website': "https://www.cybrosys.com", 'depends': ['point_of_sale', 'uom'], 'data': - [ 'data/uom_data.xml', + [ + 'security/ir.model.access.csv', + 'data/uom_data.xml', 'views/res_config_settings_views.xml', 'views/product_template_views.xml', 'views/pos_order_views.xml', diff --git a/product_multi_uom_pos/doc/RELEASE_NOTES.md b/product_multi_uom_pos/doc/RELEASE_NOTES.md index 2d5d39a34..d50e12ad7 100644 --- a/product_multi_uom_pos/doc/RELEASE_NOTES.md +++ b/product_multi_uom_pos/doc/RELEASE_NOTES.md @@ -36,4 +36,10 @@ #### 13.01.2025 #### Version 17.0.1.0.4 ##### BUG FIX -- Solved the issue sale details report \ No newline at end of file +- Solved the issue sale details report + +#### 27.05.2025 +#### Version 17.0.1.0.5 +##### UPDT +- Bug Fix - 1) Changed the work flow + 2) Changed the many-to-many field in to one-to-many for adding uom and its price. diff --git a/product_multi_uom_pos/models/__init__.py b/product_multi_uom_pos/models/__init__.py index 5ab7460a8..5dcd36716 100644 --- a/product_multi_uom_pos/models/__init__.py +++ b/product_multi_uom_pos/models/__init__.py @@ -26,3 +26,4 @@ from . import stock_picking from . import pos_config from . import report_sale_details from . import res_config_settings +from . import pos_multi_uom diff --git a/product_multi_uom_pos/models/pos_multi_uom.py b/product_multi_uom_pos/models/pos_multi_uom.py new file mode 100644 index 000000000..070ceed7c --- /dev/null +++ b/product_multi_uom_pos/models/pos_multi_uom.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +############################################################################# +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2024-TODAY Cybrosys Technologies(). +# Author: Cybrosys Techno Solutions() +# +# 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 fields, models + + +class PosMultiUom(models.Model): + """ + Model for managing Point of Sale (POS) Multi Unit of Measure (UoM). + This model represents the association between a product template and its + multiple unit of measure options for the Point of Sale module. + """ + _name = 'pos.multi.uom' + _description = 'POS Multi UoM' + + product_template_id = fields.Many2one('product.template', + string='Product Template', + help='Inverse field of one2many' + 'field POS Multiple UoM in' + 'product.template') + category_id = fields.Many2one( + related='product_template_id.uom_id.category_id', + string='UoM Category', help='Category of unit of measure') + uom_id = fields.Many2one('uom.uom', string='Unit Of Measure', + domain="[('category_id', '=', category_id)]", + help="Choose a UoM") + price = fields.Float(string='Sale Price', help="Set a price for selected " + "UoM") diff --git a/product_multi_uom_pos/models/pos_session.py b/product_multi_uom_pos/models/pos_session.py index 9c2023af2..809a3e059 100644 --- a/product_multi_uom_pos/models/pos_session.py +++ b/product_multi_uom_pos/models/pos_session.py @@ -31,3 +31,20 @@ class PosSession(models.Model): result = super()._loader_params_product_product() result['search_params']['fields'].append('pos_multi_uom_ids') return result + + def _pos_ui_models_to_load(self): + """Loading model 'pos.multi.uom' to POS""" + result = super()._pos_ui_models_to_load() + result.append('pos.multi.uom') + return result + + def _loader_params_pos_multi_uom(self): + """Loading fields of model 'pos.multi.uom' to POS""" + return { + 'search_params': { + 'fields': ['uom_id', 'price', 'product_template_id']} + } + + def _get_pos_ui_pos_multi_uom(self, params): + """Loading new model to POS""" + return self.env['pos.multi.uom'].search_read(**params['search_params']) diff --git a/product_multi_uom_pos/models/product_template.py b/product_multi_uom_pos/models/product_template.py index 7c04ad276..9ef81a5f3 100644 --- a/product_multi_uom_pos/models/product_template.py +++ b/product_multi_uom_pos/models/product_template.py @@ -27,9 +27,23 @@ class ProductTemplate(models.Model): of measure""" _inherit = 'product.template' - product_uom_category_id = fields.Many2one(related='uom_id.category_id') - pos_multi_uom_ids = fields.Many2many('uom.uom', 'product_template_id', + multi_uom = fields.Boolean(compute='_compute_multi_uom', string='Multi UoM', + help='A boolean field to show the one2many field' + 'POS Multiple UoM if the Multi UoM option' + ' is enabled in Configuration settings') + pos_multi_uom_ids = fields.One2many('pos.multi.uom', 'product_template_id', string="POS Multiple UoM", - domain="[('category_id', '=', product_uom_category_id)]", help='These UoM can be selected from ' - 'PoS') \ No newline at end of file + 'PoS') + + def _compute_multi_uom(self): + """ + Updates the 'multi_uom' field based on the configuration parameter + 'product_multi_uom_pos.pos_multi_uom'. + """ + status = self.env['ir.config_parameter'].sudo().get_param( + 'product_multi_uom_pos.pos_multi_uom') + + self.write({ + 'multi_uom': status + }) \ No newline at end of file diff --git a/product_multi_uom_pos/security/ir.model.access.csv b/product_multi_uom_pos/security/ir.model.access.csv new file mode 100644 index 000000000..459fbb366 --- /dev/null +++ b/product_multi_uom_pos/security/ir.model.access.csv @@ -0,0 +1,2 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_pos_multi_uom,access.pos.multi.uom,model_pos_multi_uom,base.group_user,1,1,1,1 diff --git a/product_multi_uom_pos/static/description/assets/screenshots/2.png b/product_multi_uom_pos/static/description/assets/screenshots/2.png index ed312257a..09af405fe 100644 Binary files a/product_multi_uom_pos/static/description/assets/screenshots/2.png and b/product_multi_uom_pos/static/description/assets/screenshots/2.png differ diff --git a/product_multi_uom_pos/static/src/overrides/app/store/store.js b/product_multi_uom_pos/static/src/overrides/app/store/store.js new file mode 100644 index 000000000..4fcf01f88 --- /dev/null +++ b/product_multi_uom_pos/static/src/overrides/app/store/store.js @@ -0,0 +1,11 @@ +/** @odoo-module */ +import { PosStore } from "@point_of_sale/app/store/pos_store"; +import { patch } from "@web/core/utils/patch"; + +patch(PosStore.prototype, { + // @Override + async _processData(loadedData) { + await super._processData(...arguments); + this.pos_multi_uom = loadedData['pos.multi.uom']; + }, +}); diff --git a/product_multi_uom_pos/static/src/overrides/generic_components/orderline/orderline.xml b/product_multi_uom_pos/static/src/overrides/generic_components/orderline/orderline.xml index a86af494b..60b2ee485 100644 --- a/product_multi_uom_pos/static/src/overrides/generic_components/orderline/orderline.xml +++ b/product_multi_uom_pos/static/src/overrides/generic_components/orderline/orderline.xml @@ -5,31 +5,31 @@ t-inherit="point_of_sale.Orderline" t-inherit-mode="extension" owl="1"> - - - - - + + + diff --git a/product_multi_uom_pos/static/src/overrides/models/orderline.js b/product_multi_uom_pos/static/src/overrides/models/orderline.js index 4419cb017..e0eb62415 100644 --- a/product_multi_uom_pos/static/src/overrides/models/orderline.js +++ b/product_multi_uom_pos/static/src/overrides/models/orderline.js @@ -43,28 +43,28 @@ patch(Orderline.prototype, { return this.product.get_unit(); }, onSelectionChangedUom(ev) { - var uom_id = ev.target.value - var selected_uom = this.env.services.pos.units_by_id[uom_id] - if(this.props.slots['product-name']){ - var selected_product = this.props.slots['product-name'].__ctx.line - } - else{ - var selected_product= this.props.slots['default'].__ctx.line - } - selected_product.set_uom({0:selected_uom.id,1:selected_uom.name}) - selected_product.price_type = "manual"; - if (selected_uom.uom_type == "smaller"){ - selected_product.set_unit_price(selected_product.product.lst_price * (1 / selected_uom.ratio)); - } else { - selected_product.set_unit_price(selected_product.product.lst_price * selected_uom.ratio); - } - + var splitTargetValue = ev.target.value.split(',') + var price = splitTargetValue[0] + var uomId = splitTargetValue[1] + var uomName = splitTargetValue[2] + // Set the selected unit of measure on the order line + const currentOrder = this.env.services.pos.get_order(); + currentOrder.selected_orderline.set_uom({0:uomId,1:uomName}) + // Set the price_manually_set flag to indicate that the price was manually set + currentOrder.selected_orderline.price_manually_set = true; + // Set the unit price of selected UoM on the order line + currentOrder.selected_orderline.set_unit_price(price); }, getUom(self) { const currentOrder = self.env.services.pos.get_order(); const currentLine = currentOrder.orderlines.find((line) => line.full_product_name === self.props.line.productName) - const uom = currentLine.product.pos_multi_uom_ids - const filteredData = self.env.services.pos.pos_multi_uom.filter(obj => currentLine.product.pos_multi_uom_ids.includes(obj.id)); + var filteredData = {} + if(currentLine){ + const uom = currentLine.product.pos_multi_uom_ids + if(uom){ + filteredData = self.env.services.pos.pos_multi_uom.filter(obj => currentLine.product.pos_multi_uom_ids.includes(obj.id)); + } + } return filteredData; }, resetUom(){ @@ -79,7 +79,6 @@ patch(Orderline.prototype, { getUom: this.getUom, resetUom: this.resetUom, onSelectionChangedUom: this.onSelectionChangedUom, - multiUom: [...this.product.pos_multi_uom_ids], }; }, }); diff --git a/product_multi_uom_pos/views/product_template_views.xml b/product_multi_uom_pos/views/product_template_views.xml index 349ba6c23..6400a8234 100644 --- a/product_multi_uom_pos/views/product_template_views.xml +++ b/product_multi_uom_pos/views/product_template_views.xml @@ -9,8 +9,15 @@ product.template - - + + + + + + + +