[IMP]: mailgateway script: Improvement for attachment,

[IMP]: crm: Improvement in lead to opportunity wizard for leads history lines

bzr revid: rpa@tinyerp.com-20100323061825-fw7np8dhnzvi0t93
This commit is contained in:
rpa (Open ERP) 2010-03-23 11:48:25 +05:30
parent 35095a09ed
commit 815b276826
2 changed files with 45 additions and 7 deletions

View File

@ -182,8 +182,7 @@ class email_parser(object):
if getattr(e, 'faultCode', '') and 'AccessError' in e.faultCode:
e = '\n\nThe Specified user does not have an access to the CRM case.'
print e
attachments = message['attachment']
attachments = message['attachment']
for attach in attachments or []:
data_attach = {
'name': str(attach),
@ -266,7 +265,7 @@ class email_parser(object):
data = {
# 'description': body['body'],
}
act = 'case_pending'
act = 'case_open'
if 'state' in actions:
if actions['state'] in ['draft', 'close', 'cancel', 'open', 'pending']:
act = 'case_' + actions['state']
@ -291,6 +290,17 @@ class email_parser(object):
self.rpc(self.model, act, [id])
self.rpc(self.model, 'write', [id], data)
attachments = body['attachment']
for attach in attachments or []:
data_attach = {
'name': str(attach),
'datas': binascii.b2a_base64(str(attachments[attach])),
'datas_fname': str(attach),
'description': 'Mail attachment',
'res_model': self.model,
'res_id': id
}
self.rpc('ir.attachment', 'create', data_attach)
self.rpc(self.model, 'history', [id], 'Send', True, msg['From'], body['body'])
return id
@ -323,6 +333,17 @@ class email_parser(object):
# 'description':body,
#}
#self.rpc(self.model, 'write', [id], data)
attachments = message['attachment']
for attach in attachments or []:
data_attach = {
'name': str(attach),
'datas': binascii.b2a_base64(str(attachments[attach])),
'datas_fname': str(attach),
'description': 'Mail attachment',
'res_model': self.model,
'res_id': id
}
self.rpc('ir.attachment', 'create', data_attach)
self.rpc(self.model, 'history', [id], 'Send', True, msg['From'], message['body'])
return id

View File

@ -227,8 +227,10 @@ class lead2opportunity(partner_create):
id3 = data_obj.browse(cr, uid, id3, context=context).res_id
lead_case_obj = pool.get('crm.lead')
opportunity_case_obj = pool.get('crm.opportunity')
for lead in lead_case_obj.browse(cr, uid, data['ids']):
history_obj = pool.get('crm.case.history')
opportunity_case_obj = pool.get('crm.opportunity')
model_obj = pool.get('ir.model')
for lead in lead_case_obj.browse(cr, uid, data['ids']):
new_opportunity_id = opportunity_case_obj.create(cr, uid, {
'name': data['form']['name'],
'planned_revenue': data['form']['planned_revenue'],
@ -240,11 +242,15 @@ class lead2opportunity(partner_create):
'partner_address_id':lead.partner_address_id.id,
'priority': lead.priority,
'phone': lead.phone,
'email_from': lead.email_from
'email_from': lead.email_from,
})
new_opportunity = opportunity_case_obj.browse(cr, uid, new_opportunity_id)
model_ids = model_obj.search(cr, uid, [('model','=','crm.opportunity')])
for his_id in lead.history_line:
history_ids = history_obj.copy(cr, uid, his_id.id, {'model_id' : model_ids[0], 'res_id':new_opportunity})
vals = {
'partner_id': data['form']['partner_id'],
}
@ -332,6 +338,8 @@ class crm_lead2opportunity(osv.osv_memory):
lead_obj = self.pool.get('crm.lead')
opp_obj = self. pool.get('crm.opportunity')
data_obj = self.pool.get('ir.model.data')
history_obj = pool.get('crm.case.history')
model_obj = pool.get('ir.model')
# Get Opportunity views
result = data_obj._get_id(cr, uid, 'crm', 'view_crm_case_opportunities_filter')
@ -344,6 +352,8 @@ class crm_lead2opportunity(osv.osv_memory):
id3 = data_obj.browse(cr, uid, id3, context=context).res_id
lead = lead_obj.browse(cr, uid, record_id, context=context)
model_ids = model_obj.search(cr, uid, [('model','=','crm.opportunity')])
for this in self.browse(cr, uid, ids, context=context):
new_opportunity_id = opp_obj.create(cr, uid, {
@ -370,6 +380,13 @@ class crm_lead2opportunity(osv.osv_memory):
lead_obj.write(cr, uid, [lead.id], vals)
lead_obj.case_close(cr, uid, [lead.id])
# Copy lead history to opportunity
for his_id in lead.history_line:
history_ids = history_obj.copy(cr, uid, his_id.id, \
{'model_id': model_ids[0], \
'res_id': new_opportunity_id})
opp_obj.case_open(cr, uid, [new_opportunity_id])
value = {