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
|
2011-07-03 13:19:07 +02:00
|
|
|
from trytond.pool import Pool
|
2009-06-25 17:37:37 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class Allocation(ModelSQL, ModelView):
|
2012-09-24 22:18:07 +02:00
|
|
|
__name__ = 'project.allocation'
|
2022-10-11 00:44:50 +02:00
|
|
|
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
|
2013-12-19 14:45:18 +01:00
|
|
|
def write(cls, *args):
|
2012-09-24 22:18:07 +02:00
|
|
|
Work = Pool().get('project.work')
|
2013-12-19 14:45:18 +01:00
|
|
|
super(Allocation, cls).write(*args)
|
2009-06-25 17:37:37 +02:00
|
|
|
|
2012-09-24 22:18:07 +02:00
|
|
|
works = Work.search([
|
2013-12-19 14:45:18 +01:00
|
|
|
('allocations', 'in',
|
|
|
|
|
[a.id for allocations in args[::2] for a in allocations]),
|
2010-08-16 19:28:32 +02:00
|
|
|
])
|
2009-06-25 17:37:37 +02:00
|
|
|
|
2012-09-24 22:18:07 +02:00
|
|
|
for work in works:
|
|
|
|
|
work.reset_leveling()
|
|
|
|
|
for work in works:
|
|
|
|
|
work.compute_dates()
|
2009-06-25 17:37:37 +02:00
|
|
|
|
2012-09-24 22:18:07 +02:00
|
|
|
@classmethod
|
2013-01-06 22:18:13 +01:00
|
|
|
def create(cls, vlist):
|
|
|
|
|
allocations = super(Allocation, cls).create(vlist)
|
|
|
|
|
for allocation in allocations:
|
|
|
|
|
allocation.work.reset_leveling()
|
|
|
|
|
allocation.work.compute_dates()
|
|
|
|
|
return allocations
|
2009-06-25 17:37:37 +02:00
|
|
|
|
2012-09-24 22:18:07 +02:00
|
|
|
@classmethod
|
|
|
|
|
def delete(cls, allocations):
|
|
|
|
|
works = [a.work for a in allocations]
|
|
|
|
|
super(Allocation, cls).delete(allocations)
|
2009-06-25 17:37:37 +02:00
|
|
|
|
2012-09-24 22:18:07 +02:00
|
|
|
for work in works:
|
|
|
|
|
work.reset_leveling()
|
|
|
|
|
for work in works:
|
|
|
|
|
work.compute_dates()
|