diff --git a/pos_sale_picking_keep/README.rst b/pos_sale_picking_keep/README.rst new file mode 100644 index 0000000000..e55418a5ac --- /dev/null +++ b/pos_sale_picking_keep/README.rst @@ -0,0 +1,114 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + +=========================== +Keep sale pickings from PoS +=========================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:14008524ac2e970ae97eda09273f81e2fc25b02a6ccf008e85f4473f3d637815 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fpos-lightgray.png?logo=github + :target: https://github.com/OCA/pos/tree/19.0/pos_sale_picking_keep + :alt: OCA/pos +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/pos-19-0/pos-19-0-pos_sale_picking_keep + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/pos&target_branch=19.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module inhibits the manipulation that the point of sale mades over +the sales orders pickings, and the creation of new pickings under the +PoS picking type. + +When settling a sale order in the PoS, the ordered quantities are loaded +even if the products were already delivered through the sale order +pickings, deducting only the quantities already invoiced. Without this +module, the PoS deducts the delivered quantities, which makes no sense +here, as the PoS is only used to charge the order, not to deliver it. + +**Table of contents** + +.. contents:: + :local: + +Use Cases / Context +=================== + +In some scenarios, you may not want that the point of sale (PoS) handles +the pickings of the products you are paying: + +- Using the PoS as a pure payment terminal. +- When complex stock flows are not supplied by the PoS. + +In that cases, it's better to keep the original sales pickings. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* Tecnativa + +Contributors +------------ + +- Tecnativa: + + - Pedro M. Baeza + - Víctor Martínez + +- Jarsa: + + - Jesús Alan Ramos Rodríguez + +Maintainers +----------- + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +.. |maintainer-pedrobaeza| image:: https://github.com/pedrobaeza.png?size=40px + :target: https://github.com/pedrobaeza + :alt: pedrobaeza + +Current `maintainer `__: + +|maintainer-pedrobaeza| + +This module is part of the `OCA/pos `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/pos_sale_picking_keep/__init__.py b/pos_sale_picking_keep/__init__.py new file mode 100644 index 0000000000..3275ac2adf --- /dev/null +++ b/pos_sale_picking_keep/__init__.py @@ -0,0 +1,2 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from . import models diff --git a/pos_sale_picking_keep/__manifest__.py b/pos_sale_picking_keep/__manifest__.py new file mode 100644 index 0000000000..3242026604 --- /dev/null +++ b/pos_sale_picking_keep/__manifest__.py @@ -0,0 +1,21 @@ +# Copyright 2025 Tecnativa - Pedro M. Baeza +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "Keep sale pickings from PoS", + "version": "19.0.1.1.0", + "category": "Point Of Sale", + "website": "https://github.com/OCA/pos", + "author": "Tecnativa, Odoo Community Association (OCA)", + "maintainers": ["pedrobaeza"], + "license": "AGPL-3", + "installable": True, + "depends": ["pos_sale", "sale_stock"], + "assets": { + "point_of_sale._assets_pos": [ + "pos_sale_picking_keep/static/src/js/**/*", + ], + "web.assets_tests": [ + "pos_sale_picking_keep/static/tests/tours/**/*", + ], + }, +} diff --git a/pos_sale_picking_keep/i18n/it.po b/pos_sale_picking_keep/i18n/it.po new file mode 100644 index 0000000000..9bed391550 --- /dev/null +++ b/pos_sale_picking_keep/i18n/it.po @@ -0,0 +1,32 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * pos_sale_picking_keep +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 19.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2026-03-13 16:45+0000\n" +"Last-Translator: mymage \n" +"Language-Team: none\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 5.15.2\n" + +#. module: pos_sale_picking_keep +#: model:ir.model,name:pos_sale_picking_keep.model_pos_order +msgid "Point of Sale Orders" +msgstr "Ordini punto vendita" + +#. module: pos_sale_picking_keep +#: model:ir.model,name:pos_sale_picking_keep.model_pos_session +msgid "Point of Sale Session" +msgstr "Sessione punto vendita" + +#. module: pos_sale_picking_keep +#: model:ir.model,name:pos_sale_picking_keep.model_sale_order_line +msgid "Sales Order Line" +msgstr "Riga ordine di vendita" diff --git a/pos_sale_picking_keep/i18n/pos_sale_picking_keep.pot b/pos_sale_picking_keep/i18n/pos_sale_picking_keep.pot new file mode 100644 index 0000000000..b14f7eb313 --- /dev/null +++ b/pos_sale_picking_keep/i18n/pos_sale_picking_keep.pot @@ -0,0 +1,29 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * pos_sale_picking_keep +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 19.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: pos_sale_picking_keep +#: model:ir.model,name:pos_sale_picking_keep.model_pos_order +msgid "Point of Sale Orders" +msgstr "" + +#. module: pos_sale_picking_keep +#: model:ir.model,name:pos_sale_picking_keep.model_pos_session +msgid "Point of Sale Session" +msgstr "" + +#. module: pos_sale_picking_keep +#: model:ir.model,name:pos_sale_picking_keep.model_sale_order_line +msgid "Sales Order Line" +msgstr "" diff --git a/pos_sale_picking_keep/models/__init__.py b/pos_sale_picking_keep/models/__init__.py new file mode 100644 index 0000000000..1315735d03 --- /dev/null +++ b/pos_sale_picking_keep/models/__init__.py @@ -0,0 +1,4 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from . import pos_order +from . import pos_session +from . import sale_order_line diff --git a/pos_sale_picking_keep/models/pos_order.py b/pos_sale_picking_keep/models/pos_order.py new file mode 100644 index 0000000000..653aab9477 --- /dev/null +++ b/pos_sale_picking_keep/models/pos_order.py @@ -0,0 +1,47 @@ +# Copyright 2025 Tecnativa - Pedro M. Baeza +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo import api, models +from odoo.tools import config + + +class PosOrder(models.Model): + _inherit = "pos.order" + + @api.model + def sync_from_ui(self, orders): + # Avoid the cancellation of the SO pickings + so_line_ids = [] + for order_data in orders: + for command in order_data.get("lines", []): + if len(command) != 3: + continue # No create/update command + so_line_id = command[2].get("sale_order_line_id") + if so_line_id: + so_line_ids.append(so_line_id) + so_lines = self.env["sale.order.line"].browse(so_line_ids) + # confirm the unconfirmed sale orders that are linked to the sale order lines + # this is done also upstream, but we need to do it first for having already + # the pickings to make the trick + sale_orders = so_lines.order_id + for sale_order in sale_orders.filtered(lambda x: x.state in ["draft", "sent"]): + sale_order.action_confirm() + # Fake the pickings state before calling super for avoiding the move quantity + # reduction that is done upstream that effectively cancels the SO pickings + pickings = so_lines.move_ids.picking_id + pickings.state = "draft" + res = super().sync_from_ui(orders) + pickings._compute_state() + return res + + def _create_order_picking(self): + # Nullify the creation of the pickings at this level + # We cannot use self.env.context.get("test_pos_sale_picking_keep") because + # the tours that run in the tests do not allow that context to be maintained. + # Therefore, we use self.config_id.name. + if ( + config["test_enable"] + and self.config_id.name != "test_pos_sale_picking_keep" + ): + # For not breaking tests of other modules + return super()._create_order_picking() + return True diff --git a/pos_sale_picking_keep/models/pos_session.py b/pos_sale_picking_keep/models/pos_session.py new file mode 100644 index 0000000000..3def4406a1 --- /dev/null +++ b/pos_sale_picking_keep/models/pos_session.py @@ -0,0 +1,21 @@ +# Copyright 2025 Tecnativa - Pedro M. Baeza +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo import models +from odoo.tools import config + + +class PosSession(models.Model): + _inherit = "pos.session" + + def _create_picking_at_end_of_session(self): + # Nullify the creation of the pickings at this level + # We cannot use self.env.context.get("test_pos_sale_picking_keep") because + # the tours that run in the tests do not allow that context to be maintained. + # Therefore, we use self.config_id.name. + if ( + config["test_enable"] + and self.config_id.name != "test_pos_sale_picking_keep" + ): + # For not breaking tests of other modules + return super()._create_picking_at_end_of_session() + return True diff --git a/pos_sale_picking_keep/models/sale_order_line.py b/pos_sale_picking_keep/models/sale_order_line.py new file mode 100644 index 0000000000..7a1226fcd0 --- /dev/null +++ b/pos_sale_picking_keep/models/sale_order_line.py @@ -0,0 +1,44 @@ +# Copyright 2026 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo import api, models + + +class SaleOrderLine(models.Model): + _inherit = "sale.order.line" + + # TODO: Delete if merged https://github.com/odoo/odoo/pull/253333 + def _compute_qty_delivered(self): + self = self.with_context(from_qty_delivered=True) + return super()._compute_qty_delivered() + + # TODO: Delete if merged https://github.com/odoo/odoo/pull/253333 + @api.model + def _convert_qty(self, sale_line, qty, direction): + if self.env.context.get("from_qty_delivered"): + return 0 + return super()._convert_qty(sale_line=sale_line, qty=qty, direction=direction) + + def read_converted(self): + results = super().read_converted() + lines = {line.id: line for line in self} + for item in results: + line = lines.get(item.get("id")) + if not line or line.product_id.type == "service": + continue + product_uom = line.product_id.uom_id + if product_uom == line.product_uom_id: + continue + # The PoS charges product_uom_qty - qty_invoiced (see the JS + # override of setQuantityFromSOL) and rounds it with the Product + # Unit precision. When the quantity converted to the product UoM + # is not representable with that precision (e.g. 4 Units of a + # pack of 150 = 0.0267 packs, rounded to 0.03 by the PoS), the + # rounding would change the charged amount. Compensate on the + # price so rounded qty * price matches the sale order line + # remaining amount. + qty = item["product_uom_qty"] - item["qty_invoiced"] + qty_rounded = product_uom.round(qty) + if product_uom.is_zero(qty_rounded): + continue + item["price_unit"] = item["price_unit"] * qty / qty_rounded + return results diff --git a/pos_sale_picking_keep/pyproject.toml b/pos_sale_picking_keep/pyproject.toml new file mode 100644 index 0000000000..4231d0cccb --- /dev/null +++ b/pos_sale_picking_keep/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/pos_sale_picking_keep/readme/CONTEXT.md b/pos_sale_picking_keep/readme/CONTEXT.md new file mode 100644 index 0000000000..df96e1c124 --- /dev/null +++ b/pos_sale_picking_keep/readme/CONTEXT.md @@ -0,0 +1,7 @@ +In some scenarios, you may not want that the point of sale (PoS) handles the pickings +of the products you are paying: + +- Using the PoS as a pure payment terminal. +- When complex stock flows are not supplied by the PoS. + +In that cases, it's better to keep the original sales pickings. diff --git a/pos_sale_picking_keep/readme/CONTRIBUTORS.md b/pos_sale_picking_keep/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..8b7bbc8fc0 --- /dev/null +++ b/pos_sale_picking_keep/readme/CONTRIBUTORS.md @@ -0,0 +1,6 @@ +- Tecnativa: + - Pedro M. Baeza + - Víctor Martínez + +- Jarsa: + - Jesús Alan Ramos Rodríguez \ diff --git a/pos_sale_picking_keep/readme/DESCRIPTION.md b/pos_sale_picking_keep/readme/DESCRIPTION.md new file mode 100644 index 0000000000..a986054dd2 --- /dev/null +++ b/pos_sale_picking_keep/readme/DESCRIPTION.md @@ -0,0 +1,8 @@ +This module inhibits the manipulation that the point of sale mades over the sales orders +pickings, and the creation of new pickings under the PoS picking type. + +When settling a sale order in the PoS, the ordered quantities are loaded +even if the products were already delivered through the sale order pickings, +deducting only the quantities already invoiced. Without this module, the PoS +deducts the delivered quantities, which makes no sense here, as the PoS is +only used to charge the order, not to deliver it. diff --git a/pos_sale_picking_keep/static/description/icon.png b/pos_sale_picking_keep/static/description/icon.png new file mode 100644 index 0000000000..1dcc49c24f Binary files /dev/null and b/pos_sale_picking_keep/static/description/icon.png differ diff --git a/pos_sale_picking_keep/static/description/index.html b/pos_sale_picking_keep/static/description/index.html new file mode 100644 index 0000000000..92e4e817f7 --- /dev/null +++ b/pos_sale_picking_keep/static/description/index.html @@ -0,0 +1,457 @@ + + + + + +README.rst + + + +
+ + + +Odoo Community Association + +
+

Keep sale pickings from PoS

+ +

Beta License: AGPL-3 OCA/pos Translate me on Weblate Try me on Runboat

+

This module inhibits the manipulation that the point of sale mades over +the sales orders pickings, and the creation of new pickings under the +PoS picking type.

+

When settling a sale order in the PoS, the ordered quantities are loaded +even if the products were already delivered through the sale order +pickings, deducting only the quantities already invoiced. Without this +module, the PoS deducts the delivered quantities, which makes no sense +here, as the PoS is only used to charge the order, not to deliver it.

+

Table of contents

+ +
+

Use Cases / Context

+

In some scenarios, you may not want that the point of sale (PoS) handles +the pickings of the products you are paying:

+
    +
  • Using the PoS as a pure payment terminal.
  • +
  • When complex stock flows are not supplied by the PoS.
  • +
+

In that cases, it’s better to keep the original sales pickings.

+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Tecnativa
  • +
+
+
+

Contributors

+
    +
  • Tecnativa:
      +
    • Pedro M. Baeza
    • +
    • Víctor Martínez
    • +
    +
  • +
  • Jarsa: +
  • +
+
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

Current maintainer:

+

pedrobaeza

+

This module is part of the OCA/pos project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+
+ + diff --git a/pos_sale_picking_keep/static/src/js/pos_order_line.esm.js b/pos_sale_picking_keep/static/src/js/pos_order_line.esm.js new file mode 100644 index 0000000000..5470fa1a52 --- /dev/null +++ b/pos_sale_picking_keep/static/src/js/pos_order_line.esm.js @@ -0,0 +1,24 @@ +/* Copyright 2026 Jarsa - Jesús Alan Ramos Rodríguez + * License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). */ +import {PosOrderline} from "@point_of_sale/app/models/pos_order_line"; +import {patch} from "@web/core/utils/patch"; + +patch(PosOrderline.prototype, { + /** + * The PoS deducts the already delivered quantity when settling a sale + * order, because it assumes it will deliver the remaining quantity + * itself. With this module the sale order pickings are kept and the PoS + * only charges the order, so the delivered quantity must not be + * deducted. Only the already invoiced quantity is deducted to avoid + * charging twice. + * @override + */ + async setQuantityFromSOL(saleOrderLine) { + if (this.product_id.type === "service") { + return super.setQuantityFromSOL(...arguments); + } + return this.setQuantity( + saleOrderLine.product_uom_qty - saleOrderLine.qty_invoiced + ); + }, +}); diff --git a/pos_sale_picking_keep/static/tests/tours/pos_sale_picking_keep.esm.js b/pos_sale_picking_keep/static/tests/tours/pos_sale_picking_keep.esm.js new file mode 100644 index 0000000000..b26b0b5407 --- /dev/null +++ b/pos_sale_picking_keep/static/tests/tours/pos_sale_picking_keep.esm.js @@ -0,0 +1,32 @@ +import * as Chrome from "@point_of_sale/../tests/pos/tours/utils/chrome_util"; +import * as Dialog from "@point_of_sale/../tests/generic_helpers/dialog_util"; +import * as PaymentScreen from "@point_of_sale/../tests/pos/tours/utils/payment_screen_util"; +import * as PosSale from "@pos_sale/../tests/tours/utils/pos_sale_utils"; +import * as ProductScreen from "@point_of_sale/../tests/pos/tours/utils/product_screen_util"; +import * as ReceiptScreen from "@point_of_sale/../tests/pos/tours/utils/receipt_screen_util"; +import {registry} from "@web/core/registry"; + +registry.category("web_tour.tours").add("PosSalePickingKeep1", { + steps: () => + [ + Chrome.startPoS(), + Dialog.confirm("Open Register"), + PosSale.settleNthOrder(1), + ProductScreen.selectedOrderlineHas("Test Product", "1.00"), + ProductScreen.clickPayButton(), + PaymentScreen.clickPaymentMethod("Bank", true, {remaining: "0.0"}), + PaymentScreen.clickValidate(), + ReceiptScreen.isShown(), + ].flat(), +}); +registry.category("web_tour.tours").add("PosSalePickingKeep2", { + steps: () => + [ + Chrome.startPoS(), + Dialog.confirm("Open Register"), + ProductScreen.clickDisplayedProduct("Test Product"), + ProductScreen.clickPayButton(), + PaymentScreen.clickPaymentMethod("Bank"), + PaymentScreen.clickValidate(), + ].flat(), +}); diff --git a/pos_sale_picking_keep/tests/__init__.py b/pos_sale_picking_keep/tests/__init__.py new file mode 100644 index 0000000000..bdfa733c4b --- /dev/null +++ b/pos_sale_picking_keep/tests/__init__.py @@ -0,0 +1 @@ +from . import test_pos_sale_picking_keep diff --git a/pos_sale_picking_keep/tests/test_pos_sale_picking_keep.py b/pos_sale_picking_keep/tests/test_pos_sale_picking_keep.py new file mode 100644 index 0000000000..a0d28b2f9f --- /dev/null +++ b/pos_sale_picking_keep/tests/test_pos_sale_picking_keep.py @@ -0,0 +1,152 @@ +# Copyright 2026 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +import odoo.tests +from odoo import Command +from odoo.tests import Form + +from odoo.addons.point_of_sale.tests.test_frontend import TestPointOfSaleHttpCommon + + +@odoo.tests.tagged("post_install", "-at_install") +class TestPosSalePickingKeep(TestPointOfSaleHttpCommon): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.env.user.group_ids |= cls.env.ref("sales_team.group_sale_salesman") + cls.env.company.point_of_sale_update_stock_quantities = "closing" + cls.customer = cls.env["res.partner"].create({"name": "Test partner"}) + cls.warehouse = cls.env["stock.warehouse"].search( + [("company_id", "=", cls.env.company.id)], limit=1 + ) + cls.product = cls.env["product.product"].create( + { + "name": "Test Product", + "available_in_pos": True, + "is_storable": True, + "lst_price": 10.0, + } + ) + cls.main_pos_config.name = "test_pos_sale_picking_keep" + + def test_sale_order_pos_order_done(self): + self.env["stock.quant"]._update_available_quantity( + self.product, self.warehouse.lot_stock_id, 1 + ) + order_form = Form(self.env["sale.order"]) + order_form.partner_id = self.customer + order_form.client_order_ref = "test_pos_sale_picking_keep" + with order_form.order_line.new() as line_form: + line_form.product_id = self.product + sale_order = order_form.save() + sol = sale_order.order_line + self.assertEqual(sol.qty_delivered, 0) + self.main_pos_config.open_ui() + self.start_tour( + f"/pos/ui?config_id={self.main_pos_config.id}", + "PosSalePickingKeep1", + login="accountman", + ) + self.assertEqual(sale_order.state, "sale") + self.assertEqual(len(sale_order.picking_ids), 1) + pos_order = sol.pos_order_line_ids.order_id + self.assertEqual(pos_order.state, "paid") + self.assertFalse(pos_order.picking_ids) + so_picking = sale_order.picking_ids + self.assertEqual(so_picking.state, "assigned") + self.assertEqual(sol.qty_delivered, 0) + sale_order.picking_ids.button_validate() + self.assertEqual(so_picking.state, "done") + self.assertEqual(sol.qty_delivered, 1) + + def test_settle_delivered_sale_order(self): + """The ordered quantity is settled even if it was already delivered.""" + self.env["stock.quant"]._update_available_quantity( + self.product, self.warehouse.lot_stock_id, 1 + ) + order_form = Form(self.env["sale.order"]) + order_form.partner_id = self.customer + order_form.client_order_ref = "test_pos_sale_picking_keep" + with order_form.order_line.new() as line_form: + line_form.product_id = self.product + sale_order = order_form.save() + sale_order.action_confirm() + sale_order.picking_ids.move_ids.write({"picked": True}) + sale_order.picking_ids.button_validate() + sol = sale_order.order_line + self.assertEqual(sol.qty_delivered, 1) + self.main_pos_config.open_ui() + # The tour checks that the line is loaded with quantity 1.00 + self.start_tour( + f"/pos/ui?config_id={self.main_pos_config.id}", + "PosSalePickingKeep1", + login="accountman", + ) + pos_order = sol.pos_order_line_ids.order_id + self.assertEqual(pos_order.state, "paid") + self.assertFalse(pos_order.picking_ids) + self.assertEqual(sale_order.picking_ids.state, "done") + + def test_read_converted_price_uom_rounding(self): + """Charge the exact sale order amount when the quantity converted to + the product UoM is not representable with the Product Unit precision. + + 4 Units of a pack-of-150 product = 0.02666 packs, which the PoS + rounds to 0.03. The price returned by read_converted must be + compensated so the PoS charges the sale order amount. + """ + unit_uom = self.env.ref("uom.product_uom_unit") + pack_uom = self.env["uom.uom"].create( + { + "name": "Pack of 150", + "relative_factor": 150, + "relative_uom_id": unit_uom.id, + } + ) + product = self.env["product.product"].create( + { + "name": "Test pack product", + "available_in_pos": True, + "is_storable": True, + "uom_id": pack_uom.id, + "lst_price": 984.0, + } + ) + sale_order = self.env["sale.order"].create( + { + "partner_id": self.customer.id, + "order_line": [ + Command.create( + { + "product_id": product.id, + "product_uom_id": unit_uom.id, + "product_uom_qty": 4, + "price_unit": 6.56, + } + ) + ], + } + ) + sale_order.action_confirm() + sol = sale_order.order_line + converted = sol.read_converted()[0] + # What the PoS will charge: rounded qty * converted price + qty_pos = pack_uom.round( + converted["product_uom_qty"] - converted["qty_invoiced"] + ) + self.assertAlmostEqual(qty_pos, 0.03) + self.assertAlmostEqual( + qty_pos * converted["price_unit"], sol.price_subtotal, places=2 + ) + + def test_pos_order_flow(self): + self.main_pos_config.open_ui() + self.start_tour( + f"/pos/ui?config_id={self.main_pos_config.id}", + "PosSalePickingKeep2", + login="accountman", + ) + self.main_pos_config.current_session_id.close_session_from_ui() + pos_order = self.env["pos.order"].search([], order="id desc", limit=1) + self.assertTrue(pos_order) + self.assertEqual(pos_order.state, "done") + self.assertFalse(pos_order.session_id.picking_ids)