[IMP]: mailgate_way: Improvement in mail_gateway for the changes in crm objects, now they "_inherits" the mailgate.thread

bzr revid: rpa@tinyerp.com-20100519133928-kt7m3vz4etmgu2i0
This commit is contained in:
rpa (Open ERP)
2010-05-19 19:09:28 +05:30
parent 0fde2df8ff
commit 209efb21ae
2 changed files with 64 additions and 61 deletions
+27 -51
View File
@@ -22,60 +22,38 @@
from osv import osv, fields
import time
class one2many_domain(fields.one2many):
def set(self, cr, obj, id, field, values, user=None, context=None):
if not values:
return
return super(one2many_domain, self).set(cr, obj, id, field, values,
user=user, context=context)
def get(self, cr, obj, ids, name, user=None, offset=0, context=None, values=None):
if not context:
context = {}
res = {}
msg_obj = obj.pool.get('mailgate.message')
for thread in obj.browse(cr, user, ids, context=context):
final = msg_obj.search(cr, user, self._domain + [('thread_id', '=', thread.id)], context=context)
res[thread.id] = final
return res
class mailgate_thread(osv.osv):
'''
Mailgateway Thread
'''
_name = 'mailgate.thread'
_description = 'Mailgateway Thread'
def _get_log_ids(self, cr, uid, ids, field_names, arg, context=None):
"""Gets id for case log from history of particular case
@param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current user’s ID for security checks,
@param ids: List of Case IDs
@param context: A standard dictionary for contextual values
@return:Dictionary of History Ids
"""
if not context:
context = {}
result = {}
domain = []
history_obj = False
model_obj = self.pool.get('ir.model')
history_obj = self.pool.get('mailgate.message')
if 'message_ids' in field_names:
name = 'message_ids'
domain += [('email_to', '!=', False)]
if 'log_ids' in field_names:
name = 'log_ids'
domain += [('email_to', '=', False)]
model_ids = model_obj.search(cr, uid, [('model', '=', self._name)])
domain += [('model_id', '=', model_ids[0])]
for case in self.browse(cr, uid, ids, context):
domain1 = domain + [('res_id', '=', case.id)]
history_ids = history_obj.search(cr, uid, domain1, context=context)
if history_ids:
result[case.id] = {name: history_ids}
else:
result[case.id] = {name: []}
return result
_rec_name = 'thread'
_columns = {
'name':fields.char('Name', size=64),
'active': fields.boolean('Active'),
'message_ids': fields.function(_get_log_ids, method=True, type='one2many', \
multi="message_ids", relation="mailgate.message", string="Messages"),
'log_ids': fields.function(_get_log_ids, method=True, type='one2many', \
multi="log_ids", relation="mailgate.message", string="Logs"),
}
'thread': fields.char('Thread', size=32, required=False),
'message_ids': one2many_domain('mailgate.message', 'thread_id', 'Messages', domain=[('history', '=', True)], required=False),
'log_ids': one2many_domain('mailgate.message', 'thread_id', 'Logs', domain=[('history', '=', False)], required=False),
}
def __history(self, cr, uid, cases, keyword, history=False, email=False, details=None, email_from=False, message_id=False, context={}):
"""
@param self: The object pointer
@@ -89,7 +67,6 @@ class mailgate_thread(osv.osv):
@param context: A standard dictionary for contextual values"""
if not context:
context = {}
# The mailgate sends the ids of the cases and not the object list
if all(isinstance(case_id, (int, long)) for case_id in cases) and context.get('model'):
cases = self.pool.get(context['model']).browse(cr, uid, cases, context=context)
@@ -103,13 +80,13 @@ class mailgate_thread(osv.osv):
'name': keyword,
'user_id': uid,
'date': time.strftime('%Y-%m-%d %H:%M:%S'),
'model_id' : model_ids and model_ids[0] or False,
'res_id': case.id,
'thread_id': case.id,
'section_id': case.section_id.id,
'message_id':message_id
'message_id': message_id
}
if history:
data['history'] = True
data['description'] = details or case.description
data['email_to'] = email or \
(case.section_id and case.section_id.reply_to) or \
@@ -140,8 +117,7 @@ class mailgate_message(osv.osv):
'name':fields.char('Message', size=64),
'thread_id':fields.many2one('mailgate.thread', 'Thread'),
'date': fields.datetime('Date'),
'model_id': fields.many2one('ir.model', "Model"),
'res_id': fields.integer('Resource ID'),
'history': fields.boolean('Is History?', required=False),
'user_id': fields.many2one('res.users', 'User Responsible', readonly=True),
'message': fields.text('Description'),
'email_from': fields.char('Email From', size=84),
+37 -10
View File
@@ -9,9 +9,8 @@
<form string="maligate message">
<field name="name" />
<field name="date" />
<field name="model_id" />
<field name="res_id" />
<field name="user_id" />
<field name="history" />
<field name="message_id" />
<notebook colspan="4">
<page>
@@ -51,20 +50,19 @@
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Mailgateway Thread">
<field name="name" select="1"/>
<separator string="Messages" colspan="4"/>
<field name="message_ids" nolabel="1" colspan="4">
<tree string="Mailgateway Message">
<field name="thread" select="1"/>
<separator string="Logs" colspan="4"/>
<field name="log_ids" nolabel="1" colspan="4" domain="[('history', '=', True)]">
<tree string="Mailgateway Logs">
<field name="name" select="1" />
<field name="date" />
</tree>
<form string="Maligate Message">
<form string="Maligate Logs">
<field name="name" />
<field name="date" />
<field name="model_id" />
<field name="res_id" />
<field name="user_id" />
<field name="message_id" />
<field name="history" />
<notebook colspan="4">
<page string="Email Details">
<group col="4" colspan="4">
@@ -82,6 +80,35 @@
</notebook>
</form>
</field>
<separator string="Histories" colspan="4"/>
<field name="message_ids" nolabel="1" colspan="4" domain="[('history', '=', True)]">
<tree string="Mailgateway Histories">
<field name="name" select="1" />
<field name="date" />
</tree>
<form string="Maligate Histories">
<field name="name" />
<field name="date" />
<field name="user_id" />
<field name="message_id" />
<field name="history" />
<notebook colspan="4">
<page string="Email Details">
<group col="4" colspan="4">
<separator string="Email Details" colspan="4"/>
<field name="email_from" />
<field name="email_to" />
<field name="email_cc" />
<field name="email_bcc" />
</group>
</page>
<page string="Attachments">
<separator string="Attachments" colspan="4"/>
<field name="attachment_ids" nolabel="1" colspan="4" />
</page>
</notebook>
</form>
</field>
</form>
</field>
</record>
@@ -92,7 +119,7 @@
<field name="type">tree</field>
<field name="arch" type="xml">
<tree string="Mailgateway Thread">
<field name="name" select="1" />
<field name="thread" select="1" />
<field name="message_ids" />
</tree>
</field>