Skip to content

Commit 7da2649

Browse files
committed
[ADD] pos_second_uom: create custom module for adding second UOM in product
added a field of second uom and added a quantity button in pos screen, which allows to enter the quantity in the second uom and automatically converts to Primary uom of product.
1 parent fbf9ee9 commit 7da2649

File tree

11 files changed

+146
-0
lines changed

11 files changed

+146
-0
lines changed

pos_second_uom/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import models

pos_second_uom/__manifest__.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "POS second UOM",
3+
"version": "1.0",
4+
"depends": ["base", "point_of_sale", "web"],
5+
"category": "Sales/Point of Sale",
6+
"data": ["views/product_view.xml"],
7+
"assets": {
8+
"point_of_sale._assets_pos": [
9+
"pos_second_uom/static/src/**/",
10+
],
11+
},
12+
"sequence": 1,
13+
"application": True,
14+
"license": "OEEL-1",
15+
}

pos_second_uom/models/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import product_template
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from odoo import fields, models
2+
3+
4+
class ProductTemplate(models.Model):
5+
_inherit = "product.template"
6+
7+
uom_category_id = fields.Many2one(
8+
related="uom_id.category_id", string="UOM Category", readonly=True, store=True
9+
)
10+
11+
pos_second_uom_id = fields.Many2one(
12+
comodel_name="uom.uom",
13+
string="POS second UOM",
14+
domain="[('category_id', '=', uom_category_id)]",
15+
store=True,
16+
)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { Component } from "@odoo/owl"
2+
import { useService } from "@web/core/utils/hooks";
3+
import { AddQuantityDialog } from "../add_quantity_dialog/add_quantity_dialog";
4+
5+
6+
export class AddQuantityButton extends Component {
7+
static template = "pos_second_uom.AddQuantityButton"
8+
9+
setup() {
10+
super.setup();
11+
this.dialogService = useService("dialog");
12+
}
13+
14+
onClick() {
15+
this.dialogService.add(AddQuantityDialog)
16+
}
17+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<templates id="pos_add_quantity_button" xml:space="preserve">
3+
<t t-name="pos_second_uom.AddQuantityButton">
4+
<button class="set-partner btn btn-light btn-lg lh-lg text-truncate w-auto" t-on-click="onClick">
5+
Add Quantity
6+
</button>
7+
</t>
8+
</templates>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/** @odoo-module **/
2+
3+
import { Component, useRef } from "@odoo/owl";
4+
import { Dialog } from "@web/core/dialog/dialog";
5+
import { usePos } from "@point_of_sale/app/store/pos_hook";
6+
7+
export class AddQuantityDialog extends Component {
8+
static template = "pos_second_uom.AddQuantityDialog";
9+
10+
static components = { Dialog };
11+
12+
static props = {
13+
close: { type: Function }
14+
};
15+
16+
setup() {
17+
this.pos = usePos()
18+
this.quantityInputRef = useRef("quantityInput");
19+
}
20+
21+
confirm() {
22+
const quantity = this.quantityInputRef.el.value;
23+
const order = this.pos.get_order();
24+
const selectedOrderline = order.get_selected_orderline();
25+
const product = selectedOrderline.get_product();
26+
const originalUOM = product.uom_id.category_id.uom_ids[0];
27+
const secondUOM = product.uom_id.category_id.uom_ids[1];
28+
const convertedQuantity = quantity * (secondUOM.factor_inv / originalUOM.factor);
29+
selectedOrderline.set_quantity(convertedQuantity);
30+
this.props.close();
31+
}
32+
33+
cancel() {
34+
this.props.close();
35+
}
36+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<templates id="pos_add_quantity_dialog" xml:space="preserve">
3+
<t t-name="pos_second_uom.AddQuantityDialog">
4+
<Dialog title="'Add Quantity'" size="'md'">
5+
<main class="modal-body p-4">
6+
<div>
7+
<label for="quantityInput" class="form-label mb-2">Quantity:</label>
8+
<input type="number" id="quantityInput" class="form-control" value="1" min="1" t-ref="quantityInput"/>
9+
</div>
10+
</main>
11+
<t t-set-slot="footer">
12+
<button type="button" class="btn btn-secondary me-2" t-on-click="cancel">Cancel</button>
13+
<button type="button" class="btn btn-primary" t-on-click="confirm">Confirm</button>
14+
</t>
15+
</Dialog>
16+
</t>
17+
</templates>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { patch } from "@web/core/utils/patch";
2+
import { ControlButtons } from "@point_of_sale/app/screens/product_screen/control_buttons/control_buttons";
3+
import { AddQuantityButton } from "../add_quantity_button/add_quantity_button";
4+
5+
patch(ControlButtons, {
6+
setup() {
7+
super.setup();
8+
},
9+
components: {
10+
...ControlButtons.components,
11+
AddQuantityButton,
12+
},
13+
});
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<templates id="pos_add_quantity_button" xml:space="preserve">
3+
<t t-name="pos_second_uom.AddQuantityButton" t-inherit="point_of_sale.ControlButtons" t-inherit-mode="extension">
4+
<xpath expr="//button[hasclass('flex-shrink-0')]" position="before">
5+
<AddQuantityButton/>
6+
</xpath>
7+
</t>
8+
</templates>

0 commit comments

Comments
 (0)