changeset a8550d684cac in modules/account_payment_stripe:default
details:
https://hg.tryton.org/modules/account_payment_stripe?cmd=changeset;node=a8550d684cac
description:
Add ir.message and use custom exceptions
issue3672
diffstat:
message.xml | 13 +++++++++++++
payment.py | 30 +++++++++++-------------------
tryton.cfg | 1 +
3 files changed, 25 insertions(+), 19 deletions(-)
diffs (100 lines):
diff -r 0a69068bf926 -r a8550d684cac message.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/message.xml Sat Dec 29 14:20:29 2018 +0100
@@ -0,0 +1,13 @@
+<?xml version="1.0"?>
+<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
+this repository contains the full copyright notices and license terms. -->
+<tryton>
+ <data group="1">
+ <record model="ir.message" id="msg_no_stripe_token">
+ <field name="text">To process payment "%(payment)s" you must set a
Stripe token or customer.</field>
+ </record>
+ <record model="ir.message" id="msg_stripe_receivable">
+ <field name="text">You cannot use stripe journal "%(journal)s" on
receivable payment "%(payment)s".</field>
+ </record>
+ </data>
+</tryton>
diff -r 0a69068bf926 -r a8550d684cac payment.py
--- a/payment.py Fri Nov 02 20:07:30 2018 +0100
+++ b/payment.py Sat Dec 29 14:20:29 2018 +0100
@@ -9,6 +9,7 @@
import stripe
+from trytond.i18n import gettext
from trytond.model import (
ModelSQL, ModelView, Workflow, DeactivableMixin, fields)
from trytond.pool import PoolMeta, Pool
@@ -19,6 +20,9 @@
from trytond.url import HOSTNAME
from trytond.wizard import Wizard, StateAction
+from trytond.modules.account_payment.exceptions import (
+ ProcessError, PaymentValidationError)
+
__all__ = ['Journal', 'Group', 'Payment', 'Account', 'Customer',
'Checkout', 'CheckoutPage']
logger = logging.getLogger(__name__)
@@ -46,14 +50,6 @@
class Group(metaclass=PoolMeta):
__name__ = 'account.payment.group'
- @classmethod
- def __setup__(cls):
- super(Group, cls).__setup__()
- cls._error_messages.update({
- 'no_stripe_token': ('No Stripe token found '
- 'for payment "%(payment)s".'),
- })
-
def process_stripe(self):
pool = Pool()
Payment = pool.get('account.payment')
@@ -66,9 +62,9 @@
payment.stripe_customer = customer
break
else:
- self.raise_user_error('no_stripe_token', {
- 'payment': payment.rec_name,
- })
+ raise ProcessError(
+ gettext('account_payment_stripe.msg_no_stripe_token',
+ payment=payment.rec_name))
Payment.save(self.payments)
Payment.__queue__.stripe_charge(self.payments)
@@ -181,10 +177,6 @@
cls.amount.depends.append('stripe_capture_needed')
cls.stripe_amount.states.update(cls.amount.states)
cls.stripe_amount.depends.extend(cls.amount.depends)
- cls._error_messages.update({
- 'stripe_receivable': ('Stripe journal "%(journal)s" '
- 'can only be used for receivable payment "%(payment)s".'),
- })
cls._buttons.update({
'stripe_checkout': {
'invisible': (~Eval('state', 'draft').in_(
@@ -305,10 +297,10 @@
def check_stripe_journal(self):
if (self.kind != 'receivable'
and self.journal.process_method == 'stripe'):
- self.raise_user_error('stripe_receivable', {
- 'journal': self.journal.rec_name,
- 'payment': self.rec_name,
- })
+ raise PaymentValidationError(
+ gettext('account_payment_stripe.msg_stripe_receivable',
+ journal=self.journal.rec_name,
+ payment=self.rec_name))
@classmethod
def create(cls, vlist):
diff -r 0a69068bf926 -r a8550d684cac tryton.cfg
--- a/tryton.cfg Fri Nov 02 20:07:30 2018 +0100
+++ b/tryton.cfg Sat Dec 29 14:20:29 2018 +0100
@@ -7,3 +7,4 @@
party
xml:
payment.xml
+ message.xml