From 41dc27a42d6faedbf08b4a1660dd8dbe3896d721 Mon Sep 17 00:00:00 2001 From: Denis Roussel Date: Tue, 28 Jul 2026 19:55:51 +0200 Subject: [PATCH] [FIX] pos_payment_method_cashdro: Use correct payment line retrieval method + Improve http Allow to retrieve correctly the payment line at request sending Add http only option --- pos_payment_method_cashdro/models/__init__.py | 1 - .../models/pos_payment_method.py | 13 +++++++++++++ pos_payment_method_cashdro/models/pos_session.py | 14 -------------- .../static/src/js/payment_cashdro.esm.js | 9 ++++++--- .../views/pos_payment_method_views.xml | 4 ++++ 5 files changed, 23 insertions(+), 18 deletions(-) delete mode 100644 pos_payment_method_cashdro/models/pos_session.py diff --git a/pos_payment_method_cashdro/models/__init__.py b/pos_payment_method_cashdro/models/__init__.py index 604d90cb18..58690ef8d9 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 285984a90f..5fff6152a7 100644 --- a/pos_payment_method_cashdro/models/pos_payment_method.py +++ b/pos_payment_method_cashdro/models/pos_payment_method.py @@ -15,6 +15,11 @@ def _get_payment_terminal_selection(self): ) cashdro_user = fields.Char() cashdro_password = fields.Char() + cashdro_http = fields.Boolean( + string="Use HTTP connection", + help="Check this to enable HTTP (not secure) connection. You should enable it" + " also in Cashdro configuration interface.", + ) def _onchange_journal_id(self): """Cash payment method force the `use_payment_terminal` to `False` as @@ -33,3 +38,11 @@ def _compute_hide_use_payment_terminal(self): return super( PosPaymentMethod, self - cash_payment_types )._compute_hide_use_payment_terminal() + + def _load_pos_data_fields(self, config_id): + return super()._load_pos_data_fields(config_id) + [ + "cashdro_host", + "cashdro_user", + "cashdro_password", + "cashdro_http", + ] 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 6123090956..0000000000 --- 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/payment_cashdro.esm.js b/pos_payment_method_cashdro/static/src/js/payment_cashdro.esm.js index 0c0bdf2e20..8bfe97ec89 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,12 +107,15 @@ 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 method = this.pos + .get_order() + .get_selected_paymentline().payment_method_id; const host = method && method.cashdro_host; if (!host) { return false; } - let url = `${host}/Cashdro3WS/index.php`; + const connection = method.cashdro_http ? `http://` : `https://`; + let url = `${connection}${host}/Cashdro3WS/index.php`; url += `?name=${method.cashdro_user}`; url += `&password=${method.cashdro_password}`; return url; @@ -125,7 +128,7 @@ export class PaymentCashdro extends PaymentInterface { const operationType = parameters.amount > 0 ? 4 : 3; parameters = {...parameters, amount: Math.abs(parameters.amount)}; let url = `${this._cashdro_url()}&operation=startOperation&type=${operationType}`; - url += `&posid=pos-${this.pos.pos_session.name}`; + url += `&posid=pos-${this.pos.session.name}`; url += `&posuser=${user}`; url += `¶meters=${encodeURIComponent(JSON.stringify(parameters))}`; return url; diff --git a/pos_payment_method_cashdro/views/pos_payment_method_views.xml b/pos_payment_method_cashdro/views/pos_payment_method_views.xml index 79e43a8ff2..bdcee1d3a1 100644 --- a/pos_payment_method_cashdro/views/pos_payment_method_views.xml +++ b/pos_payment_method_cashdro/views/pos_payment_method_views.xml @@ -10,6 +10,10 @@ invisible="use_payment_terminal != 'cashdro'" required="use_payment_terminal == 'cashdro'" /> +