Files
tryton/allocation.py
T

59 lines
1.8 KiB
Python
Raw Normal View History

2009-06-25 17:37:37 +02: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.
from trytond.model import ModelView, ModelSQL, 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'
_name = 'project.allocation'
_description = __doc__
_rec_name = 'employee'
employee = fields.Many2One('company.employee', 'Employee', required=True,
select=1)
work = fields.Many2One('project.work', 'Work', required=True,
select=1)
percentage = fields.Float('Percentage', digits=(16, 2), required=True)
2010-08-16 19:28:32 +02:00
def default_percentage(self):
2009-06-25 17:37:37 +02:00
return 100
2010-08-16 19:28:32 +02:00
def write(self, ids, values):
2011-07-03 13:19:07 +02:00
work_obj = Pool().get('project.work')
2010-08-16 19:28:32 +02:00
res = super(Allocation, self).write(ids, values)
2009-06-25 17:37:37 +02:00
if isinstance(ids, (int, long)):
ids = [ids]
2010-08-16 19:28:32 +02:00
work_ids = work_obj.search([
2009-06-25 17:37:37 +02:00
('allocations', 'in', ids),
2010-08-16 19:28:32 +02:00
])
2009-06-25 17:37:37 +02:00
for work_id in work_ids:
2010-08-16 19:28:32 +02:00
work_obj.reset_leveling(work_id)
2009-06-25 17:37:37 +02:00
for work_id in work_ids:
2010-08-16 19:28:32 +02:00
work_obj.compute_dates(work_id)
2009-06-25 17:37:37 +02:00
return res
2010-08-16 19:28:32 +02:00
def create(self, values):
2011-07-03 13:19:07 +02:00
work_obj = Pool().get('project.work')
2010-08-16 19:28:32 +02:00
allocation_id = super(Allocation, self).create(values)
allocation = self.browse(allocation_id)
work_obj.reset_leveling(allocation.work.id)
work_obj.compute_dates(allocation.work.id)
2009-06-25 17:37:37 +02:00
2010-08-16 19:28:32 +02:00
def delete(self, ids):
2011-07-03 13:19:07 +02:00
work_obj = Pool().get('project.work')
2010-08-16 19:28:32 +02:00
allocations = self.browse(ids)
2009-06-25 17:37:37 +02:00
work_ids = [a.work.id for a in allocations]
2010-08-16 19:28:32 +02:00
res = super(Allocation, self).delete(ids)
2009-06-25 17:37:37 +02:00
for work_id in work_ids:
2010-08-16 19:28:32 +02:00
work_obj.reset_leveling(work_id)
2009-06-25 17:37:37 +02:00
for work_id in work_ids:
2010-08-16 19:28:32 +02:00
work_obj.compute_dates(work_id)
2009-06-25 17:37:37 +02:00
return res
Allocation()