Add ir.message and use custom exceptions
issue3672
This commit is contained in:
+13
-14
@@ -6,14 +6,18 @@ import logging
|
||||
|
||||
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 @@ class InvoiceChorus(ModelSQL, ModelView, _SyntaxMixin, metaclass=PoolMeta):
|
||||
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 @@ class InvoiceChorus(ModelSQL, ModelView, _SyntaxMixin, metaclass=PoolMeta):
|
||||
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):
|
||||
|
||||
@@ -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
|
||||
+16
@@ -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>
|
||||
@@ -12,3 +12,4 @@ extras_depend:
|
||||
xml:
|
||||
account.xml
|
||||
party.xml
|
||||
message.xml
|
||||
|
||||
Reference in New Issue
Block a user