# -*- coding: utf-8 -*- # © 2014 Compassion CH - Cyril Sester # © 2014 Serv. Tecnol. Avanzados - Pedro M. Baeza # © 2016 Akretion (Alexis de Lattre ) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from openerp import models, fields, api class AccountInvoice(models.Model): _inherit = 'account.invoice' mandate_id = fields.Many2one( 'account.banking.mandate', string='Direct Debit Mandate', ondelete='restrict', readonly=True, states={'draft': [('readonly', False)]}) @api.model def line_get_convert(self, line, part): """Copy mandate from invoice to account move line""" res = super(AccountInvoice, self).line_get_convert(line, part) if line.get('type') == 'dest' and line.get('invoice_id'): invoice = self.browse(line['invoice_id']) if invoice.type in ('out_invoice', 'out_refund'): res['mandate_id'] = invoice.mandate_id.id or False return res