Include timesheet line name in access error when it is invoiced

This commit is contained in:
Cédric Krier
2023-05-09 14:05:40 +02:00
parent b69dae7205
commit 4f7504d9d0
2 changed files with 22 additions and 11 deletions
+7 -4
View File
@@ -3,11 +3,14 @@
this repository contains the full copyright notices and license terms. -->
<tryton>
<data grouped="1">
<record model="ir.message" id="msg_modify_invoiced_line">
<field name="text">You cannot modify an invoiced line.</field>
<record model="ir.message" id="msg_invoiced_timesheet_line_modify_duration">
<field name="text">You cannot modify the duration of timesheet line "%(line)s" because it has been invoiced.</field>
</record>
<record model="ir.message" id="msg_delete_invoiced_line">
<field name="text">You cannot delete an invoiced line.</field>
<record model="ir.message" id="msg_invoiced_timesheet_line_modify_work">
<field name="text">You cannot modify the work of timesheet line "%(line)s" because it has been invoiced.</field>
</record>
<record model="ir.message" id="msg_invoiced_timesheet_line_delete">
<field name="text">You cannot delete timesheet line "%(line)s" because it has been invoiced.</field>
</record>
<record model="ir.message" id="msg_product_missing_account_revenue">
<field name="text">To invoice work "%(work)s" you must define an account revenue for product "%(product)s".</field>
+15 -7
View File
@@ -26,13 +26,21 @@ class Line(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)):
raise AccessError(
gettext('project_invoice.msg_modify_invoiced_line'))
line = next(l for l in lines if l.invoice_line)
if 'duration' in values:
msg = 'msg_invoiced_timesheet_line_modify_duration'
else:
msg = 'msg_invoiced_timesheet_line_modify_work'
raise AccessError(gettext(
f'project_invoice.{msg}',
line=line.rec_name))
super().write(*args)
@classmethod
def delete(cls, records):
if any(r.invoice_line for r in records):
raise AccessError(
gettext('project_invoice.msg_delete_invoiced_line'))
super().delete(records)
def delete(cls, lines):
if any(r.invoice_line for r in lines):
line = next((l for l in lines if l.invoice_line))
raise AccessError(gettext(
'project_invoice.msg_invoiced_timesheet_line_delete',
line=line.rec_name))
super().delete(lines)