From 2405f334e2e39f06e2de569b86042b2693400d8b Mon Sep 17 00:00:00 2001 From: Numerigraphe - Lionel Sausin Date: Wed, 7 Jul 2010 17:29:09 +0200 Subject: [PATCH 01/27] [FIX] account: wrong invoice number sequence for fiscal year in a certain case [FIX] account: context not initialized correctly in sequence lp bug: https://launchpad.net/bugs/602188 fixed bzr revid: ls@numerigraphe.fr-20100707152909-ocjbj6c784oqeg54 --- addons/account/invoice.py | 8 ++++++-- addons/account/sequence.py | 11 ++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/addons/account/invoice.py b/addons/account/invoice.py index 62f998fa751..6e2ff2a7baa 100644 --- a/addons/account/invoice.py +++ b/addons/account/invoice.py @@ -923,12 +923,16 @@ class account_invoice(osv.osv): obj_inv = self.browse(cr, uid, ids)[0] for (id, invtype, number, move_id, reference) in cr.fetchall(): if not number: + tmp_context = { + 'fiscalyear_id': inv.period_id.fiscalyear_id.id + } if obj_inv.journal_id.invoice_sequence_id: sid = obj_inv.journal_id.invoice_sequence_id.id number = self.pool.get('ir.sequence').get_id(cr, uid, sid, 'id', {'fiscalyear_id': obj_inv.period_id.fiscalyear_id.id}) else: - number = self.pool.get('ir.sequence').get(cr, uid, - 'account.invoice.' + invtype) + number = obj_seq.get_id(cr, uid, + 'account.invoice.%s' % invtype, + 'code=%s', context=tmp_context) if invtype in ('in_invoice', 'in_refund'): ref = reference else: diff --git a/addons/account/sequence.py b/addons/account/sequence.py index c90e9ef93c7..1186d4b8c7f 100644 --- a/addons/account/sequence.py +++ b/addons/account/sequence.py @@ -19,7 +19,7 @@ # ############################################################################## -from osv import fields,osv +from osv import fields, osv class ir_sequence_fiscalyear(osv.osv): _name = 'account.sequence.fiscalyear' @@ -31,7 +31,7 @@ class ir_sequence_fiscalyear(osv.osv): } _sql_constraints = [ - ('main_id', 'CHECK (sequence_main_id != sequence_id)', 'Main Sequence must be different from current !'), + ('main_id', 'CHECK (sequence_main_id != sequence_id)', 'Main Sequence must be different from current !'), ] ir_sequence_fiscalyear() @@ -41,15 +41,16 @@ class ir_sequence(osv.osv): _columns = { 'fiscal_ids' : fields.one2many('account.sequence.fiscalyear', 'sequence_main_id', 'Sequences') } - def get_id(self, cr, uid, sequence_id, test='id', context={}): + def get_id(self, cr, uid, sequence_id, test='id', context=None): + if context is None: + context = {} cr.execute('select id from ir_sequence where '+test+'=%s and active=%s', (sequence_id, True,)) res = cr.dictfetchone() if res: for line in self.browse(cr, uid, res['id'], context=context).fiscal_ids: if line.fiscalyear_id.id==context.get('fiscalyear_id', False): return super(ir_sequence, self).get_id(cr, uid, line.sequence_id.id, test="id", context=context) - return super(ir_sequence, self).get_id(cr, uid, sequence_id, test, context) + return super(ir_sequence, self).get_id(cr, uid, sequence_id, test, context=context) ir_sequence() - # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: From dbf34fd87eed009dfecf0c15c42430d1c42a0231 Mon Sep 17 00:00:00 2001 From: Numerigraphe - Lionel Sausin Date: Wed, 7 Jul 2010 17:33:14 +0200 Subject: [PATCH 02/27] [REF] account: code formating in sequence bzr revid: ls@numerigraphe.fr-20100707153314-thxkmi5k9my09eq4 --- addons/account/sequence.py | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/addons/account/sequence.py b/addons/account/sequence.py index 1186d4b8c7f..b75e7f3e34e 100644 --- a/addons/account/sequence.py +++ b/addons/account/sequence.py @@ -25,13 +25,17 @@ class ir_sequence_fiscalyear(osv.osv): _name = 'account.sequence.fiscalyear' _rec_name = "sequence_main_id" _columns = { - "sequence_id": fields.many2one("ir.sequence", 'Sequence', required=True, ondelete='cascade'), - "sequence_main_id": fields.many2one("ir.sequence", 'Main Sequence', required=True, ondelete='cascade'), - "fiscalyear_id": fields.many2one('account.fiscalyear', 'Fiscal Year', required=True, ondelete='cascade') + "sequence_id": fields.many2one("ir.sequence", 'Sequence', required=True, + ondelete='cascade'), + "sequence_main_id": fields.many2one("ir.sequence", 'Main Sequence', + required=True, ondelete='cascade'), + "fiscalyear_id": fields.many2one('account.fiscalyear', 'Fiscal Year', + required=True, ondelete='cascade') } _sql_constraints = [ - ('main_id', 'CHECK (sequence_main_id != sequence_id)', 'Main Sequence must be different from current !'), + ('main_id', 'CHECK (sequence_main_id != sequence_id)', + 'Main Sequence must be different from current !'), ] ir_sequence_fiscalyear() @@ -39,18 +43,25 @@ ir_sequence_fiscalyear() class ir_sequence(osv.osv): _inherit = 'ir.sequence' _columns = { - 'fiscal_ids' : fields.one2many('account.sequence.fiscalyear', 'sequence_main_id', 'Sequences') + 'fiscal_ids' : fields.one2many('account.sequence.fiscalyear', + 'sequence_main_id', 'Sequences') } def get_id(self, cr, uid, sequence_id, test='id', context=None): if context is None: context = {} - cr.execute('select id from ir_sequence where '+test+'=%s and active=%s', (sequence_id, True,)) + cr.execute('select id from ir_sequence where ' + + test + '=%s and active=%s', (sequence_id, True,)) res = cr.dictfetchone() if res: - for line in self.browse(cr, uid, res['id'], context=context).fiscal_ids: - if line.fiscalyear_id.id==context.get('fiscalyear_id', False): - return super(ir_sequence, self).get_id(cr, uid, line.sequence_id.id, test="id", context=context) - return super(ir_sequence, self).get_id(cr, uid, sequence_id, test, context=context) + for line in self.browse(cr, uid, res['id'], + context=context).fiscal_ids: + if line.fiscalyear_id.id == context.get('fiscalyear_id', False): + return super(ir_sequence, self).get_id(cr, uid, + line.sequence_id.id, + test="id", + context=context) + return super(ir_sequence, self).get_id(cr, uid, sequence_id, test, + context=context) ir_sequence() # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: From 4dc7691b1a6840b26d13350edeed29ed78c55dc8 Mon Sep 17 00:00:00 2001 From: Numerigraphe - Lionel Sausin Date: Mon, 12 Jul 2010 12:12:41 +0200 Subject: [PATCH 03/27] [FIX] account: wrong variable name bzr revid: ls@numerigraphe.fr-20100712101241-cn1unvdzds3dy2ol --- addons/account/invoice.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/addons/account/invoice.py b/addons/account/invoice.py index 6e2ff2a7baa..05ca7d5d36e 100644 --- a/addons/account/invoice.py +++ b/addons/account/invoice.py @@ -920,15 +920,15 @@ class account_invoice(osv.osv): 'FROM account_invoice ' \ 'WHERE id IN %s', (tuple(ids),)) - obj_inv = self.browse(cr, uid, ids)[0] + inv = self.browse(cr, uid, ids)[0] for (id, invtype, number, move_id, reference) in cr.fetchall(): if not number: tmp_context = { 'fiscalyear_id': inv.period_id.fiscalyear_id.id } - if obj_inv.journal_id.invoice_sequence_id: - sid = obj_inv.journal_id.invoice_sequence_id.id - number = self.pool.get('ir.sequence').get_id(cr, uid, sid, 'id', {'fiscalyear_id': obj_inv.period_id.fiscalyear_id.id}) + if inv.journal_id.invoice_sequence_id: + sid = inv.journal_id.invoice_sequence_id.id + number = self.pool.get('ir.sequence').get_id(cr, uid, sid, 'id', {'fiscalyear_id': inv.period_id.fiscalyear_id.id}) else: number = obj_seq.get_id(cr, uid, 'account.invoice.%s' % invtype, @@ -1578,4 +1578,4 @@ class res_partner(osv.osv): res_partner() -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: \ No newline at end of file +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: From 3dec5629c96aab45601f8277e2c1264fcca32d3b Mon Sep 17 00:00:00 2001 From: Numerigraphe - Lionel Sausin Date: Mon, 12 Jul 2010 12:40:05 +0200 Subject: [PATCH 04/27] [FIX] account: wrong variable name [IMP] account: sequence view [REF] account: small cleanup lp bug: https://launchpad.net/bugs/602188 fixed bzr revid: ls@numerigraphe.fr-20100712104005-4vkqdu4lcsqgzt21 --- addons/account/invoice.py | 14 +++++++++----- addons/account/sequence_view.xml | 4 ++++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/addons/account/invoice.py b/addons/account/invoice.py index 05ca7d5d36e..d475a2e19b4 100644 --- a/addons/account/invoice.py +++ b/addons/account/invoice.py @@ -927,12 +927,16 @@ class account_invoice(osv.osv): 'fiscalyear_id': inv.period_id.fiscalyear_id.id } if inv.journal_id.invoice_sequence_id: - sid = inv.journal_id.invoice_sequence_id.id - number = self.pool.get('ir.sequence').get_id(cr, uid, sid, 'id', {'fiscalyear_id': inv.period_id.fiscalyear_id.id}) + sequence_id = inv.journal_id.invoice_sequence_id.id + number = self.pool.get('ir.sequence').get_id(cr, uid, + sequence_id, + 'id', + context=tmp_context) else: - number = obj_seq.get_id(cr, uid, - 'account.invoice.%s' % invtype, - 'code=%s', context=tmp_context) + number = self.pool.get('ir.sequence').get_id(cr, uid, + 'account.invoice.%s' % invtype, + 'code', + context=tmp_context) if invtype in ('in_invoice', 'in_refund'): ref = reference else: diff --git a/addons/account/sequence_view.xml b/addons/account/sequence_view.xml index 2d4d159cb41..565725d5d71 100644 --- a/addons/account/sequence_view.xml +++ b/addons/account/sequence_view.xml @@ -14,6 +14,10 @@ +
+ + + From 0b510c279838bd48f26bed5d80a7bc5c1f20fcf0 Mon Sep 17 00:00:00 2001 From: Numerigraphe - Lionel Sausin Date: Tue, 13 Jul 2010 10:58:52 +0200 Subject: [PATCH 05/27] [ADD] test for bug 602188: wrong invoice number sequence for fiscal year in a certain case bzr revid: ls@numerigraphe.fr-20100713085852-mkvywgcdmx2ule58 --- addons/account/__openerp__.py | 1 + .../account/test/sequence_bug602188_test.xml | 53 +++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 addons/account/test/sequence_bug602188_test.xml diff --git a/addons/account/__openerp__.py b/addons/account/__openerp__.py index d3a58272b89..c663ed29e06 100644 --- a/addons/account/__openerp__.py +++ b/addons/account/__openerp__.py @@ -124,6 +124,7 @@ module named account_vouchers 'project/analytic_account_demo.xml', 'demo/account_minimal.xml', 'account_unit_test.xml', + 'test/sequence_bug602188_test.xml', 'board_account_demo.xml', ], 'test': [ diff --git a/addons/account/test/sequence_bug602188_test.xml b/addons/account/test/sequence_bug602188_test.xml new file mode 100644 index 00000000000..3a9200b98e6 --- /dev/null +++ b/addons/account/test/sequence_bug602188_test.xml @@ -0,0 +1,53 @@ + + + + + + + + + + account.invoice.out_invoice + + TEST- + -bug602188 + + + + + + + + + + + + + + + + + draft + out_invoice + + lp:602188 + + + + + + open + TEST-042-bug602188 + + + + + + + + From a9a8c13e68a3a8d75a61d625cc783e523de054db Mon Sep 17 00:00:00 2001 From: Numerigraphe - Lionel Sausin Date: Tue, 13 Jul 2010 17:53:13 +0200 Subject: [PATCH 06/27] [REF] account: rewrite the sequence test in YAML bzr revid: ls@numerigraphe.fr-20100713155313-cw7e9l5gjhfkba70 --- addons/account/__openerp__.py | 2 +- addons/account/test/account_sequence_test.yml | 45 ++++++++++++++++ .../account/test/sequence_bug602188_test.xml | 53 ------------------- 3 files changed, 46 insertions(+), 54 deletions(-) create mode 100644 addons/account/test/account_sequence_test.yml delete mode 100644 addons/account/test/sequence_bug602188_test.xml diff --git a/addons/account/__openerp__.py b/addons/account/__openerp__.py index c663ed29e06..09e51486ad2 100644 --- a/addons/account/__openerp__.py +++ b/addons/account/__openerp__.py @@ -124,10 +124,10 @@ module named account_vouchers 'project/analytic_account_demo.xml', 'demo/account_minimal.xml', 'account_unit_test.xml', - 'test/sequence_bug602188_test.xml', 'board_account_demo.xml', ], 'test': [ + 'test/account_sequence_test.yml', 'test/account_customer_invoice.yml', 'test/account_supplier_invoice.yml', 'test/account_change_currency.yml', diff --git a/addons/account/test/account_sequence_test.yml b/addons/account/test/account_sequence_test.yml new file mode 100644 index 00000000000..3be824d2ca0 --- /dev/null +++ b/addons/account/test/account_sequence_test.yml @@ -0,0 +1,45 @@ +- In order to test the invoice numbering, I create a sequence for out invoices. +- !record {model: ir.sequence, id: seq_out_invoice_test}: + name: Account Invoice Out for the demonstration Fiscal Year # XXX indicate the name of the fiscal year + code: account.invoice.out_invoice + padding: 3 + prefix: FY- + suffix: -TEST + number_next: 42 + +- I link the new sequence to the demo sequence and the demo fiscal years. +- !record {model: account.sequence.fiscalyear, id: seq_out_invoice_test_fy}: + sequence_id: seq_out_invoice_test + sequence_main_id: seq_out_invoice + fiscalyear_id: data_fiscalyear + +- I create a draft customer invoice in a period of the demo fiscal year +- !record {model: account.invoice, id: invoice_seq_test}: + account_id: account.a_recv + address_contact_id: base.res_partner_address_zen + address_invoice_id: base.res_partner_address_zen + company_id: base.main_company + currency_id: base.EUR + invoice_line: + - account_id: account.a_sale + name: '[PC3] Medium PC' + price_unit: 900.0 + quantity: 10.0 + product_id: product.product_product_pc3 + uos_id: product.product_uom_unit + journal_id: account.sales_journal + partner_id: base.res_partner_3 + reference_type: none + period_id: period_1 + +- I create the invoice, as is I clicked on the "Create" button +- !workflow {model: account.invoice, action: invoice_open, ref: invoice_seq_test} + +- I check that the invoice state is "Open" +- !assert {model: account.invoice, id: invoice_seq_test}: + - state == 'open' + +- I check that the invoice got the right number using our sequence + # This used to fail because of bug #602188 +- !assert {model: account.invoice, id: invoice_seq_test}: + - number == 'FY-042-TEST' diff --git a/addons/account/test/sequence_bug602188_test.xml b/addons/account/test/sequence_bug602188_test.xml deleted file mode 100644 index 3a9200b98e6..00000000000 --- a/addons/account/test/sequence_bug602188_test.xml +++ /dev/null @@ -1,53 +0,0 @@ - - - - - - - - - - account.invoice.out_invoice - - TEST- - -bug602188 - - - - - - - - - - - - - - - - - draft - out_invoice - - lp:602188 - - - - - - open - TEST-042-bug602188 - - - - - - - - From 24945daabbfbe5d8d7eac5f98624e400b8e86681 Mon Sep 17 00:00:00 2001 From: "rpa (Open ERP)" Date: Thu, 15 Jul 2010 13:03:13 +0530 Subject: [PATCH 07/27] [IMP]: crm: Improvement in forward to partner and send email wizard bzr revid: rpa@tinyerp.com-20100715073313-29e4qbtpk9np9sot --- addons/crm/__openerp__.py | 2 +- addons/crm/wizard/crm_forward_to_partner.py | 54 ++++++++++--------- .../wizard/crm_forward_to_partner_view.xml | 52 +++++++++--------- addons/crm/wizard/crm_send_email.py | 34 ++++++------ addons/crm/wizard/crm_send_email_view.xml | 8 +-- 5 files changed, 80 insertions(+), 70 deletions(-) diff --git a/addons/crm/__openerp__.py b/addons/crm/__openerp__.py index f23b61df5ea..00b964a2039 100644 --- a/addons/crm/__openerp__.py +++ b/addons/crm/__openerp__.py @@ -83,8 +83,8 @@ Create dashboard for CRM that includes: 'wizard/crm_opportunity_to_phonecall_view.xml', 'wizard/crm_partner_to_opportunity_view.xml', - 'wizard/crm_forward_to_partner_view.xml', 'wizard/crm_send_email_view.xml', + 'wizard/crm_forward_to_partner_view.xml', 'wizard/crm_custom_create_menu_view.xml', 'crm_view.xml', diff --git a/addons/crm/wizard/crm_forward_to_partner.py b/addons/crm/wizard/crm_forward_to_partner.py index 1a6e1fb505b..def6ddf1812 100644 --- a/addons/crm/wizard/crm_forward_to_partner.py +++ b/addons/crm/wizard/crm_forward_to_partner.py @@ -23,7 +23,7 @@ import base64 import itertools import time - +import re from osv import osv, fields import tools from tools.translate import _ @@ -31,6 +31,7 @@ from tools.translate import _ class crm_lead_forward_to_partner(osv.osv_memory): """Forwards lead history""" _name = 'crm.lead.forward.to.partner' + _inherit = "crm.send.mail" _columns = { 'name': fields.selection([('user', 'User'), ('partner', 'Partner'), \ @@ -38,19 +39,12 @@ class crm_lead_forward_to_partner(osv.osv_memory): 'user_id': fields.many2one('res.users', "User"), 'partner_id' : fields.many2one('res.partner', 'Partner'), 'address_id' : fields.many2one('res.partner.address', 'Address'), - 'email_from' : fields.char('From', required=True, size=128), - 'email_to' : fields.char('To', required=True, size=128), - 'subject' : fields.char('Subject', required=True, size=128), - 'message' : fields.text('Message', required=True), - 'history': fields.selection([('latest', 'Latest email'), ('whole', 'Whole Story'), ('info', 'Case Information')], 'Send history', required=True), - 'add_cc': fields.boolean('Add as CC', required=False, help="Check this box if you want this address to be added in the CC list"\ - " for this case, in order to receive all future conversations"), + 'history': fields.selection([('info', 'Case Information'), ('latest', 'Latest email'), ('whole', 'Whole Story')], 'Send history', required=True), } _defaults = { 'name' : 'email', - 'history': 'info', - 'add_cc': True, + 'history': 'latest', 'email_from': lambda self, cr, uid, *a: self.pool.get('res.users')._get_email_from(cr, uid, uid)[uid] } @@ -117,7 +111,7 @@ class crm_lead_forward_to_partner(osv.osv_memory): res_id = context.get('active_id') msg_val = self._get_case_history(cr, uid, history_type, res_id, context=context) if msg_val: - res = {'value': {'message' : '\n\n' + msg_val}} + res = {'value': {'body' : '\n\n' + msg_val}} return res def _get_case_history(self, cr, uid, history_type, res_id, context=None): @@ -125,22 +119,23 @@ class crm_lead_forward_to_partner(osv.osv_memory): return msg_val = '' + case_info = self.get_lead_details(cr, uid, res_id, context=context) model_pool = self.pool.get('crm.lead') + if history_type == 'info': - msg_val = self.get_lead_details(cr, uid, res_id, context=context) + msg_val = case_info elif history_type == 'whole': log_ids = model_pool.browse(cr, uid, res_id, context=context).message_ids log_ids = [x.id for x in log_ids] - if not log_ids: - raise osv.except_osv('Warning!', 'There is no history to send') - msg_val = self.get_whole_history(cr, uid, log_ids, context=context) + msg_val = case_info + '\n\n' + self.get_whole_history(cr, uid, log_ids, context=context) elif history_type == 'latest': log_ids = model_pool.browse(cr, uid, res_id, context=context).message_ids if not log_ids: - raise osv.except_osv('Warning!', 'There is no history to send') - msg_val = self.get_latest_history(cr, uid, log_ids[0].id, context=context) + msg_val = case_info + else: + msg_val = case_info + '\n\n' + self.get_latest_history(cr, uid, log_ids[0].id, context=context) return msg_val @@ -186,13 +181,14 @@ class crm_lead_forward_to_partner(osv.osv_memory): if not res_id or not model: return {} + email_re = r'([^ ,<@]+@[^> ,]+)' this = self.browse(cr, uid, ids[0], context=context) case_pool = self.pool.get(model) case = case_pool.browse(cr, uid, res_id, context=context) emails = [this.email_to] - body = case_pool.format_body(this.message) + body = case_pool.format_body(this.body) email_from = this.email_from or False # extract attachements from case and emails according to mode @@ -226,13 +222,19 @@ class crm_lead_forward_to_partner(osv.osv_memory): else: raise osv.except_osv(_('Error!'), _('Unable to send mail. Please check SMTP is configured properly.')) - if this.add_cc and (not case.email_cc or not this.email_to in case.email_cc): - case_pool.write(cr, uid, case.id, {'email_cc' : case.email_cc and case.email_cc + ', ' + this.email_to or this.email_to}) + email_cc = re.findall(email_re, case.email_cc or '') + new_cc = '' + for to in this.email_to.split(','): + email_to = re.findall(email_re, to) + email_to = email_to and email_to[0] or '' + if email_to not in email_cc: + new_cc += ', ' + to + case_pool.write(cr, uid, case.id, {'email_cc' : case.email_cc and case.email_cc + new_cc}) return {} def get_lead_details(self, cr, uid, lead_id, context=None): - message = [] + body = [] lead_proxy = self.pool.get('crm.lead') lead = lead_proxy.browse(cr, uid, lead_id, context=context) if not lead.type or lead.type == 'lead': @@ -258,10 +260,10 @@ class crm_lead_forward_to_partner(osv.osv_memory): else: value = lead[field_name] - message.append("%s: %s" % (field_definition.string, value or '')) + body.append("%s: %s" % (field_definition.string, value or '')) elif lead.type == 'opportunity': pa = lead.partner_address_id - message = [ + body = [ "Partner: %s" % (lead.partner_id.name_get()[0][1]), "Contact: %s" % (pa.name or ''), "Title: %s" % (pa.title or ''), @@ -277,7 +279,7 @@ class crm_lead_forward_to_partner(osv.osv_memory): "Fax: %s" % (pa.fax or ''), "Mobile: %s" % (pa.mobile or ''), ] - return "\n".join(message + ['---']) + return "\n".join(body + ['---']) def default_get(self, cr, uid, fields, context=None): """ @@ -295,10 +297,10 @@ class crm_lead_forward_to_partner(osv.osv_memory): lead_proxy = self.pool.get('crm.lead') lead = lead_proxy.browse(cr, uid, active_id, context=context) - message = self._get_case_history(cr, uid, defaults.get('history', 'latest'), lead.id, context=context) + body = self._get_case_history(cr, uid, defaults.get('history', 'latest'), lead.id, context=context) defaults.update({ 'subject' : '%s: %s' % (_('Fwd'), lead.name), - 'message' : message, + 'body' : body, }) return defaults diff --git a/addons/crm/wizard/crm_forward_to_partner_view.xml b/addons/crm/wizard/crm_forward_to_partner_view.xml index e8a60cea01f..d2705c8f0db 100644 --- a/addons/crm/wizard/crm_forward_to_partner_view.xml +++ b/addons/crm/wizard/crm_forward_to_partner_view.xml @@ -5,41 +5,45 @@ crm_lead_forward_to_partner crm.lead.forward.to.partner form + -
- - - - - - - + + + + + + + + + + + + - - - - - - - - - - - + + Forward to Partner crm.lead.forward.to.partner form form + new diff --git a/addons/crm/wizard/crm_send_email.py b/addons/crm/wizard/crm_send_email.py index bc2b5357c15..02acee1c1d2 100644 --- a/addons/crm/wizard/crm_send_email.py +++ b/addons/crm/wizard/crm_send_email.py @@ -49,7 +49,7 @@ class crm_send_new_email(osv.osv_memory): 'email_cc' : fields.char('CC', size=512, help="Carbon Copy: list of recipients that will receive"\ " a copy of this mail, and future communication related to this case"), 'subject': fields.char('Subject', size=512, required=True), - 'text': fields.text('Message', required=True), + 'body': fields.text('Message Body', required=True), 'state': fields.selection(crm.AVAILABLE_STATES, string='Set New State To', required=True), 'attachment_ids' : fields.one2many('crm.send.mail.attachment', 'wizard_id'), } @@ -68,10 +68,10 @@ class crm_send_new_email(osv.osv_memory): if not context: context = {} - if not context.get('model'): + if not context.get('active_model'): raise osv.except_osv(_('Error'), _('Can not send mail!')) - model = context.get('model') + model = context.get('active_model') case_pool = self.pool.get(model) res_id = context and context.get('active_id', False) or False @@ -91,16 +91,16 @@ class crm_send_new_email(osv.osv_memory): hist = hist_obj.browse(cr, uid, res_id) message_id = hist.message_id model = hist.model - model_pool = self.pool.get(model) + case_pool = self.pool.get(model) res_id = hist.res_id ref_id = hist.ref_id - case = model_pool.browse(cr, uid, res_id) + case = case_pool.browse(cr, uid, res_id) emails = [obj.email_to] email_cc = obj.email_cc and obj.email_cc.split(',') or '' emails = filter(None, emails) - body = obj.text + body = obj.body - body = case_pool.format_body(body) + body = body and tools.ustr(body) or '' email_from = getattr(obj, 'email_from', False) x_headers = {} if message_id: @@ -124,7 +124,7 @@ class crm_send_new_email(osv.osv_memory): case_pool.history(cr, uid, [case], _('Send'), history=True, \ email=obj.email_to, details=body, \ subject=obj.subject, email_from=email_from, \ - email_cc=email_cc, message_id=message_id, \ + email_cc=', '.join(email_cc), message_id=message_id, \ references=ref_id or message_id, attach=attach) if obj.state == 'unchanged': pass @@ -145,7 +145,7 @@ class crm_send_new_email(osv.osv_memory): if not context: context = {} - if not context.get('model'): + if not context.get('active_model'): raise osv.except_osv(_('Error'), _('Can not send mail!')) res = super(crm_send_new_email, self).default_get(cr, uid, fields, context=context) @@ -154,7 +154,7 @@ class crm_send_new_email(osv.osv_memory): res.update(self.get_reply_defaults(cr, uid, fields, context=context)) return res - model = context.get('model') + model = context.get('active_model') mod_obj = self.pool.get(model) res_id = context and context.get('active_ids', []) or [] @@ -172,8 +172,8 @@ class crm_send_new_email(osv.osv_memory): res.update({'subject': tools.ustr(context.get('subject', case.name) or '')}) if 'email_cc' in fields: res.update({'email_cc': tools.ustr(case.email_cc or '')}) - if 'text' in fields: - res.update({'text': u'\n'+(tools.ustr(case.user_id.signature or ''))}) + if 'body' in fields: + res.update({'body': u'\n'+(tools.ustr(case.user_id.signature or ''))}) if 'state' in fields: res.update({'state': u'pending'}) @@ -209,7 +209,7 @@ class crm_send_new_email(osv.osv_memory): signature = u'\n' + (tools.ustr(case.user_id.signature or '')) + u'\n' original = [signature] - if include_original == True and 'text' in fields: + if include_original == True and 'body' in fields: header = u'-------- Original Message --------' sender = u'From: %s' %(tools.ustr(hist.email_from or '')) to = u'To: %s' % (tools.ustr(hist.email_to or '')) @@ -218,10 +218,14 @@ class crm_send_new_email(osv.osv_memory): original = [signature, header, sender, to, sentdate, desc] - res['text']= u'\n' + u'\n'.join(original) + res['body']= u'\n' + u'\n'.join(original) if 'subject' in fields: res.update({u'subject': u'Re: %s' %(tools.ustr(hist.name or ''))}) + if 'email_cc' in fields: + res.update({'email_cc': case.email_cc and tools.ustr(case.email_cc) or False}) + if 'reply_to' in fields: + res.update({'reply_to': case.section_id.reply_to}) if 'state' in fields: res['state'] = u'pending' return res @@ -239,7 +243,7 @@ class crm_send_new_email(osv.osv_memory): if not context: context = {} - if not context.get('model'): + if not context.get('active_model'): raise osv.except_osv(_('Error'), _('Can not send mail!')) return True diff --git a/addons/crm/wizard/crm_send_email_view.xml b/addons/crm/wizard/crm_send_email_view.xml index df7218cbc02..aac7d854b88 100644 --- a/addons/crm/wizard/crm_send_email_view.xml +++ b/addons/crm/wizard/crm_send_email_view.xml @@ -9,7 +9,7 @@ crm.send.mail form -
+ @@ -19,7 +19,7 @@ - + @@ -46,7 +46,7 @@ - Send New Mail + Send Mail crm.send.mail form form @@ -77,7 +77,7 @@ - +