Browse Source

May 30: [FIX] Bug Fixed 'product_multi_uom_pos'

pull/313/merge
Cybrosys Technologies 2 months ago
parent
commit
4224a571d7
  1. 6
      product_multi_uom_pos/__manifest__.py
  2. 8
      product_multi_uom_pos/doc/RELEASE_NOTES.md
  3. 1
      product_multi_uom_pos/models/__init__.py
  4. 46
      product_multi_uom_pos/models/pos_multi_uom.py
  5. 17
      product_multi_uom_pos/models/pos_session.py
  6. 22
      product_multi_uom_pos/models/product_template.py
  7. 2
      product_multi_uom_pos/security/ir.model.access.csv
  8. BIN
      product_multi_uom_pos/static/description/assets/screenshots/2.png
  9. 11
      product_multi_uom_pos/static/src/overrides/app/store/store.js
  10. 50
      product_multi_uom_pos/static/src/overrides/generic_components/orderline/orderline.xml
  11. 37
      product_multi_uom_pos/static/src/overrides/models/orderline.js
  12. 11
      product_multi_uom_pos/views/product_template_views.xml

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

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

1
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

46
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(<https://www.cybrosys.com>).
# Author: Cybrosys Techno Solutions(<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 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")

17
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'])

22
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')
'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
})

2
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
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
2 access_pos_multi_uom access.pos.multi.uom model_pos_multi_uom base.group_user 1 1 1 1

BIN
product_multi_uom_pos/static/description/assets/screenshots/2.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 118 KiB

After

Width:  |  Height:  |  Size: 116 KiB

11
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'];
},
});

50
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">
<xpath expr="//ul[hasclass('info-list')]" position="after">
<t t-if="line.onSelectionChangedUom">
<t t-if="this.env.services.pos.config.pos_multi_uom and line.multiUom and line.multiUom.length > 0">
<button id="reset_uom" style="margin-top: 25px; background:transparent;border:transparent;
margin-bottom: 5px;margin-left: 180px;"
t-on-click="line.resetUom">
<i class="fa fa-rotate-left"/>
</button>
<select style="width:32%;height:25px;border-radius:5px;border:1px solid transparent;margin-top: -22px;
margin-bottom: 5px;margin-left: 10px; background: rgb(95 115 116 / 20%);"
id="select_uom" class="select_uom"
t-on-change="line.onSelectionChangedUom"
t-ref="uom_value">
<option value="change_uom" id="change_uom"
selected="selected"
disabled="disabled">Change UoM</option>
<t t-foreach="line.multiUom" t-as="item"
t-key="item">
<option id="select_uom"
class="select_uom"
t-att-value="item">
<div><span t-esc="this.env.services.pos.units_by_id[item].name"/></div>
</option>
</t>
</select>
</t>
<t t-if="line.onSelectionChangedUom and line.getUom(this).length != 0">
<button id="reset_uom" style="margin-top: 15px; background:transparent;border:transparent;
margin-bottom: 5px;margin-left: 180px;"
t-on-click="line.resetUom">
<i class="fa fa-rotate-left" style="transform: translateY(25%);"/>
</button>
<select style="width:32%;height:25px;border-radius:5px;border:1px solid transparent;margin-top: -22px;
margin-bottom: 5px;margin-left: 10px; background: rgb(95 115 116 / 20%);"
id="select_uom" class="select_uom"
t-on-change="line.onSelectionChangedUom"
t-ref="uom_value">
<option value="change_uom" id="change_uom"
selected="selected"
disabled="disabled">Change UoM</option>
<t t-foreach="line.getUom(this)" t-as="item"
t-key="item.id">
<option id="select_uom"
class="select_uom"
t-att-value="[item.price,item.uom_id[0],item.uom_id[1]]">
<div><span>$ <t
t-esc="item.price"/> per
<t t-esc="item.uom_id[1]"/></span></div>
</option>
</t>
</select>
</t>
</xpath>
</t>

37
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],
};
},
});

11
product_multi_uom_pos/views/product_template_views.xml

@ -9,8 +9,15 @@
<field name="model">product.template</field>
<field name="arch" type="xml">
<xpath expr="//field[@name='pos_categ_ids']" position="after">
<field name="pos_multi_uom_ids" widget="many2many_tags"/>
<field name="product_uom_category_id"/>
<field name="multi_uom" invisible="1"/>
<field name="pos_multi_uom_ids"
invisible="multi_uom == False">
<tree editable="bottom">
<field name="uom_id"/>
<field name="price"/>
<field name="category_id" invisible="1"/>
</tree>
</field>
</xpath>
</field>
</record>

Loading…
Cancel
Save