2010-04-06 06:13:55 +00:00
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
2010-07-19 12:17:16 +00:00
from lxml import etree
2012-12-06 14:56:32 +00:00
from openerp import tools
from openerp . tools . translate import _
from openerp . osv import fields , osv
2010-04-06 06:13:55 +00:00
class project_task_delegate ( osv . osv_memory ) :
_name = ' project.task.delegate '
_description = ' Task Delegate '
_columns = {
2014-05-21 09:52:05 +00:00
' name ' : fields . char ( ' Delegated Title ' , required = True , help = " New title of the task delegated to the user " ) ,
' prefix ' : fields . char ( ' Your Task Title ' , help = " Title for your validation task " ) ,
2011-11-17 15:09:14 +00:00
' project_id ' : fields . many2one ( ' project.project ' , ' Project ' , help = " User you want to delegate this task to " ) ,
2010-04-06 06:13:55 +00:00
' user_id ' : fields . many2one ( ' res.users ' , ' Assign To ' , required = True , help = " User you want to delegate this task to " ) ,
' new_task_description ' : fields . text ( ' New Task Description ' , help = " Reinclude the description of the task in the task of the user " ) ,
' planned_hours ' : fields . float ( ' Planned Hours ' , help = " Estimated time to close this task by the delegated user " ) ,
2011-11-17 15:09:14 +00:00
' planned_hours_me ' : fields . float ( ' Hours to Validate ' , help = " Estimated time for you to validate the work done by the user to whom you delegate this task " ) ,
' state ' : fields . selection ( [ ( ' pending ' , ' Pending ' ) , ( ' done ' , ' Done ' ) , ] , ' Validation State ' , help = " New state of your own task. Pending will be reopened automatically when the delegated task is closed " )
2010-08-13 12:20:05 +00:00
}
2010-04-06 06:13:55 +00:00
2011-11-17 15:09:14 +00:00
def onchange_project_id ( self , cr , uid , ids , project_id = False , context = None ) :
project_project = self . pool . get ( ' project.project ' )
if not project_id :
return { ' value ' : { ' user_id ' : False } }
project = project_project . browse ( cr , uid , project_id , context = context )
return { ' value ' : { ' user_id ' : project . user_id and project . user_id . id or False } }
2010-08-27 12:05:25 +00:00
def default_get ( self , cr , uid , fields , context = None ) :
"""
This function gets default values
"""
res = super ( project_task_delegate , self ) . default_get ( cr , uid , fields , context = context )
2010-07-02 14:37:06 +00:00
if context is None :
context = { }
2010-08-27 12:05:25 +00:00
record_id = context and context . get ( ' active_id ' , False ) or False
2011-11-17 15:09:14 +00:00
if not record_id :
return res
2010-08-27 12:05:25 +00:00
task_pool = self . pool . get ( ' project.task ' )
task = task_pool . browse ( cr , uid , record_id , context = context )
2010-11-19 12:16:04 +00:00
task_name = tools . ustr ( task . name )
2010-09-20 06:11:01 +00:00
2011-11-17 15:09:14 +00:00
if ' project_id ' in fields :
2011-12-16 16:25:48 +00:00
res [ ' project_id ' ] = int ( task . project_id . id ) if task . project_id else False
2011-11-17 15:09:14 +00:00
2010-08-27 12:05:25 +00:00
if ' name ' in fields :
2010-11-10 11:59:59 +00:00
if task_name . startswith ( _ ( ' CHECK: ' ) ) :
2011-02-02 13:24:29 +00:00
newname = tools . ustr ( task_name ) . replace ( _ ( ' CHECK: ' ) , ' ' )
2010-04-06 06:13:55 +00:00
else :
2011-02-02 13:24:29 +00:00
newname = tools . ustr ( task_name or ' ' )
2011-12-16 16:25:48 +00:00
res [ ' name ' ] = newname
2010-08-27 12:05:25 +00:00
if ' planned_hours ' in fields :
2011-12-16 16:25:48 +00:00
res [ ' planned_hours ' ] = task . remaining_hours or 0.0
2010-08-27 12:05:25 +00:00
if ' prefix ' in fields :
2010-11-10 11:59:59 +00:00
if task_name . startswith ( _ ( ' CHECK: ' ) ) :
2011-02-02 13:24:29 +00:00
newname = tools . ustr ( task_name ) . replace ( _ ( ' CHECK: ' ) , ' ' )
2010-04-06 06:13:55 +00:00
else :
2011-02-02 13:24:29 +00:00
newname = tools . ustr ( task_name or ' ' )
2011-03-09 04:58:22 +00:00
prefix = _ ( ' CHECK: %s ' ) % newname
2011-12-16 16:25:48 +00:00
res [ ' prefix ' ] = prefix
2010-08-27 12:05:25 +00:00
if ' new_task_description ' in fields :
2011-12-16 16:25:48 +00:00
res [ ' new_task_description ' ] = task . description
2010-08-27 12:05:25 +00:00
return res
2010-04-06 06:13:55 +00:00
_defaults = {
' planned_hours_me ' : 1.0 ,
' state ' : ' pending ' ,
2010-07-08 10:14:24 +00:00
}
2010-08-13 12:20:05 +00:00
2010-07-19 12:17:16 +00:00
def fields_view_get ( self , cr , uid , view_id = None , view_type = ' form ' , context = None , toolbar = False , submenu = False ) :
2015-08-06 12:18:37 +00:00
res = super ( project_task_delegate , self ) . fields_view_get ( cr , uid , view_id , view_type , context = context , toolbar = toolbar , submenu = submenu )
2010-08-27 12:05:25 +00:00
users_pool = self . pool . get ( ' res.users ' )
2010-12-13 06:43:09 +00:00
obj_tm = users_pool . browse ( cr , uid , uid , context = context ) . company_id . project_time_mode_id
2010-08-27 12:05:25 +00:00
tm = obj_tm and obj_tm . name or ' Hours '
2010-07-19 12:17:16 +00:00
if tm in [ ' Hours ' , ' Hour ' ] :
return res
eview = etree . fromstring ( res [ ' arch ' ] )
def _check_rec ( eview ) :
if eview . attrib . get ( ' widget ' , ' ' ) == ' float_time ' :
eview . set ( ' widget ' , ' float ' )
for child in eview :
_check_rec ( child )
return True
_check_rec ( eview )
res [ ' arch ' ] = etree . tostring ( eview )
2010-08-27 12:05:25 +00:00
for field in res [ ' fields ' ] :
if ' Hours ' in res [ ' fields ' ] [ field ] [ ' string ' ] :
res [ ' fields ' ] [ field ] [ ' string ' ] = res [ ' fields ' ] [ field ] [ ' string ' ] . replace ( ' Hours ' , tm )
2010-07-19 12:17:16 +00:00
return res
2010-08-13 12:20:05 +00:00
2010-08-27 12:05:25 +00:00
def delegate ( self , cr , uid , ids , context = None ) :
2010-07-02 14:37:06 +00:00
if context is None :
context = { }
2010-08-27 12:05:25 +00:00
task_id = context . get ( ' active_id ' , False )
task_pool = self . pool . get ( ' project.task ' )
2010-04-06 06:13:55 +00:00
delegate_data = self . read ( cr , uid , ids , context = context ) [ 0 ]
2011-11-18 06:52:26 +00:00
delegated_tasks = task_pool . do_delegate ( cr , uid , [ task_id ] , delegate_data , context = context )
2011-11-17 15:09:14 +00:00
models_data = self . pool . get ( ' ir.model.data ' )
action_model , action_id = models_data . get_object_reference ( cr , uid , ' project ' , ' action_view_task ' )
view_model , task_view_form_id = models_data . get_object_reference ( cr , uid , ' project ' , ' view_task_form2 ' )
view_model , task_view_tree_id = models_data . get_object_reference ( cr , uid , ' project ' , ' view_task_tree2 ' )
2014-07-06 14:44:26 +00:00
action = self . pool [ action_model ] . read ( cr , uid , [ action_id ] , context = context ) [ 0 ]
2011-11-18 06:52:26 +00:00
action [ ' res_id ' ] = delegated_tasks [ task_id ]
2011-11-17 15:09:14 +00:00
action [ ' view_id ' ] = False
action [ ' views ' ] = [ ( task_view_form_id , ' form ' ) , ( task_view_tree_id , ' tree ' ) ]
action [ ' help ' ] = False
return action
2010-04-06 06:13:55 +00:00
2011-11-22 08:51:38 +00:00
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: