From fb5b3d1f7ebad5d3ea6b28b3540a51a7e977be1a Mon Sep 17 00:00:00 2001 From: GitHub Copilot Date: Tue, 11 Aug 2026 13:30:49 +0200 Subject: [PATCH] [ADD] pos_payment_method_cashdro_rounding: migration to 18.0 Migrated from the 17.0 branch (4fbf328). APIs that no longer exist in 18.0: * `order.selected_paymentline` -> `order.get_selected_paymentline()` * `ErrorPopup` + `env.services.popup` -> `AlertDialog` + `env.services.dialog` * `/** @odoo-module */`, implicit in `.esm.js` since 17.0 The rounding itself needed a different approach: `get_rounding_applied()` now reads `taxTotals.order_rounding`, only computed over payments that are already `is_done()`. The CashDro line is still `waiting` when the amount is requested, so a literal port would always have added 0. `getDefaultAmountDueToPayIn()` is the 18.0 equivalent: it applies `getRoundedRemaining()` honouring both `cash_rounding` and `only_round_cash_method`, and is what core itself uses for the default amount of a payment line. Only `_cashdro_payment_url()` is patched now, instead of duplicating the whole `cashdro_send_payment_request()`, so the request flow, the acknowledge, the polling and the error handling stay in the base module. With no cash rounding configured the patch delegates to `super` and changes nothing. Co-Authored-By: Claude Opus 5 --- .../__init__.py | 2 + .../__manifest__.py | 18 +++++++++ .../static/src/js/cashdro_rounding.esm.js | 37 +++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 pos_payment_method_cashdro_rounding/__init__.py create mode 100644 pos_payment_method_cashdro_rounding/__manifest__.py create mode 100644 pos_payment_method_cashdro_rounding/static/src/js/cashdro_rounding.esm.js diff --git a/pos_payment_method_cashdro_rounding/__init__.py b/pos_payment_method_cashdro_rounding/__init__.py new file mode 100644 index 0000000..9f3f569 --- /dev/null +++ b/pos_payment_method_cashdro_rounding/__init__.py @@ -0,0 +1,2 @@ +# Copyright Criptomart +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). diff --git a/pos_payment_method_cashdro_rounding/__manifest__.py b/pos_payment_method_cashdro_rounding/__manifest__.py new file mode 100644 index 0000000..a16b1e3 --- /dev/null +++ b/pos_payment_method_cashdro_rounding/__manifest__.py @@ -0,0 +1,18 @@ +{ + "name": "POS CashDro Rounding", + "version": "18.0.1.0.0", + "summary": "Apply cash/currency rounding to CashDro payment request amount.", + "category": "Point of Sale", + "license": "AGPL-3", + "author": "Criptomart", + "depends": [ + "point_of_sale", + "pos_payment_method_cashdro", + ], + "assets": { + "point_of_sale._assets_pos": [ + "pos_payment_method_cashdro_rounding/static/src/js/cashdro_rounding.esm.js", + ], + }, + "installable": True, +} diff --git a/pos_payment_method_cashdro_rounding/static/src/js/cashdro_rounding.esm.js b/pos_payment_method_cashdro_rounding/static/src/js/cashdro_rounding.esm.js new file mode 100644 index 0000000..eb01842 --- /dev/null +++ b/pos_payment_method_cashdro_rounding/static/src/js/cashdro_rounding.esm.js @@ -0,0 +1,37 @@ +/* Copyright Criptomart + License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + + Apply the PoS cash rounding to the amount requested to the CashDro, keeping + the OCA integration flow untouched. +*/ + +import { PaymentCashdro } from "@pos_payment_method_cashdro/js/payment_cashdro.esm"; +import { patch } from "@web/core/utils/patch"; + +patch(PaymentCashdro.prototype, { + /** + * @override + * The base module asks the CashDro for the plain due amount, which ignores + * the cash rounding configured in the PoS. As the drawer can only give back + * change with the coins it holds, we request the amount the customer is + * really expected to pay: the due amount with the cash rounding applied, + * which is the very same amount core defaults a payment line to. + * + * Only the url builder is patched so the rest of the payment flow of the + * base module (request, acknowledge, polling and error handling) is kept. + */ + _cashdro_payment_url(parameters) { + const order = this.pos.get_order(); + const line = order.get_selected_paymentline(); + if (!line || !order.shouldRound(line.payment_method_id)) { + return super._cashdro_payment_url(...arguments); + } + // CashDro treats decimals as positions in an integer, so we round the + // product to avoid the trailing decimals of the floating point + // computation or the drawer would reject our request. + const amount = Math.round( + order.getDefaultAmountDueToPayIn(line.payment_method_id) * 100 + ); + return super._cashdro_payment_url({ ...parameters, amount }); + }, +});