From e46a978c2fd62fc6bcc977068d53c3dda49540eb Mon Sep 17 00:00:00 2001 From: Stephane Wirtel Date: Tue, 11 May 2010 15:51:57 +0200 Subject: [PATCH 1/9] [IMP] crm: Use an osv_memory to represent the attachments in the send email wizard bzr revid: stephane@openerp.com-20100511135157-f2w58mbbdjtzts3j --- addons/crm/wizard/crm_send_email.py | 61 ++++++++++++++--------- addons/crm/wizard/crm_send_email_view.xml | 27 ++++++---- 2 files changed, 56 insertions(+), 32 deletions(-) diff --git a/addons/crm/wizard/crm_send_email.py b/addons/crm/wizard/crm_send_email.py index ae9ff8541c6..506bca661a0 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() 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 @@ - - - + +
+ + + + + + + From ac3e6c51ba6019aa10b3c5445d17b5577bbb6d10 Mon Sep 17 00:00:00 2001 From: Stephane Wirtel Date: Tue, 11 May 2010 16:45:16 +0200 Subject: [PATCH 2/9] [FIX] crm: Rename 'Contact Name' to 'Company Name' bzr revid: stephane@openerp.com-20100511144516-vy7c7478745u0nel --- addons/crm/crm_lead.py | 2 +- addons/crm/crm_lead_view.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 @@ - + From 823e69341e844235250e5440158254d30fb89d78 Mon Sep 17 00:00:00 2001 From: Stephane Wirtel Date: Tue, 11 May 2010 16:45:48 +0200 Subject: [PATCH 3/9] [FIX] crm: Remove the '\r' character in the Mailgateway bzr revid: stephane@openerp.com-20100511144548-fpq3uzh85407f5q7 --- addons/crm/scripts/openerp_mailgate/openerp_mailgate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/crm/scripts/openerp_mailgate/openerp_mailgate.py b/addons/crm/scripts/openerp_mailgate/openerp_mailgate.py index 607b0fbd434..110a922c27f 100755 --- a/addons/crm/scripts/openerp_mailgate/openerp_mailgate.py +++ b/addons/crm/scripts/openerp_mailgate/openerp_mailgate.py @@ -168,7 +168,7 @@ 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): From 9e382c11a7d83e2e5bfd9064d1741b68dec6ce50 Mon Sep 17 00:00:00 2001 From: Stephane Wirtel Date: Tue, 11 May 2010 17:02:58 +0200 Subject: [PATCH 4/9] [FIX] crm: mailgateway: Use the right fields from the email for the 'From' and 'To' in the crm.case (and decode them) bzr revid: stephane@openerp.com-20100511150258-6cbaxmkgi598m14o --- addons/crm/scripts/openerp_mailgate/openerp_mailgate.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/addons/crm/scripts/openerp_mailgate/openerp_mailgate.py b/addons/crm/scripts/openerp_mailgate/openerp_mailgate.py index 110a922c27f..5775319ee0a 100755 --- a/addons/crm/scripts/openerp_mailgate/openerp_mailgate.py +++ b/addons/crm/scripts/openerp_mailgate/openerp_mailgate.py @@ -175,6 +175,7 @@ class email_parser(object): 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): From 41ef3a09e8e9fb1b18449678c601928d086ff851 Mon Sep 17 00:00:00 2001 From: Stephane Wirtel Date: Tue, 11 May 2010 17:30:43 +0200 Subject: [PATCH 5/9] [FIX] crm: Add the signature of the user in the 'reply to the mail' wizard bzr revid: stephane@openerp.com-20100511153043-6iiq1lzykdrb81q8 --- addons/crm/wizard/crm_send_email.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/addons/crm/wizard/crm_send_email.py b/addons/crm/wizard/crm_send_email.py index 506bca661a0..f62c3b2b8f3 100644 --- a/addons/crm/wizard/crm_send_email.py +++ b/addons/crm/wizard/crm_send_email.py @@ -217,7 +217,11 @@ 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] + + 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: From 5365ed0efcb1bcfcbc85810f575d5a904118b4d0 Mon Sep 17 00:00:00 2001 From: Stephane Wirtel Date: Tue, 11 May 2010 17:40:23 +0200 Subject: [PATCH 6/9] [FIX] crm: Check if there is a model for the log of the crm.case bzr revid: stephane@openerp.com-20100511154023-joyuanu159l6bw00 --- addons/crm/wizard/crm_send_email.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/addons/crm/wizard/crm_send_email.py b/addons/crm/wizard/crm_send_email.py index f62c3b2b8f3..b31a08e465e 100644 --- a/addons/crm/wizard/crm_send_email.py +++ b/addons/crm/wizard/crm_send_email.py @@ -202,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: From 9f92862f80e4fff53514e7f5421a547e867678d7 Mon Sep 17 00:00:00 2001 From: Stephane Wirtel Date: Tue, 11 May 2010 18:53:54 +0200 Subject: [PATCH 7/9] [FIX] crm: Change the help message for the active field in the case bzr revid: stephane@openerp.com-20100511165354-jlab2xsh2t58p8yc --- addons/crm/crm.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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.\ From c1fa53db2bd9fba956dfad34b4f29de8cb0bf5ac Mon Sep 17 00:00:00 2001 From: Stephane Wirtel Date: Tue, 11 May 2010 18:54:16 +0200 Subject: [PATCH 8/9] [FIX] crm: Declare the signature variable bzr revid: stephane@openerp.com-20100511165416-vmilmnn9zws8dxrd --- addons/crm/wizard/crm_send_email.py | 1 + 1 file changed, 1 insertion(+) diff --git a/addons/crm/wizard/crm_send_email.py b/addons/crm/wizard/crm_send_email.py index b31a08e465e..a3a86d4b509 100644 --- a/addons/crm/wizard/crm_send_email.py +++ b/addons/crm/wizard/crm_send_email.py @@ -223,6 +223,7 @@ class crm_send_new_email(osv.osv_memory): sentdate = 'Date: %s' % (hist.date) desc = '\n%s'%(hist.description) + signature = '' if case.user_id.signature: signature = '--\n' + case.user_id.signature From 8e7c75cdbe5cea97d2d2331edb1092b8a8c49d51 Mon Sep 17 00:00:00 2001 From: Fabien Pinckaers Date: Tue, 11 May 2010 23:27:24 +0200 Subject: [PATCH 9/9] [IMP] typo bzr revid: fp@tinyerp.com-20100511212724-1jwdgpto1meccg62 --- addons/stock/stock.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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)]}),