[IMP]: Improvements in crm classes for _inherits(mailgate.thread),

* Moved some functions of action rule for crm_case into crm.py to solve the problem of (python)inheritance

bzr revid: rpa@tinyerp.com-20100519134243-75vrkkymk9k3jssr
This commit is contained in:
rpa (Open ERP) 2010-05-19 19:12:43 +05:30
parent 209efb21ae
commit 37aeeae462
6 changed files with 129 additions and 119 deletions

View File

@ -202,6 +202,21 @@ class crm_case(object):
return {'value': {'email_from': False}}
address = self.pool.get('res.partner.address').browse(cr, uid, add)
return {'value': {'email_from': address.email}}
def _history(self, cr, uid, cases, keyword, history=False, email=False, details=None, email_from=False, message_id=False, context={}):
mailgate_pool = self.pool.get('mailgate.thread')
return mailgate_pool._history(cr, uid, cases, keyword, history=history, email=email, details=details, email_from=email_from, message_id=message_id, context=context)
def _action(self, cr, uid, cases, state_to, scrit=None, context={}):
if not context:
context = {}
context['state_to'] = state_to
rule_obj = self.pool.get('base.action.rule')
model_obj = self.pool.get('ir.model')
model_ids = model_obj.search(cr, uid, [('model','=',self._name)])
rule_ids = rule_obj.search(cr, uid, [('name','=',model_ids[0])])
return rule_obj._action(cr, uid, rule_ids, cases, scrit=scrit, context=context)
def case_open(self, cr, uid, ids, *args):
"""Opens Case
@ -311,6 +326,107 @@ class crm_case(object):
self._action(cr, uid, cases, 'draft')
return True
def remind_partner(self, cr, uid, ids, context={}, attach=False):
"""
@param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current users ID for security checks,
@param ids: List of Remind Partner's IDs
@param context: A standard dictionary for contextual values
"""
return self.remind_user(cr, uid, ids, context, attach,
destination=False)
def remind_user(self, cr, uid, ids, context={}, attach=False,destination=True):
"""
@param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current users ID for security checks,
@param ids: List of Remind user's IDs
@param context: A standard dictionary for contextual values
"""
for case in self.browse(cr, uid, ids):
if not case.section_id.reply_to:
raise osv.except_osv(_('Error!'), ("Reply To is not specified in the sales team"))
if not case.email_from:
raise osv.except_osv(_('Error!'), ("Partner Email is not specified in Case"))
if case.section_id.reply_to and case.email_from:
src = case.email_from
dest = case.section_id.reply_to
body = ""
body = case.email_last or case.description
if not destination:
src, dest = dest, src
if body and case.user_id.signature:
body += '\n\n%s' % (case.user_id.signature)
body = self.format_body(body)
dest = [dest]
attach_to_send = None
if attach:
attach_ids = self.pool.get('ir.attachment').search(cr, uid, [('res_model', '=', 'mailgate.thread'), ('res_id', '=', case.id)])
attach_to_send = self.pool.get('ir.attachment').read(cr, uid, attach_ids, ['datas_fname','datas'])
attach_to_send = map(lambda x: (x['datas_fname'], base64.decodestring(x['datas'])), attach_to_send)
# Send an email
flag = tools.email_send(
src,
dest,
"Reminder: [%s] %s" % (str(case.id), case.name, ),
body,
reply_to=case.section_id.reply_to,
openobject_id=str(case.id),
attach=attach_to_send
)
self._history(cr, uid, [case], _('Send'), history=True, email=dest, details=body, email_from=src)
#if flag:
# raise osv.except_osv(_('Email!'),("Email Successfully Sent"))
#else:
# raise osv.except_osv(_('Email Fail!'),("Email is not sent successfully"))
return True
def _check(self, cr, uid, ids=False, context={}):
"""
Function called by the scheduler to process cases for date actions
Only works on not done and cancelled cases
@param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current users ID for security checks,
@param context: A standard dictionary for contextual values
"""
cr.execute('select * from crm_case \
where (date_action_last<%s or date_action_last is null) \
and (date_action_next<=%s or date_action_next is null) \
and state not in (\'cancel\',\'done\')',
(time.strftime("%Y-%m-%d %H:%M:%S"),
time.strftime('%Y-%m-%d %H:%M:%S')))
ids2 = map(lambda x: x[0], cr.fetchall() or [])
cases = self.browse(cr, uid, ids2, context)
return self._action(cr, uid, cases, False, context=context)
def _action(self, cr, uid, cases, state_to, scrit=None, context={}):
if not context:
context = {}
context['state_to'] = state_to
rule_obj = self.pool.get('base.action.rule')
model_obj = self.pool.get('ir.model')
model_ids = model_obj.search(cr, uid, [('model','=',self._name)])
rule_ids = rule_obj.search(cr, uid, [('name','=',model_ids[0])])
return rule_obj._action(cr, uid, rule_ids, cases, scrit=scrit, context=context)
def format_body(self, body):
return self.pool.get('base.action.rule').format_body(body)
def format_mail(self, obj, body):
return self.pool.get('base.action.rule').format_mail(obj, body)
class crm_case_section(osv.osv):
"""Sales Team"""

View File

@ -34,120 +34,6 @@ from osv.orm import except_orm
import crm
class case(osv.osv):
""" Case """
_inherit = 'mailgate.thread'
_description = 'case'
_columns = {
'date_action_last': fields.datetime('Last Action', readonly=1),
'date_action_next': fields.datetime('Next Action', readonly=1),
}
def remind_partner(self, cr, uid, ids, context={}, attach=False):
"""
@param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current users ID for security checks,
@param ids: List of Remind Partner's IDs
@param context: A standard dictionary for contextual values
"""
return self.remind_user(cr, uid, ids, context, attach,
destination=False)
def remind_user(self, cr, uid, ids, context={}, attach=False,destination=True):
"""
@param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current users ID for security checks,
@param ids: List of Remind user's IDs
@param context: A standard dictionary for contextual values
"""
for case in self.browse(cr, uid, ids):
if not case.section_id.reply_to:
raise osv.except_osv(_('Error!'), ("Reply To is not specified in the sales team"))
if not case.email_from:
raise osv.except_osv(_('Error!'), ("Partner Email is not specified in Case"))
if case.section_id.reply_to and case.email_from:
src = case.email_from
dest = case.section_id.reply_to
body = ""
body = case.email_last or case.description
if not destination:
src, dest = dest, src
if body and case.user_id.signature:
body += '\n\n%s' % (case.user_id.signature)
body = self.format_body(body)
dest = [dest]
attach_to_send = None
if attach:
attach_ids = self.pool.get('ir.attachment').search(cr, uid, [('res_model', '=', 'mailgate.thread'), ('res_id', '=', case.id)])
attach_to_send = self.pool.get('ir.attachment').read(cr, uid, attach_ids, ['datas_fname','datas'])
attach_to_send = map(lambda x: (x['datas_fname'], base64.decodestring(x['datas'])), attach_to_send)
# Send an email
flag = tools.email_send(
src,
dest,
"Reminder: [%s] %s" % (str(case.id), case.name, ),
body,
reply_to=case.section_id.reply_to,
openobject_id=str(case.id),
attach=attach_to_send
)
self._history(cr, uid, [case], _('Send'), history=True, email=dest, details=body, email_from=src)
#if flag:
# raise osv.except_osv(_('Email!'),("Email Successfully Sent"))
#else:
# raise osv.except_osv(_('Email Fail!'),("Email is not sent successfully"))
return True
def _check(self, cr, uid, ids=False, context={}):
"""
Function called by the scheduler to process cases for date actions
Only works on not done and cancelled cases
@param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current users ID for security checks,
@param context: A standard dictionary for contextual values
"""
cr.execute('select * from crm_case \
where (date_action_last<%s or date_action_last is null) \
and (date_action_next<=%s or date_action_next is null) \
and state not in (\'cancel\',\'done\')',
(time.strftime("%Y-%m-%d %H:%M:%S"),
time.strftime('%Y-%m-%d %H:%M:%S')))
ids2 = map(lambda x: x[0], cr.fetchall() or [])
cases = self.browse(cr, uid, ids2, context)
return self._action(cr, uid, cases, False, context=context)
def _action(self, cr, uid, cases, state_to, scrit=None, context={}):
if not context:
context = {}
context['state_to'] = state_to
rule_obj = self.pool.get('base.action.rule')
model_obj = self.pool.get('ir.model')
model_ids = model_obj.search(cr, uid, [('model','=',self._name)])
rule_ids = rule_obj.search(cr, uid, [('name','=',model_ids[0])])
return rule_obj._action(cr, uid, rule_ids, cases, scrit=scrit, context=context)
def format_body(self, body):
return self.pool.get('base.action.rule').format_body(body)
def format_mail(self, obj, body):
return self.pool.get('base.action.rule').format_mail(obj, body)
case()
class base_action_rule(osv.osv):
""" Base Action Rule """
_inherit = 'base.action.rule'

View File

@ -28,13 +28,14 @@ import mx.DateTime
from tools.translate import _
from crm import crm_case
class crm_lead(osv.osv, crm_case):
class crm_lead(osv.osv, crm_case, ):
""" CRM Lead Case """
_name = "crm.lead"
_description = "Leads Cases"
_order = "priority, id desc"
_inherit = ['res.partner.address', 'mailgate.thread']
_inherit = ['res.partner.address']
_inherits = {'mailgate.thread': 'thread_id'}
def _compute_day(self, cr, uid, ids, fields, args, context={}):
"""
@ -95,6 +96,10 @@ class crm_lead(osv.osv, crm_case):
_columns = {
# From crm.case
'name': fields.char('Name', size=64),
'active': fields.boolean('Active', required=False),
'date_action_last': fields.datetime('Last Action', readonly=1),
'date_action_next': fields.datetime('Next Action', readonly=1),
'email_from': fields.char('Email', size=128, help="These people will receive email."),
'section_id': fields.many2one('crm.case.section', 'Sales Team', \
select=True, help='Sales team to which Case belongs to.\
@ -107,6 +112,7 @@ and users by email"),
'write_date': fields.datetime('Update Date' , readonly=True),
# Lead fields
'thread_id': fields.many2one('mailgate.thread', 'Thread', required=False),
'categ_id': fields.many2one('crm.case.categ', 'Lead Source', \
domain="[('section_id','=',section_id),\
('object_id.model', '=', 'crm.lead')]"),
@ -148,7 +154,7 @@ and users by email"),
'company_id': lambda s, cr, uid, c: s.pool.get('res.company')._company_default_get(cr, uid, 'crm.lead', context=c),
'priority': lambda *a: crm.AVAILABLE_PRIORITIES[2][0],
}
def case_open(self, cr, uid, ids, *args):
"""Overrides cancel for crm_case for setting Open Date
@param self: The object pointer

View File

@ -9,7 +9,7 @@
<field name="domain">['|', ('type','=','lead'), ('type','=',False)]</field>
<field name="view_id" ref="crm_case_tree_view_leads"/>
<field name="search_view_id" ref="crm.view_crm_case_leads_filter"/>
<field name="context">{'search_default_current':1}</field>
<field name="context">{'search_default_current':1, 'default_type': 'lead'}</field>
</record>
<record model="ir.actions.act_window.view" id="action_crm_tag_tree_view_leads_all">

View File

@ -27,7 +27,7 @@
<field name="res_model">crm.lead</field>
<field name="view_mode">tree,form,graph</field>
<field name="domain">[('type','=','opportunity')]</field>
<field name="context">{'search_default_current':1}</field>
<field name="context">{'search_default_current':1, 'default_type': 'opportunity'}</field>
<field name="view_id" ref="crm_case_tree_view_oppor"/>
<field name="search_view_id" ref="crm.view_crm_case_opportunities_filter"/>
</record>

View File

@ -35,6 +35,8 @@ class crm_phonecall(osv.osv, crm_case):
_columns = {
# From crm.case
'name': fields.char('Name', size=64),
'active': fields.boolean('Active', required=False),
'section_id': fields.many2one('crm.case.section', 'Sales Team', \
select=True, help='Sales team to which Case belongs to.\
Define Responsible user and Email account for mail gateway.'),