[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,133 @@
|
|||
From 11c65e8000282b9a761346f1fbff16e09581fc17 Mon Sep 17 00:00:00 2001
|
||||
From: Criptomart <ofi@criptomart.net>
|
||||
Date: Tue, 11 Aug 2026 13:21:28 +0200
|
||||
Subject: [PATCH] [FIX] pos_payment_method_cashdro: leftovers of the 17.0 API
|
||||
|
||||
The 18.0 migration kept three uses of APIs that no longer exist, and the
|
||||
module has neither tests nor tours (it needs a physical drawer), so the CI
|
||||
can't catch them.
|
||||
|
||||
* `_cashdro_url()` reads `order.selected_paymentline`, replaced by
|
||||
`order.get_selected_paymentline()` in 18.0. Reading `.payment_method` on
|
||||
the resulting `undefined` throws a TypeError on every payment, which
|
||||
`cashdro_send_payment_request()` swallows into a generic "An error occurred
|
||||
while connecting to the cashdro" dialog.
|
||||
|
||||
* The `add_paymentline()` patch checks `line.payment_method`, renamed to
|
||||
`line.payment_method_id` in 18.0, so the payment line is never zeroed and
|
||||
keeps the default due amount instead of the amount the customer inserts.
|
||||
|
||||
* `_loader_params_pos_payment_method()` is the 17.0 loading API, replaced in
|
||||
18.0 by `_load_pos_data_fields()` on each model. The override is dead code
|
||||
and the CashDro credentials never reach the front end, so `_cashdro_url()`
|
||||
has no host to build the url with.
|
||||
---
|
||||
pos_payment_method_cashdro/__manifest__.py | 2 +-
|
||||
pos_payment_method_cashdro/models/__init__.py | 1 -
|
||||
.../models/pos_payment_method.py | 11 ++++++++++-
|
||||
pos_payment_method_cashdro/models/pos_session.py | 14 --------------
|
||||
.../static/src/js/models.esm.js | 4 ++--
|
||||
.../static/src/js/payment_cashdro.esm.js | 3 ++-
|
||||
6 files changed, 15 insertions(+), 20 deletions(-)
|
||||
delete mode 100644 pos_payment_method_cashdro/models/pos_session.py
|
||||
|
||||
diff --git a/pos_payment_method_cashdro/__manifest__.py b/pos_payment_method_cashdro/__manifest__.py
|
||||
index 708aac5..c19a642 100644
|
||||
--- a/pos_payment_method_cashdro/__manifest__.py
|
||||
+++ b/pos_payment_method_cashdro/__manifest__.py
|
||||
@@ -3,7 +3,7 @@
|
||||
{
|
||||
"name": "PoS Payment Method CashDro",
|
||||
"summary": "Allows to pay with CashDro Terminals on the Point of Sale",
|
||||
- "version": "18.0.1.0.2",
|
||||
+ "version": "18.0.1.0.3",
|
||||
"category": "Point Of Sale",
|
||||
"website": "https://github.com/OCA/pos",
|
||||
"author": "Tecnativa, Odoo Community Association (OCA)",
|
||||
diff --git a/pos_payment_method_cashdro/models/__init__.py b/pos_payment_method_cashdro/models/__init__.py
|
||||
index 604d90c..58690ef 100644
|
||||
--- a/pos_payment_method_cashdro/models/__init__.py
|
||||
+++ b/pos_payment_method_cashdro/models/__init__.py
|
||||
@@ -1,2 +1 @@
|
||||
from . import pos_payment_method
|
||||
-from . import pos_session
|
||||
diff --git a/pos_payment_method_cashdro/models/pos_payment_method.py b/pos_payment_method_cashdro/models/pos_payment_method.py
|
||||
index 285984a..08a64a1 100644
|
||||
--- a/pos_payment_method_cashdro/models/pos_payment_method.py
|
||||
+++ b/pos_payment_method_cashdro/models/pos_payment_method.py
|
||||
@@ -1,6 +1,6 @@
|
||||
# Copyright 2021 Tecnativa - David Vidal
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
-from odoo import fields, models
|
||||
+from odoo import api, fields, models
|
||||
|
||||
|
||||
class PosPaymentMethod(models.Model):
|
||||
@@ -16,6 +16,15 @@ class PosPaymentMethod(models.Model):
|
||||
cashdro_user = fields.Char()
|
||||
cashdro_password = fields.Char()
|
||||
|
||||
+ @api.model
|
||||
+ def _load_pos_data_fields(self, config_id):
|
||||
+ """The front end needs the credentials to build the CashDro url"""
|
||||
+ return super()._load_pos_data_fields(config_id) + [
|
||||
+ "cashdro_host",
|
||||
+ "cashdro_user",
|
||||
+ "cashdro_password",
|
||||
+ ]
|
||||
+
|
||||
def _onchange_journal_id(self):
|
||||
"""Cash payment method force the `use_payment_terminal` to `False` as
|
||||
it's assumed that a cash journal can't have a payment terminal. Let's keep
|
||||
diff --git a/pos_payment_method_cashdro/models/pos_session.py b/pos_payment_method_cashdro/models/pos_session.py
|
||||
deleted file mode 100644
|
||||
index 6123090..0000000
|
||||
--- a/pos_payment_method_cashdro/models/pos_session.py
|
||||
+++ /dev/null
|
||||
@@ -1,14 +0,0 @@
|
||||
-# Copyright 2024 Tecnativa - David Vidal
|
||||
-# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
-from odoo import models
|
||||
-
|
||||
-
|
||||
-class PosSession(models.Model):
|
||||
- _inherit = "pos.session"
|
||||
-
|
||||
- def _loader_params_pos_payment_method(self):
|
||||
- result = super()._loader_params_pos_payment_method()
|
||||
- result["search_params"]["fields"].extend(
|
||||
- ["cashdro_host", "cashdro_user", "cashdro_password"]
|
||||
- )
|
||||
- return result
|
||||
diff --git a/pos_payment_method_cashdro/static/src/js/models.esm.js b/pos_payment_method_cashdro/static/src/js/models.esm.js
|
||||
index d228f08..d1ee2f7 100644
|
||||
--- a/pos_payment_method_cashdro/static/src/js/models.esm.js
|
||||
+++ b/pos_payment_method_cashdro/static/src/js/models.esm.js
|
||||
@@ -22,8 +22,8 @@ patch(PosOrder.prototype, {
|
||||
return line;
|
||||
}
|
||||
if (
|
||||
- line.payment_method &&
|
||||
- line.payment_method.use_payment_terminal === "cashdro" &&
|
||||
+ line.payment_method_id &&
|
||||
+ line.payment_method_id.use_payment_terminal === "cashdro" &&
|
||||
line.amount > 0 // For refund transactions we need to keep the amount
|
||||
) {
|
||||
line.set_amount(0);
|
||||
diff --git a/pos_payment_method_cashdro/static/src/js/payment_cashdro.esm.js b/pos_payment_method_cashdro/static/src/js/payment_cashdro.esm.js
|
||||
index 0c0bdf2..2c618bf 100644
|
||||
--- a/pos_payment_method_cashdro/static/src/js/payment_cashdro.esm.js
|
||||
+++ b/pos_payment_method_cashdro/static/src/js/payment_cashdro.esm.js
|
||||
@@ -107,7 +107,8 @@ export class PaymentCashdro extends PaymentInterface {
|
||||
_cashdro_url() {
|
||||
// Cashdro machines don't support safe POST calls, so we're sending
|
||||
// all the data quite unsafely constantly...
|
||||
- const method = this.pos.get_order().selected_paymentline.payment_method;
|
||||
+ 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;
|
||||
--
|
||||
2.43.0
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue