[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
This commit is contained in:
mra (Open ERP) 2010-03-17 12:45:53 +05:30
parent 2319355294
commit 838fc7e85c
7 changed files with 31 additions and 29 deletions

View File

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
##############################################################################
#
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
@ -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 <http://www.gnu.org/licenses/>.
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
@ -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']:

View File

@ -18,8 +18,6 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
{
"name" : "Long Term Project Management",
"version": "1.1",

View File

@ -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}

View File

@ -36,7 +36,7 @@ compute_form = """<?xml version="1.0" ?>
</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():

View File

@ -40,7 +40,7 @@ success_msg = """<?xml version="1.0" ?>
</form>"""
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)

View File

@ -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={}):

View File

@ -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')