# -*- coding: utf-8 -*-
##############################################################################
#
#    Odoo, Open Source Management Solution
#    Copyright (C) 2016-TODAY Prime Consulting SA, Cape Verde (<http://prime.cv>).
#
##############################################################################

from odoo import models, fields, api

class AccountInvoice(models.Model):
    _inherit = "account.invoice"

    @api.model
    def create(self, vals):
        """Set Journal Id used in sales order 
        """
        context = self.env.context or {}
        if context.get('active_model', False) and context['active_model'] == 'sale.order':
            journal_id = self.env['sale.order'].browse(context['active_ids'])[0].account_journal_id
            if journal_id:
                vals['journal_id'] = journal_id.id
        return super(AccountInvoice, self).create(vals)
        