Include timesheet line name in access error when it is invoiced
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user