[IMP]: crm project_issue: implement compute day function in this module
bzr revid: ksa@tinyerp.co.in-20100405084054-vdc6tz5i8dtr1it9
This commit is contained in:
parent
470ee954cd
commit
59be5d42e2
|
@ -503,8 +503,8 @@ class crm_case(osv.osv):
|
|||
s[section] = dict([(v, k) for (k, v) in s[section].iteritems()])
|
||||
if st in s[section]:
|
||||
self.write(cr, uid, [case.id], {'stage_id': s[section][st]})
|
||||
return True
|
||||
|
||||
return True
|
||||
|
||||
def history(self, cr, uid, ids, keyword, history=False, email=False, details=None, context={}):
|
||||
"""
|
||||
@param self: The object pointer
|
||||
|
@ -552,7 +552,7 @@ class crm_case(osv.osv):
|
|||
(case.section_id and case.section_id.reply_to) or \
|
||||
(case.user_id and case.user_id.address_id and \
|
||||
case.user_id.address_id.email) or tools.config.get('email_from',False)
|
||||
res = obj.create(cr, uid, data, context)
|
||||
res = obj.create(cr, uid, data, context)
|
||||
return True
|
||||
_history = __history
|
||||
|
||||
|
@ -631,7 +631,7 @@ class crm_case(osv.osv):
|
|||
self.__history(cr, uid, cases, _('Send'), history=True, email=False)
|
||||
for case in cases:
|
||||
self.write(cr, uid, [case.id], {
|
||||
'description': False,
|
||||
'description': False,
|
||||
})
|
||||
emails = [case.email_from] + (case.email_cc or '').split(',')
|
||||
emails = filter(None, emails)
|
||||
|
@ -645,11 +645,11 @@ class crm_case(osv.osv):
|
|||
_("No E-Mail ID Found for your Company address!"))
|
||||
|
||||
tools.email_send(
|
||||
emailfrom,
|
||||
emails,
|
||||
'[' + str(case.id) + '] ' + case.name,
|
||||
self.format_body(body),
|
||||
reply_to = case.section_id.reply_to,
|
||||
emailfrom,
|
||||
emails,
|
||||
'[' + str(case.id) + '] ' + case.name,
|
||||
self.format_body(body),
|
||||
reply_to = case.section_id.reply_to,
|
||||
openobject_id = str(case.id)
|
||||
)
|
||||
self.__history(cr, uid, [case], _('Send'), history=True, email=emails, details=body, email_from=emailfrom)
|
||||
|
@ -814,11 +814,11 @@ class crm_case_log(osv.osv):
|
|||
_order = "id desc"
|
||||
_columns = {
|
||||
'name': fields.char('Status', size=64),
|
||||
'date': fields.datetime('Date'),
|
||||
'section_id': fields.many2one('crm.case.section', 'Section'),
|
||||
'user_id': fields.many2one('res.users', 'User Responsible', readonly=True),
|
||||
'model_id': fields.many2one('ir.model', "Model"),
|
||||
'res_id': fields.integer('Resource ID'),
|
||||
'date': fields.datetime('Date'),
|
||||
'section_id': fields.many2one('crm.case.section', 'Section'),
|
||||
'user_id': fields.many2one('res.users', 'User Responsible', readonly=True),
|
||||
'model_id': fields.many2one('ir.model', "Model"),
|
||||
'res_id': fields.integer('Resource ID'),
|
||||
}
|
||||
|
||||
_defaults = {
|
||||
|
|
|
@ -23,6 +23,7 @@ from osv import fields, osv, orm
|
|||
from datetime import datetime, timedelta
|
||||
import crm
|
||||
import math
|
||||
from mx import DateTime
|
||||
from tools.translate import _
|
||||
|
||||
class crm_lead(osv.osv):
|
||||
|
@ -92,11 +93,11 @@ class crm_lead(osv.osv):
|
|||
|
||||
'user_id': fields.many2one('res.users', 'Salesman'),
|
||||
'referred': fields.char('Referred By', size=32),
|
||||
'date_open': fields.datetime('Opened', readonly=True),
|
||||
'date_open': fields.datetime('Opened', readonly=True),
|
||||
'day_open': fields.function(_compute_day, string='Days to Open', \
|
||||
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', \
|
||||
method=True, multi='day_close', type="integer", store=True),
|
||||
method=True, multi='day_close', type="integer", store=True),
|
||||
'function_name': fields.char('Function', size=64),
|
||||
}
|
||||
|
||||
|
|
|
@ -40,8 +40,7 @@ class crm_opportunity(osv.osv):
|
|||
_order = "id desc"
|
||||
_inherit = 'crm.case'
|
||||
|
||||
def _compute_openday(self, cr, uid, ids, name, args, context={}):
|
||||
|
||||
def _compute_day(self, cr, uid, ids, fields, args, context={}):
|
||||
"""
|
||||
@param cr: the current row, from the database cursor,
|
||||
@param uid: the current user’s ID for security checks,
|
||||
|
@ -49,45 +48,37 @@ class crm_opportunity(osv.osv):
|
|||
@return: difference between current date and log date
|
||||
@param context: A standard dictionary for contextual values
|
||||
"""
|
||||
result = {}
|
||||
for r in self.browse(cr, uid, ids , context):
|
||||
result[r.id] = 0
|
||||
model_id = self.pool.get('ir.model').search(cr, uid, [('model', '=', 'crm.opportunity')])
|
||||
log_obj = self.pool.get('crm.case.log')
|
||||
hist_id = log_obj.search(cr, uid, [('model_id', '=', model_id[0]), \
|
||||
('res_id', '=', r.id), \
|
||||
('name', '=', 'Open')])
|
||||
log_obj = self.pool.get('crm.case.log')
|
||||
model_obj = self.pool.get('ir.model')
|
||||
cal_obj = self.pool.get('resource.calendar')
|
||||
|
||||
if hist_id:
|
||||
# Considering last log for opening case
|
||||
log = log_obj.browse(cr, uid, hist_id[-1])
|
||||
date_lead_open = datetime.strptime(r.create_date, "%Y-%m-%d %H:%M:%S")
|
||||
date_log_open = datetime.strptime(log.date, "%Y-%m-%d %H:%M:%S")
|
||||
ans = date_lead_open - date_log_open
|
||||
duration = float(ans.days) + (float(ans.seconds) / 86400)
|
||||
result[r.id] = abs(int(duration))
|
||||
return result
|
||||
model_ids = model_obj.search(cr, uid, [('model', '=', self._name)])
|
||||
model_id = False
|
||||
if len(model_ids):
|
||||
model_id = model_ids[0]
|
||||
|
||||
def _compute_closeday(self, cr, uid, ids, name, args, context={}):
|
||||
res = {}
|
||||
for lead in self.browse(cr, uid, ids , context):
|
||||
for field in fields:
|
||||
res[lead.id] = {}
|
||||
duration = 0
|
||||
if field == 'day_open':
|
||||
if lead.date_open:
|
||||
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")
|
||||
|
||||
"""
|
||||
@param cr: the current row, from the database cursor,
|
||||
@param uid: the current user’s ID for security checks,
|
||||
@param ids: List of closeday’s IDs
|
||||
@return: difference between current date and closed date
|
||||
@param context: A standard dictionary for contextual values
|
||||
"""
|
||||
result = {}
|
||||
for r in self.browse(cr, uid, ids , context):
|
||||
result[r.id] = 0
|
||||
ans = date_open - date_create
|
||||
duration = float(ans.days) + (float(ans.seconds) / 86400)
|
||||
|
||||
if r.date_closed:
|
||||
date_create = datetime.strptime(r.create_date, "%Y-%m-%d %H:%M:%S")
|
||||
date_close = datetime.strptime(r.date_closed, "%Y-%m-%d %H:%M:%S")
|
||||
ans = date_close - date_create
|
||||
duration = float(ans.days) + (float(ans.seconds) / 86400)
|
||||
result[r.id] = abs(int(duration))
|
||||
return result
|
||||
elif field == 'day_close':
|
||||
if lead.date_closed:
|
||||
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")
|
||||
|
||||
ans = date_close - date_create
|
||||
duration = float(ans.days) + (float(ans.seconds) / 86400)
|
||||
res[lead.id][field] = abs(int(duration))
|
||||
return res
|
||||
|
||||
_columns = {
|
||||
'stage_id': fields.many2one ('crm.case.stage', 'Stage', \
|
||||
|
@ -113,11 +104,12 @@ class crm_opportunity(osv.osv):
|
|||
\nWhen the case is over, the state is set to \'Done\'.\
|
||||
\nIf the case needs to be reviewed then the state is set to \'Pending\'.'),
|
||||
|
||||
'day_open': fields.function(_compute_openday, string='Days to Open', \
|
||||
method=True, type="integer", store=True),
|
||||
'day_close': fields.function(_compute_closeday, string='Days to Close', \
|
||||
method=True, type="integer", store=True),
|
||||
}
|
||||
'date_open': fields.datetime('Opened', readonly=True),
|
||||
'day_open': fields.function(_compute_day, string='Days to Open', \
|
||||
method=True, multi='day_open', type="integer", store=True),
|
||||
'day_close': fields.function(_compute_day, string='Days to Close', \
|
||||
method=True, multi='day_close', type="integer", store=True),
|
||||
}
|
||||
|
||||
def onchange_stage_id(self, cr, uid, ids, stage_id, context={}):
|
||||
|
||||
|
|
|
@ -138,12 +138,14 @@
|
|||
<field name="create_date"/>
|
||||
<field name="write_date"/>
|
||||
<field name="date_closed"/>
|
||||
<field name="date_open"/>
|
||||
</group>
|
||||
<group col="2" colspan="2">
|
||||
<separator string="Misc" colspan="2"/>
|
||||
<field name="active"/>
|
||||
<field name="day_open"/>
|
||||
<field name="day_close"/>
|
||||
|
||||
</group>
|
||||
<separator colspan="4" string="References"/>
|
||||
<field name="ref"/>
|
||||
|
|
|
@ -37,37 +37,45 @@ class project_issue(osv.osv):
|
|||
_order = "priority, id desc"
|
||||
_inherit = 'crm.case'
|
||||
|
||||
def _compute_openday(self, cr, uid, ids, name, args, context={}):
|
||||
result = {}
|
||||
for r in self.browse(cr, uid, ids , context):
|
||||
result[r.id] = 0
|
||||
model_id = self.pool.get('ir.model').search(cr, uid, [('model', '=', 'project.issue')])
|
||||
log_obj = self.pool.get('crm.case.log')
|
||||
hist_id = log_obj.search(cr, uid, [('model_id', '=', model_id[0]), \
|
||||
('res_id', '=', r.id), \
|
||||
('name', '=', 'Open')])
|
||||
def _compute_day(self, cr, uid, ids, fields, args, context={}):
|
||||
"""
|
||||
@param cr: the current row, from the database cursor,
|
||||
@param uid: the current user’s ID for security checks,
|
||||
@param ids: List of Openday’s IDs
|
||||
@return: difference between current date and log date
|
||||
@param context: A standard dictionary for contextual values
|
||||
"""
|
||||
log_obj = self.pool.get('crm.case.log')
|
||||
model_obj = self.pool.get('ir.model')
|
||||
cal_obj = self.pool.get('resource.calendar')
|
||||
|
||||
if hist_id:
|
||||
# Considering last log for opening case
|
||||
log = log_obj.browse(cr, uid, hist_id[-1])
|
||||
date_lead_open = datetime.strptime(r.create_date, "%Y-%m-%d %H:%M:%S")
|
||||
date_log_open = datetime.strptime(log.date, "%Y-%m-%d %H:%M:%S")
|
||||
ans = date_lead_open - date_log_open
|
||||
duration = float(ans.days) + (float(ans.seconds) / 86400)
|
||||
result[r.id] = abs(int(duration))
|
||||
return result
|
||||
model_ids = model_obj.search(cr, uid, [('model', '=', self._name)])
|
||||
model_id = False
|
||||
if len(model_ids):
|
||||
model_id = model_ids[0]
|
||||
|
||||
def _compute_closeday(self, cr, uid, ids, name, args, context={}):
|
||||
result = {}
|
||||
for r in self.browse(cr, uid, ids , context):
|
||||
result[r.id] = 0
|
||||
if r.date_closed:
|
||||
date_create = datetime.strptime(r.create_date, "%Y-%m-%d %H:%M:%S")
|
||||
date_close = datetime.strptime(r.date_closed, "%Y-%m-%d %H:%M:%S")
|
||||
ans = date_close - date_create
|
||||
duration = float(ans.days) + (float(ans.seconds) / 86400)
|
||||
result[r.id] = abs(int(duration))
|
||||
return result
|
||||
res = {}
|
||||
for lead in self.browse(cr, uid, ids , context):
|
||||
for field in fields:
|
||||
res[lead.id] = {}
|
||||
duration = 0
|
||||
if field == 'day_open':
|
||||
if lead.date_open:
|
||||
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")
|
||||
|
||||
ans = date_open - date_create
|
||||
duration = float(ans.days) + (float(ans.seconds) / 86400)
|
||||
|
||||
elif field == 'day_close':
|
||||
if lead.date_closed:
|
||||
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")
|
||||
|
||||
ans = date_close - date_create
|
||||
duration = float(ans.days) + (float(ans.seconds) / 86400)
|
||||
res[lead.id][field] = abs(int(duration))
|
||||
return res
|
||||
|
||||
_columns = {
|
||||
'date_closed': fields.datetime('Closed', readonly=True),
|
||||
|
@ -84,11 +92,12 @@ class project_issue(osv.osv):
|
|||
'project_id':fields.many2one('project.project', 'Project'),
|
||||
'duration': fields.float('Duration'),
|
||||
'task_id': fields.many2one('project.task', 'Task', domain="[('project_id','=',project_id)]"),
|
||||
'day_open': fields.function(_compute_openday, string='Days to Open', \
|
||||
method=True, type="integer", store=True),
|
||||
'day_close': fields.function(_compute_closeday, string='Days to Close', \
|
||||
method=True, type="integer", store=True),
|
||||
'assigned_to' : fields.many2one('res.users', 'Assigned to'),
|
||||
'date_open': fields.datetime('Opened', readonly=True),
|
||||
'day_open': fields.function(_compute_day, string='Days to Open', \
|
||||
method=True, multi='day_open', type="integer", store=True),
|
||||
'day_close': fields.function(_compute_day, string='Days to Close', \
|
||||
method=True, multi='day_close', type="integer", store=True),
|
||||
'assigned_to' : fields.many2one('res.users', 'Assigned to'),
|
||||
'timesheet_ids' : fields.one2many('hr.analytic.timesheet', 'issue_id', 'Timesheets'),
|
||||
'analytic_account_id' : fields.many2one('account.analytic.account', 'Analytic Account',
|
||||
domain="[('partner_id', '=', partner_id)]",
|
||||
|
|
|
@ -77,7 +77,13 @@
|
|||
<group col="2" colspan="2">
|
||||
<separator colspan="2" string="Date"/>
|
||||
<field name="date_closed"/>
|
||||
<field name="date_open"/>
|
||||
</group>
|
||||
<group colspan="2" col="2">
|
||||
<separator string="Statistics" colspan="2" col="2"/>
|
||||
<field name="day_open"/>
|
||||
<field name="day_close"/>
|
||||
</group>
|
||||
<group col="2" colspan="2">
|
||||
<separator string="References" colspan="2"/>
|
||||
<field name="id"/>
|
||||
|
@ -88,7 +94,7 @@
|
|||
<separator string="Action Information" colspan="4"/>
|
||||
<field name="name" colspan="4"/>
|
||||
<field name="date" />
|
||||
<field name="user_id" />
|
||||
<field name="user_id" />
|
||||
</form>
|
||||
</field>
|
||||
</page>
|
||||
|
|
Loading…
Reference in New Issue