diff --git a/addons/payment/models/payment_acquirer.py b/addons/payment/models/payment_acquirer.py index a00151254a3..4cf1fd8249f 100644 --- a/addons/payment/models/payment_acquirer.py +++ b/addons/payment/models/payment_acquirer.py @@ -99,12 +99,19 @@ class PaymentAcquirer(models.Model): default=lambda self: _("Your payment has been cancelled."), translate=True) # Feature support fields - support_authorization = fields.Boolean(string="Authorize Mechanism Supported") - support_fees_computation = fields.Boolean(string="Fees Computation Supported") - support_tokenization = fields.Boolean(string="Tokenization Supported") + support_fees = fields.Boolean( + string="Fees Supported", compute='_compute_feature_support_fields' + ) + support_manual_capture = fields.Boolean( + string="Manual Capture Supported", compute='_compute_feature_support_fields' + ) support_refund = fields.Selection( string="Type of Refund Supported", selection=[('full_only', "Full Only"), ('partial', "Partial")], + compute='_compute_feature_support_fields', + ) + support_tokenization = fields.Boolean( + string="Tokenization Supported", compute='_compute_feature_support_fields' ) # Kanban view fields @@ -204,6 +211,18 @@ class PaymentAcquirer(models.Model): elif payment_method_line: payment_method_line.unlink() + def _compute_feature_support_fields(self): + """ Compute the feature support fields. + + For an acquirer to support one or more additional feature, it must override this method. + + :return: None + """ + self.update(dict.fromkeys( + ('support_fees', 'support_manual_capture', 'support_refund', 'support_tokenization'), + None, + )) + def _get_default_payment_method_id(self): self.ensure_one() return self.env.ref('account.account_payment_method_manual_in').id diff --git a/addons/payment/models/payment_transaction.py b/addons/payment/models/payment_transaction.py index 44d96686073..4da7ba1f2d2 100644 --- a/addons/payment/models/payment_transaction.py +++ b/addons/payment/models/payment_transaction.py @@ -159,7 +159,7 @@ class PaymentTransaction(models.Model): def _check_state_authorized_supported(self): """ Check that authorization is supported for a transaction in the 'authorized' state. """ illegal_authorize_state_txs = self.filtered( - lambda tx: tx.state == 'authorized' and not tx.acquirer_id.support_authorization + lambda tx: tx.state == 'authorized' and not tx.acquirer_id.support_manual_capture ) if illegal_authorize_state_txs: raise ValidationError(_( diff --git a/addons/payment/tests/test_payments.py b/addons/payment/tests/test_payments.py index c341986e90c..a4b26d85e13 100644 --- a/addons/payment/tests/test_payments.py +++ b/addons/payment/tests/test_payments.py @@ -36,7 +36,7 @@ class TestPayments(PaymentCommon): def test_full_amount_available_for_refund_when_refunds_are_pending(self): self.acquirer.write({ 'support_refund': 'full_only', # Should simply not be False - 'support_authorization': True, # To create transaction in the 'authorized' state + 'support_manual_capture': True, # To create transaction in the 'authorized' state }) tx = self.create_transaction('redirect', state='done') tx._reconcile_after_done() # Create the payment diff --git a/addons/payment/views/payment_acquirer_views.xml b/addons/payment/views/payment_acquirer_views.xml index f9b8bf92ac2..ff0e819321b 100644 --- a/addons/payment/views/payment_acquirer_views.xml +++ b/addons/payment/views/payment_acquirer_views.xml @@ -6,8 +6,8 @@ payment.acquirer
- - + + @@ -57,7 +57,7 @@ - + @@ -68,7 +68,7 @@ - + @@ -83,7 +83,7 @@ - + diff --git a/addons/payment_adyen/data/payment_acquirer_data.xml b/addons/payment_adyen/data/payment_acquirer_data.xml index 2ba34125ccc..4166c024d69 100644 --- a/addons/payment_adyen/data/payment_acquirer_data.xml +++ b/addons/payment_adyen/data/payment_acquirer_data.xml @@ -4,10 +4,6 @@ adyen - True - False - partial - True True diff --git a/addons/payment_adyen/models/payment_acquirer.py b/addons/payment_adyen/models/payment_acquirer.py index ab813bcdf87..dcd025238d6 100644 --- a/addons/payment_adyen/models/payment_acquirer.py +++ b/addons/payment_adyen/models/payment_acquirer.py @@ -61,6 +61,17 @@ class PaymentAcquirer(models.Model): if values.get(field_name): # Test the value in case we're duplicating an acquirer values[field_name] = re.sub(r'[vV]\d+(/.*)?', '', values[field_name]) + #=== COMPUTE METHODS ===# + + def _compute_feature_support_fields(self): + """ Override of `payment` to enable additional features. """ + super()._compute_feature_support_fields() + self.filtered(lambda acq: acq.provider == 'adyen').update({ + 'support_manual_capture': True, + 'support_refund': 'partial', + 'support_tokenization': True, + }) + #=== BUSINESS METHODS ===# def _adyen_make_request( diff --git a/addons/payment_alipay/data/payment_acquirer_data.xml b/addons/payment_alipay/data/payment_acquirer_data.xml index de3bb829326..ba71ff23c4e 100644 --- a/addons/payment_alipay/data/payment_acquirer_data.xml +++ b/addons/payment_alipay/data/payment_acquirer_data.xml @@ -4,10 +4,6 @@ alipay - False - True - - False diff --git a/addons/payment_alipay/models/payment_acquirer.py b/addons/payment_alipay/models/payment_acquirer.py index ec1d9d703c0..b457569fc47 100644 --- a/addons/payment_alipay/models/payment_acquirer.py +++ b/addons/payment_alipay/models/payment_acquirer.py @@ -29,6 +29,17 @@ class PaymentAcquirer(models.Model): alipay_seller_email = fields.Char( string="Alipay Seller Email", help="The public Alipay partner email") + #=== COMPUTE METHODS ===# + + def _compute_feature_support_fields(self): + """ Override of `payment` to enable additional features. """ + super()._compute_feature_support_fields() + self.filtered(lambda acq: acq.provider == 'alipay').update({ + 'support_fees': True, + }) + + # === BUSINESS METHODS ===# + @api.model def _get_compatible_acquirers(self, *args, currency_id=None, **kwargs): """ Override of payment to unlist Alipay acquirers for unsupported currencies. """ diff --git a/addons/payment_authorize/data/payment_acquirer_data.xml b/addons/payment_authorize/data/payment_acquirer_data.xml index a97be86e255..fac5cb334d3 100644 --- a/addons/payment_authorize/data/payment_acquirer_data.xml +++ b/addons/payment_authorize/data/payment_acquirer_data.xml @@ -4,10 +4,6 @@ authorize - True - False - - True True diff --git a/addons/payment_authorize/models/payment_acquirer.py b/addons/payment_authorize/models/payment_acquirer.py index 0653934b36c..a5d9886767a 100644 --- a/addons/payment_authorize/models/payment_acquirer.py +++ b/addons/payment_authorize/models/payment_acquirer.py @@ -39,6 +39,8 @@ class PaymentAcquirer(models.Model): required_if_provider='authorize', ) + # === CONSTRAINT METHODS ===# + @api.constrains('authorize_payment_method_type') def _check_payment_method_type(self): for acquirer in self.filtered(lambda acq: acq.provider == "authorize"): @@ -49,6 +51,18 @@ class PaymentAcquirer(models.Model): "method type on the duplicated acquirer." )) + #=== COMPUTE METHODS ===# + + def _compute_feature_support_fields(self): + """ Override of `payment` to enable additional features. """ + super()._compute_feature_support_fields() + self.filtered(lambda acq: acq.provider == 'authorize').update({ + 'support_manual_capture': True, + 'support_tokenization': True, + }) + + # === ONCHANGE METHODS ===# + @api.onchange('authorize_payment_method_type') def _onchange_authorize_payment_method_type(self): if self.authorize_payment_method_type == 'bank_account': @@ -65,6 +79,8 @@ class PaymentAcquirer(models.Model): 'payment.payment_icon_cc_visa', )])] + # === ACTION METHODS ===# + def action_update_merchant_details(self): """ Fetch the merchant details to update the client key and the account currency. """ self.ensure_one() @@ -90,6 +106,8 @@ class PaymentAcquirer(models.Model): self.authorize_currency_id = currency self.authorize_client_key = res_content.get('publicClientKey') + # === BUSINESS METHODS ===# + @api.model def _get_compatible_acquirers(self, *args, currency_id=None, **kwargs): """ Override of payment to unlist Authorize acquirers for unsupported currencies. """ diff --git a/addons/payment_buckaroo/data/payment_acquirer_data.xml b/addons/payment_buckaroo/data/payment_acquirer_data.xml index 8a5ea041eab..862874eab69 100644 --- a/addons/payment_buckaroo/data/payment_acquirer_data.xml +++ b/addons/payment_buckaroo/data/payment_acquirer_data.xml @@ -4,10 +4,6 @@ buckaroo - False - False - - False diff --git a/addons/payment_mollie/data/payment_acquirer_data.xml b/addons/payment_mollie/data/payment_acquirer_data.xml index d7a620b7ef7..369fbe7ba00 100755 --- a/addons/payment_mollie/data/payment_acquirer_data.xml +++ b/addons/payment_mollie/data/payment_acquirer_data.xml @@ -4,10 +4,6 @@ mollie - False - False - - False diff --git a/addons/payment_ogone/data/payment_acquirer_data.xml b/addons/payment_ogone/data/payment_acquirer_data.xml index cb79a0173f0..f04beafbabd 100644 --- a/addons/payment_ogone/data/payment_acquirer_data.xml +++ b/addons/payment_ogone/data/payment_acquirer_data.xml @@ -4,11 +4,7 @@ ogone - False - False - True True - diff --git a/addons/payment_ogone/models/payment_acquirer.py b/addons/payment_ogone/models/payment_acquirer.py index d79aa294197..bebfafcfc74 100644 --- a/addons/payment_ogone/models/payment_acquirer.py +++ b/addons/payment_ogone/models/payment_acquirer.py @@ -31,6 +31,17 @@ class PaymentAcquirer(models.Model): ogone_shakey_out = fields.Char( string="SHA Key OUT", required_if_provider='ogone', groups='base.group_system') + #=== COMPUTE METHODS ===# + + def _compute_feature_support_fields(self): + """ Override of `payment` to enable additional features. """ + super()._compute_feature_support_fields() + self.filtered(lambda acq: acq.provider == 'ogone').update({ + 'support_tokenization': True, + }) + + #=== BUSINESS METHODS ===# + @api.model def _get_compatible_acquirers(self, *args, is_validation=False, **kwargs): """ Override of payment to unlist Ogone acquirers for validation operations. """ diff --git a/addons/payment_paypal/data/payment_acquirer_data.xml b/addons/payment_paypal/data/payment_acquirer_data.xml index 2df7ac173e4..78aea6590b7 100644 --- a/addons/payment_paypal/data/payment_acquirer_data.xml +++ b/addons/payment_paypal/data/payment_acquirer_data.xml @@ -4,10 +4,6 @@ paypal - False - True - - False diff --git a/addons/payment_paypal/models/payment_acquirer.py b/addons/payment_paypal/models/payment_acquirer.py index f9af41b6f29..98cb25a674a 100644 --- a/addons/payment_paypal/models/payment_acquirer.py +++ b/addons/payment_paypal/models/payment_acquirer.py @@ -24,6 +24,17 @@ class PaymentAcquirer(models.Model): paypal_use_ipn = fields.Boolean( string="Use IPN", help="Paypal Instant Payment Notification", default=True) + #=== COMPUTE METHODS ===# + + def _compute_feature_support_fields(self): + """ Override of `payment` to enable additional features. """ + super()._compute_feature_support_fields() + self.filtered(lambda acq: acq.provider == 'paypal').update({ + 'support_fees': True, + }) + + #=== BUSINESS METHODS ===# + @api.model def _get_compatible_acquirers(self, *args, currency_id=None, **kwargs): """ Override of payment to unlist PayPal acquirers when the currency is not supported. """ diff --git a/addons/payment_payulatam/data/payment_acquirer_data.xml b/addons/payment_payulatam/data/payment_acquirer_data.xml index a2d30f902a2..e3d3a80d4e4 100644 --- a/addons/payment_payulatam/data/payment_acquirer_data.xml +++ b/addons/payment_payulatam/data/payment_acquirer_data.xml @@ -4,10 +4,6 @@ payulatam - False - False - - False diff --git a/addons/payment_payumoney/data/payment_acquirer_data.xml b/addons/payment_payumoney/data/payment_acquirer_data.xml index 63b8536225e..802efb3effc 100644 --- a/addons/payment_payumoney/data/payment_acquirer_data.xml +++ b/addons/payment_payumoney/data/payment_acquirer_data.xml @@ -4,10 +4,6 @@ payumoney - False - False - - False diff --git a/addons/payment_sips/data/payment_acquirer_data.xml b/addons/payment_sips/data/payment_acquirer_data.xml index fd226c0d550..f9954e2cf2f 100644 --- a/addons/payment_sips/data/payment_acquirer_data.xml +++ b/addons/payment_sips/data/payment_acquirer_data.xml @@ -4,10 +4,6 @@ sips - False - False - - False diff --git a/addons/payment_stripe/data/payment_acquirer_data.xml b/addons/payment_stripe/data/payment_acquirer_data.xml index 2e6993ba77f..7893cdb02e9 100644 --- a/addons/payment_stripe/data/payment_acquirer_data.xml +++ b/addons/payment_stripe/data/payment_acquirer_data.xml @@ -3,10 +3,6 @@ stripe - True - False - - True True diff --git a/addons/payment_stripe/models/payment_acquirer.py b/addons/payment_stripe/models/payment_acquirer.py index 47a9c33ca88..a51ccf51f1c 100644 --- a/addons/payment_stripe/models/payment_acquirer.py +++ b/addons/payment_stripe/models/payment_acquirer.py @@ -34,6 +34,16 @@ class PaymentAcquirer(models.Model): "authenticate the messages sent from Stripe to Odoo.", groups='base.group_system') + #=== COMPUTE METHODS ===# + + def _compute_feature_support_fields(self): + """ Override of `payment` to enable additional features. """ + super()._compute_feature_support_fields() + self.filtered(lambda acq: acq.provider == 'stripe').update({ + 'support_manual_capture': True, + 'support_tokenization': True, + }) + #=== CONSTRAINT METHODS ===# @api.constrains('state', 'stripe_publishable_key', 'stripe_secret_key') diff --git a/addons/payment_test/data/payment_acquirer_data.xml b/addons/payment_test/data/payment_acquirer_data.xml index 33b6bbd9065..1f4c22fccdf 100644 --- a/addons/payment_test/data/payment_acquirer_data.xml +++ b/addons/payment_test/data/payment_acquirer_data.xml @@ -4,10 +4,6 @@ test - False - False - - True True diff --git a/addons/payment_test/models/payment_acquirer.py b/addons/payment_test/models/payment_acquirer.py index 6cb2265608f..580b80359a1 100644 --- a/addons/payment_test/models/payment_acquirer.py +++ b/addons/payment_test/models/payment_acquirer.py @@ -9,6 +9,8 @@ class PaymentAcquirer(models.Model): provider = fields.Selection(selection_add=[('test', 'Test')], ondelete={'test': 'set default'}) + #=== COMPUTE METHODS ===# + @api.depends('provider') def _compute_view_configuration_fields(self): """ Override of payment to hide the credentials page. @@ -18,6 +20,15 @@ class PaymentAcquirer(models.Model): super()._compute_view_configuration_fields() self.filtered(lambda acq: acq.provider == 'test').show_credentials_page = False + def _compute_feature_support_fields(self): + """ Override of `payment` to enable additional features. """ + super()._compute_feature_support_fields() + self.filtered(lambda acq: acq.provider == 'test').update({ + 'support_tokenization': True, + }) + + # === CONSTRAINT METHODS ===# + @api.constrains('state', 'provider') def _check_acquirer_state(self): if self.filtered(lambda a: a.provider == 'test' and a.state not in ('test', 'disabled')): diff --git a/addons/payment_transfer/data/payment_acquirer_data.xml b/addons/payment_transfer/data/payment_acquirer_data.xml index e66f0302aa4..277235aa29f 100644 --- a/addons/payment_transfer/data/payment_acquirer_data.xml +++ b/addons/payment_transfer/data/payment_acquirer_data.xml @@ -5,10 +5,6 @@ transfer enabled - False - False - - False diff --git a/addons/payment_transfer/models/payment_acquirer.py b/addons/payment_transfer/models/payment_acquirer.py index 5704b2d08b5..fba80b4ac71 100644 --- a/addons/payment_transfer/models/payment_acquirer.py +++ b/addons/payment_transfer/models/payment_acquirer.py @@ -19,7 +19,7 @@ class PaymentAcquirer(models.Model): :return: None """ super()._compute_view_configuration_fields() - self.filtered(lambda acq: acq.provider == 'transfer').write({ + self.filtered(lambda acq: acq.provider == 'transfer').update({ 'show_credentials_page': False, 'show_payment_icon_ids': False, 'show_pre_msg': False,