2009-12-18 12:24:20 +00:00
# -*- coding: utf-8 -*-
##############################################################################
2010-04-08 09:22:36 +00:00
#
2009-12-18 12:24:20 +00:00
# OpenERP, Open Source Management Solution
2010-01-12 09:18:39 +00:00
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
2009-12-18 12:24:20 +00:00
#
# 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
2010-04-08 09:22:36 +00:00
# along with this program. If not, see <http://www.gnu.org/licenses/>.
2009-12-18 12:24:20 +00:00
#
##############################################################################
from osv import fields , osv
2012-01-27 13:48:25 +00:00
from openerp . addons . caldav import calendar
2010-08-10 05:22:52 +00:00
from datetime import datetime
2010-11-10 07:35:00 +00:00
from tools . translate import _
from base_calendar import base_calendar
2010-08-12 11:09:14 +00:00
from project . project import task as base_project_task
2009-12-18 12:24:20 +00:00
class project_task ( osv . osv ) :
2010-01-19 13:47:20 +00:00
_name = " project.task "
2011-07-08 13:12:03 +00:00
_inherit = [ " project.task " , " calendar.todo " ]
2009-12-18 12:24:20 +00:00
_columns = {
2010-08-12 11:09:14 +00:00
# force inherit from project.project_task so that
# calendar.todo.active is masked oute
' active ' : base_project_task . _columns [ ' active ' ] ,
2010-10-27 11:37:15 +00:00
' date_deadline ' : base_project_task . _columns [ ' date_deadline ' ] ,
2010-07-02 14:37:06 +00:00
' write_date ' : fields . datetime ( ' Write Date ' ) ,
2010-08-12 11:09:14 +00:00
' create_date ' : fields . datetime ( ' Create Date ' , readonly = True ) ,
2010-04-08 09:22:36 +00:00
' attendee_ids ' : fields . many2many ( ' calendar.attendee ' , \
' task_attendee_rel ' , ' task_id ' , ' attendee_id ' , ' Attendees ' ) ,
2010-07-13 07:21:49 +00:00
' state ' : fields . selection ( [ ( ' draft ' , ' Draft ' ) , ( ' open ' , ' In Progress ' ) , ( ' pending ' , ' Pending ' ) , ( ' cancelled ' , ' Cancelled ' ) , ( ' done ' , ' Done ' ) ] , ' State ' , readonly = True , required = True ,
help = ' If the task is created the state is \' Draft \' . \n If the task is started, the state becomes \' In Progress \' . \n If review is needed the task is in \' Pending \' state. \
\n If the task is over , the states is set to \' Done \' . ' ) ,
}
2011-07-08 12:06:28 +00:00
2010-07-13 07:21:49 +00:00
_defaults = {
' state ' : ' draft ' ,
}
2010-04-08 09:22:36 +00:00
2010-11-10 07:35:00 +00:00
def open_task ( self , cr , uid , ids , context = None ) :
"""
Open Task Form for Project Task .
@param cr : the current row , from the database cursor ,
@param uid : the current user ’ s ID for security checks ,
@param ids : List of project task ’ s IDs
@param context : A standard dictionary for contextual values
@return : Dictionary value which open Project Task form .
"""
2010-11-11 13:30:06 +00:00
data_pool = self . pool . get ( ' ir.model.data ' )
2010-11-10 07:35:00 +00:00
value = { }
2010-11-11 13:30:06 +00:00
task_form_id = data_pool . get_object ( cr , uid , ' project ' , ' view_task_form2 ' )
task_tree_id = data_pool . get_object ( cr , uid , ' project ' , ' view_task_tree2 ' )
task_calendar_id = data_pool . get_object ( cr , uid , ' project ' , ' view_task_calendar ' )
2010-11-10 07:35:00 +00:00
for id in ids :
value = {
' name ' : _ ( ' Tasks ' ) ,
' view_type ' : ' form ' ,
' view_mode ' : ' form,tree ' ,
' res_model ' : ' project.task ' ,
' view_id ' : False ,
' views ' : [ ( task_form_id , ' form ' ) , ( task_tree_id , ' tree ' ) , ( task_calendar_id , ' calendar ' ) ] ,
' type ' : ' ir.actions.act_window ' ,
' res_id ' : base_calendar . base_calendar_id2real_id ( id ) ,
' nodestroy ' : True
}
return value
2010-04-08 09:22:36 +00:00
def import_cal ( self , cr , uid , data , data_id = None , context = None ) :
2010-02-11 14:08:46 +00:00
todo_obj = self . pool . get ( ' basic.calendar.todo ' )
vals = todo_obj . import_cal ( cr , uid , data , context = context )
return self . check_import ( cr , uid , vals , context = context )
2010-04-08 09:22:36 +00:00
2010-07-02 14:37:06 +00:00
def check_import ( self , cr , uid , vals , context = None ) :
if context is None :
context = { }
2010-02-11 14:08:46 +00:00
ids = [ ]
for val in vals :
2010-11-22 10:37:53 +00:00
obj_tm = self . pool . get ( ' res.users ' ) . browse ( cr , uid , uid , context = context ) . company_id . project_time_mode_id
2010-07-13 07:21:49 +00:00
if not val . get ( ' planned_hours ' , False ) :
2010-02-11 14:08:46 +00:00
# 'Computes duration' in days
plan = 0.0
if val . get ( ' date ' ) and val . get ( ' date_deadline ' ) :
start = datetime . strptime ( val [ ' date ' ] , ' % Y- % m- %d % H: % M: % S ' )
end = datetime . strptime ( val [ ' date_deadline ' ] , ' % Y- % m- %d % H: % M: % S ' )
diff = end - start
plan = ( diff . seconds / float ( 86400 ) + diff . days ) * obj_tm . factor
val [ ' planned_hours ' ] = plan
else :
# Converts timedelta into hours
hours = ( val [ ' planned_hours ' ] . seconds / float ( 3600 ) ) + \
( val [ ' planned_hours ' ] . days * 24 )
val [ ' planned_hours ' ] = hours
2010-04-12 12:01:15 +00:00
exists , r_id = calendar . uid2openobjectid ( cr , val [ ' id ' ] , self . _name , val . get ( ' recurrent_id ' ) )
2010-02-11 14:08:46 +00:00
val . pop ( ' id ' )
if exists :
self . write ( cr , uid , [ exists ] , val )
ids . append ( exists )
else :
2011-07-08 15:35:07 +00:00
#set user_id with id, needed later
val . update ( { ' user_id ' : uid } )
2010-02-11 14:08:46 +00:00
task_id = self . create ( cr , uid , val )
ids . append ( task_id )
return ids
2010-04-08 09:22:36 +00:00
2010-07-02 14:37:06 +00:00
def export_cal ( self , cr , uid , ids , context = None ) :
if context is None :
context = { }
2010-02-11 14:08:46 +00:00
task_datas = self . read ( cr , uid , ids , [ ] , context = { ' read ' : True } )
tasks = [ ]
for task in task_datas :
if task . get ( ' planned_hours ' , None ) and task . get ( ' date_deadline ' , None ) :
task . pop ( ' planned_hours ' )
tasks . append ( task )
todo_obj = self . pool . get ( ' basic.calendar.todo ' )
ical = todo_obj . export_cal ( cr , uid , tasks , context = { ' model ' : self . _name } )
calendar_val = ical . serialize ( )
2010-07-02 14:37:06 +00:00
return calendar_val . replace ( ' " ' , ' ' ) . strip ( )
2010-02-11 14:08:46 +00:00
2009-12-18 13:44:31 +00:00
project_task ( )
2009-12-18 12:24:20 +00:00
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: