[ADD] pos_payment_method_cashdro_fix: 17.0 API leftovers in the OCA base module
The 18.0 migration of `pos_payment_method_cashdro` (OCA/pos@6a4c251d) kept three uses of APIs removed in 18.0. The module has no tests nor tours and needs a physical drawer to be exercised, so the OCA CI can't catch them: * `_cashdro_url()` reads `order.selected_paymentline`, so `.payment_method` on the resulting `undefined` throws a TypeError on every payment, swallowed into a generic "An error occurred while connecting to the cashdro" dialog. * The `add_paymentline()` patch checks `line.payment_method`, renamed to `payment_method_id`, so the line keeps the default due amount instead of waiting for the amount the customer inserts. * `_loader_params_pos_payment_method()` is the 17.0 loading API, replaced by `_load_pos_data_fields()`. Dead code, so the CashDro credentials never reach the front end. Patched from the outside, as OCA sources are not to be modified. Written to stay harmless once fixed upstream: the Python override only adds the missing fields and the JS patches are idempotent against the fixed code. `upstream/pos_payment_method_cashdro-18.0-fixes.patch` holds the same fixes as a ready to send `git format-patch`, verified with `git apply --check`. This module is temporary and should be removed once that lands in OCA/pos. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
parent
fb5b3d1f7e
commit
4615da6dae
14 changed files with 426 additions and 0 deletions
|
|
@ -0,0 +1,31 @@
|
|||
/* Copyright 2026 - Today Criptomart
|
||||
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
|
||||
The `add_paymentline` patch of `pos_payment_method_cashdro` checks
|
||||
`line.payment_method`, renamed to `payment_method_id` in 18.0, so the
|
||||
condition is never met and the line keeps the default due amount instead of
|
||||
waiting for the amount the customer actually inserts in the drawer.
|
||||
*/
|
||||
|
||||
import { PosOrder } from "@point_of_sale/app/models/pos_order";
|
||||
import { patch } from "@web/core/utils/patch";
|
||||
|
||||
patch(PosOrder.prototype, {
|
||||
/**
|
||||
* @override
|
||||
* Set the amount to 0 as it's going to be filled by the Cashdro response.
|
||||
*/
|
||||
add_paymentline() {
|
||||
const line = super.add_paymentline(...arguments);
|
||||
if (!line) {
|
||||
return line;
|
||||
}
|
||||
if (
|
||||
line.payment_method_id?.use_payment_terminal === "cashdro" &&
|
||||
line.amount > 0 // For refund transactions we need to keep the amount
|
||||
) {
|
||||
line.set_amount(0);
|
||||
}
|
||||
return line;
|
||||
},
|
||||
});
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
/* Copyright 2026 - Today Criptomart
|
||||
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
|
||||
`_cashdro_url` was left with the 17.0 API in the 18.0 migration of
|
||||
`pos_payment_method_cashdro`: `order.selected_paymentline` no longer exists,
|
||||
so reading `.payment_method` on it throws a TypeError that the caller
|
||||
swallows as a generic connection error. Rewritten with the 18.0 accessors.
|
||||
*/
|
||||
|
||||
import { PaymentCashdro } from "@pos_payment_method_cashdro/js/payment_cashdro.esm";
|
||||
import { patch } from "@web/core/utils/patch";
|
||||
|
||||
patch(PaymentCashdro.prototype, {
|
||||
/**
|
||||
* @override
|
||||
* The whole body has to be replaced: the very first statement is the one
|
||||
* that breaks, so there is nothing left to delegate to `super`.
|
||||
*/
|
||||
_cashdro_url() {
|
||||
// Cashdro machines don't support safe POST calls, so we're sending
|
||||
// all the data quite unsafely constantly...
|
||||
const order = this.pos.get_order();
|
||||
const method = order.get_selected_paymentline()?.payment_method_id;
|
||||
const host = method && method.cashdro_host;
|
||||
if (!host) {
|
||||
return false;
|
||||
}
|
||||
let url = `${host}/Cashdro3WS/index.php`;
|
||||
url += `?name=${method.cashdro_user}`;
|
||||
url += `&password=${method.cashdro_password}`;
|
||||
return url;
|
||||
},
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue