changeset d896dc60c010 in modules/account_product:default
details:
https://hg.tryton.org/modules/account_product?cmd=changeset;node=d896dc60c010
description:
Add ir.message and use custom exceptions
issue3672
diffstat:
exceptions.py | 12 ++++++++++++
message.xml | 13 +++++++++++++
product.py | 37 +++++++++++++------------------------
tryton.cfg | 1 +
4 files changed, 39 insertions(+), 24 deletions(-)
diffs (130 lines):
diff -r d59b4c241e0e -r d896dc60c010 exceptions.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/exceptions.py Sat Dec 29 14:20:29 2018 +0100
@@ -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
+
+
+class AccountError(UserError):
+ pass
+
+
+class TaxError(UserError):
+ pass
diff -r d59b4c241e0e -r d896dc60c010 message.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/message.xml Sat Dec 29 14:20:29 2018 +0100
@@ -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_missing_account">
+ <field name="text">There is no "%(field)s" defined for
"%(name)s".</field>
+ </record>
+ <record model="ir.message" id="msg_missing_taxes">
+ <field name="text">There is no account category defined on product
"%(name)s".</field>
+ </record>
+ </data>
+</tryton>
diff -r d59b4c241e0e -r d896dc60c010 product.py
--- a/product.py Wed Nov 07 15:57:29 2018 +0100
+++ b/product.py Sat Dec 29 14:20:29 2018 +0100
@@ -4,6 +4,7 @@
from sql import Null
+from trytond.i18n import gettext
from trytond.model import ModelSQL, fields
from trytond.pyson import Eval, Or, Bool
from trytond import backend
@@ -13,6 +14,8 @@
from trytond.modules.company.model import (
CompanyMultiValueMixin, CompanyValueMixin)
+from .exceptions import AccountError, TaxError
+
__all__ = ['Category', 'CategoryAccount',
'CategoryCustomerTax', 'CategorySupplierTax',
'Template', 'Product', 'account_used', 'template_property',
@@ -33,10 +36,10 @@
if not account and not Transaction().readonly:
field = (
self.fields_get([field_string])[field_string]['string'])
- self.raise_user_error('missing_account', {
- 'field': field,
- 'name': self.rec_name,
- })
+ raise AccountError(
+ gettext('account_product.msg_missing_account',
+ field=field,
+ name=self.rec_name))
if account:
return account.current()
return wrapper
@@ -130,10 +133,6 @@
@classmethod
def __setup__(cls):
super(Category, cls).__setup__()
- cls._error_messages.update({
- 'missing_account': ('There is no '
- '"%(field)s" defined on the category "%(name)s"'),
- })
cls.parent.domain = [
('accounting', '=', Eval('accounting', False)),
cls.parent.domain or []]
@@ -290,16 +289,6 @@
('accounting', '=', True),
])
- @classmethod
- def __setup__(cls):
- super(Template, cls).__setup__()
- cls._error_messages.update({
- 'missing_account': ('There is no '
- '"%(field)s" defined on the product "%(name)s"'),
- 'missing_taxes': ('There is no account category defined '
- 'on the product "%(name)s"'),
- })
-
def get_account(self, name, **pattern):
if self.account_category:
return self.account_category.get_account(name, **pattern)
@@ -330,9 +319,9 @@
if Transaction().readonly:
taxes = []
else:
- self.raise_user_error('missing_taxes', {
- 'name': self.rec_name,
- })
+ raise TaxError(
+ gettext('account_product.msg_missing_taxes',
+ name=self.rec_name))
return taxes
@property
@@ -347,9 +336,9 @@
if Transaction().readonly:
taxes = []
else:
- self.raise_user_error('missing_taxes', {
- 'name': self.rec_name,
- })
+ raise TaxError(
+ gettext('account_product.msg_missing_taxes',
+ name=self.rec_name))
return taxes
diff -r d59b4c241e0e -r d896dc60c010 tryton.cfg
--- a/tryton.cfg Wed Nov 07 15:57:29 2018 +0100
+++ b/tryton.cfg Sat Dec 29 14:20:29 2018 +0100
@@ -9,3 +9,4 @@
product.xml
configuration.xml
account.xml
+ message.xml