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):
|
|
|
|
|
'Allocation'
|
2012-09-24 22:18:07 +02:00
|
|
|
__name__ = 'project.allocation'
|
2009-06-25 17:37:37 +02:00
|
|
|
employee = fields.Many2One('company.employee', 'Employee', required=True,
|
2014-08-01 17:56:28 +02:00
|
|
|
select=True, ondelete='CASCADE')
|
2009-06-25 17:37:37 +02:00
|
|
|
work = fields.Many2One('project.work', 'Work', required=True,
|
2014-08-01 17:56:28 +02:00
|
|
|
select=True, ondelete='CASCADE')
|
2014-09-10 21:02:53 +02:00
|
|
|
percentage = fields.Float('Percentage', digits=(16, 2), required=True,
|
|
|
|
|
domain=[('percentage', '>', 0.0)])
|
2009-06-25 17:37:37 +02:00
|
|
|
|
2012-09-24 22:18:07 +02:00
|
|
|
@classmethod
|
2014-09-10 21:02:53 +02:00
|
|
|
def __register__(cls, module_name):
|
|
|
|
|
super(Allocation, cls).__register__(module_name)
|
|
|
|
|
|
2018-07-24 22:01:08 +02:00
|
|
|
table = cls.__table_handler__(module_name)
|
|
|
|
|
|
2014-09-10 21:02:53 +02:00
|
|
|
# Migration from 3.2:
|
|
|
|
|
table.drop_constraint('percentage_positive')
|
2012-07-26 08:06:23 +05:30
|
|
|
|
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()
|