From cfc4b471422e8c55697d6fb1e58020cc281f86e1 Mon Sep 17 00:00:00 2001 From: Telmo Santos Date: Tue, 26 Apr 2022 07:35:15 +0200 Subject: [PATCH 1/2] [FIX] payment_environment: Fix state usage --- .../models/payment_acquirer.py | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/payment_environment/models/payment_acquirer.py b/payment_environment/models/payment_acquirer.py index 0709c5a..a298708 100644 --- a/payment_environment/models/payment_acquirer.py +++ b/payment_environment/models/payment_acquirer.py @@ -2,7 +2,8 @@ # @author Iván Todorovich # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) -from odoo import models +from odoo import fields, models +from odoo.osv import expression class PaymentAcquirer(models.Model): @@ -21,3 +22,26 @@ class PaymentAcquirer(models.Model): } acquirer_fields.update(base_fields) return acquirer_fields + + state = fields.Selection(search="_search_state",) + + def _search_state(self, operator, value): + """ + As state field is now managed as server environment fields, + the field is considered as a computed fields. + Then, we need to define a custom search function + to be able to search on this field. + + We don't want to cover all cases, + just search implemented in core function + to display the acquirers when generating the payment link. + + See module payment in controller/portal.py function pay() + Used domain is: ('state', 'in', ['enabled', 'test']) + """ + if operator == "in" and isinstance(value, list): + valid_acquirers = self.search([]).filtered_domain([("state", "in", value)]) + if valid_acquirers: + return [("id", "in", valid_acquirers.ids)] + + return expression.FALSE_DOMAIN From 2f17a86de140cc59884e9eaef58ac3549253cca4 Mon Sep 17 00:00:00 2001 From: Telmo Santos Date: Tue, 26 Apr 2022 08:46:27 +0200 Subject: [PATCH 2/2] Remove state from payment acquirer order --- payment_environment/models/payment_acquirer.py | 1 + 1 file changed, 1 insertion(+) diff --git a/payment_environment/models/payment_acquirer.py b/payment_environment/models/payment_acquirer.py index a298708..5f3da60 100644 --- a/payment_environment/models/payment_acquirer.py +++ b/payment_environment/models/payment_acquirer.py @@ -13,6 +13,7 @@ class PaymentAcquirer(models.Model): "server.env.techname.mixin", "server.env.mixin", ] + _order = "module_state, sequence, name" @property def _server_env_fields(self):