Add ir.message and use custom exceptions
issue3672
This commit is contained in:
1 parent
f7ff79c558
commit
5f56b8f767
5 files changed
+36
-23
No files matched your search
@@ -0,0 +1,8 @@
|
||||
# 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.model.exceptions import ValidationError
|
||||
|
||||
|
||||
class DepositError(ValidationError):
|
||||
pass
|
||||
+7
-9
@@ -1,11 +1,14 @@
|
||||
# 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 ModelView, Workflow, fields
|
||||
from trytond.wizard import Wizard, StateView, StateTransition, Button
|
||||
from trytond.pyson import Eval
|
||||
from trytond.transaction import Transaction
|
||||
|
||||
from .exceptions import DepositError
|
||||
|
||||
__all__ = ['Invoice', 'InvoiceLine',
|
||||
'DepositRecall', 'DepositRecallStart']
|
||||
|
||||
@@ -16,11 +19,6 @@ class Invoice(metaclass=PoolMeta):
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
super(Invoice, cls).__setup__()
|
||||
cls._error_messages.update({
|
||||
'deposit_not_enough': (
|
||||
'The account "%(account)s" for party "%(party)s" '
|
||||
'has not enough deposit.'),
|
||||
})
|
||||
cls._buttons.update({
|
||||
'recall_deposit': {
|
||||
'invisible': Eval('state') != 'draft',
|
||||
@@ -106,10 +104,10 @@ class Invoice(metaclass=PoolMeta):
|
||||
|
||||
for party, account, sign in to_check:
|
||||
if not party.check_deposit(account, sign):
|
||||
cls.raise_user_error('deposit_not_enough', {
|
||||
'account': account.rec_name,
|
||||
'party': party.rec_name,
|
||||
})
|
||||
raise DepositError(
|
||||
gettext('account_deposit.msg_deposit_not_enough',
|
||||
account=account.rec_name,
|
||||
party=party.rec_name))
|
||||
|
||||
|
||||
class InvoiceLine(metaclass=PoolMeta):
|
||||
|
||||
+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_erase_party_deposit">
|
||||
<field name="text">You cannot erase party "%(party)s" while they have deposit at company "%(company)s".</field>
|
||||
</record>
|
||||
<record model="ir.message" id="msg_deposit_not_enough">
|
||||
<field name="text">The account "%(account)s" has not enough deposit from party "%(party)s".</field>
|
||||
</record>
|
||||
</data>
|
||||
</tryton>
|
||||
@@ -6,12 +6,15 @@ from sql import Null, Literal, For
|
||||
from sql.aggregate import Sum
|
||||
from sql.conditionals import Coalesce
|
||||
|
||||
from trytond.i18n import gettext
|
||||
from trytond.pool import PoolMeta, Pool
|
||||
from trytond.model import fields
|
||||
from trytond.pyson import Eval
|
||||
from trytond.transaction import Transaction
|
||||
from trytond.tools import grouped_slice, reduce_ids
|
||||
|
||||
from trytond.modules.party.exceptions import EraseError
|
||||
|
||||
|
||||
__all__ = ['Party', 'PartyErase']
|
||||
|
||||
@@ -135,18 +138,9 @@ class Party(metaclass=PoolMeta):
|
||||
class PartyErase(metaclass=PoolMeta):
|
||||
__name__ = 'party.erase'
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
super(PartyErase, cls).__setup__()
|
||||
cls._error_messages.update({
|
||||
'deposit': (
|
||||
'The party "%(party)s" can not be erased '
|
||||
'because he has deposit for the company "%(company)s".'),
|
||||
})
|
||||
|
||||
def check_erase_company(self, party, company):
|
||||
if party.deposit:
|
||||
self.raise_user_error('deposit', {
|
||||
'party': party.rec_name,
|
||||
'company': company.rec_name,
|
||||
})
|
||||
raise EraseError(
|
||||
gettext('account_deposit.msg_erase_party_deposit',
|
||||
party=party.rec_name,
|
||||
company=company.rec_name))
|
||||
+1
-1
@@ -20,4 +20,4 @@ xml:
|
||||
minimal_chart_pt.xml
|
||||
minimal_chart_ru.xml
|
||||
minimal_chart_sl.xml
|
||||
|
||||
message.xml
|
||||
Reference in new issue
Block a user