Add ir.message and use custom exceptions
issue3672
This commit is contained in:
+8
-11
@@ -8,6 +8,7 @@ from sql.conditionals import Case, Coalesce
|
||||
from sql.functions import Abs
|
||||
|
||||
from trytond import backend
|
||||
from trytond.i18n import gettext
|
||||
from trytond.pool import Pool, PoolMeta
|
||||
from trytond.model import ModelSQL, ModelView, fields
|
||||
from trytond.pyson import Eval, If, Bool
|
||||
@@ -17,6 +18,7 @@ from trytond.transaction import Transaction
|
||||
from trytond.tools.multivalue import migrate_property
|
||||
from trytond.modules.company.model import CompanyValueMixin
|
||||
|
||||
from .exceptions import BlockedWarning
|
||||
from .payment import KINDS
|
||||
|
||||
__all__ = ['MoveLine', 'PayLine', 'PayLineAskJournal',
|
||||
@@ -202,13 +204,6 @@ class PayLine(Wizard):
|
||||
])
|
||||
pay = StateAction('account_payment.act_payment_form')
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
super(PayLine, cls).__setup__()
|
||||
cls._error_messages.update({
|
||||
'blocked': 'The Line "%(line)s" is blocked.',
|
||||
})
|
||||
|
||||
def _get_journals(self):
|
||||
journals = {}
|
||||
for journal in getattr(self.ask_journal, 'journals', []):
|
||||
@@ -287,6 +282,7 @@ class PayLine(Wizard):
|
||||
pool = Pool()
|
||||
Line = pool.get('account.move.line')
|
||||
Payment = pool.get('account.payment')
|
||||
Warning = pool.get('res.user.warning')
|
||||
|
||||
lines = Line.browse(Transaction().context['active_ids'])
|
||||
journals = self._get_journals()
|
||||
@@ -294,10 +290,11 @@ class PayLine(Wizard):
|
||||
payments = []
|
||||
for line in lines:
|
||||
if line.payment_blocked:
|
||||
self.raise_user_warning('blocked:%s' % line,
|
||||
'blocked', {
|
||||
'line': line.rec_name,
|
||||
})
|
||||
warning_name = 'blocked:%s' % line
|
||||
if Warning.check(warning_name):
|
||||
raise BlockedWarning(warning_name,
|
||||
gettext('account_payment.msg_pay_line_blocked',
|
||||
line=line.rec_name))
|
||||
payments.append(self.get_payment(line, journals))
|
||||
Payment.save(payments)
|
||||
return action, {
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
|
||||
from trytond.exceptions import UserError, UserWarning
|
||||
from trytond.model.exceptions import ValidationError
|
||||
|
||||
|
||||
class ProcessError(UserError):
|
||||
pass
|
||||
|
||||
|
||||
class OverpayWarning(UserWarning):
|
||||
pass
|
||||
|
||||
|
||||
class PaymentValidationError(ValidationError):
|
||||
pass
|
||||
|
||||
|
||||
class BlockedWarning(UserWarning):
|
||||
pass
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
<?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_payment_delete_draft">
|
||||
<field name="text">To delete payment "%(payment)s" you must reset it to draft state.</field>
|
||||
</record>
|
||||
<record model="ir.message" id="msg_payment_overpay">
|
||||
<field name="text">Payment "%(payment)s" overpays line "%(line)s".</field>
|
||||
</record>
|
||||
<record model="ir.message" id="msg_erase_party_pending_payment">
|
||||
<field name="text">You cannot erase party "%(party)s" while they have pending payments with company "%(company)s".</field>
|
||||
</record>
|
||||
<record model="ir.message" id="msg_pay_line_blocked">
|
||||
<field name="text">Line "%(line)s" is blocked for payment.</field>
|
||||
</record>
|
||||
</data>
|
||||
</tryton>
|
||||
@@ -1,8 +1,10 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
from trytond.i18n import gettext
|
||||
from trytond.pool import PoolMeta, Pool
|
||||
from trytond.model import ModelSQL, fields
|
||||
from trytond.modules.company.model import CompanyValueMixin
|
||||
from trytond.modules.party.exceptions import EraseError
|
||||
|
||||
__all__ = ['Party', 'PartyPaymentDirectDebit', 'PartyReplace', 'PartyErase']
|
||||
payment_direct_debit = fields.Boolean(
|
||||
@@ -42,16 +44,6 @@ class PartyReplace(metaclass=PoolMeta):
|
||||
class PartyErase(metaclass=PoolMeta):
|
||||
__name__ = 'party.erase'
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
super(PartyErase, cls).__setup__()
|
||||
cls._error_messages.update({
|
||||
'pending_payment': (
|
||||
'The party "%(party)s" can not be erased '
|
||||
'because he has pending payments '
|
||||
'for the company "%(company)s".'),
|
||||
})
|
||||
|
||||
def check_erase_company(self, party, company):
|
||||
pool = Pool()
|
||||
Payment = pool.get('account.payment')
|
||||
@@ -62,7 +54,7 @@ class PartyErase(metaclass=PoolMeta):
|
||||
('state', 'not in', ['succeeded', 'failed']),
|
||||
])
|
||||
if payments:
|
||||
self.raise_user_error('pending_payment', {
|
||||
'party': party.rec_name,
|
||||
'company': company.rec_name,
|
||||
})
|
||||
raise EraseError(
|
||||
gettext('account_payment.msg_erase_party_pending_payment',
|
||||
party=party.rec_name,
|
||||
company=company.rec_name))
|
||||
|
||||
+13
-18
@@ -2,13 +2,17 @@
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
from itertools import groupby
|
||||
|
||||
from trytond.i18n import gettext
|
||||
from trytond.model import Workflow, ModelView, ModelSQL, fields
|
||||
from trytond.model.exceptions import AccessError
|
||||
from trytond.pyson import Eval, If
|
||||
from trytond.rpc import RPC
|
||||
from trytond.transaction import Transaction
|
||||
from trytond.wizard import Wizard, StateView, StateAction, Button
|
||||
from trytond.pool import Pool
|
||||
|
||||
from .exceptions import OverpayWarning
|
||||
|
||||
__all__ = ['Journal', 'Group', 'Payment',
|
||||
'ProcessPaymentStart', 'ProcessPayment']
|
||||
|
||||
@@ -183,10 +187,6 @@ class Payment(Workflow, ModelSQL, ModelView):
|
||||
def __setup__(cls):
|
||||
super(Payment, cls).__setup__()
|
||||
cls._order.insert(0, ('date', 'DESC'))
|
||||
cls._error_messages.update({
|
||||
'delete_draft': ('Payment "%s" must be in draft before '
|
||||
'deletion.'),
|
||||
})
|
||||
cls._transitions |= set((
|
||||
('draft', 'approved'),
|
||||
('approved', 'processing'),
|
||||
@@ -290,7 +290,9 @@ class Payment(Workflow, ModelSQL, ModelView):
|
||||
def delete(cls, payments):
|
||||
for payment in payments:
|
||||
if payment.state != 'draft':
|
||||
cls.raise_user_error('delete_draft', (payment.rec_name))
|
||||
raise AccessError(
|
||||
gettext('account_payment.msg_payment_delete_draft',
|
||||
payment=payment.rec_name))
|
||||
super(Payment, cls).delete(payments)
|
||||
|
||||
@classmethod
|
||||
@@ -350,14 +352,6 @@ class ProcessPayment(Wizard):
|
||||
])
|
||||
process = StateAction('account_payment.act_payment_group_form')
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
super(ProcessPayment, cls).__setup__()
|
||||
cls._error_messages.update({
|
||||
'overpay': 'The Payment "%(payment)s" overpays '
|
||||
'the Line "%(line)s".',
|
||||
})
|
||||
|
||||
def _group_payment_key(self, payment):
|
||||
return (('journal', payment.journal.id), ('kind', payment.kind))
|
||||
|
||||
@@ -369,15 +363,16 @@ class ProcessPayment(Wizard):
|
||||
def do_process(self, action):
|
||||
pool = Pool()
|
||||
Payment = pool.get('account.payment')
|
||||
Warning = pool.get('res.user.warning')
|
||||
payments = Payment.browse(Transaction().context['active_ids'])
|
||||
|
||||
for payment in payments:
|
||||
if payment.line and payment.line.payment_amount < 0:
|
||||
self.raise_user_warning(str(payment),
|
||||
'overpay', {
|
||||
'payment': payment.rec_name,
|
||||
'line': payment.line.rec_name,
|
||||
})
|
||||
if Warning.check(str(payment)):
|
||||
raise OverpayWarning(str(payment),
|
||||
gettext('account_payment.msg_payment_overpay',
|
||||
payment=payment.rec_name,
|
||||
line=payment.line.rec_name))
|
||||
|
||||
groups = []
|
||||
payments = sorted(payments, key=self._group_payment_key)
|
||||
|
||||
@@ -127,4 +127,4 @@ Try to pay blocked line::
|
||||
>>> pay_line.execute('start') # doctest: +IGNORE_EXCEPTION_DETAIL
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
UserWarning: ...
|
||||
BlockedWarning: ...
|
||||
|
||||
@@ -13,3 +13,4 @@ xml:
|
||||
payment.xml
|
||||
account.xml
|
||||
party.xml
|
||||
message.xml
|
||||
|
||||
Reference in New Issue
Block a user