Add ir.message and use UserWarning/UserError

This commit is contained in:
?ngel ?lvarez 2019-01-10 15:12:00 +01:00
parent 8a1a916d54
commit c28daeb58e
4 changed files with 21 additions and 20 deletions

View file

@ -7,6 +7,8 @@ from trytond.pool import Pool, PoolMeta
from trytond.pyson import Eval
from trytond.transaction import Transaction
from trytond.tools import decistmt
from trytond.i18n import gettext
from trytond.exceptions import UserError
__all__ = ['Manager', 'Agent']
@ -22,15 +24,6 @@ class Manager(ModelSQL, ModelView):
], depends=['agent'])
company = fields.Many2One('company.company', 'Company', required=True)
@classmethod
def __setup__(cls):
super(Manager, cls).__setup__()
cls._error_messages.update({
'invalid_formula': ('Invalid formula "%(formula)s" in '
'commission manager "%(line)s" with exception '
'"%(exception)s".'),
})
@staticmethod
def default_company():
return Transaction().context.get('company')

View file

@ -1,6 +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.pool import PoolMeta
from trytond.i18n import gettext
from trytond.exceptions import UserError
__all__ = ['InvoiceLine']
@ -9,14 +11,6 @@ class InvoiceLine(metaclass=PoolMeta):
__name__ = 'account.invoice.line'
__metaclass__ = PoolMeta
@classmethod
def __setup__(cls):
super(InvoiceLine, cls).__setup__()
cls._error_messages.update({
'manager_without_plan': ('No commission plan assigned '
'for manager "%s"'),
})
@property
def agent_plans_used(self):
used = super(InvoiceLine, self).agent_plans_used
@ -26,8 +20,8 @@ class InvoiceLine(metaclass=PoolMeta):
manager = self.invoice.agent.manager
if not manager.agent.plan:
self.raise_user_error('manager_without_plan', {
'manager': manager.rec_name,
})
raise UserError(gettext(
'commission_manager.manager_without_plan',
manager=manager.rec_name))
used.append((manager.agent, manager.agent.plan))
return used

13
message.xml Normal file
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="invalid_formula">
<field name="text">Invalid formula "%(formula)s" in commission manager "%(line)s" with exception "%(exception)s".</field>
</record>
<record model="ir.message" id="manager_without_plan">
<field name="text">No commission plan assigned for manager "%(manager)s"</field>
</record>
</data>
</tryton>

View file

@ -5,3 +5,4 @@ depends:
commission
xml:
commission.xml
message.xml