Add ir.message and use custom exceptions

issue3672
This commit is contained in:
Cédric Krier committed 2018-12-29 14:20:28 +01:00
1 parent 8dbb600335
commit e73aa09821
4 files changed
+53 -20

No files matched your search

+12
View File
@@ -0,0 +1,12 @@
# 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
class CreditLimitError(UserError):
pass
class CreditLimitWarning(UserWarning):
pass
+13
View File
@@ -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_party_credit_limit_amount">
<field name="text">Party "%(party)s" has reached their credit limit of %(limit)s.</field>
</record>
<record model="ir.message" id="msg_party_credit_limit_dunning">
<field name="text">Party "%(party)s" has reached the credit limit level of %(dunning)s.</field>
</record>
</data>
</tryton>
+27 -20
View File
@@ -1,6 +1,7 @@
# 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 import backend
from trytond.i18n import gettext
from trytond.model import ModelSQL, fields
from trytond.pool import Pool, PoolMeta
from trytond.transaction import Transaction
@@ -8,6 +9,8 @@ from trytond.pyson import Eval
from trytond.tools.multivalue import migrate_property
from trytond.modules.company.model import CompanyValueMixin
from .exceptions import CreditLimitError, CreditLimitWarning
__all__ = ['Party', 'PartyCreditLimitAmount']
@@ -27,16 +30,6 @@ class Party(metaclass=PoolMeta):
credit_limit_amounts = fields.One2Many(
'party.party.credit_limit_amount', 'party', "Credit Limit Amounts")
@classmethod
def __setup__(cls):
super(Party, cls).__setup__()
cls._error_messages.update({
'credit_limit_amount': (
'"%s" has reached the credit limit amount (%s)'),
'credit_limit_dunning': (
'"%s" has reached the dunning credit limit (%s)'),
})
@classmethod
def default_credit_limit_amount(cls, **pattern):
pool = Pool()
@@ -70,6 +63,7 @@ class Party(metaclass=PoolMeta):
Group = pool.get('res.group')
Company = pool.get('company.company')
Lang = pool.get('ir.lang')
Warning = pool.get('res.user.warning')
if self.credit_limit_amount is None:
return
@@ -92,14 +86,20 @@ class Party(metaclass=PoolMeta):
if self.credit_limit_amount < self.credit_amount + amount:
company = Company(Transaction().context.get('company'))
lang = Lang.get()
limit = lang.currency(self.credit_limit_amount, company.currency)
if not in_group():
self.raise_user_error('credit_limit_amount',
(self.rec_name, lang.currency(
self.credit_limit_amount, company.currency)))
raise CreditLimitError(
gettext('account_credit_limit'
'.msg_party_credit_limit_amount',
party=self.rec_name,
limit=limit))
warning_name = 'credit_limit_amount_%s' % origin
self.raise_user_warning(warning_name, 'credit_limit_amount',
(self.rec_name, lang.currency(
self.credit_limit_amount, company.currency)))
if Warning.check(warning_name):
raise CreditLimitWarning(warning_name,
gettext('account_credit_limit'
'.msg_party_credit_limit_amount',
party=self.rec_name,
limit=limit))
if Dunning:
dunnings = Dunning.search([
@@ -110,11 +110,18 @@ class Party(metaclass=PoolMeta):
if dunnings:
dunning = dunnings[0]
if not in_group():
self.raise_user_error('credit_limit_dunning',
(self.rec_name, dunning.rec_name))
raise CreditLimitError(
gettext('account_credit_limit'
'.msg_party_credit_limit_dunning',
party=self.rec_name,
dunning=dunning.rec_name))
warning_name = 'credit_limit_dunning_%s' % origin
self.raise_user_warning(warning_name, 'credit_limit_dunning',
(self.rec_name, dunning.rec_name))
if Warning.check(warning_name):
raise CreditLimitWarning(warning_name,
gettext('account_credit_limit'
'.msg_party_credit_limit_dunning',
party=self.rec_name,
dunning=dunning.rec_name))
def get_credit_limit_digits(self, name):
pool = Pool()
+1
View File
@@ -10,3 +10,4 @@ extras_depend:
xml:
account.xml
party.xml
message.xml