diff --git a/addons/account/account_invoice.py b/addons/account/account_invoice.py index 3e86c4963b7..b0671e501ae 100644 --- a/addons/account/account_invoice.py +++ b/addons/account/account_invoice.py @@ -391,29 +391,34 @@ class account_invoice(osv.osv): ''' This function opens a window to compose an email, with the edi invoice template message loaded by default ''' - mod_obj = self.pool.get('ir.model.data') - template = mod_obj.get_object_reference(cr, uid, 'account', 'email_template_edi_invoice') - template_id = template and template[1] or False - res = mod_obj.get_object_reference(cr, uid, 'mail', 'email_compose_message_wizard_form') - res_id = res and res[1] or False + assert len(ids) == 1, 'This option should only be used for a single id at a time.' + ir_model_data = self.pool.get('ir.model.data') + try: + template_id = ir_model_data.get_object_reference(cr, uid, 'account', 'email_template_edi_invoice')[1] + except ValueError: + template_id = False + try: + compose_form_id = ir_model_data.get_object_reference(cr, uid, 'mail', 'email_compose_message_wizard_form')[1] + except ValueError: + compose_form_id = False ctx = dict(context) ctx.update({ 'default_model': 'account.invoice', 'default_res_id': ids[0], - 'default_use_template': True, + 'default_use_template': bool(template_id), 'default_template_id': template_id, 'default_composition_mode': 'comment', + 'mark_invoice_as_sent': True, }) return { + 'type': 'ir.actions.act_window', 'view_type': 'form', 'view_mode': 'form', 'res_model': 'mail.compose.message', - 'views': [(res_id, 'form')], - 'view_id': res_id, - 'type': 'ir.actions.act_window', + 'views': [(compose_form_id, 'form')], + 'view_id': compose_form_id, 'target': 'new', 'context': ctx, - 'nodestroy': True, } def confirm_paid(self, cr, uid, ids, context=None): @@ -1726,8 +1731,6 @@ class account_invoice_tax(osv.osv): }) return res -account_invoice_tax() - class res_partner(osv.osv): """ Inherits partner and adds invoice information in the partner form """ @@ -1741,16 +1744,14 @@ class res_partner(osv.osv): default.update({'invoice_ids' : []}) return super(res_partner, self).copy(cr, uid, id, default, context) -res_partner() -class mail_message(osv.osv): - _name = 'mail.message' - _inherit = 'mail.message' +class mail_compose_message(osv.osv): + _inherit = 'mail.compose.message' - def _postprocess_sent_message(self, cr, uid, message, context=None): - if message.model == 'account.invoice': - self.pool.get('account.invoice').write(cr, uid, [message.res_id], {'sent':True}, context=context) - return super(mail_message, self)._postprocess_sent_message(cr, uid, message=message, context=context) + def send_mail(self, cr, uid, ids, context=None): + context = context or {} + if context.get('default_model') == 'account.invoice' and context.get('default_res_id') and context.get('mark_invoice_as_sent'): + self.pool.get('account.invoice').write(cr, uid, [context['default_res_id']], {'sent': True}, context=context) + return super(mail_compose_message, self).send_mail(cr, uid, ids, context=context) -mail_message() # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/account/edi/invoice.py b/addons/account/edi/invoice.py index 751eb8656f7..3e27bc5ea99 100644 --- a/addons/account/edi/invoice.py +++ b/addons/account/edi/invoice.py @@ -2,7 +2,7 @@ ############################################################################## # # OpenERP, Open Source Business Applications -# Copyright (c) 2011 OpenERP S.A. +# Copyright (c) 2011-2012 OpenERP S.A. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as @@ -19,9 +19,8 @@ # ############################################################################## -from osv import fields, osv, orm +from openerp.osv import osv from edi import EDIMixin -from edi.models import edi INVOICE_LINE_EDI_STRUCT = { 'name': True, @@ -71,16 +70,6 @@ INVOICE_EDI_STRUCT = { class account_invoice(osv.osv, EDIMixin): _inherit = 'account.invoice' - def action_invoice_sent(self, cr, uid, ids, context=None): - """"Override this method to add a link to mail""" - if context is None: - context = {} - invoice_objs = self.browse(cr, uid, ids, context=context) - edi_token = self.pool.get('edi.document').export_edi(cr, uid, invoice_objs, context = context)[0] - web_root_url = self.pool.get('ir.config_parameter').get_param(cr, uid, 'web.base.url') - ctx = dict(context, edi_web_url_view=edi.EDI_VIEW_WEB_URL % (web_root_url, cr.dbname, edi_token)) - return super(account_invoice, self).action_invoice_sent(cr, uid, ids, context=ctx) - def edi_export(self, cr, uid, records, edi_struct=None, context=None): """Exports a supplier or customer invoice""" edi_struct = dict(edi_struct or INVOICE_EDI_STRUCT) @@ -111,8 +100,8 @@ class account_invoice(osv.osv, EDIMixin): return tax_account def _edi_invoice_account(self, cr, uid, partner_id, invoice_type, context=None): - partner_pool = self.pool.get('res.partner') - partner = partner_pool.browse(cr, uid, partner_id, context=context) + res_partner = self.pool.get('res.partner') + partner = res_partner.browse(cr, uid, partner_id, context=context) if invoice_type in ('out_invoice', 'out_refund'): invoice_account = partner.property_account_receivable else: @@ -136,31 +125,30 @@ class account_invoice(osv.osv, EDIMixin): self._edi_requires_attributes(('company_id','company_address','type'), edi_document) res_partner = self.pool.get('res.partner') - src_company_id, src_company_name = edi_document.pop('company_id') + xid, company_name = edi_document.pop('company_id') + # Retrofit address info into a unified partner info (changed in v7 - used to keep them separate) + company_address_edi = edi_document.pop('company_address') + company_address_edi['name'] = company_name + company_address_edi['is_company'] = True + company_address_edi['__import_model'] = 'res.partner' + company_address_edi['__id'] = xid # override address ID, as of v7 they should be the same anyway + if company_address_edi.get('logo'): + company_address_edi['image'] = company_address_edi.pop('logo') invoice_type = edi_document['type'] - partner_value = {} - if invoice_type in ('out_invoice', 'out_refund'): - partner_value.update({'customer': True}) - if invoice_type in ('in_invoice', 'in_refund'): - partner_value.update({'supplier': True}) - - # imported company_address = new partner address - address_info = edi_document.pop('company_address') - if 'name' not in address_info: - address_info['name'] = src_company_name - address_info['type'] = 'invoice' - address_info.update(partner_value) - address_id = res_partner.edi_import(cr, uid, address_info, context=context) + if invoice_type.startswith('out_'): + company_address_edi['customer'] = True + else: + company_address_edi['supplier'] = True + partner_id = res_partner.edi_import(cr, uid, company_address_edi, context=context) # modify edi_document to refer to new partner - partner_address = res_partner.browse(cr, uid, address_id, context=context) - address_edi_m2o = self.edi_m2o(cr, uid, partner_address, context=context) - edi_document['partner_id'] = address_edi_m2o - edi_document.pop('partner_address', False) # ignored - - return address_id + partner = res_partner.browse(cr, uid, partner_id, context=context) + partner_edi_m2o = self.edi_m2o(cr, uid, partner, context=context) + edi_document['partner_id'] = partner_edi_m2o + edi_document.pop('partner_address', None) # ignored, that's supposed to be our own address! + return partner_id def edi_import(self, cr, uid, edi_document, context=None): """ During import, invoices will import the company that is provided in the invoice as @@ -200,7 +188,7 @@ class account_invoice(osv.osv, EDIMixin): invoice_type = invoice_type.startswith('in_') and invoice_type.replace('in_','out_') or invoice_type.replace('out_','in_') edi_document['type'] = invoice_type - #import company as a new partner + # import company as a new partner partner_id = self._edi_import_company(cr, uid, edi_document, context=context) # Set Account diff --git a/addons/account/edi/invoice_action_data.xml b/addons/account/edi/invoice_action_data.xml index d86ebca3537..7cc4f4978f7 100644 --- a/addons/account/edi/invoice_action_data.xml +++ b/addons/account/edi/invoice_action_data.xml @@ -1,17 +1,6 @@ - - - if (object.type in ('out_invoice', 'out_refund')) and not object.partner_id.opt_out: object.edi_export_and_email(template_ext_id='account.email_template_edi_invoice', context=context) - - code - ir.actions.server - - True - Auto-email confirmed invoices - - Email Templates @@ -27,28 +16,25 @@ - - - - - - - Automated Invoice Notification Mail + Invoice - Send by Email ${object.user_id.email or object.company_id.email or 'noreply@localhost'} ${object.company_id.name} Invoice (Ref ${object.number or 'n/a' }) ${object.partner_id.id} + + Invoice_${(object.number or '').replace('/','_')}_${object.state == 'draft' and 'draft' or ''}

Hello${object.partner_id.name and ' ' or ''}${object.partner_id.name or ''},

-

A new invoice is available for ${object.partner_id.name}:

+

A new invoice is available for you:

  REFERENCES
@@ -58,21 +44,17 @@ % if object.origin:   Order reference: ${object.origin}
% endif + % if object.user_id:   Your contact: ${object.user_id.name} + % endif

-

- You can view the invoice document, download it and pay online using the following link: -

- View Invoice - % if object.company_id.paypal_account and object.type in ('out_invoice', 'in_refund'): <% comp_name = quote(object.company_id.name) inv_number = quote(object.number) paypal_account = quote(object.company_id.paypal_account) - inv_amount = quote(str(object.amount_total)) + inv_amount = quote(str(object.residual)) cur_name = quote(object.currency_id.name) paypal_url = "https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=%s&item_name=%s%%20Invoice%%20%s&" \ "invoice=%s&amount=%s&currency_code=%s&button_subtype=services&no_note=1&bn=OpenERP_Invoice_PayNow_%s" % \ diff --git a/addons/account/res_config_view.xml b/addons/account/res_config_view.xml index 52c8c8daaa9..4bfd3697d89 100644 --- a/addons/account/res_config_view.xml +++ b/addons/account/res_config_view.xml @@ -227,7 +227,7 @@ - +