# -*- 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)

# -*- 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)

    def action_number(self, cr, uid, ids, context=None):
        res = super(account_invoice, self).\
            action_number(cr, uid, ids, context=context)
        for invoice in self.browse(cr, uid, ids, context=context):
            if invoice.bvr_reference and not invoice.transaction_id:
                invoice.write({'transaction_id': invoice.bvr_reference})
        return res

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