diff --git a/addons/account_followup/__openerp__.py b/addons/account_followup/__openerp__.py index aef4a62c0b8..b316f5039a3 100644 --- a/addons/account_followup/__openerp__.py +++ b/addons/account_followup/__openerp__.py @@ -45,7 +45,7 @@ Note that if you want to check the followup level for a given partner/account en 'author': 'OpenERP SA', 'website': 'http://www.openerp.com', 'images': ['images/follow_ups.jpeg','images/send_followups.jpeg'], - 'depends': ['account_accountant'], + 'depends': ['account_accountant', 'mail'], 'init_xml': [], 'update_xml': [ 'security/ir.model.access.csv', diff --git a/addons/account_followup/account_followup_demo.xml b/addons/account_followup/account_followup_demo.xml index 2bf627de9b7..01b275de306 100644 --- a/addons/account_followup/account_followup_demo.xml +++ b/addons/account_followup/account_followup_demo.xml @@ -17,9 +17,9 @@ Dear %(partner_name)s, -Exception made if there was a mistake of ours, it seems that the following amount staid unpaid. Please, take appropriate measures in order to carry out this payment in the next 8 days. +Exception made if there was a mistake of ours, it seems that the following amount stays unpaid. Please, take appropriate measures in order to carry out this payment in the next 8 days. -Would your payment have been carried out after this mail was sent, please consider the present one as void. Do not hesitate to contact our accounting department at (+32).10.68.94.39. +Would your payment have been carried out after this mail was sent, please ignore this message. Do not hesitate to contact our accounting department at (+32).10.68.94.39. Best Regards, diff --git a/addons/account_followup/wizard/account_followup_print.py b/addons/account_followup/wizard/account_followup_print.py index 18b0fc1b874..78f1b8b34c7 100644 --- a/addons/account_followup/wizard/account_followup_print.py +++ b/addons/account_followup/wizard/account_followup_print.py @@ -205,6 +205,7 @@ class account_followup_print_all(osv.osv_memory): move_obj = self.pool.get('account.move.line') user_obj = self.pool.get('res.users') line_obj = self.pool.get('account_followup.stat') + mail_message = self.pool.get('mail.message') if context is None: context = {} @@ -277,7 +278,7 @@ class account_followup_print_all(osv.osv_memory): msg = '' if dest: try: - tools.email_send(src, dest, sub, body) + mail_message.schedule_with_attach(cr, uid, src, dest, sub, body, context=context) msg_sent += partner.name + '\n' except Exception, e: raise osv.except_osv('Error !', e ) diff --git a/addons/base_action_rule/__openerp__.py b/addons/base_action_rule/__openerp__.py index b6796f8958d..1170557efad 100644 --- a/addons/base_action_rule/__openerp__.py +++ b/addons/base_action_rule/__openerp__.py @@ -37,7 +37,7 @@ trigger an automatic reminder email. """, 'author': 'OpenERP SA', 'website': 'http://www.openerp.com', - 'depends': ['base'], + 'depends': ['base', 'mail'], 'init_xml': [ 'base_action_rule_data.xml' ], diff --git a/addons/base_action_rule/base_action_rule.py b/addons/base_action_rule/base_action_rule.py index 2db23e75893..805c35e4462 100644 --- a/addons/base_action_rule/base_action_rule.py +++ b/addons/base_action_rule/base_action_rule.py @@ -24,7 +24,7 @@ from tools.translate import _ from datetime import datetime from datetime import timedelta from tools.safe_eval import safe_eval -import pooler +import pooler import re import time import tools @@ -39,7 +39,7 @@ class base_action_rule(osv.osv): _name = 'base.action.rule' _description = 'Action Rules' - + def _state_get(self, cr, uid, context=None): """ Get State @param self: The object pointer @@ -55,7 +55,7 @@ class base_action_rule(osv.osv): @param uid: the current user’s ID for security checks, @param context: A standard dictionary for contextual values """ return [('', '')] - + def priority_get(self, cr, uid, context=None): """ Get Priority @param self: The object pointer @@ -65,57 +65,57 @@ class base_action_rule(osv.osv): return [('', '')] _columns = { - 'name': fields.char('Rule Name', size=64, required=True), - 'model_id': fields.many2one('ir.model', 'Object', required=True), - 'create_date': fields.datetime('Create Date', readonly=1), + 'name': fields.char('Rule Name', size=64, required=True), + 'model_id': fields.many2one('ir.model', 'Object', required=True), + 'create_date': fields.datetime('Create Date', readonly=1), 'active': fields.boolean('Active', help="If the active field is set to False,\ - it will allow you to hide the rule without removing it."), + it will allow you to hide the rule without removing it."), 'sequence': fields.integer('Sequence', help="Gives the sequence order \ -when displaying a list of rules."), +when displaying a list of rules."), 'trg_date_type': fields.selection([ - ('none', 'None'), - ('create', 'Creation Date'), - ('action_last', 'Last Action Date'), - ('date', 'Date'), - ('deadline', 'Deadline'), - ], 'Trigger Date', size=16), + ('none', 'None'), + ('create', 'Creation Date'), + ('action_last', 'Last Action Date'), + ('date', 'Date'), + ('deadline', 'Deadline'), + ], 'Trigger Date', size=16), 'trg_date_range': fields.integer('Delay after trigger date', \ help="Delay After Trigger Date,\ specifies you can put a negative number. If you need a delay before the \ -trigger date, like sending a reminder 15 minutes before a meeting."), +trigger date, like sending a reminder 15 minutes before a meeting."), 'trg_date_range_type': fields.selection([('minutes', 'Minutes'), ('hour', 'Hours'), \ - ('day', 'Days'), ('month', 'Months')], 'Delay type'), - 'trg_user_id': fields.many2one('res.users', 'Responsible'), - 'trg_partner_id': fields.many2one('res.partner', 'Partner'), - 'trg_partner_categ_id': fields.many2one('res.partner.category', 'Partner Category'), - 'trg_state_from': fields.selection(_state_get, 'State', size=16), - 'trg_state_to': fields.selection(_state_get, 'Button Pressed', size=16), + ('day', 'Days'), ('month', 'Months')], 'Delay type'), + 'trg_user_id': fields.many2one('res.users', 'Responsible'), + 'trg_partner_id': fields.many2one('res.partner', 'Partner'), + 'trg_partner_categ_id': fields.many2one('res.partner.category', 'Partner Category'), + 'trg_state_from': fields.selection(_state_get, 'State', size=16), + 'trg_state_to': fields.selection(_state_get, 'Button Pressed', size=16), - 'act_method': fields.char('Call Object Method', size=64), - 'act_user_id': fields.many2one('res.users', 'Set Responsible to'), - 'act_state': fields.selection(_state_get, 'Set State to', size=16), + 'act_method': fields.char('Call Object Method', size=64), + 'act_user_id': fields.many2one('res.users', 'Set Responsible to'), + 'act_state': fields.selection(_state_get, 'Set State to', size=16), 'act_email_cc': fields.char('Add Watchers (Cc)', size=250, help="\ These people will receive a copy of the future communication between partner \ -and users by email"), +and users by email"), 'act_remind_partner': fields.boolean('Remind Partner', help="Check \ -this if you want the rule to send a reminder by email to the partner."), +this if you want the rule to send a reminder by email to the partner."), 'act_remind_user': fields.boolean('Remind Responsible', help="Check \ -this if you want the rule to send a reminder by email to the user."), - 'act_reply_to': fields.char('Reply-To', size=64), - 'act_remind_attach': fields.boolean('Remind with Attachment', help="Check this if you want that all documents attached to the object be attached to the reminder email sent."), +this if you want the rule to send a reminder by email to the user."), + 'act_reply_to': fields.char('Reply-To', size=64), + 'act_remind_attach': fields.boolean('Remind with Attachment', help="Check this if you want that all documents attached to the object be attached to the reminder email sent."), 'act_mail_to_user': fields.boolean('Mail to Responsible', help="Check\ - this if you want the rule to send an email to the responsible person."), - 'act_mail_to_watchers': fields.boolean('Mail to Watchers (CC)', + this if you want the rule to send an email to the responsible person."), + 'act_mail_to_watchers': fields.boolean('Mail to Watchers (CC)', help="Check this if you want \ -the rule to mark CC(mail to any other person defined in actions)."), +the rule to mark CC(mail to any other person defined in actions)."), 'act_mail_to_email': fields.char('Mail to these Emails', size=128, \ - help="Email-id of the persons whom mail is to be sent"), - 'act_mail_body': fields.text('Mail body', help="Content of mail"), + help="Email-id of the persons whom mail is to be sent"), + 'act_mail_body': fields.text('Mail body', help="Content of mail"), 'regex_name': fields.char('Regex on Resource Name', size=128, help="Regular expression for matching name of the resource\ \ne.g.: 'urgent.*' will search for records having name starting with the string 'urgent'\ -\nNote: This is case sensitive search."), - 'server_action_id': fields.many2one('ir.actions.server', 'Server Action', help="Describes the action name.\neg:on which object which action to be taken on basis of which condition"), - 'filter_id':fields.many2one('ir.filters', 'Filter', required=False), +\nNote: This is case sensitive search."), + 'server_action_id': fields.many2one('ir.actions.server', 'Server Action', help="Describes the action name.\neg:on which object which action to be taken on basis of which condition"), + 'filter_id':fields.many2one('ir.filters', 'Filter', required=False), 'act_email_from' : fields.char('Email From', size=64, required=False, help="Use a python expression to specify the right field on which one than we will use for the 'From' field of the header"), 'act_email_to' : fields.char('Email To', size=64, required=False, @@ -124,17 +124,17 @@ the rule to mark CC(mail to any other person defined in actions)."), } _defaults = { - 'active': lambda *a: True, - 'trg_date_type': lambda *a: 'none', - 'trg_date_range_type': lambda *a: 'day', - 'act_mail_to_user': lambda *a: 0, - 'act_remind_partner': lambda *a: 0, - 'act_remind_user': lambda *a: 0, - 'act_mail_to_watchers': lambda *a: 0, + 'active': lambda *a: True, + 'trg_date_type': lambda *a: 'none', + 'trg_date_range_type': lambda *a: 'day', + 'act_mail_to_user': lambda *a: 0, + 'act_remind_partner': lambda *a: 0, + 'act_remind_user': lambda *a: 0, + 'act_mail_to_watchers': lambda *a: 0, } - + _order = 'sequence' - + def onchange_model_id(self, cr, uid, ids, name): #This is not a good solution as it will affect the domain only on onchange res = {'domain':{'filter_id':[]}} @@ -174,7 +174,7 @@ the rule to mark CC(mail to any other person defined in actions)."), self.pre_action(cr, uid, [new_id], model, context=context) return new_id return make_call_old - + def _write(self, old_write, model, context=None): if context is None: context = {} @@ -202,9 +202,9 @@ the rule to mark CC(mail to any other person defined in actions)."), return True def create(self, cr, uid, vals, context=None): res_id = super(base_action_rule, self).create(cr, uid, vals, context=context) - self._register_hook(cr, uid, [res_id], context=context) + self._register_hook(cr, uid, [res_id], context=context) return res_id - + def write(self, cr, uid, ids, vals, context=None): res = super(base_action_rule, self).write(cr, uid, ids, vals, context=context) self._register_hook(cr, uid, ids, context=context) @@ -268,22 +268,19 @@ the rule to mark CC(mail to any other person defined in actions)."), return body and tools.ustr(body) or '' def format_mail(self, obj, body): - """ Foramat Mail - @param self: The object pointer """ - data = { - 'object_id': obj.id, - 'object_subject': hasattr(obj, 'name') and obj.name or False, - 'object_date': hasattr(obj, 'date') and obj.date or False, - 'object_description': hasattr(obj, 'description') and obj.description or False, - 'object_user': hasattr(obj, 'user_id') and (obj.user_id and obj.user_id.name) or '/', + 'object_id': obj.id, + 'object_subject': hasattr(obj, 'name') and obj.name or False, + 'object_date': hasattr(obj, 'date') and obj.date or False, + 'object_description': hasattr(obj, 'description') and obj.description or False, + 'object_user': hasattr(obj, 'user_id') and (obj.user_id and obj.user_id.name) or '/', 'object_user_email': hasattr(obj, 'user_id') and (obj.user_id and \ obj.user_id.user_email) or '/', 'object_user_phone': hasattr(obj, 'partner_address_id') and (obj.partner_address_id and \ obj.partner_address_id.phone) or '/', - 'partner': hasattr(obj, 'partner_id') and (obj.partner_id and obj.partner_id.name) or '/', + 'partner': hasattr(obj, 'partner_id') and (obj.partner_id and obj.partner_id.name) or '/', 'partner_email': hasattr(obj, 'partner_address_id') and (obj.partner_address_id and\ - obj.partner_address_id.email) or '/', + obj.partner_address_id.email) or '/', } return self.format_body(body % data) @@ -302,6 +299,7 @@ the rule to mark CC(mail to any other person defined in actions)."), if context is None: context = {} + mail_message = self.pool.get('mail.message') body = self.format_mail(obj, body) if not emailfrom: if hasattr(obj, 'user_id') and obj.user_id and obj.user_id.user_email: @@ -311,9 +309,9 @@ the rule to mark CC(mail to any other person defined in actions)."), emailfrom = tools.ustr(emailfrom) reply_to = emailfrom if not emailfrom: - raise osv.except_osv(_('Error!'), + raise osv.except_osv(_('Error!'), _("No E-Mail ID Found for your Company address!")) - return tools.email_send(emailfrom, emails, name, body, reply_to=reply_to, openobject_id=str(obj.id)) + return mail_message.schedule_with_attach(cr, uid, emailfrom, emails, name, body, model='base.action.rule', reply_to=reply_to, res_id=obj.id) def do_check(self, cr, uid, action, obj, context=None): @@ -324,7 +322,7 @@ the rule to mark CC(mail to any other person defined in actions)."), @param context: A standard dictionary for contextual values """ if context is None: context = {} - ok = True + ok = True if action.filter_id: if action.model_id.model == action.filter_id.model_id: context.update(eval(action.filter_id.context)) @@ -479,7 +477,7 @@ the rule to mark CC(mail to any other person defined in actions)."), return True _constraints = [ - (_check_mail, 'Error: The mail is not well formated', ['act_mail_body']), + (_check_mail, 'Error: The mail is not well formated', ['act_mail_body']), ] base_action_rule() diff --git a/addons/mail_gateway/__openerp__.py b/addons/base_calendar/__openerp__.py similarity index 57% rename from addons/mail_gateway/__openerp__.py rename to addons/base_calendar/__openerp__.py index af1e28e0c2c..6edb978301f 100644 --- a/addons/mail_gateway/__openerp__.py +++ b/addons/base_calendar/__openerp__.py @@ -20,30 +20,37 @@ ############################################################################## { - 'name': 'Email Gateway System', - 'version': '1.0', - 'category': 'Tools', + "name" : "Basic Calendar Functionality", + "version" : "1.0", + "depends" : ["base", "mail"], 'complexity': "easy", 'description': """ -The generic email gateway system allows to send and receive emails. -=================================================================== +This is a full-featured calendar system. +======================================== - * History of emails - * Easy integration with any module""", - 'author': 'OpenERP SA', +It supports: + - Calendar of events + - Alerts (create requests) + - Recurring events + - Invitations to people""", + "author" : "OpenERP SA", + 'category': 'Tools', 'website': 'http://www.openerp.com', - 'depends': ['base'], - 'init_xml': [], - 'update_xml': [ - "mail_gateway_view.xml", - "res_partner_view.xml", - 'security/ir.model.access.csv' - + "init_xml" : [ + 'base_calendar_data.xml' ], - 'demo_xml': [], - 'installable': True, - 'active': False, - 'certificate': '001056784984222247309', - 'images': ['images/customer_history.jpeg','images/messages_form.jpeg','images/messages_list.jpeg'], + "demo_xml" : [], + "update_xml" : [ + 'security/calendar_security.xml', + 'security/ir.model.access.csv', + 'wizard/base_calendar_invite_attendee_view.xml', + 'base_calendar_view.xml' + ], + "test" : ['test/base_calendar_test.yml'], + "installable" : True, + "active" : False, + "certificate" : "00694071962960352821", + 'images': ['images/base_calendar1.jpeg','images/base_calendar2.jpeg','images/base_calendar3.jpeg','images/base_calendar4.jpeg',], } + # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/base_calendar/base_calendar.py b/addons/base_calendar/base_calendar.py index a128e18fcc1..e020984a647 100644 --- a/addons/base_calendar/base_calendar.py +++ b/addons/base_calendar/base_calendar.py @@ -484,6 +484,7 @@ property or property parameter."), context = {} company = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.name + mail_message = self.pool.get('mail.message') for att in self.browse(cr, uid, ids, context=context): sign = att.sent_by_uid and att.sent_by_uid.signature or '' sign = '
'.join(sign and sign.split('\n') or []) @@ -510,14 +511,15 @@ property or property parameter."), body = html_invitation % body_vals if mail_to and email_from: attach = self.get_ics_file(cr, uid, res_obj, context=context) - tools.email_send( + mail_message.schedule_with_attach(cr, uid, email_from, mail_to, sub, body, - attach=attach and [('invitation.ics', attach)] or None, + attachments=attach and {'invitation.ics': attach} or None, subtype='html', - reply_to=email_from + reply_to=email_from, + context=context ) return True @@ -812,6 +814,7 @@ class calendar_alarm(osv.osv): """ if context is None: context = {} + mail_message = self.pool.get('mail.message') current_datetime = datetime.now() request_obj = self.pool.get('res.request') alarm_ids = self.search(cr, uid, [('state', '!=', 'done')], context=context) @@ -893,11 +896,12 @@ From: for att in alarm.attendee_ids: mail_to.append(att.user_id.user_email) if mail_to: - tools.email_send( + mail_message.schedule_with_attach(cr, uid, tools.config.get('email_from', False), mail_to, sub, - body + body, + context=context ) if next_trigger_date: update_vals.update({'trigger_date': next_trigger_date}) @@ -1038,7 +1042,7 @@ rule or repeating pattern of time to exclude from the recurring rule."), 'user_id': fields.many2one('res.users', 'Responsible', states={'done': [('readonly', True)]}), 'organizer': fields.char("Organizer", size=256, states={'done': [('readonly', True)]}), # Map with Organizer Attribure of VEvent. 'organizer_id': fields.many2one('res.users', 'Organizer', states={'done': [('readonly', True)]}), - 'end_type' : fields.selection([('count', 'Fix amout of times'), ('end_date','End date')], 'Way to end reccurency'), + 'end_type' : fields.selection([('count', 'Number of repetitions'), ('end_date','End date')], 'Recurrence termination'), 'interval': fields.integer('Repeat every', help="Repeat every (Days/Week/Month/Year)"), 'count': fields.integer('Repeat', help="Repeat x times"), 'mo': fields.boolean('Mon'), @@ -1199,13 +1203,14 @@ rule or repeating pattern of time to exclude from the recurring rule."), return (datas.get('end_type') == 'count' and (';COUNT=' + str(datas.get('count'))) or '') +\ ((datas.get('end_date_new') and datas.get('end_type') == 'end_date' and (';UNTIL=' + datas.get('end_date_new'))) or '') - + freq=datas.get('rrule_type') if freq == 'none': return '' - interval_srting = datas.get('interval') and (';INTERVAL=' + str(datas.get('interval'))) or '' - return 'FREQ=' + freq.upper() + get_week_string(freq, datas) + interval_srting + get_end_date(datas) + get_month_string(freq, datas) + interval_srting = datas.get('interval') and (';INTERVAL=' + str(datas.get('interval'))) or '' + + return 'FREQ=' + freq.upper() + get_week_string(freq, datas) + interval_srting + get_end_date(datas) + get_month_string(freq, datas) def remove_virtual_id(self, ids): if isinstance(ids, (str, int)): @@ -1216,9 +1221,8 @@ rule or repeating pattern of time to exclude from the recurring rule."), for id in ids: res.append(base_calendar_id2real_id(id)) return res - - def search(self, cr, uid, args, offset=0, limit=0, order=None, - context=None, count=False): + + def search(self, cr, uid, args, offset=0, limit=0, order=None, context=None, count=False): args_without_date = [] start_date = False until_date = False @@ -1250,7 +1254,6 @@ rule or repeating pattern of time to exclude from the recurring rule."), else: return res - def get_edit_all(self, cr, uid, id, vals=None): """ return true if we have to edit all meeting from the same recurrent @@ -1277,7 +1280,8 @@ rule or repeating pattern of time to exclude from the recurring rule."), return date_start == split_id[1] except Exception: return True - + + def write(self, cr, uid, ids, vals, context=None, check=True, update_check=True): if context is None: context = {} @@ -1289,7 +1293,6 @@ rule or repeating pattern of time to exclude from the recurring rule."), res = False for event_id in select: real_event_id = base_calendar_id2real_id(event_id) - edit_all = self.get_edit_all(cr, uid, event_id, vals=vals) if edit_all: if self.need_to_update(event_id, vals): diff --git a/addons/crm/__openerp__.py b/addons/crm/__openerp__.py index 5e812207921..c2dd5027b71 100644 --- a/addons/crm/__openerp__.py +++ b/addons/crm/__openerp__.py @@ -59,7 +59,7 @@ Creates a dashboard for CRM that includes: 'base_action_rule', 'base_setup', 'process', - 'mail_gateway', + 'mail', 'base_calendar', 'resource', 'board' @@ -85,7 +85,6 @@ Creates a dashboard for CRM that includes: 'wizard/crm_opportunity_to_phonecall_view.xml', 'wizard/crm_partner_to_opportunity_view.xml', - 'wizard/crm_send_email_view.xml', 'wizard/crm_add_note_view.xml', 'wizard/crm_merge_opportunities_view.xml', diff --git a/addons/crm/crm.py b/addons/crm/crm.py index d745e285986..c7bc461fa1f 100644 --- a/addons/crm/crm.py +++ b/addons/crm/crm.py @@ -116,39 +116,12 @@ class crm_case_section(osv.osv): ('code_uniq', 'unique (code)', 'The code of the sales team must be unique !') ] - def _check_recursion(self, cr, uid, ids, context=None): - - """ - Checks for recursion level for sales team - @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 Sales team ids - """ - level = 100 - - while len(ids): - cr.execute('select distinct parent_id from crm_case_section where id IN %s', (tuple(ids),)) - ids = filter(None, map(lambda x: x[0], cr.fetchall())) - if not level: - return False - level -= 1 - - return True - _constraints = [ - (_check_recursion, 'Error ! You cannot create recursive Sales team.', ['parent_id']) + (osv.osv._check_recursion, 'Error ! You cannot create recursive Sales team.', ['parent_id']) ] def name_get(self, cr, uid, ids, context=None): - """Overrides orm name_get method - @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 sales team ids - """ - if context is None: - context = {} + """Overrides orm name_get method""" if not isinstance(ids, list) : ids = [ids] res = [] @@ -174,13 +147,7 @@ class crm_case_categ(osv.osv): } def _find_object_id(self, cr, uid, context=None): - """Finds id for case object - @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 - """ - + """Finds id for case object""" object_id = context and context.get('object_id', False) or False ids = self.pool.get('ir.model').search(cr, uid, [('model', '=', object_id)]) return ids and ids[0] @@ -217,6 +184,9 @@ class crm_base(object): if not context.get('portal'): return False # was user.address_id.id, but address_id has been removed + user = self.pool.get('res.users').browse(cr, uid, uid, context=context) + if hasattr(user, 'partner_address_id') and user.partner_address_id: + return user.partner_address_id return False def _get_default_partner(self, cr, uid, context=None): @@ -228,6 +198,8 @@ class crm_base(object): if not context.get('portal', False): return False user = self.pool.get('res.users').browse(cr, uid, uid, context=context) + if hasattr(user, 'partner_address_id') and user.partner_address_id: + return user.partner_address_id return user.company_id.partner_id.id def _get_default_email(self, cr, uid, context=None): @@ -255,9 +227,9 @@ class crm_base(object): def onchange_partner_address_id(self, cr, uid, ids, add, email=False): """This function returns value of partner email based on Partner Address - @param ids: List of case IDs - @param add: Id of Partner's address - @email: Partner's email ID + :param ids: List of case IDs + :param add: Id of Partner's address + :param email: Partner's email ID """ if not add: return {'value': {'email_from': False}} @@ -269,9 +241,9 @@ class crm_base(object): def onchange_partner_id(self, cr, uid, ids, part, email=False): """This function returns value of partner address based on partner - @param ids: List of case IDs - @param part: Partner's id - @email: Partner's email ID + :param ids: List of case IDs + :param part: Partner's id + :param email: Partner's email ID """ data={} if part: @@ -282,6 +254,7 @@ class crm_base(object): def case_open(self, cr, uid, ids, *args): """Opens Case + :param ids: List of case Ids """ cases = self.browse(cr, uid, ids) for case in cases: @@ -295,7 +268,7 @@ class crm_base(object): def case_close(self, cr, uid, ids, *args): """Closes Case - @param ids: List of case Ids + :param ids: List of case Ids """ cases = self.browse(cr, uid, ids) cases[0].state # to fill the browse record cache @@ -306,7 +279,7 @@ class crm_base(object): def case_cancel(self, cr, uid, ids, *args): """Cancels Case - @param ids: List of case Ids + :param ids: List of case Ids """ cases = self.browse(cr, uid, ids) cases[0].state # to fill the browse record cache @@ -317,6 +290,7 @@ class crm_base(object): def case_pending(self, cr, uid, ids, *args): """Marks case as pending + :param ids: List of case Ids """ cases = self.browse(cr, uid, ids) cases[0].state # to fill the browse record cache @@ -326,13 +300,14 @@ class crm_base(object): def case_reset(self, cr, uid, ids, *args): """Resets case as draft + :param ids: List of case Ids """ cases = self.browse(cr, uid, ids) cases[0].state # to fill the browse record cache self.write(cr, uid, ids, {'state': 'draft', 'active': True}) self._action(cr, uid, cases, 'draft') return True - + def _action(self, cr, uid, cases, state_to, scrit=None, context=None): if context is None: context = {} @@ -394,10 +369,9 @@ class crm_case(crm_base): return self.stage_change(cr, uid, ids, '<', 'sequence desc', context) def copy(self, cr, uid, id, default=None, context=None): - """ Overrides orm copy method. - """ - if context is None: - context = {} + """Overrides orm copy method to avoid copying messages, + as well as date_closed and date_open columns if they + exist.""" if default is None: default = {} @@ -409,19 +383,11 @@ class crm_case(crm_base): default.update({ 'date_open': False }) return super(osv.osv, self).copy(cr, uid, id, default, context=context) - def _history(self, cr, uid, cases, keyword, history=False, subject=None, email=False, details=None, email_from=False, message_id=False, attach=[], context=None): - mailgate_pool = self.pool.get('mailgate.thread') - return mailgate_pool.history(cr, uid, cases, keyword, history=history,\ - subject=subject, email=email, \ - details=details, email_from=email_from,\ - message_id=message_id, attach=attach, \ - context=context) def case_open(self, cr, uid, ids, *args): - """Opens Case - """ + """Opens Case""" cases = self.browse(cr, uid, ids) - self._history(cr, uid, cases, _('Open')) + self.message_append(cr, uid, cases, _('Open')) for case in cases: data = {'state': 'open', 'active': True } if not case.user_id: @@ -431,11 +397,10 @@ class crm_case(crm_base): return True def case_close(self, cr, uid, ids, *args): - """Closes Case - """ + """Closes Case""" cases = self.browse(cr, uid, ids) cases[0].state # to fill the browse record cache - self._history(cr, uid, cases, _('Close')) + self.message_append(cr, uid, cases, _('Close')) self.write(cr, uid, ids, {'state': 'done', 'date_closed': time.strftime('%Y-%m-%d %H:%M:%S'), }) @@ -446,12 +411,10 @@ class crm_case(crm_base): return True def case_escalate(self, cr, uid, ids, *args): - """Escalates case to top level - """ + """Escalates case to parent level""" cases = self.browse(cr, uid, ids) for case in cases: data = {'active': True} - if case.section_id.parent_id: data['section_id'] = case.section_id.parent_id.id if case.section_id.parent_id.change_responsible: @@ -461,16 +424,15 @@ class crm_case(crm_base): raise osv.except_osv(_('Error !'), _('You can not escalate, You are already at the top level regarding your sales-team category.')) self.write(cr, uid, [case.id], data) cases = self.browse(cr, uid, ids) - self._history(cr, uid, cases, _('Escalate')) + self.message_append(cr, uid, cases, _('Escalate')) self._action(cr, uid, cases, 'escalate') return True def case_cancel(self, cr, uid, ids, *args): - """Cancels Case - """ + """Cancels Case""" cases = self.browse(cr, uid, ids) cases[0].state # to fill the browse record cache - self._history(cr, uid, cases, _('Cancel')) + self.message_append(cr, uid, cases, _('Cancel')) self.write(cr, uid, ids, {'state': 'cancel', 'active': True}) self._action(cr, uid, cases, 'cancel') @@ -480,56 +442,37 @@ class crm_case(crm_base): return True def case_pending(self, cr, uid, ids, *args): - """Marks case as pending - """ + """Marks case as pending""" cases = self.browse(cr, uid, ids) cases[0].state # to fill the browse record cache - self._history(cr, uid, cases, _('Pending')) + self.message_append(cr, uid, cases, _('Pending')) self.write(cr, uid, ids, {'state': 'pending', 'active': True}) self._action(cr, uid, cases, 'pending') return True def case_reset(self, cr, uid, ids, *args): - """Resets case as draft - """ - state = 'draft' + """Resets case as draft""" + state = 'draft' if 'crm.phonecall' in args: - state = 'open' + state = 'open' cases = self.browse(cr, uid, ids) cases[0].state # to fill the browse record cache - self._history(cr, uid, cases, _('Draft')) + self.message_append(cr, uid, cases, _('Draft')) self.write(cr, uid, ids, {'state': state, 'active': True}) self._action(cr, uid, cases, state) return True def remind_partner(self, cr, uid, ids, context=None, 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=None, 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 case's IDs to remind - @param context: A standard dictionary for contextual values - """ + mail_message = self.pool.get('mail.message') for case in self.browse(cr, uid, ids, context=context): if not destination and not case.email_from: return False if not case.user_id.user_email: return False - if destination and case.section_id.user_id: case_email = case.section_id.user_id.user_email else: @@ -550,37 +493,31 @@ class crm_case(crm_base): body = self.format_body(body) - attach_to_send = None + attach_to_send = {} if attach: attach_ids = self.pool.get('ir.attachment').search(cr, uid, [('res_model', '=', self._name), ('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) + attach_to_send = dict(map(lambda x: (x['datas_fname'], base64.decodestring(x['datas'])), attach_to_send)) - # Send an email - subject = "Reminder: [%s] %s" % (str(case.id), case.name,) - tools.email_send( + # Send an email + subject = "Reminder: [%s] %s" % (str(case.id), case.name, ) + mail_message.schedule_with_attach(cr, uid, src, [dest], subject, body, - reply_to=case.section_id.reply_to or '', - openobject_id=str(case.id), - attach=attach_to_send + model='crm.case', + reply_to=case.section_id.reply_to, + res_id=case.id, + attachments=attach_to_send, + context=context ) - self._history(cr, uid, [case], _('Send'), history=True, subject=subject, email=dest, details=body, email_from=src) - return True def _check(self, cr, uid, ids=False, context=None): - """ - 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 + """Function called by the scheduler to process cases for date actions + Only works on not done and cancelled cases """ cr.execute('select * from crm_case \ where (date_action_last<%s or date_action_last is null) \ @@ -599,9 +536,7 @@ class crm_case(crm_base): def format_mail(self, obj, body): return self.pool.get('base.action.rule').format_mail(obj, body) - def message_followers(self, cr, uid, ids, context=None): - """ Get a list of emails of the people following this thread - """ + def message_thread_followers(self, cr, uid, ids, context=None): res = {} for case in self.browse(cr, uid, ids, context=context): l=[] @@ -613,12 +548,7 @@ class crm_case(crm_base): return res def _links_get(self, cr, uid, context=None): - """Gets links value for reference field - @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 - """ + """Gets links value for reference field""" obj = self.pool.get('res.request.link') ids = obj.search(cr, uid, []) res = obj.read(cr, uid, ids, ['object', 'name'], context) @@ -634,10 +564,8 @@ class users(osv.osv): def create(self, cr, uid, vals, context=None): res = super(users, self).create(cr, uid, vals, context=context) section_obj=self.pool.get('crm.case.section') - - if vals.get('context_section_id', False): + if vals.get('context_section_id'): section_obj.write(cr, uid, [vals['context_section_id']], {'member_ids':[(4, res)]}, context) return res users() - diff --git a/addons/crm/crm_action_rule.py b/addons/crm/crm_action_rule.py index 31dcc0be56a..559d257820a 100644 --- a/addons/crm/crm_action_rule.py +++ b/addons/crm/crm_action_rule.py @@ -40,12 +40,12 @@ class base_action_rule(osv.osv): 'regex_history' : fields.char('Regular Expression on Case History', size=128), 'act_section_id': fields.many2one('crm.case.section', 'Set Team to'), 'act_categ_id': fields.many2one('crm.case.categ', 'Set Category to'), - 'act_mail_to_partner': fields.boolean('Mail to Partner', help="Check \ -this if you want the rule to send an email to the partner."), + 'act_mail_to_partner': fields.boolean('Mail to Partner', + help="Check this if you want the rule to send an email to the partner."), } - def email_send(self, cr, uid, obj, emails, body, emailfrom=tools.config.get('email_from', False), context=None): + mail_message = self.pool.get('mail.message') body = self.format_mail(obj, body) if not emailfrom: if hasattr(obj, 'user_id') and obj.user_id and obj.user_id.user_email: @@ -58,15 +58,10 @@ this if you want the rule to send an email to the partner."), else: reply_to = emailfrom if not emailfrom: - raise osv.except_osv(_('Error!'), - _("No E-Mail ID Found for your Company address!")) - return tools.email_send(emailfrom, emails, name, body, reply_to=reply_to, openobject_id=str(obj.id)) + raise osv.except_osv(_('Error!'), _("No E-Mail Found for your Company address!")) + return mail_message.schedule_with_attach(cr, uid, emailfrom, emails, name, body, model='base.action.rule', reply_to=reply_to, res_id=obj.id) def do_check(self, cr, uid, action, obj, context=None): - """ @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""" ok = super(base_action_rule, self).do_check(cr, uid, action, obj, context=context) if hasattr(obj, 'section_id'): @@ -74,9 +69,8 @@ this if you want the rule to send an email to the partner."), if hasattr(obj, 'categ_id'): ok = ok and (not action.trg_categ_id or action.trg_categ_id.id == obj.categ_id.id) - #Cheking for history + #Cheking for history regex = action.regex_history - result_history = True if regex: res = False ptrn = re.compile(str(regex)) @@ -85,23 +79,17 @@ this if you want the rule to send an email to the partner."), if _result: res = True break - result_history = res - ok = ok and (not regex or result_history) + ok = ok and res - res_count = True if action.trg_max_history: res_count = False - history_ids = filter(lambda x: x.history, obj.message_ids) + history_ids = filter(lambda x: x.email_from, obj.message_ids) if len(history_ids) <= action.trg_max_history: res_count = True - ok = ok and res_count + ok = ok and res_count return ok def do_action(self, cr, uid, action, model_obj, obj, context=None): - """ @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 """ res = super(base_action_rule, self).do_action(cr, uid, action, model_obj, obj, context=context) write = {} @@ -118,8 +106,8 @@ this if you want the rule to send an email to the partner."), write['email_cc'] = obj.act_email_cc # Put state change by rule in communication history - if hasattr(obj, 'state') and action.act_state: - model_obj._history(cr, uid, [obj], _(action.act_state)) + if hasattr(obj, 'state') and hasattr(obj, 'message_append') and action.act_state: + model_obj.message_append(cr, uid, [obj], _(action.act_state)) model_obj.write(cr, uid, [obj.id], write, context) emails = [] @@ -134,22 +122,12 @@ this if you want the rule to send an email to the partner."), def state_get(self, cr, uid, context=None): - """Gets available states for crm - @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 """ + """Gets available states for crm""" res = super(base_action_rule, self).state_get(cr, uid, context=context) return res + crm.AVAILABLE_STATES def priority_get(self, cr, uid, context=None): - """@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 """ res = super(base_action_rule, self).priority_get(cr, uid, context=context) return res + crm.AVAILABLE_PRIORITIES -base_action_rule() - # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/crm/crm_lead.py b/addons/crm/crm_lead.py index fae37ed54a4..c409ce2aef2 100644 --- a/addons/crm/crm_lead.py +++ b/addons/crm/crm_lead.py @@ -40,7 +40,15 @@ class crm_lead(crm_case, osv.osv): _name = "crm.lead" _description = "Lead/Opportunity" _order = "priority,date_action,id desc" - _inherit = ['mailgate.thread','res.partner.address'] + _inherit = ['mail.thread','res.partner.address'] + + # overridden because res.partner.address has an inconvenient name_get, + # especially if base_contact is installed. + def name_get(self, cr, user, ids, context=None): + if isinstance(ids, (int, long)): + ids = [ids] + return [(r['id'], tools.ustr(r[self._rec_name])) + for r in self.read(cr, user, ids, [self._rec_name], context)] def _compute_day(self, cr, uid, ids, fields, args, context=None): """ @@ -101,8 +109,8 @@ class crm_lead(crm_case, osv.osv): def _history_search(self, cr, uid, obj, name, args, context=None): res = [] - msg_obj = self.pool.get('mailgate.message') - message_ids = msg_obj.search(cr, uid, [('history','=',True), ('name', args[0][1], args[0][2])], context=context) + msg_obj = self.pool.get('mail.message') + message_ids = msg_obj.search(cr, uid, [('email_from','!=',False), ('subject', args[0][1], args[0][2])], context=context) lead_ids = self.search(cr, uid, [('message_ids', 'in', message_ids)], context=context) if lead_ids: @@ -115,8 +123,8 @@ class crm_lead(crm_case, osv.osv): for obj in self.browse(cr, uid, ids, context=context): res[obj.id] = '' for msg in obj.message_ids: - if msg.history: - res[obj.id] = msg.name + if msg.email_from: + res[obj.id] = msg.subject break return res @@ -163,7 +171,7 @@ class crm_lead(crm_case, osv.osv): \nIf the case is in progress the state is set to \'Open\'.\ \nWhen the case is over, the state is set to \'Done\'.\ \nIf the case needs to be reviewed then the state is set to \'Pending\'.'), - 'message_ids': fields.one2many('mailgate.message', 'res_id', 'Messages', domain=[('model','=',_name)]), + 'message_ids': fields.one2many('mail.message', 'res_id', 'Messages', domain=[('model','=',_name)]), 'subjects': fields.function(_get_email_subject, fnct_search=_history_search, string='Subject of Email', type='char', size=64), @@ -335,16 +343,14 @@ class crm_lead(crm_case, osv.osv): } return value - def message_new(self, cr, uid, msg, context=None): - """ Automatically calls when new email message arrives - """ - mailgate_pool = self.pool.get('email.server.tools') + def message_new(self, cr, uid, msg, custom_values=None, context=None): + """Automatically calls when new email message arrives""" + res_id = super(crm_lead, self).message_new(cr, uid, msg, custom_values=custom_values, context=context) + subject = msg.get('subject') or _("No Subject") + body = msg.get('body_text') - subject = msg.get('subject') or _("No Subject") - body = msg.get('body') msg_from = msg.get('from') priority = msg.get('priority') - vals = { 'name': subject, 'email_from': msg_from, @@ -352,45 +358,27 @@ class crm_lead(crm_case, osv.osv): 'description': body, 'user_id': False, } - if msg.get('priority', False): + if priority: vals['priority'] = priority + vals.update(self.message_partner_by_email(cr, uid, msg.get('from', False))) + self.write(cr, uid, [res_id], vals, context) + return res_id - res = mailgate_pool.get_partner(cr, uid, msg.get('from') or msg.get_unixfrom()) - if res: - vals.update(res) - - res = self.create(cr, uid, vals, context) - attachents = msg.get('attachments', []) - for attactment in attachents or []: - data_attach = { - 'name': attactment, - 'datas':binascii.b2a_base64(str(attachents.get(attactment))), - 'datas_fname': attactment, - 'description': 'Mail attachment', - 'res_model': self._name, - 'res_id': res, - } - self.pool.get('ir.attachment').create(cr, uid, data_attach) - - return res - - def message_update(self, cr, uid, ids, vals={}, msg="", default_act='pending', context=None): - """ - @param ids: List of update mail’s IDs - """ + def message_update(self, cr, uid, ids, msg, vals={}, default_act='pending', context=None): if isinstance(ids, (str, int, long)): ids = [ids] + super(crm_lead, self).message_update(cr, uid, ids, msg, context=context) + if msg.get('priority') in dict(crm.AVAILABLE_PRIORITIES): vals['priority'] = msg.get('priority') - maps = { 'cost':'planned_cost', 'revenue': 'planned_revenue', 'probability':'probability' } vls = {} - for line in msg['body'].split('\n'): + for line in msg['body_text'].split('\n'): line = line.strip() res = tools.misc.command_re.match(line) if res and maps.get(res.group(1).lower()): @@ -408,12 +396,6 @@ class crm_lead(crm_case, osv.osv): res = self.write(cr, uid, [case.id], values, context=context) return res - def msg_send(self, cr, uid, id, *args, **argv): - """ Send The Message - @param ids: List of email’s IDs - """ - return True - def action_makeMeeting(self, cr, uid, ids, context=None): """ This opens Meeting's calendar view to schedule meeting on current Opportunity @@ -459,24 +441,6 @@ class crm_lead(crm_case, osv.osv): } return value - def write(self, cr, uid, ids, vals, context=None): - if not context: - context = {} - - if 'date_closed' in vals: - return super(crm_lead,self).write(cr, uid, ids, vals, context=context) - - if 'stage_id' in vals and vals['stage_id']: - stage_obj = self.pool.get('crm.case.stage').browse(cr, uid, vals['stage_id'], context=context) - self.history(cr, uid, ids, _("Changed Stage to: %s") % stage_obj.name, details=_("Changed Stage to: %s") % stage_obj.name) - message='' - for case in self.browse(cr, uid, ids, context=context): - if case.type == 'lead' or context.get('stage_type',False)=='lead': - message = _("The stage of lead '%s' has been changed to '%s'.") % (case.name, stage_obj.name) - elif case.type == 'opportunity': - message = _("The stage of opportunity '%s' has been changed to '%s'.") % (case.name, stage_obj.name) - self.log(cr, uid, case.id, message) - return super(crm_lead,self).write(cr, uid, ids, vals, context) def unlink(self, cr, uid, ids, context=None): for lead in self.browse(cr, uid, ids, context): @@ -486,6 +450,26 @@ class crm_lead(crm_case, osv.osv): return super(crm_lead, self).unlink(cr, uid, ids, context) + def write(self, cr, uid, ids, vals, context=None): + if not context: + context = {} + + if 'date_closed' in vals: + return super(crm_lead,self).write(cr, uid, ids, vals, context=context) + + if 'stage_id' in vals and vals['stage_id']: + stage_obj = self.pool.get('crm.case.stage').browse(cr, uid, vals['stage_id'], context=context) + text = _("Changed Stage to: %s") % stage_obj.name + self.message_append(cr, uid, ids, text, body_text=text, context=context) + message='' + for case in self.browse(cr, uid, ids, context=context): + if case.type == 'lead' or context.get('stage_type',False)=='lead': + message = _("The stage of lead '%s' has been changed to '%s'.") % (case.name, stage_obj.name) + elif case.type == 'opportunity': + message = _("The stage of opportunity '%s' has been changed to '%s'.") % (case.name, stage_obj.name) + self.log(cr, uid, case.id, message) + return super(crm_lead,self).write(cr, uid, ids, vals, context) + crm_lead() # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/crm/crm_lead_view.xml b/addons/crm/crm_lead_view.xml index 0ad576fd470..f76d32b1710 100644 --- a/addons/crm/crm_lead_view.xml +++ b/addons/crm/crm_lead_view.xml @@ -97,10 +97,10 @@ - + + + + + + + + + + + + + + + + + + +