From 7da2649157c9b824f14fdc36cf8ea7925af9f2ef Mon Sep 17 00:00:00 2001 From: alap-odoo Date: Wed, 2 Jul 2025 17:50:29 +0530 Subject: [PATCH] [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. --- pos_second_uom/__init__.py | 1 + pos_second_uom/__manifest__.py | 15 ++++++++ pos_second_uom/models/__init__.py | 1 + pos_second_uom/models/product_template.py | 16 +++++++++ .../add_quantity_button.js | 17 +++++++++ .../add_quantity_button.xml | 8 +++++ .../add_quantity_dialog.js | 36 +++++++++++++++++++ .../add_quantity_dialog.xml | 17 +++++++++ .../src/control_buttons/control_buttons.js | 13 +++++++ .../src/control_buttons/control_buttons.xml | 8 +++++ pos_second_uom/views/product_view.xml | 14 ++++++++ 11 files changed, 146 insertions(+) create mode 100644 pos_second_uom/__init__.py create mode 100644 pos_second_uom/__manifest__.py create mode 100644 pos_second_uom/models/__init__.py create mode 100644 pos_second_uom/models/product_template.py create mode 100644 pos_second_uom/static/src/add_quantity_button/add_quantity_button.js create mode 100644 pos_second_uom/static/src/add_quantity_button/add_quantity_button.xml create mode 100644 pos_second_uom/static/src/add_quantity_dialog/add_quantity_dialog.js create mode 100644 pos_second_uom/static/src/add_quantity_dialog/add_quantity_dialog.xml create mode 100644 pos_second_uom/static/src/control_buttons/control_buttons.js create mode 100644 pos_second_uom/static/src/control_buttons/control_buttons.xml create mode 100644 pos_second_uom/views/product_view.xml diff --git a/pos_second_uom/__init__.py b/pos_second_uom/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/pos_second_uom/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/pos_second_uom/__manifest__.py b/pos_second_uom/__manifest__.py new file mode 100644 index 00000000000..7c331cdf626 --- /dev/null +++ b/pos_second_uom/__manifest__.py @@ -0,0 +1,15 @@ +{ + "name": "POS second UOM", + "version": "1.0", + "depends": ["base", "point_of_sale", "web"], + "category": "Sales/Point of Sale", + "data": ["views/product_view.xml"], + "assets": { + "point_of_sale._assets_pos": [ + "pos_second_uom/static/src/**/", + ], + }, + "sequence": 1, + "application": True, + "license": "OEEL-1", +} diff --git a/pos_second_uom/models/__init__.py b/pos_second_uom/models/__init__.py new file mode 100644 index 00000000000..e8fa8f6bf1e --- /dev/null +++ b/pos_second_uom/models/__init__.py @@ -0,0 +1 @@ +from . import product_template diff --git a/pos_second_uom/models/product_template.py b/pos_second_uom/models/product_template.py new file mode 100644 index 00000000000..7c177c69e69 --- /dev/null +++ b/pos_second_uom/models/product_template.py @@ -0,0 +1,16 @@ +from odoo import fields, models + + +class ProductTemplate(models.Model): + _inherit = "product.template" + + uom_category_id = fields.Many2one( + related="uom_id.category_id", string="UOM Category", readonly=True, store=True + ) + + pos_second_uom_id = fields.Many2one( + comodel_name="uom.uom", + string="POS second UOM", + domain="[('category_id', '=', uom_category_id)]", + store=True, + ) diff --git a/pos_second_uom/static/src/add_quantity_button/add_quantity_button.js b/pos_second_uom/static/src/add_quantity_button/add_quantity_button.js new file mode 100644 index 00000000000..b407909dbaf --- /dev/null +++ b/pos_second_uom/static/src/add_quantity_button/add_quantity_button.js @@ -0,0 +1,17 @@ +import { Component } from "@odoo/owl" +import { useService } from "@web/core/utils/hooks"; +import { AddQuantityDialog } from "../add_quantity_dialog/add_quantity_dialog"; + + +export class AddQuantityButton extends Component { + static template = "pos_second_uom.AddQuantityButton" + + setup() { + super.setup(); + this.dialogService = useService("dialog"); + } + + onClick() { + this.dialogService.add(AddQuantityDialog) + } +} diff --git a/pos_second_uom/static/src/add_quantity_button/add_quantity_button.xml b/pos_second_uom/static/src/add_quantity_button/add_quantity_button.xml new file mode 100644 index 00000000000..99063384517 --- /dev/null +++ b/pos_second_uom/static/src/add_quantity_button/add_quantity_button.xml @@ -0,0 +1,8 @@ + + + + + + diff --git a/pos_second_uom/static/src/add_quantity_dialog/add_quantity_dialog.js b/pos_second_uom/static/src/add_quantity_dialog/add_quantity_dialog.js new file mode 100644 index 00000000000..981c71bbc7d --- /dev/null +++ b/pos_second_uom/static/src/add_quantity_dialog/add_quantity_dialog.js @@ -0,0 +1,36 @@ +/** @odoo-module **/ + +import { Component, useRef } from "@odoo/owl"; +import { Dialog } from "@web/core/dialog/dialog"; +import { usePos } from "@point_of_sale/app/store/pos_hook"; + +export class AddQuantityDialog extends Component { + static template = "pos_second_uom.AddQuantityDialog"; + + static components = { Dialog }; + + static props = { + close: { type: Function } + }; + + setup() { + this.pos = usePos() + this.quantityInputRef = useRef("quantityInput"); + } + + confirm() { + const quantity = this.quantityInputRef.el.value; + const order = this.pos.get_order(); + const selectedOrderline = order.get_selected_orderline(); + const product = selectedOrderline.get_product(); + const originalUOM = product.uom_id.category_id.uom_ids[0]; + const secondUOM = product.uom_id.category_id.uom_ids[1]; + const convertedQuantity = quantity * (secondUOM.factor_inv / originalUOM.factor); + selectedOrderline.set_quantity(convertedQuantity); + this.props.close(); + } + + cancel() { + this.props.close(); + } +} diff --git a/pos_second_uom/static/src/add_quantity_dialog/add_quantity_dialog.xml b/pos_second_uom/static/src/add_quantity_dialog/add_quantity_dialog.xml new file mode 100644 index 00000000000..34559a77f66 --- /dev/null +++ b/pos_second_uom/static/src/add_quantity_dialog/add_quantity_dialog.xml @@ -0,0 +1,17 @@ + + + + +
+
+ + +
+
+ + + + +
+
+
diff --git a/pos_second_uom/static/src/control_buttons/control_buttons.js b/pos_second_uom/static/src/control_buttons/control_buttons.js new file mode 100644 index 00000000000..13bb9b98436 --- /dev/null +++ b/pos_second_uom/static/src/control_buttons/control_buttons.js @@ -0,0 +1,13 @@ +import { patch } from "@web/core/utils/patch"; +import { ControlButtons } from "@point_of_sale/app/screens/product_screen/control_buttons/control_buttons"; +import { AddQuantityButton } from "../add_quantity_button/add_quantity_button"; + +patch(ControlButtons, { + setup() { + super.setup(); + }, + components: { + ...ControlButtons.components, + AddQuantityButton, + }, +}); diff --git a/pos_second_uom/static/src/control_buttons/control_buttons.xml b/pos_second_uom/static/src/control_buttons/control_buttons.xml new file mode 100644 index 00000000000..dbfb1e32d92 --- /dev/null +++ b/pos_second_uom/static/src/control_buttons/control_buttons.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/pos_second_uom/views/product_view.xml b/pos_second_uom/views/product_view.xml new file mode 100644 index 00000000000..404d11e5c4c --- /dev/null +++ b/pos_second_uom/views/product_view.xml @@ -0,0 +1,14 @@ + + + + product.template.form.inherit + product.template + + + + + + + + +