diff --git a/addons/payment_stripe/i18n/payment_stripe.pot b/addons/payment_stripe/i18n/payment_stripe.pot index 27219e15f1c..7802c3d3588 100644 --- a/addons/payment_stripe/i18n/payment_stripe.pot +++ b/addons/payment_stripe/i18n/payment_stripe.pot @@ -6,8 +6,8 @@ msgid "" msgstr "" "Project-Id-Version: Odoo Server 15.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2022-01-11 09:46+0000\n" -"PO-Revision-Date: 2022-01-11 09:46+0000\n" +"POT-Creation-Date: 2022-02-22 14:45+0000\n" +"PO-Revision-Date: 2022-02-22 14:45+0000\n" "Last-Translator: \n" "Language-Team: \n" "MIME-Version: 1.0\n" @@ -191,6 +191,14 @@ msgid "" "You cannot create a Stripe Webhook if your Stripe Secret Key is not set." msgstr "" +#. module: payment_stripe +#: code:addons/payment_stripe/models/payment_acquirer.py:0 +#, python-format +msgid "" +"You cannot set the acquirer to Test Mode while it is linked with your Stripe" +" account." +msgstr "" + #. module: payment_stripe #: code:addons/payment_stripe/models/payment_acquirer.py:0 #, python-format diff --git a/addons/payment_stripe/models/payment_acquirer.py b/addons/payment_stripe/models/payment_acquirer.py index 1eb84d28dfc..01d26006c99 100644 --- a/addons/payment_stripe/models/payment_acquirer.py +++ b/addons/payment_stripe/models/payment_acquirer.py @@ -6,7 +6,7 @@ import uuid import requests from werkzeug.urls import url_join, url_encode -from odoo import _, fields, models +from odoo import _, api, fields, models from odoo.exceptions import ValidationError from odoo.addons.payment_stripe.const import API_VERSION, PROXY_URL, WEBHOOK_HANDLED_EVENTS @@ -32,6 +32,41 @@ class PaymentAcquirer(models.Model): "authenticate the messages sent from Stripe to Odoo.", groups='base.group_system') + #=== CONSTRAINT METHODS ===# + + @api.constrains('state', 'stripe_publishable_key', 'stripe_secret_key') + def _check_state_of_connected_account_is_never_test(self): + """ Check that the acquirer of a connected account can never been set to 'test'. + + This constraint is defined in the present module to allow the export of the translation + string of the `ValidationError` that can be raised by the internal module responsible for + Stripe Connect, although this constraint depends on a field that is defined in that external + module. + Additionally, having the field defined in the external module prevents from using it + as a trigger for this constraint. This is however not a problem because the field `state` is + used as trigger, and we always write on `state` when we write on the internal field. + + :return: None + """ + for acquirer in self: + if acquirer.state == 'test' and acquirer._stripe_has_connected_account(): + raise ValidationError(_( + "You cannot set the acquirer to Test Mode while it is linked with your Stripe " + "account." + )) + + def _stripe_has_connected_account(self): + """ Return whether the acquirer is linked to a connected Stripe account. + + Note: This method is overridden by the internal module responsible for Stripe Connect. + Note: self.ensure_one() + + :return: Whether the acquirer is linked to a connected Stripe account + :rtype: bool + """ + self.ensure_one() + return False + # === ACTION METHODS === # def action_stripe_connect_account(self, menu_id=None): diff --git a/addons/payment_stripe/views/payment_views.xml b/addons/payment_stripe/views/payment_views.xml index f43cc51af21..882dfcd7e1d 100644 --- a/addons/payment_stripe/views/payment_views.xml +++ b/addons/payment_stripe/views/payment_views.xml @@ -9,7 +9,7 @@ + attrs="{'invisible': ['|', '|', ('provider', '!=', 'stripe'), ('stripe_secret_key', '!=', False), ('stripe_publishable_key', '!=', False)]}">