From 4f7504d9d013cc92c13fb3d5512ae42cd3b18fff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 9 May 2023 14:05:40 +0200 Subject: [PATCH] Include timesheet line name in access error when it is invoiced --- modules/project_invoice/message.xml | 11 +++++++---- modules/project_invoice/timesheet.py | 22 +++++++++++++++------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/modules/project_invoice/message.xml b/modules/project_invoice/message.xml index 211012405d..50a76e1fdc 100644 --- a/modules/project_invoice/message.xml +++ b/modules/project_invoice/message.xml @@ -3,11 +3,14 @@ this repository contains the full copyright notices and license terms. --> - - You cannot modify an invoiced line. + + You cannot modify the duration of timesheet line "%(line)s" because it has been invoiced. - - You cannot delete an invoiced line. + + You cannot modify the work of timesheet line "%(line)s" because it has been invoiced. + + + You cannot delete timesheet line "%(line)s" because it has been invoiced. To invoice work "%(work)s" you must define an account revenue for product "%(product)s". diff --git a/modules/project_invoice/timesheet.py b/modules/project_invoice/timesheet.py index 62899a9628..c020c0b1b9 100644 --- a/modules/project_invoice/timesheet.py +++ b/modules/project_invoice/timesheet.py @@ -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)