changeset 0b4702c77fce in modules/account_fr_chorus:default
details:
https://hg.tryton.org/modules/account_fr_chorus?cmd=changeset;node=0b4702c77fce
description:
Add ir.message and use custom exceptions
issue3672
diffstat:
account.py | 27 +++++++++++++--------------
exceptions.py | 8 ++++++++
message.xml | 16 ++++++++++++++++
tryton.cfg | 1 +
4 files changed, 38 insertions(+), 14 deletions(-)
diffs (106 lines):
diff -r 12c187e6dd54 -r 0b4702c77fce account.py
--- a/account.py Mon Oct 01 13:19:48 2018 +0200
+++ b/account.py Sat Dec 29 14:20:28 2018 +0100
@@ -6,14 +6,18 @@
import requests
+from trytond.i18n import gettext
from trytond.config import config
from trytond.model import ModelSQL, ModelView, Workflow, Unique, fields
+from trytond.model.exceptions import AccessError
from trytond.pool import PoolMeta, Pool
from trytond.pyson import Eval, Bool, If
from trytond.transaction import Transaction
from trytond.modules.company.model import CompanyValueMixin
+from .exceptions import InvoiceChorusValidationError
+
CERT = (
config.get('account_fr_chorus', 'certificate'),
config.get('account_fr_chorus', 'privatekey'))
@@ -137,16 +141,9 @@
t = cls.__table__()
cls._sql_constraints = [
('invoice_unique', Unique(t, t.invoice),
- "Invoice can be registered only once for Chorus."),
+ 'account_fr_chorus.msg_invoice_unique'),
]
- cls._error_messages.update({
- 'no_siret': 'The address "%(address)s" is missing a SIRET.',
- 'delete_sent': (
- 'The Chorus invoice "%(invoice)s" can not be deleted '
- 'once sent.'),
- })
-
@classmethod
def default_syntax(cls):
pool = Pool()
@@ -163,17 +160,19 @@
record.invoice.invoice_address]
for address in addresses:
if not address.siret:
- cls.raise_user_error('no_siret', {
- 'address': address.rec_name,
- })
+ raise InvoiceChorusValidationError(
+ gettext('account_fr_chorus'
+ '.msg_invoice_address_no_siret',
+ invoice=record.invoice.rec_name,
+ address=address.rec_name))
@classmethod
def delete(cls, records):
for record in records:
if record.number:
- cls.raise_user_error('delete_sent', {
- 'invoice': record.invoice.rec_name,
- })
+ raise AccessError(
+ gettext('account_fr_chorus.msg_invoice_delete_sent',
+ invoice=record.invoice.rec_name))
super(InvoiceChorus, cls).delete(records)
def _send_context(self):
diff -r 12c187e6dd54 -r 0b4702c77fce exceptions.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/exceptions.py Sat Dec 29 14:20:28 2018 +0100
@@ -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 InvoiceChorusValidationError(ValidationError):
+ pass
diff -r 12c187e6dd54 -r 0b4702c77fce message.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/message.xml Sat Dec 29 14:20:28 2018 +0100
@@ -0,0 +1,16 @@
+<?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_invoice_unique">
+ <field name="text">You can create only one Chorus invoice per
invoice.</field>
+ </record>
+ <record model="ir.message" id="msg_invoice_address_no_siret">
+ <field name="text">To create a Chorus invoice for "%(invoice)s",
you must set a SIRET on address "%(address)s".</field>
+ </record>
+ <record model="ir.message" id="msg_invoice_delete_sent">
+ <field name="text">You cannot delete Chorus invoice "%(invoice)s"
because it is sent.</field>
+ </record>
+ </data>
+</tryton>
diff -r 12c187e6dd54 -r 0b4702c77fce tryton.cfg
--- a/tryton.cfg Mon Oct 01 13:19:48 2018 +0200
+++ b/tryton.cfg Sat Dec 29 14:20:28 2018 +0100
@@ -12,3 +12,4 @@
xml:
account.xml
party.xml
+ message.xml