diff --git a/addons/crm/crm.py b/addons/crm/crm.py index 34d8b46bcf4..fd629edc745 100644 --- a/addons/crm/crm.py +++ b/addons/crm/crm.py @@ -315,8 +315,7 @@ class crm_case(osv.osv): _columns = { 'id': fields.integer('ID', readonly=True), 'name': fields.char('Description', size=1024, required=True), - 'active': fields.boolean('Active', help="If the active field is set to\ - true, it will allow you to hide the case without removing it."), + 'active': fields.boolean('Active', help="If the active field is set to false, it will allow you to hide the case without removing it."), 'description': fields.text('Description'), 'section_id': fields.many2one('crm.case.section', 'Sales Team', \ select=True, help='Sales team to which Case belongs to.\ diff --git a/addons/crm/crm_lead.py b/addons/crm/crm_lead.py index 9c4c38875c5..d6995cb6644 100644 --- a/addons/crm/crm_lead.py +++ b/addons/crm/crm_lead.py @@ -113,7 +113,7 @@ class crm_lead(osv.osv): 'type_id': fields.many2one('crm.case.resource.type', 'Lead Type', \ domain="[('section_id','=',section_id),\ ('object_id.model', '=', 'crm.lead')]"), - 'partner_name': fields.char("Contact Name", size=64), + 'partner_name': fields.char("Company Name", size=64), 'priority': fields.selection(crm.AVAILABLE_PRIORITIES, 'Priority'), 'date_closed': fields.datetime('Closed', readonly=True), diff --git a/addons/crm/crm_lead_view.xml b/addons/crm/crm_lead_view.xml index 9608616debd..ade89c792b1 100644 --- a/addons/crm/crm_lead_view.xml +++ b/addons/crm/crm_lead_view.xml @@ -69,7 +69,7 @@ - + diff --git a/addons/crm/scripts/openerp_mailgate/openerp_mailgate.py b/addons/crm/scripts/openerp_mailgate/openerp_mailgate.py index 607b0fbd434..5775319ee0a 100755 --- a/addons/crm/scripts/openerp_mailgate/openerp_mailgate.py +++ b/addons/crm/scripts/openerp_mailgate/openerp_mailgate.py @@ -168,13 +168,14 @@ class email_parser(object): def _decode_header(self, s): from email.Header import decode_header - s = decode_header(s) + s = decode_header(s.replace('\r', '')) return ''.join(map(lambda x:self._to_decode(x[0], [x[1]]), s or [])) def msg_new(self, msg): message = self.msg_body_get(msg) msg_subject = self._decode_header(msg['Subject']) msg_from = self._decode_header(msg['From']) + msg_to = self._decode_header(msg['To']) msg_cc = self._decode_header(msg['Cc'] or '') data = { @@ -189,7 +190,7 @@ class email_parser(object): try: id = self.rpc(self.model, 'create', data) - self.rpc(self.model, 'history', [id], 'Receive', True, msg['From'], message['body'], False, False, {'model' : self.model}) + self.rpc(self.model, 'history', [id], 'Receive', True, msg_to, message['body'], msg_from, False, {'model' : self.model}) #self.rpc(self.model, 'case_open', [id]) except Exception, e: if getattr(e, 'faultCode', '') and 'AccessError' in e.faultCode: @@ -314,7 +315,7 @@ class email_parser(object): 'res_id': id } self.rpc('ir.attachment', 'create', data_attach) - self.rpc(self.model, 'history', [id], 'Send', True, msg['From'], body['body']) + self.rpc(self.model, 'history', [id], 'Send', True, self._decode_header(msg['From']), body['body']) return id def msg_send(self, msg, emails, priority=None): @@ -357,7 +358,7 @@ class email_parser(object): 'res_id': id } self.rpc('ir.attachment', 'create', data_attach) - self.rpc(self.model, 'history', [id], 'Send', True, msg['From'], message['body']) + self.rpc(self.model, 'history', [id], 'Send', True, self._decode_header(msg['From']), message['body']) return id def msg_test(self, msg, case_str): diff --git a/addons/crm/wizard/crm_send_email.py b/addons/crm/wizard/crm_send_email.py index ae9ff8541c6..a3a86d4b509 100644 --- a/addons/crm/wizard/crm_send_email.py +++ b/addons/crm/wizard/crm_send_email.py @@ -26,6 +26,24 @@ import base64 import tools from crm import crm +class crm_send_new_email(osv.osv_memory): + """ Sends new email for the case""" + _name = "crm.send.mail" + +crm_send_new_email() + +class crm_send_new_email_attachment(osv.osv_memory): + _name = 'crm.send.mail.attachment' + + _columns = { + 'binary' : fields.binary('Attachment', required=True), + 'name' : fields.char('Name', size=128, required=True), + + 'wizard_id' : fields.many2one('crm.send.mail', 'Wizard', required=True), + } + +crm_send_new_email_attachment() + class crm_send_new_email(osv.osv_memory): """ Sends new email for the case""" _name = "crm.send.mail" @@ -38,12 +56,8 @@ class crm_send_new_email(osv.osv_memory): 'subject': fields.char('Subject', size=128, required=True), 'text': fields.text('Message', required=True), 'state': fields.selection(crm.AVAILABLE_STATES, string='Set New State To', required=True), - 'doc1': fields.binary("Attachment1"), - 'doc1_fname': fields.char("File Name", size=64), - 'doc2': fields.binary("Attachment2"), - 'doc2_fname': fields.char("File Name", size=64), - 'doc3': fields.binary("Attachment3"), - 'doc3_fname': fields.char("File Name", size=64), + + 'attachment_ids' : fields.one2many('crm.send.mail.attachment', 'wizard_id'), } def action_cancel(self, cr, uid, ids, context=None): @@ -68,12 +82,13 @@ class crm_send_new_email(osv.osv_memory): case_pool = self.pool.get(model) res_id = context and context.get('active_id', False) or False - for data in self.read(cr, uid, ids, context=context): - attach = filter(lambda x: x, [data['doc1'], data['doc2'], data['doc3']]) - attach = map(lambda x: (data['doc' + str(attach.index(x) + 1) \ - + '_fname'], base64.decodestring(x)), attach) - message_id = None - + for obj in self.browse(cr, uid, ids, context=context): + attach = [ + (x.name, base64.decodestring(x.binary)) for x in obj.attachment_ids + ] + + message_id = None + case = case_pool.browse(cr, uid, res_id) if context.get('mail', 'new') == 'new': if len(case.history_line): @@ -84,13 +99,13 @@ class crm_send_new_email(osv.osv_memory): model = hist.log_id.model_id.model model_pool = self.pool.get(model) case = model_pool.browse(cr, uid, hist.log_id.res_id) - emails = [data['email_to']] + (data['email_cc'] or '').split(',') + emails = [obj.email_to] + (obj.email_cc or '').split(',') emails = filter(None, emails) - body = data['text'] + body = obj.text body = case_pool.format_body(body) - email_from = data.get('email_from', False) - case_pool._history(cr, uid, [case], _('Send'), history=True, email=data['email_to'], details=body, email_from=email_from, message_id=message_id) + email_from = getattr(obj, 'email_from', False) + case_pool._history(cr, uid, [case], _('Send'), history=True, email=obj.email_to, details=body, email_from=email_from, message_id=message_id) x_headers = dict() #x_headers = { @@ -106,7 +121,7 @@ class crm_send_new_email(osv.osv_memory): uid=uid, server_id=case.section_id.server_id.id, emailto=emails, - subject=data['subject'], + subject=obj.subject, body="
%s
" % body, attachments=attach, headers=x_headers @@ -115,7 +130,7 @@ class crm_send_new_email(osv.osv_memory): flag = tools.email_send( email_from, emails, - data['subject'], + obj.subject, body, attach=attach, reply_to=case.section_id.reply_to, @@ -124,14 +139,14 @@ class crm_send_new_email(osv.osv_memory): ) if flag: - if data['state'] == 'unchanged': + if obj.state == 'unchanged': pass - elif data['state'] == 'done': + elif obj.state == 'done': case_pool.case_close(cr, uid, [case.id]) - elif data['state'] == 'draft': + elif obj.state == 'draft': case_pool.case_reset(cr, uid, [case.id]) - elif data['state'] in ['cancel', 'open', 'pending']: - act = 'case_' + data['state'] + elif obj.state in ['cancel', 'open', 'pending']: + act = 'case_' + obj.state getattr(case_pool, act)(cr, uid, [case.id]) cr.commit() @@ -187,6 +202,11 @@ class crm_send_new_email(osv.osv_memory): res = {} for hist in hist_obj.browse(cr, uid, res_ids): model = hist.log_id.model_id.model + + # In the case where the crm.case does not exist in the database + if not model: + return {} + model_pool = self.pool.get(model) case = model_pool.browse(cr, uid, hist.log_id.res_id) if 'email_to' in fields: @@ -202,7 +222,12 @@ class crm_send_new_email(osv.osv_memory): to = 'To: %s' % (hist.email_to or '') sentdate = 'Date: %s' % (hist.date) desc = '\n%s'%(hist.description) - original = [header, sender, to, sentdate, desc] + + signature = '' + if case.user_id.signature: + signature = '--\n' + case.user_id.signature + + original = [header, sender, to, sentdate, desc, signature] original = '\n'.join(original) res['text']=original if 'subject' in fields: diff --git a/addons/crm/wizard/crm_send_email_view.xml b/addons/crm/wizard/crm_send_email_view.xml index 49758245eb0..35d78f895fc 100644 --- a/addons/crm/wizard/crm_send_email_view.xml +++ b/addons/crm/wizard/crm_send_email_view.xml @@ -19,12 +19,15 @@
- - - - - - + +
+ + + + + + +
@@ -60,9 +63,15 @@ - - - + +
+ + + + + + + diff --git a/addons/stock/stock.py b/addons/stock/stock.py index 3795351e03a..dcb054c1cf7 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -490,7 +490,7 @@ class stock_picking(osv.osv): 'min_date': fields.function(get_min_max_date, fnct_inv=_set_minimum_date, multi="min_max_date", method=True, store=True, type='datetime', string='Expected Date', select=1, help="Expected date for Picking. Default it takes current date"), 'date': fields.datetime('Order Date', help="Date of Order"), - 'date_done': fields.datetime('Date Done', help="Date of completion"), + 'date_done': fields.datetime('Date Done', help="Date of Completion"), 'max_date': fields.function(get_min_max_date, fnct_inv=_set_maximum_date, multi="min_max_date", method=True, store=True, type='datetime', string='Max. Expected Date', select=2), 'move_lines': fields.one2many('stock.move', 'picking_id', 'Entry lines', states={'done': [('readonly', True)], 'cancel': [('readonly', True)]}),