From 838fc7e85c800559d850362cb3607cd43caa0444 Mon Sep 17 00:00:00 2001 From: "mra (Open ERP)" Date: Wed, 17 Mar 2010 12:45:53 +0530 Subject: [PATCH] [IMP] project_long_term: Bug fixes and clean [IMP] project: if the task description is not available it will take task name to send mail to partner on Done button bzr revid: mra@tinyerp.com-20100317071553-3ydcpes6z8f52744 --- addons/project/wizard/close_task.py | 12 ++++++------ addons/project_long_term/__terp__.py | 2 -- addons/project_long_term/project_long_term.py | 14 +++++++++----- .../wizard/compute_phases_date.py | 5 ++--- .../project_long_term/wizard/compute_tasks_date.py | 4 ++-- .../project_long_term/wizard/working_calendar.py | 10 +++++----- addons/resource/resource.py | 13 +++++++------ 7 files changed, 31 insertions(+), 29 deletions(-) diff --git a/addons/project/wizard/close_task.py b/addons/project/wizard/close_task.py index f577929a8f6..89e4409f643 100644 --- a/addons/project/wizard/close_task.py +++ b/addons/project/wizard/close_task.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (). # @@ -15,7 +15,7 @@ # 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 . +# along with this program. If not, see . # ############################################################################## @@ -37,7 +37,8 @@ mail_fields = { } def email_send(cr, uid, ids, to_adr, description, context={}): - for task in pooler.get_pool(cr.dbname).get('project.task').browse(cr, uid, ids, context): + pool = pooler.get_pool(cr.dbname) + for task in pool.get('project.task').browse(cr, uid, ids, context=context): project = task.project_id subject = "Task '%s' closed" % task.name if task.user_id and task.user_id.address_id and task.user_id.address_id.email: @@ -45,7 +46,6 @@ def email_send(cr, uid, ids, to_adr, description, context={}): signature = task.user_id.signature else: raise wizard.except_wizard(_('Error'), _("Couldn't send mail because your email address is not configured!")) - if to_adr: val = { 'name': task.name, @@ -75,8 +75,8 @@ class wizard_close(wizard.interface): partner_id = task.partner_id or task.project_id.partner_id if partner_id and partner_id.address[0].email: email = partner_id.address[0].email - return {'description': task.description, 'email':email} - + return {'description': task.description or task.name, 'email':email} + def _data_send(self, cr, uid, data, context): task_obj = pooler.get_pool(cr.dbname).get('project.task') if data['form']['email']: diff --git a/addons/project_long_term/__terp__.py b/addons/project_long_term/__terp__.py index 03d8cd8f11f..25529f5b245 100644 --- a/addons/project_long_term/__terp__.py +++ b/addons/project_long_term/__terp__.py @@ -18,8 +18,6 @@ # along with this program. If not, see . # ############################################################################## - - { "name" : "Long Term Project Management", "version": "1.1", diff --git a/addons/project_long_term/project_long_term.py b/addons/project_long_term/project_long_term.py index 684fbcc776a..f0e2a78282f 100644 --- a/addons/project_long_term/project_long_term.py +++ b/addons/project_long_term/project_long_term.py @@ -265,20 +265,24 @@ class task(osv.osv): def onchange_planned(self, cr, uid, ids, project, user_id=False, planned=0.0, effective=0.0, date_start=None, occupation_rate=0.0): result = {} + resource = False resource_obj = self.pool.get('resource.resource') project_pool = self.pool.get('project.project') resource_calendar = self.pool.get('resource.calendar') + if not project: + return {'value' : result} if date_start: hrs = float(planned / float(occupation_rate)) calendar_id = project_pool.browse(cr, uid, project).resource_calendar_id.id dt_start = mx.DateTime.strptime(date_start, '%Y-%m-%d %H:%M:%S') resource_id = resource_obj.search(cr, uid, [('user_id','=',user_id)]) if resource_id: - resource = resource_obj.browse(cr, uid, resource_id)[0] - hrs = planned / (float(occupation_rate) * resource.time_efficiency) - if resource.calendar_id.id: - calendar_id = resource.calendar_id.id - work_times = resource_calendar.interval_get(cr, uid, calendar_id, dt_start, hrs or 0.0, resource.id or False) + resource_data = resource_obj.browse(cr, uid, resource_id)[0] + resource = resource_data.id + hrs = planned / (float(occupation_rate) * resource_data.time_efficiency) + if resource_data.calendar_id.id: + calendar_id = resource_data.calendar_id.id + work_times = resource_calendar.interval_get(cr, uid, calendar_id, dt_start, hrs or 0.0, resource or False) result['date_end'] = work_times[-1][1].strftime('%Y-%m-%d %H:%M:%S') result['remaining_hours'] = planned - effective return {'value' : result} diff --git a/addons/project_long_term/wizard/compute_phases_date.py b/addons/project_long_term/wizard/compute_phases_date.py index f7e49f23247..96e6ce5f2d4 100644 --- a/addons/project_long_term/wizard/compute_phases_date.py +++ b/addons/project_long_term/wizard/compute_phases_date.py @@ -36,7 +36,7 @@ compute_form = """ """ compute_fields = { - 'project_id': {'string':'Project', 'type':'many2one', 'relation':'project.project'}, + 'project_id': {'string':'Project', 'type':'many2one', 'relation':'project.project', 'help': 'If you do not specify project then it will take All projects with state=draft, open, pending'}, } @@ -49,7 +49,6 @@ class wizard_compute_phases(wizard.interface): calendar_id -- working calendar of the project """ - pool = pooler.get_pool(cr.dbname) phase_obj = pool.get('project.phase') resource_obj = pool.get('resource.resource') @@ -83,7 +82,7 @@ class wizard_compute_phases(wizard.interface): # If project has working calendar then that # else the default one would be considered if calendar_id: - working_days = wkcal.compute_working_calendar(cr, uid, calendar_id) + working_days = wkcal.compute_working_calendar(cr, uid, calendar_id, context=context) vacation = tuple(wkcal.compute_leaves(cr, uid, calendar_id)) def phase(): diff --git a/addons/project_long_term/wizard/compute_tasks_date.py b/addons/project_long_term/wizard/compute_tasks_date.py index 17a2b90b50b..dbe4739e199 100644 --- a/addons/project_long_term/wizard/compute_tasks_date.py +++ b/addons/project_long_term/wizard/compute_tasks_date.py @@ -40,7 +40,7 @@ success_msg = """ """ compute_fields = { - 'project_id': {'string':'Project', 'type':'many2one', 'relation':'project.project', 'required':'True'}, + 'project_id': {'string':'Project', 'type':'many2one', 'relation':'project.project', 'required':True}, } class wizard_compute_tasks(wizard.interface): @@ -118,7 +118,7 @@ class wizard_compute_tasks(wizard.interface): priorty = priority_dict[each_task.priority] if each_task.user_id: for resource in resources: - if resource.__name__ == each_task.user_id.name: + if resource.__name__ == each_task.user_id.name: # check me!! task = create_tasks(i, hours, priorty, resource) else: task = create_tasks(i, hours, priorty) diff --git a/addons/project_long_term/wizard/working_calendar.py b/addons/project_long_term/wizard/working_calendar.py index f3474d81a58..ba8ec7db150 100644 --- a/addons/project_long_term/wizard/working_calendar.py +++ b/addons/project_long_term/wizard/working_calendar.py @@ -56,11 +56,11 @@ def compute_leaves(cr, uid, calendar_id, resource_id=False, resource_calendar=Fa ], context=context) leaves = resource_calendar_leaves_obj.read(cr, uid, leave_ids, ['date_from', 'date_to'], context=context) for i in range(len(leaves)): - dt_start = datetime.datetime.strptime(leaves[i]['date_from'], '%Y-%m-%d %H:%M:%S') - dt_end = datetime.datetime.strptime(leaves[i]['date_to'], '%Y-%m-%d %H:%M:%S') - no = dt_end - dt_start - [leave_list.append((dt_start + datetime.timedelta(days=x)).strftime('%Y-%m-%d')) for x in range(int(no.days + 1))] - leave_list.sort() + dt_start = datetime.datetime.strptime(leaves[i]['date_from'], '%Y-%m-%d %H:%M:%S') + dt_end = datetime.datetime.strptime(leaves[i]['date_to'], '%Y-%m-%d %H:%M:%S') + no = dt_end - dt_start + [leave_list.append((dt_start + datetime.timedelta(days=x)).strftime('%Y-%m-%d')) for x in range(int(no.days + 1))] + leave_list.sort() return leave_list def compute_working_calendar(cr, uid, calendar_id, context={}): diff --git a/addons/resource/resource.py b/addons/resource/resource.py index 09a752850c9..38ba539c912 100755 --- a/addons/resource/resource.py +++ b/addons/resource/resource.py @@ -21,6 +21,7 @@ import mx.DateTime import time import math + from osv import fields, osv from tools.translate import _ @@ -34,7 +35,7 @@ class resource_calendar(osv.osv): 'manager' : fields.many2one('res.users', 'Workgroup manager'), } _defaults = { - 'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'resource.calendar', c) + 'company_id': lambda self, cr, uid, c: self.pool.get('res.company')._company_default_get(cr, uid, 'resource.calendar', c) } def interval_min_get(self, cr, uid, id, dt_from, hours, resource=False): @@ -152,9 +153,9 @@ class resource_resource(osv.osv): 'active' : fields.boolean('Active', help="If the active field is set to true, it will allow you to hide the resource record without removing it."), 'company_id' : fields.many2one('res.company', 'Company', required=True), 'resource_type': fields.selection([('user','Human'),('material','Material')], 'Resource Type', required=True), - 'user_id' : fields.many2one('res.users', 'User',help='Related user name for the resource to manage its access.'), - 'time_efficiency' : fields.float('Efficiency factor', size=8, required=True,help="This field depict the efficiency of the resource to complete tasks. e.g resource put alone on a phase of 5 days with 5 tasks assigned to him, will show a load of 100% for this phase by default, but if we put a efficency of 200%, then his load will only be 50%."), - 'calendar_id' : fields.many2one("resource.calendar", "Working time",help="Define the schedule of resource"), + 'user_id' : fields.many2one('res.users', 'User', help='Related user name for the resource to manage its access.'), + 'time_efficiency' : fields.float('Efficiency factor', size=8, required=True, help="This field depict the efficiency of the resource to complete tasks. e.g resource put alone on a phase of 5 days with 5 tasks assigned to him, will show a load of 100% for this phase by default, but if we put a efficency of 200%, then his load will only be 50%."), + 'calendar_id' : fields.many2one("resource.calendar", "Working time", help="Define the schedule of resource"), } _defaults = { 'resource_type' : lambda *a: 'user', @@ -187,7 +188,7 @@ class resource_calendar_leaves(osv.osv): 'date_to' : fields.datetime('End Date', required=True), 'resource_id' : fields.many2one("resource.resource", "Resource", help="If empty, this is a generic holiday for the company. If a resource is set, the holiday/leave is only for this resource"), } - def check_dates(self, cr, uid, ids): + def check_dates(self, cr, uid, ids, context={}): leave = self.read(cr, uid, ids[0], ['date_from', 'date_to']) if leave['date_from'] and leave['date_to']: if leave['date_from'] > leave['date_to']: @@ -198,7 +199,7 @@ class resource_calendar_leaves(osv.osv): (check_dates, 'Error! leave start-date must be lower then leave end-date.', ['date_from', 'date_to']) ] - def onchange_resource(self,cr,uid,ids,resource): + def onchange_resource(self,cr, uid, ids, resource, context={}): result = {} if resource: resource_pool = self.pool.get('resource.resource')