[IMP] crm, project_issue: open/close days should calculated base on resource calendar
bzr revid: hmo@tinyerp.com-20100407110820-sxiayfzd4robc2zl
This commit is contained in:
parent
c095986949
commit
8ccb3ca7ca
|
@ -24,7 +24,7 @@ from datetime import datetime, timedelta
|
||||||
import crm
|
import crm
|
||||||
import math
|
import math
|
||||||
import time
|
import time
|
||||||
from mx import DateTime
|
import mx.DateTime
|
||||||
from tools.translate import _
|
from tools.translate import _
|
||||||
|
|
||||||
class crm_lead(osv.osv):
|
class crm_lead(osv.osv):
|
||||||
|
@ -44,15 +44,9 @@ class crm_lead(osv.osv):
|
||||||
@param *args: Give Tuple Value
|
@param *args: Give Tuple Value
|
||||||
"""
|
"""
|
||||||
|
|
||||||
cases = self.browse(cr, uid, ids)
|
res = super(crm_lead, self).case_open(cr, uid, ids, *args)
|
||||||
for case in cases:
|
self.write(cr, uid, ids, {'date_open': time.strftime('%Y-%m-%d %H:%M:%S')})
|
||||||
data = {'state': 'open', 'active': True}
|
return res
|
||||||
if not case.user_id:
|
|
||||||
data['user_id'] = uid
|
|
||||||
data.update({'date_open': time.strftime('%Y-%m-%d %H:%M:%S')})
|
|
||||||
self.write(cr, uid, ids, data)
|
|
||||||
self._action(cr, uid, cases, 'open')
|
|
||||||
return True
|
|
||||||
|
|
||||||
def _compute_day(self, cr, uid, ids, fields, args, context={}):
|
def _compute_day(self, cr, uid, ids, fields, args, context={}):
|
||||||
"""
|
"""
|
||||||
|
@ -61,36 +55,52 @@ class crm_lead(osv.osv):
|
||||||
@param ids: List of Openday’s IDs
|
@param ids: List of Openday’s IDs
|
||||||
@return: difference between current date and log date
|
@return: difference between current date and log date
|
||||||
@param context: A standard dictionary for contextual values
|
@param context: A standard dictionary for contextual values
|
||||||
"""
|
"""
|
||||||
log_obj = self.pool.get('crm.case.log')
|
cal_obj = self.pool.get('resource.calendar')
|
||||||
model_obj = self.pool.get('ir.model')
|
res_obj = self.pool.get('resource.resource')
|
||||||
cal_obj = self.pool.get('resource.calendar')
|
|
||||||
|
|
||||||
model_ids = model_obj.search(cr, uid, [('model', '=', self._name)])
|
|
||||||
model_id = False
|
|
||||||
if len(model_ids):
|
|
||||||
model_id = model_ids[0]
|
|
||||||
|
|
||||||
res = {}
|
res = {}
|
||||||
for lead in self.browse(cr, uid, ids , context):
|
for lead in self.browse(cr, uid, ids , context):
|
||||||
for field in fields:
|
for field in fields:
|
||||||
res[lead.id] = {}
|
res[lead.id] = {}
|
||||||
duration = 0
|
duration = 0
|
||||||
|
ans = False
|
||||||
if field == 'day_open':
|
if field == 'day_open':
|
||||||
if lead.date_open:
|
if lead.date_open:
|
||||||
date_create = datetime.strptime(lead.create_date, "%Y-%m-%d %H:%M:%S")
|
date_create = datetime.strptime(lead.create_date, "%Y-%m-%d %H:%M:%S")
|
||||||
date_open = datetime.strptime(lead.date_open, "%Y-%m-%d %H:%M:%S")
|
date_open = datetime.strptime(lead.date_open, "%Y-%m-%d %H:%M:%S")
|
||||||
|
|
||||||
ans = date_open - date_create
|
ans = date_open - date_create
|
||||||
duration = float(ans.days) + (float(ans.seconds) / 86400)
|
date_until = lead.date_open
|
||||||
|
|
||||||
elif field == 'day_close':
|
elif field == 'day_close':
|
||||||
if lead.date_closed:
|
if lead.date_closed:
|
||||||
date_create = datetime.strptime(lead.create_date, "%Y-%m-%d %H:%M:%S")
|
date_create = datetime.strptime(lead.create_date, "%Y-%m-%d %H:%M:%S")
|
||||||
date_close = datetime.strptime(lead.date_closed, "%Y-%m-%d %H:%M:%S")
|
date_close = datetime.strptime(lead.date_closed, "%Y-%m-%d %H:%M:%S")
|
||||||
|
date_until = lead.date_closed
|
||||||
ans = date_close - date_create
|
ans = date_close - date_create
|
||||||
duration = float(ans.days) + (float(ans.seconds) / 86400)
|
if ans:
|
||||||
|
resource_id = False
|
||||||
|
if lead.user_id:
|
||||||
|
resource_ids = res_obj.search(cr, uid, [('user_id','=',lead.user_id.id)])
|
||||||
|
resource_id = len(resource_ids) or resource_ids[0]
|
||||||
|
|
||||||
|
duration = float(ans.days)
|
||||||
|
if lead.section_id.resource_calendar_id:
|
||||||
|
duration = float(ans.days) * 24
|
||||||
|
new_dates = cal_obj.interval_get(cr,
|
||||||
|
uid,
|
||||||
|
lead.section_id.resource_calendar_id and lead.section_id.resource_calendar_id.id or False,
|
||||||
|
mx.DateTime.strptime(lead.create_date, '%Y-%m-%d %H:%M:%S'),
|
||||||
|
duration,
|
||||||
|
resource=resource_id
|
||||||
|
)
|
||||||
|
no_days = []
|
||||||
|
date_until = mx.DateTime.strptime(date_until, '%Y-%m-%d %H:%M:%S')
|
||||||
|
for in_time, out_time in new_dates:
|
||||||
|
if in_time.date not in no_days:
|
||||||
|
no_days.append(in_time.date)
|
||||||
|
if out_time > date_until:
|
||||||
|
break
|
||||||
|
duration = len(no_days)
|
||||||
res[lead.id][field] = abs(int(duration))
|
res[lead.id][field] = abs(int(duration))
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
|
@ -140,6 +140,7 @@
|
||||||
<field name="create_date"/>
|
<field name="create_date"/>
|
||||||
<field name="write_date"/>
|
<field name="write_date"/>
|
||||||
<field name="date_closed"/>
|
<field name="date_closed"/>
|
||||||
|
<field name="date_open"/>
|
||||||
</group>
|
</group>
|
||||||
<group colspan="2" col="2">
|
<group colspan="2" col="2">
|
||||||
<separator string="Statistics" colspan="2" col="2"/>
|
<separator string="Statistics" colspan="2" col="2"/>
|
||||||
|
|
|
@ -24,6 +24,7 @@ from osv import fields,osv,orm
|
||||||
from tools.translate import _
|
from tools.translate import _
|
||||||
import crm
|
import crm
|
||||||
import time
|
import time
|
||||||
|
import mx.DateTime
|
||||||
|
|
||||||
AVAILABLE_STATES = [
|
AVAILABLE_STATES = [
|
||||||
('draft','New'),
|
('draft','New'),
|
||||||
|
@ -50,15 +51,9 @@ class crm_opportunity(osv.osv):
|
||||||
@param *args: Give Tuple Value
|
@param *args: Give Tuple Value
|
||||||
"""
|
"""
|
||||||
|
|
||||||
cases = self.browse(cr, uid, ids)
|
res = super(crm_opportunity, self).case_open(cr, uid, ids, *args)
|
||||||
for case in cases:
|
self.write(cr, uid, ids, {'date_open': time.strftime('%Y-%m-%d %H:%M:%S')})
|
||||||
data = {'state': 'open', 'active': True}
|
return res
|
||||||
if not case.user_id:
|
|
||||||
data['user_id'] = uid
|
|
||||||
data.update({'date_open': time.strftime('%Y-%m-%d %H:%M:%S')})
|
|
||||||
self.write(cr, uid, ids, data)
|
|
||||||
self._action(cr, uid, cases, 'open')
|
|
||||||
return True
|
|
||||||
|
|
||||||
def _compute_day(self, cr, uid, ids, fields, args, context={}):
|
def _compute_day(self, cr, uid, ids, fields, args, context={}):
|
||||||
"""
|
"""
|
||||||
|
@ -67,36 +62,52 @@ class crm_opportunity(osv.osv):
|
||||||
@param ids: List of Openday’s IDs
|
@param ids: List of Openday’s IDs
|
||||||
@return: difference between current date and log date
|
@return: difference between current date and log date
|
||||||
@param context: A standard dictionary for contextual values
|
@param context: A standard dictionary for contextual values
|
||||||
"""
|
"""
|
||||||
log_obj = self.pool.get('crm.case.log')
|
cal_obj = self.pool.get('resource.calendar')
|
||||||
model_obj = self.pool.get('ir.model')
|
res_obj = self.pool.get('resource.resource')
|
||||||
cal_obj = self.pool.get('resource.calendar')
|
|
||||||
|
|
||||||
model_ids = model_obj.search(cr, uid, [('model', '=', self._name)])
|
|
||||||
model_id = False
|
|
||||||
if len(model_ids):
|
|
||||||
model_id = model_ids[0]
|
|
||||||
|
|
||||||
res = {}
|
res = {}
|
||||||
for opportunity in self.browse(cr, uid, ids , context):
|
for opportunity in self.browse(cr, uid, ids , context):
|
||||||
for field in fields:
|
for field in fields:
|
||||||
res[opportunity.id] = {}
|
res[opportunity.id] = {}
|
||||||
duration = 0
|
duration = 0
|
||||||
|
ans = False
|
||||||
if field == 'day_open':
|
if field == 'day_open':
|
||||||
if opportunity.date_open:
|
if opportunity.date_open:
|
||||||
date_create = datetime.strptime(opportunity.create_date, "%Y-%m-%d %H:%M:%S")
|
date_create = datetime.strptime(opportunity.create_date, "%Y-%m-%d %H:%M:%S")
|
||||||
date_open = datetime.strptime(opportunity.date_open, "%Y-%m-%d %H:%M:%S")
|
date_open = datetime.strptime(opportunity.date_open, "%Y-%m-%d %H:%M:%S")
|
||||||
|
|
||||||
ans = date_open - date_create
|
ans = date_open - date_create
|
||||||
duration = float(ans.days) + (float(ans.seconds) / 86400)
|
date_until = opportunity.date_open
|
||||||
|
|
||||||
elif field == 'day_close':
|
elif field == 'day_close':
|
||||||
if opportunity.date_closed:
|
if opportunity.date_closed:
|
||||||
date_create = datetime.strptime(opportunity.create_date, "%Y-%m-%d %H:%M:%S")
|
date_create = datetime.strptime(opportunity.create_date, "%Y-%m-%d %H:%M:%S")
|
||||||
date_close = datetime.strptime(opportunity.date_closed, "%Y-%m-%d %H:%M:%S")
|
date_close = datetime.strptime(opportunity.date_closed, "%Y-%m-%d %H:%M:%S")
|
||||||
|
date_until = opportunity.date_closed
|
||||||
ans = date_close - date_create
|
ans = date_close - date_create
|
||||||
duration = float(ans.days) + (float(ans.seconds) / 86400)
|
if ans:
|
||||||
|
resource_id = False
|
||||||
|
if opportunity.user_id:
|
||||||
|
resource_ids = res_obj.search(cr, uid, [('user_id','=',opportunity.user_id.id)])
|
||||||
|
resource_id = len(resource_ids) or resource_ids[0]
|
||||||
|
|
||||||
|
duration = float(ans.days)
|
||||||
|
if opportunity.section_id.resource_calendar_id:
|
||||||
|
duration = float(ans.days) * 24
|
||||||
|
new_dates = cal_obj.interval_get(cr,
|
||||||
|
uid,
|
||||||
|
opportunity.section_id.resource_calendar_id and opportunity.section_id.resource_calendar_id.id or False,
|
||||||
|
mx.DateTime.strptime(opportunity.create_date, '%Y-%m-%d %H:%M:%S'),
|
||||||
|
duration,
|
||||||
|
resource=resource_id
|
||||||
|
)
|
||||||
|
no_days = []
|
||||||
|
date_until = mx.DateTime.strptime(date_until, '%Y-%m-%d %H:%M:%S')
|
||||||
|
for in_time, out_time in new_dates:
|
||||||
|
if in_time.date not in no_days:
|
||||||
|
no_days.append(in_time.date)
|
||||||
|
if out_time > date_until:
|
||||||
|
break
|
||||||
|
duration = len(no_days)
|
||||||
res[opportunity.id][field] = abs(int(duration))
|
res[opportunity.id][field] = abs(int(duration))
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
<field name="parent_id" select="2" widget="selection"/>
|
<field name="parent_id" select="2" widget="selection"/>
|
||||||
<field name="allow_unlink" select="2"/>
|
<field name="allow_unlink" select="2"/>
|
||||||
<field name="reply_to" select="2"/>
|
<field name="reply_to" select="2"/>
|
||||||
|
<field name="resource_calendar_id" select="2"/>
|
||||||
</page>
|
</page>
|
||||||
</notebook>
|
</notebook>
|
||||||
</form>
|
</form>
|
||||||
|
|
|
@ -26,6 +26,7 @@ import time
|
||||||
import time
|
import time
|
||||||
import tools
|
import tools
|
||||||
from crm import crm
|
from crm import crm
|
||||||
|
import mx.DateTime
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from osv import fields,osv,orm
|
from osv import fields,osv,orm
|
||||||
from osv.orm import except_orm
|
from osv.orm import except_orm
|
||||||
|
@ -46,15 +47,9 @@ class project_issue(osv.osv):
|
||||||
@param *args: Give Tuple Value
|
@param *args: Give Tuple Value
|
||||||
"""
|
"""
|
||||||
|
|
||||||
cases = self.browse(cr, uid, ids)
|
res = super(project_issue, self).case_open(cr, uid, ids, *args)
|
||||||
for case in cases:
|
self.write(cr, uid, ids, {'date_open': time.strftime('%Y-%m-%d %H:%M:%S')})
|
||||||
data = {'state': 'open', 'active': True}
|
return res
|
||||||
if not case.user_id:
|
|
||||||
data['user_id'] = uid
|
|
||||||
data.update({'date_open': time.strftime('%Y-%m-%d %H:%M:%S')})
|
|
||||||
self.write(cr, uid, ids, data)
|
|
||||||
self._action(cr, uid, cases, 'open')
|
|
||||||
return True
|
|
||||||
|
|
||||||
def _compute_day(self, cr, uid, ids, fields, args, context={}):
|
def _compute_day(self, cr, uid, ids, fields, args, context={}):
|
||||||
"""
|
"""
|
||||||
|
@ -63,37 +58,53 @@ class project_issue(osv.osv):
|
||||||
@param ids: List of Openday’s IDs
|
@param ids: List of Openday’s IDs
|
||||||
@return: difference between current date and log date
|
@return: difference between current date and log date
|
||||||
@param context: A standard dictionary for contextual values
|
@param context: A standard dictionary for contextual values
|
||||||
"""
|
"""
|
||||||
log_obj = self.pool.get('crm.case.log')
|
cal_obj = self.pool.get('resource.calendar')
|
||||||
model_obj = self.pool.get('ir.model')
|
res_obj = self.pool.get('resource.resource')
|
||||||
cal_obj = self.pool.get('resource.calendar')
|
|
||||||
|
|
||||||
model_ids = model_obj.search(cr, uid, [('model', '=', self._name)])
|
|
||||||
model_id = False
|
|
||||||
if len(model_ids):
|
|
||||||
model_id = model_ids[0]
|
|
||||||
|
|
||||||
res = {}
|
res = {}
|
||||||
for project in self.browse(cr, uid, ids , context):
|
for issue in self.browse(cr, uid, ids , context):
|
||||||
for field in fields:
|
for field in fields:
|
||||||
res[project.id] = {}
|
res[issue.id] = {}
|
||||||
duration = 0
|
duration = 0
|
||||||
|
ans = False
|
||||||
if field == 'day_open':
|
if field == 'day_open':
|
||||||
if project.date_open:
|
if issue.date_open:
|
||||||
date_create = datetime.strptime(project.create_date, "%Y-%m-%d %H:%M:%S")
|
date_create = datetime.strptime(issue.create_date, "%Y-%m-%d %H:%M:%S")
|
||||||
date_open = datetime.strptime(project.date_open, "%Y-%m-%d %H:%M:%S")
|
date_open = datetime.strptime(issue.date_open, "%Y-%m-%d %H:%M:%S")
|
||||||
|
|
||||||
ans = date_open - date_create
|
ans = date_open - date_create
|
||||||
duration = float(ans.days) + (float(ans.seconds) / 86400)
|
date_until = issue.date_open
|
||||||
|
|
||||||
elif field == 'day_close':
|
elif field == 'day_close':
|
||||||
if project.date_closed:
|
if issue.date_closed:
|
||||||
date_create = datetime.strptime(project.create_date, "%Y-%m-%d %H:%M:%S")
|
date_create = datetime.strptime(issue.create_date, "%Y-%m-%d %H:%M:%S")
|
||||||
date_close = datetime.strptime(project.date_closed, "%Y-%m-%d %H:%M:%S")
|
date_close = datetime.strptime(issue.date_closed, "%Y-%m-%d %H:%M:%S")
|
||||||
|
date_until = issue.date_closed
|
||||||
ans = date_close - date_create
|
ans = date_close - date_create
|
||||||
duration = float(ans.days) + (float(ans.seconds) / 86400)
|
if ans:
|
||||||
res[project.id][field] = abs(int(duration))
|
resource_id = False
|
||||||
|
if issue.user_id:
|
||||||
|
resource_ids = res_obj.search(cr, uid, [('user_id','=',issue.user_id.id)])
|
||||||
|
resource_id = len(resource_ids) or resource_ids[0]
|
||||||
|
|
||||||
|
duration = float(ans.days)
|
||||||
|
if issue.section_id.resource_calendar_id:
|
||||||
|
duration = float(ans.days) * 24
|
||||||
|
new_dates = cal_obj.interval_get(cr,
|
||||||
|
uid,
|
||||||
|
issue.section_id.resource_calendar_id and issue.section_id.resource_calendar_id.id or False,
|
||||||
|
mx.DateTime.strptime(issue.create_date, '%Y-%m-%d %H:%M:%S'),
|
||||||
|
duration,
|
||||||
|
resource=resource_id
|
||||||
|
)
|
||||||
|
no_days = []
|
||||||
|
date_until = mx.DateTime.strptime(date_until, '%Y-%m-%d %H:%M:%S')
|
||||||
|
for in_time, out_time in new_dates:
|
||||||
|
if in_time.date not in no_days:
|
||||||
|
no_days.append(in_time.date)
|
||||||
|
if out_time > date_until:
|
||||||
|
break
|
||||||
|
duration = len(no_days)
|
||||||
|
res[issue.id][field] = abs(int(duration))
|
||||||
return res
|
return res
|
||||||
|
|
||||||
_columns = {
|
_columns = {
|
||||||
|
@ -116,7 +127,7 @@ class project_issue(osv.osv):
|
||||||
method=True, multi='day_open', type="integer", store=True),
|
method=True, multi='day_open', type="integer", store=True),
|
||||||
'day_close': fields.function(_compute_day, string='Days to Close', \
|
'day_close': fields.function(_compute_day, string='Days to Close', \
|
||||||
method=True, multi='day_close', type="integer", store=True),
|
method=True, multi='day_close', type="integer", store=True),
|
||||||
'assigned_to' : fields.many2one('res.users', 'Assigned to'),
|
'assigned_to' : fields.many2one('res.users', 'Assigned to'),
|
||||||
'timesheet_ids' : fields.one2many('hr.analytic.timesheet', 'issue_id', 'Timesheets'),
|
'timesheet_ids' : fields.one2many('hr.analytic.timesheet', 'issue_id', 'Timesheets'),
|
||||||
'analytic_account_id' : fields.many2one('account.analytic.account', 'Analytic Account',
|
'analytic_account_id' : fields.many2one('account.analytic.account', 'Analytic Account',
|
||||||
domain="[('partner_id', '=', partner_id)]",
|
domain="[('partner_id', '=', partner_id)]",
|
||||||
|
|
Loading…
Reference in New Issue