Files
tryton/modules/timesheet_cost/timesheet.py
T

48 lines
1.4 KiB
Python
Raw Normal View History

2014-12-02 12:56:22 +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.
2015-09-22 19:26:13 +02:00
from trytond.model import fields
2023-01-19 11:25:25 +01:00
from trytond.pool import PoolMeta
from trytond.transaction import without_check_access
2015-09-22 19:26:13 +02:00
from .company import price_digits
2013-07-14 10:42:07 +02:00
2020-03-01 12:33:54 +01:00
class Line(metaclass=PoolMeta):
2013-07-14 10:42:07 +02:00
__name__ = 'timesheet.line'
2015-09-22 19:26:13 +02:00
cost_price = fields.Numeric('Cost Price',
digits=price_digits, required=True, readonly=True)
2013-07-14 10:42:07 +02:00
2015-09-22 19:26:13 +02:00
@classmethod
def default_cost_price(cls):
# Needed at creation as cost_price is required
return 0
@classmethod
def create(cls, vlist):
# XXX Remove cost_price because proteus set it as default value
vlist = [v.copy() for v in vlist]
for values in vlist:
values.pop('cost_price', None)
2020-03-01 12:33:54 +01:00
lines = super().create(vlist)
2015-09-22 19:26:13 +02:00
cls.sync_cost(lines)
return lines
@classmethod
def write(cls, *args):
2020-03-01 12:33:54 +01:00
super().write(*args)
2015-09-22 19:26:13 +02:00
cls.sync_cost(sum(args[0:None:2], []))
@classmethod
@without_check_access
2015-09-22 19:26:13 +02:00
def sync_cost(cls, lines):
to_write = []
lines = cls.browse(lines)
for line in lines:
cost_price = line.employee.compute_cost_price(date=line.date)
if cost_price != line.cost_price:
to_write.extend([[line], {'cost_price': cost_price}])
if to_write:
cls.write(*to_write)