From 0e39cc934574fdd7e1c540d89f243260e190f77a Mon Sep 17 00:00:00 2001 From: Elkasitu Date: Thu, 11 May 2017 12:38:21 +0200 Subject: [PATCH] [IMP] payment: Add search for token_implemented Since subscriptions only accept tokenizable (credit-cards and such) payment options, we must use the token_implemented field to filter out non-tokenizable payment options (such as wire transfer) and because token_implemented is a computed field, a search function had to be created --- addons/payment/models/payment_acquirer.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/addons/payment/models/payment_acquirer.py b/addons/payment/models/payment_acquirer.py index 2f3fc969458..4777cbc8318 100644 --- a/addons/payment/models/payment_acquirer.py +++ b/addons/payment/models/payment_acquirer.py @@ -122,7 +122,7 @@ class PaymentAcquirer(models.Model): help="This option allows customers to save their credit card as a payment token and to reuse it for a later purchase." "If you manage subscriptions (recurring invoicing), you need it to automatically charge the customer when you " "issue an invoice.") - token_implemented = fields.Boolean('Saving Card Data supported', compute='_compute_feature_support') + token_implemented = fields.Boolean('Saving Card Data supported', compute='_compute_feature_support', search='_search_is_tokenized') authorize_implemented = fields.Boolean('Authorize Mechanism Supported', compute='_compute_feature_support') fees_implemented = fields.Boolean('Fees Computation Supported', compute='_compute_feature_support') fees_active = fields.Boolean('Add Extra Fees') @@ -149,6 +149,13 @@ class PaymentAcquirer(models.Model): "resized as a 64x64px image, with aspect ratio preserved. " "Use this field anywhere a small image is required.") + def _search_is_tokenized(self, operator, value): + tokenized = self._get_feature_support()['tokenize'] + if (operator, value) in [('=', True), ('!=', False)]: + return [('provider', 'in', tokenized)] + return [('provider', 'not in', tokenized)] + + @api.multi def _compute_feature_support(self): feature_support = self._get_feature_support() for acquirer in self: