[FIX] crm: mailgate related problem

bzr revid: hmo@tinyerp.com-20100215075447-j4tcz1b0z8ao0mjj
This commit is contained in:
Harry (Open ERP) 2010-02-15 13:24:47 +05:30
parent ba65e11add
commit 01e4480005
4 changed files with 31 additions and 23 deletions

View File

@ -188,7 +188,7 @@ class crm_case_rule(osv.osv):
'trg_section_id': fields.many2one('crm.case.section', 'Section'),
# 'trg_categ_id': fields.many2one('crm.case.categ', 'Category', domain="[('section_id','=',trg_section_id)]"),
'trg_categ_id': fields.many2one('crm.case.categ', 'Category', domain="[('section_id','=',trg_section_id)]"),
'trg_user_id': fields.many2one('res.users', 'Responsible'),
'trg_partner_id': fields.many2one('res.partner', 'Partner'),
@ -365,7 +365,7 @@ class crm_case(osv.osv):
def _get_section(self, cr, uid, context):
user = self.pool.get('res.users').browse(cr, uid, uid,context=context)
return user.context_section_id
return user.context_section_id.id or False
_defaults = {
'active': lambda *a: 1,
@ -586,7 +586,7 @@ class crm_case(osv.osv):
def __history(self, cr, uid, cases, keyword, history=False, email=False, details=None, context={}):
model_obj = self.pool.get('ir.model')
model_obj = self.pool.get('ir.model')
for case in cases:
model_ids = model_obj.search(cr, uid, [('model','=',case._name)])
data = {

View File

@ -36,7 +36,7 @@ class crm_cases(osv.osv):
_name = "crm.case"
_inherit = "crm.case"
def msg_new(self, cr, uid, msg):
def msg_new(self, cr, uid, msg):
mailgate_obj = self.pool.get('mail.gateway')
msg_body = mailgate_obj.msg_body_get(msg)
data = {
@ -54,7 +54,11 @@ class crm_cases(osv.osv):
self._history(cr, uid, cases, _('Receive'), history=True, email=msg['From'])
return res
def msg_update(self, cr, uid, ids, msg, data={}, default_act='pending'):
def msg_update(self, cr, uid, ids, msg, data={}, default_act='pending'):
if isinstance(ids, (str, int, long)):
select = [ids]
else:
select = ids
mailgate_obj = self.pool.get('mail.gateway')
msg_actions, body_data = mailgate_obj.msg_act_get(msg)
data.update({
@ -65,26 +69,24 @@ class crm_cases(osv.osv):
if msg_actions['state'] in ['draft','close','cancel','open','pending']:
act = 'case_' + msg_actions['state']
for k1,k2 in [('cost','planned_cost'),('revenue','planned_revenue'),('probability','probability')]:
try:
for k1,k2 in [('cost','planned_cost'),('revenue','planned_revenue'),('probability','probability')]:
if k1 in msg_actions:
data[k2] = float(msg_actions[k1])
except:
pass
if 'priority' in msg_actions:
if msg_actions['priority'] in ('1','2','3','4','5'):
data['priority'] = msg_actions['priority']
if 'partner' in msg_actions:
data['email_from'] = msg_actions['partner'][:128]
data['email_from'] = msg_actions['partner'][:128]
res = self.write(cr, uid, ids, data)
cases = self.browse(cr, uid, [res])
res = self.write(cr, uid, select, data)
cases = self.browse(cr, uid, select)
self._history(cr, uid, cases, _('Receive'), history=True, email=msg['From'])
getattr(self,act)(cr, uid, ids)
getattr(self,act)(cr, uid, select)
return res
def emails_get(self, cr, uid, ids, context={}):
def emails_get(self, cr, uid, ids, context={}):
res = []
if isinstance(ids, (str, int, long)):
select = [ids]
@ -94,7 +96,7 @@ class crm_cases(osv.osv):
user_email = (case.user_id and case.user_id.address_id and case.user_id.address_id.email) or False
res += [(user_email, case.email_from, case.email_cc, case.priority)]
if isinstance(ids, (str, int, long)):
return len(res) and res[0] or False
return len(res) and res[0] or False
return res
def msg_send(self, cr, uid, id, *args, **argv):

View File

@ -116,10 +116,11 @@ class mail_gateway(osv.osv):
msg_id = msg_txt['Message-ID']
res_id = self.msg_parse(cr, uid, gateway_id, msg_txt)
except Exception, e:
note = "Error in Parsing Mail: %s " %(str(e))
if mailgateway:
netsvc.Logger().notifyChannel('Emailgate: Parsing mail:%s' % (mailgateway.name or
'%s (%s)'%(mailgateway.server_id.login, mailgateway.server_id.name)), netsvc.LOG_ERROR, str(e))
import traceback
note = "Error in Parsing Mail: %s " %(str(e))
netsvc.Logger().notifyChannel('Emailgate: Parsing mail:%s' % (mailgateway and (mailgateway.name or
'%s (%s)'%(mailgateway.server_id.login, mailgateway.server_id.name))) or ''
, netsvc.LOG_ERROR, traceback.format_exc())
mail_history_obj.create(cr, uid, {'name': msg_id, 'res_id': res_id, 'gateway_id': mailgateway.id, 'note': note})
return res_id, note
@ -181,9 +182,11 @@ class mail_gateway(osv.osv):
imap_server.logout()
except Exception, e:
log_messages.append("Error in Fetching Mail: %s " %(str(e)))
if mailgate_server:
netsvc.Logger().notifyChannel('Emailgate: Fetching mail:[%d]%s' % (mailgate_server.id, mailgate_server.name), netsvc.LOG_ERROR, str(e))
import traceback
log_messages.append("Error in Fetching Mail: %s " %(str(e)))
netsvc.Logger().notifyChannel('Emailgate: Fetching mail:[%d]%s' %
(mailgate_server and mailgate_server.id or 0, mailgate_server and mailgate_server.name or ''),
netsvc.LOG_ERROR, traceback.format_exc())
log_messages.append("-"*25)
log_messages.append("Total Read Mail: %d\n\n" %(len(new_messages)))
@ -305,7 +308,7 @@ class mail_gateway(osv.osv):
res_model = self.pool.get(res_model)
return res_model.msg_update(cr, uid, res_id, msg, data=data, default_act='pending')
def msg_send(self, msg, reply_to, emails, priority=None, res_id=False):
def msg_send(self, msg, reply_to, emails, priority=None, res_id=False):
if not emails:
return False
msg_to = [emails[0]]
@ -390,6 +393,7 @@ class mail_gateway_history(osv.osv):
'gateway_id': fields.many2one('mail.gateway',"Mail Gateway", required=True),
'model_id':fields.related('gateway_id', 'object_id', type='many2one', relation='ir.model', string='Model'),
'note': fields.text('Notes'),
'create_date': fields.datetime('Created Date'),
}
_order = 'id desc'
mail_gateway_history()

View File

@ -8,6 +8,7 @@
<field name="arch" type="xml">
<form string="Gateway History">
<field name="name"/>
<field name="create_date"/>
<field name="gateway_id"/>
<field name="model_id"/>
<field name="res_id"/>
@ -24,6 +25,7 @@
<field name="arch" type="xml">
<tree string="Gateway History">
<field name="name" select="1"/>
<field name="create_date"/>
<field name="model_id"/>
<field name="res_id"/>
<field name="gateway_id"/>