Add ir.message and use UserWarning/UserError

This commit is contained in:
?ngel ?lvarez 2019-01-06 10:07:35 +01:00
parent 5796336dce
commit 1ab00e6c44
3 changed files with 30 additions and 28 deletions

View File

@ -4,28 +4,14 @@ from trytond.transaction import Transaction
from trytond.pool import Pool, PoolMeta
from sql.aggregate import Sum
from sql.functions import Round
from trytond.i18n import gettext
from trytond.exceptions import UserError
__all__ = ['Invoice']
class Invoice(metaclass=PoolMeta):
__name__ = 'account.invoice'
@classmethod
def __setup__(cls):
super(Invoice, cls).__setup__()
cls._error_messages.update({
'invalid_number_date': 'You are trying to create '
'%(invoice_number)s invoice on date %(invoice_date)s. '
'There are %(invoice_count)d invoices after this date:'
'\n\n%(invoices)s',
'not_same_dates': 'You are trying to validate an invoice '
'where invoice date (%(invoice_date)s) and accounting '
'date (%(accounting_date)s) are different. That is not '
'permitted, because of invoice number and date '
'correlation.',
})
@classmethod
def validate(cls, invoices):
super(Invoice, cls).validate(invoices)
@ -45,12 +31,12 @@ class Invoice(metaclass=PoolMeta):
languages = Lang.search([('code', '=', 'en')], limit=1)
language, = languages
self.raise_user_error('not_same_dates', {
'invoice_date': Lang.strftime(self.invoice_date, language.code,
language.date),
'accounting_date': Lang.strftime(self.accounting_date,
language.code, language.date),
})
raise UserError(gettext(
'account_invoice_consecutive.not_same_dates',
invoice_date'=Lang.strftime(self.invoice_date,
language.code, language.date),
accounting_date= Lang.strftime(self.accounting_date,
language.code, language.date)))
@classmethod
def set_number(cls, invoices):
@ -110,9 +96,9 @@ class Invoice(metaclass=PoolMeta):
'date': language.strftime(inv.invoice_date),
} for inv in invs]
info = '\n'.join(info)
cls.raise_user_error('invalid_number_date', {
'invoice_number': invoice.number,
'invoice_date': language.strftime(invoice.invoice_date),
'invoice_count': len(invs),
'invoices': info,
})
raise UserError(gettext(
'account_invoice_consecutiveinvalid_number_date',
invoice_number=invoice.number,
invoice_date=language.strftime(invoice.invoice_date),
invoice_count=len(invs),
invoices=info))

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_number_date">
<field name="text">You are trying to create %(invoice_number)s invoice on date %(invoice_date)s. There are %(invoice_count)d invoices after this date:\n\n%(invoices)s.</field>
</record>
<record model="ir.message" id="not_same_dates">
<field name="text">You are trying to validate an invoice where invoice date (%(invoice_date)s) and accounting date (%(accounting_date)s) are different. That is not permitted, because of invoice number and date correlation.</field>
</record>
</data>
</tryton>

View File

@ -12,3 +12,6 @@ depends:
account_invoice
extras_depend:
account_invoice_multisequence
xml:
message.xml