2014-12-02 12:55:43 +01:00
|
|
|
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
|
|
|
|
# this repository contains the full copyright notices and license terms.
|
2018-12-29 14:20:29 +01:00
|
|
|
from trytond.i18n import gettext
|
2013-03-22 17:59:00 +01:00
|
|
|
from trytond.model import fields
|
2018-12-29 14:20:29 +01:00
|
|
|
from trytond.model.exceptions import AccessError
|
2013-03-22 17:59:00 +01:00
|
|
|
from trytond.pool import PoolMeta
|
|
|
|
|
|
|
|
|
|
|
2020-03-01 12:33:53 +01:00
|
|
|
class Line(metaclass=PoolMeta):
|
2013-03-22 17:59:00 +01:00
|
|
|
__name__ = 'timesheet.line'
|
|
|
|
|
invoice_line = fields.Many2One('account.invoice.line', 'Invoice Line',
|
|
|
|
|
readonly=True)
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def copy(cls, records, default=None):
|
|
|
|
|
if default is None:
|
|
|
|
|
default = {}
|
2018-09-01 01:02:03 +02:00
|
|
|
else:
|
|
|
|
|
default = default.copy()
|
2013-03-22 17:59:00 +01:00
|
|
|
default.setdefault('invoice_line', None)
|
2020-03-01 12:33:53 +01:00
|
|
|
return super().copy(records, default=default)
|
2013-03-22 17:59:00 +01:00
|
|
|
|
2013-05-27 18:05:46 +02:00
|
|
|
@classmethod
|
2013-12-19 14:45:16 +01:00
|
|
|
def write(cls, *args):
|
2018-05-07 16:39:51 +02:00
|
|
|
actions = iter(args)
|
|
|
|
|
for lines, values in zip(actions, actions):
|
|
|
|
|
if (('duration' in values or 'work' in values)
|
|
|
|
|
and any(l.invoice_line for l in lines)):
|
2023-05-09 14:05:40 +02:00
|
|
|
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))
|
2020-03-01 12:33:53 +01:00
|
|
|
super().write(*args)
|
2013-05-27 18:05:46 +02:00
|
|
|
|
2013-03-22 17:59:00 +01:00
|
|
|
@classmethod
|
2023-05-09 14:05:40 +02:00
|
|
|
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)
|