Add ir.message and use custom exceptions
issue3672
This commit is contained in:
1 parent
dec4c422b7
commit
ce524576a4
3 files changed
+25
-19
No files matched your search
+13
@@ -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>
|
||||
+11
-19
@@ -9,6 +9,7 @@ from operator import attrgetter
|
||||
|
||||
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.transaction import Transaction
|
||||
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 Journal(metaclass=PoolMeta):
|
||||
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 @@ class Group(metaclass=PoolMeta):
|
||||
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 @@ class Payment(metaclass=PoolMeta):
|
||||
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 @@ class Payment(metaclass=PoolMeta):
|
||||
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):
|
||||
|
||||
@@ -7,3 +7,4 @@ depends:
|
||||
party
|
||||
xml:
|
||||
payment.xml
|
||||
message.xml
|
||||
Reference in new issue
Block a user