from odoo import models


class ContractCreateInvoice(models.TransientModel):
    _inherit = 'sale.advance.payment.inv'

    def _prepare_invoice_values(self, order, so_lines, accounts):
        invoice_vals = super()._prepare_invoice_values(order, so_lines, accounts)
        if order.mt_contract_id:
            invoice_vals['mt_contract_id'] = order.mt_contract_id.id
        return invoice_vals