# -*- coding: utf-8 -*-
##############################################################################
#
#    Author: Guewen Baconnier
#    Copyright 2014 Camptocamp SA
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as
#    published by the Free Software Foundation, either version 3 of the
#    License, or (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

from openerp.osv import orm


class account_invoice(orm.Model):
    _inherit = 'account.invoice'

    def _get_bvr_ref(self, cr, uid, invoice, context=None):
        """Retrieve ESR/BVR reference form invoice in order to print it

        Returns False when no BVR reference should be generated.  No
        reference is generated when a transaction ID already exists on
        the invoice (likely generated by a payment service so BVR ref not
        used).
        """
        if invoice.transaction_id:
            return ''
        return super(account_invoice, self)._get_bvr_ref(cr, uid, invoice,
                                                         context=context)

@@ -1609,8 +1609,396 @@
 ontext)%0A
+%0A    def action_number(self, cr, uid, ids, context=None):%0A        res = super(account_invoice, self).%5C%0A            action_number(cr, uid, ids, context=context)%0A        for invoice in self.browse(cr, uid, ids, context=context):%0A            if invoice.bvr_reference and not invoice.transaction_id:%0A                invoice.write(%7B'transaction_id': invoice.bvr_reference%7D)%0A        return res%0A

copy the bvr reference in the transaction_id field so we can use it for bank statement completion