From 37aeeae4624ad455669bce5d97676de0ccf077e5 Mon Sep 17 00:00:00 2001 From: "rpa (Open ERP)" Date: Wed, 19 May 2010 19:12:43 +0530 Subject: [PATCH] [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 --- addons/crm/crm.py | 116 ++++++++++++++++++++++++++++ addons/crm/crm_action_rule.py | 114 --------------------------- addons/crm/crm_lead.py | 12 ++- addons/crm/crm_lead_menu.xml | 2 +- addons/crm/crm_opportunity_menu.xml | 2 +- addons/crm/crm_phonecall.py | 2 + 6 files changed, 129 insertions(+), 119 deletions(-) diff --git a/addons/crm/crm.py b/addons/crm/crm.py index 80b06bf7aba..da76a0d09b3 100644 --- a/addons/crm/crm.py +++ b/addons/crm/crm.py @@ -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 user’s 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 user’s 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 user’s 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""" diff --git a/addons/crm/crm_action_rule.py b/addons/crm/crm_action_rule.py index 82c60e64f23..ee5e3d357c8 100644 --- a/addons/crm/crm_action_rule.py +++ b/addons/crm/crm_action_rule.py @@ -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 user’s 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 user’s 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 user’s 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' diff --git a/addons/crm/crm_lead.py b/addons/crm/crm_lead.py index 335c7a96906..09cc6773df0 100644 --- a/addons/crm/crm_lead.py +++ b/addons/crm/crm_lead.py @@ -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 diff --git a/addons/crm/crm_lead_menu.xml b/addons/crm/crm_lead_menu.xml index d4d182a2dc5..4fef09d28df 100644 --- a/addons/crm/crm_lead_menu.xml +++ b/addons/crm/crm_lead_menu.xml @@ -9,7 +9,7 @@ ['|', ('type','=','lead'), ('type','=',False)] - {'search_default_current':1} + {'search_default_current':1, 'default_type': 'lead'} diff --git a/addons/crm/crm_opportunity_menu.xml b/addons/crm/crm_opportunity_menu.xml index 9d1ccf15258..4471c0bcb8e 100644 --- a/addons/crm/crm_opportunity_menu.xml +++ b/addons/crm/crm_opportunity_menu.xml @@ -27,7 +27,7 @@ crm.lead tree,form,graph [('type','=','opportunity')] - {'search_default_current':1} + {'search_default_current':1, 'default_type': 'opportunity'} diff --git a/addons/crm/crm_phonecall.py b/addons/crm/crm_phonecall.py index 6244ba1807a..4644f129c87 100644 --- a/addons/crm/crm_phonecall.py +++ b/addons/crm/crm_phonecall.py @@ -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.'),