Files
tryton/modules/project_plan/allocation.py
T

46 lines
1.5 KiB
Python
Raw Normal View History

2014-12-02 12:55:44 +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.
2021-12-11 17:58:43 +01:00
from trytond.model import ModelSQL, ModelView, fields
2009-06-25 17:37:37 +02:00
class Allocation(ModelSQL, ModelView):
2012-09-24 22:18:07 +02:00
__name__ = 'project.allocation'
employee = fields.Many2One(
'company.employee', "Employee", required=True, ondelete='CASCADE')
work = fields.Many2One(
'project.work', "Work", required=True, ondelete='CASCADE')
2024-11-25 23:47:12 +01:00
percentage = fields.Float(
"Percentage", digits=(None, 2), required=True,
2014-09-10 21:02:53 +02:00
domain=[('percentage', '>', 0.0)])
2009-06-25 17:37:37 +02:00
2012-09-24 22:18:07 +02:00
@staticmethod
def default_percentage():
2009-06-25 17:37:37 +02:00
return 100
2017-07-26 23:43:24 +02:00
def get_rec_name(self, name):
return self.employee.rec_name
@classmethod
def search_rec_name(cls, name, clause):
2017-09-27 18:37:31 +02:00
return [('employee.rec_name',) + tuple(clause[1:])]
2017-07-26 23:43:24 +02:00
2012-09-24 22:18:07 +02:00
@classmethod
def on_modification(cls, mode, allocations, field_names=None):
super().on_modification(mode, allocations, field_names=field_names)
if mode in {'create', 'write'}:
for allocation in allocations:
allocation.work.reset_leveling()
allocation.work.compute_dates()
2009-06-25 17:37:37 +02:00
2012-09-24 22:18:07 +02:00
@classmethod
def on_delete(cls, allocations):
callback = super().on_delete(allocations)
2012-09-24 22:18:07 +02:00
works = [a.work for a in allocations]
2009-06-25 17:37:37 +02:00
def replan():
for work in works:
work.reset_leveling()
work.compute_dates()
callback.append(replan)
return callback