Add ir.message and use custom exceptions

issue3672
This commit is contained in:
Cédric Krier committed 2018-12-29 14:20:29 +01:00
1 parent 8a5c46616d
commit 24bb7c2081
5 files changed
+60 -22

No files matched your search

+7
View File
@@ -0,0 +1,7 @@
# 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 InvoicingError(UserError):
pass
+22
View File
@@ -0,0 +1,22 @@
<?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_modify_invoiced_line">
<field name="text">You cannot modify an invoiced line.</field>
</record>
<record model="ir.message" id="msg_delete_invoiced_line">
<field name="text">You cannot delete an invoiced line.</field>
</record>
<record model="ir.message" id="msg_missing_product">
<field name="text">There is no product on work "%(work)s".</field>
</record>
<record model="ir.message" id="msg_missing_list_price">
<field name="text">There is no list price on work "%(work)s".</field>
</record>
<record model="ir.message" id="msg_missing_party">
<field name="text">There is no party on work "%(work)s".</field>
</record>
</data>
</tryton>
+6 -10
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.i18n import gettext
from trytond.model import fields
from trytond.model.exceptions import AccessError
from trytond.pool import PoolMeta
@@ -12,14 +14,6 @@ class TimesheetLine(metaclass=PoolMeta):
invoice_line = fields.Many2One('account.invoice.line', 'Invoice Line',
readonly=True)
@classmethod
def __setup__(cls):
super(TimesheetLine, cls).__setup__()
cls._error_messages.update({
'modify_invoiced_line': 'You can not modify invoiced line.',
'delete_invoiced_line': 'You can not delete invoiced line.',
})
@classmethod
def copy(cls, records, default=None):
if default is None:
@@ -35,11 +29,13 @@ class TimesheetLine(metaclass=PoolMeta):
for lines, values in zip(actions, actions):
if (('duration' in values or 'work' in values)
and any(l.invoice_line for l in lines)):
cls.raise_user_error('modify_invoiced_line')
raise AccessError(
gettext('project_invoice.msg_modify_invoiced_line'))
super(TimesheetLine, cls).write(*args)
@classmethod
def delete(cls, records):
if any(r.invoice_line for r in records):
cls.raise_user_error('delete_invoiced_line')
raise AccessError(
gettext('project_invoice.msg_delete_invoiced_line'))
super(TimesheetLine, cls).delete(records)
+1
View File
@@ -12,3 +12,4 @@ xml:
project.xml
work.xml
timesheet.xml
message.xml
+24 -12
View File
@@ -11,6 +11,7 @@ from sql import Null
from sql.aggregate import Sum
from sql.operators import Concat
from trytond.i18n import gettext
from trytond.model import ModelSQL, ModelView, fields
from trytond.pool import PoolMeta
from trytond.pyson import Eval, Bool, PYSONEncoder
@@ -19,6 +20,8 @@ from trytond.transaction import Transaction
from trytond.wizard import Wizard, StateAction
from trytond.tools import reduce_ids, grouped_slice
from .exceptions import InvoicingError
__all__ = ['Work', 'WorkInvoicedProgress', 'OpenInvoice']
@@ -79,11 +82,6 @@ class Work(metaclass=PoolMeta):
'duration_to_invoice']
},
})
cls._error_messages.update({
'missing_product': 'There is no product on work "%s".',
'missing_list_price': 'There is no list price on work "%s".',
'missing_party': 'There is no party on work "%s".',
})
@staticmethod
def default_project_invoice_method():
@@ -407,7 +405,9 @@ class Work(metaclass=PoolMeta):
journal = None
if not self.party:
self.raise_user_error('missing_party', (self.rec_name,))
raise InvoicingError(
gettext('project_invoice.msg_missing_party',
work=self.rec_name))
return Invoice(
company=self.company,
@@ -485,9 +485,13 @@ class Work(metaclass=PoolMeta):
and self.effort_hours
and self.state == 'done'):
if not self.product:
self.raise_user_error('missing_product', (self.rec_name,))
raise InvoicingError(
gettext('project_invoice.msg_missing_product',
work=self.rec_name))
elif self.list_price is None:
self.raise_user_error('missing_list_price', (self.rec_name,))
raise InvoicingError(
gettext('project_invoice.msg_missing_list_price',
work=self.rec_name))
return [{
'product': self.product,
'quantity': self.effort_hours,
@@ -516,9 +520,13 @@ class Work(metaclass=PoolMeta):
hour, quantity, self.product.default_uom)
if quantity > 0:
if not self.product:
self.raise_user_error('missing_product', (self.rec_name,))
raise InvoicingError(
gettext('project_invoice.msg_missing_product',
work=self.rec_name))
elif self.list_price is None:
self.raise_user_error('missing_list_price', (self.rec_name,))
raise InvoicingError(
gettext('project_invoice.msg_missing_list_price',
work=self.rec_name))
invoiced_progress = InvoicedProgress(work=self,
effort_duration=datetime.timedelta(hours=quantity))
return [{
@@ -540,9 +548,13 @@ class Work(metaclass=PoolMeta):
if (self.timesheet_works
and any(tw.timesheet_lines for tw in self.timesheet_works)):
if not self.product:
self.raise_user_error('missing_product', (self.rec_name,))
raise InvoicingError(
gettext('project_invoice.msg_missing_product',
work=self.rec_name))
elif self.list_price is None:
self.raise_user_error('missing_list_price', (self.rec_name,))
raise InvoicingError(
gettext('project_invoice.msg_missing_list_price',
work=self.rec_name))
return [{
'product': self.product,
'quantity': l.hours,