diff --git a/account_invoice_import/models/company.py b/account_invoice_import/models/company.py
index d2092b374f..3b04213fb4 100644
--- a/account_invoice_import/models/company.py
+++ b/account_invoice_import/models/company.py
@@ -18,6 +18,8 @@ class ResCompany(models.Model):
'Mail Gateway: Destination E-mail',
help="This field is used in multi-company setups to import the "
"invoices received by the mail gateway in the appropriate company")
+ invoice_import_create_bank_account = fields.Boolean(
+ string='Auto-create Bank Account of Supplier')
_sql_constraints = [(
'invoice_import_email_uniq',
diff --git a/account_invoice_import/models/res_config_settings.py b/account_invoice_import/models/res_config_settings.py
index 1aa978edbd..82f4707c03 100644
--- a/account_invoice_import/models/res_config_settings.py
+++ b/account_invoice_import/models/res_config_settings.py
@@ -13,3 +13,6 @@ class AccountConfigSettings(models.TransientModel):
related='company_id.adjustment_debit_account_id', readonly=False)
invoice_import_email = fields.Char(
related='company_id.invoice_import_email', readonly=False)
+ invoice_import_create_bank_account = fields.Boolean(
+ related='company_id.invoice_import_create_bank_account',
+ readonly=False)
diff --git a/account_invoice_import/views/res_config_settings.xml b/account_invoice_import/views/res_config_settings.xml
index 309dc8004a..5a318758ba 100644
--- a/account_invoice_import/views/res_config_settings.xml
+++ b/account_invoice_import/views/res_config_settings.xml
@@ -35,6 +35,10 @@
+
+
+
+
diff --git a/account_invoice_import/wizard/account_invoice_import.py b/account_invoice_import/wizard/account_invoice_import.py
index 6961ebe93e..283c2c731e 100644
--- a/account_invoice_import/wizard/account_invoice_import.py
+++ b/account_invoice_import/wizard/account_invoice_import.py
@@ -177,8 +177,8 @@ def _prepare_create_invoice_vals(self, parsed_inv, import_config=False):
ailo = self.env['account.invoice.line']
bdio = self.env['business.document.import']
rpo = self.env['res.partner']
- company_id = self.env.context.get('force_company') or\
- self.env.user.company_id.id
+ company = self.env['res.company'].browse(
+ self.env.context.get('force_company')) or self.env.user.company_id
start_end_dates_installed = hasattr(ailo, 'start_date') and\
hasattr(ailo, 'end_date')
if parsed_inv['type'] in ('out_invoice', 'out_refund'):
@@ -193,12 +193,12 @@ def _prepare_create_invoice_vals(self, parsed_inv, import_config=False):
parsed_inv.get('currency'), parsed_inv['chatter_msg'])
journal_id = aio.with_context(
type=parsed_inv['type'],
- company_id=company_id)._default_journal().id
+ company_id=company.id)._default_journal().id
vals = {
'partner_id': partner.id,
'currency_id': currency.id,
'type': parsed_inv['type'],
- 'company_id': company_id,
+ 'company_id': company.id,
'origin': parsed_inv.get('origin'),
'reference': parsed_inv.get('invoice_number'),
'date_invoice': parsed_inv.get('date'),
@@ -215,7 +215,8 @@ def _prepare_create_invoice_vals(self, parsed_inv, import_config=False):
partner = rpo.browse(vals['partner_id'])
partner_bank = bdio._match_partner_bank(
partner, parsed_inv['iban'], parsed_inv.get('bic'),
- parsed_inv['chatter_msg'], create_if_not_found=True)
+ parsed_inv['chatter_msg'],
+ create_if_not_found=company.invoice_import_create_bank_account)
if partner_bank:
vals['partner_bank_id'] = partner_bank.id
config = import_config # just to make variable name shorter
@@ -588,7 +589,7 @@ def create_invoice_action(self, parsed_inv=None, import_config=None):
invoice = self.create_invoice(parsed_inv, import_config)
invoice.message_post(body=_(
"This invoice has been created automatically via file import"))
- action = iaao.for_xml_id('account', 'action_invoice_tree2')
+ action = iaao.for_xml_id('account', 'action_vendor_bill_template')
action.update({
'view_mode': 'form,tree,calendar,graph',
'views': False,
@@ -818,7 +819,7 @@ def _prepare_create_invoice_line(self, product, uom, import_line, invoice):
return vals
@api.model
- def _prepare_update_invoice_vals(self, parsed_inv, partner):
+ def _prepare_update_invoice_vals(self, parsed_inv, invoice):
bdio = self.env['business.document.import']
vals = {
'reference': parsed_inv.get('invoice_number'),
@@ -827,9 +828,11 @@ def _prepare_update_invoice_vals(self, parsed_inv, partner):
if parsed_inv.get('date_due'):
vals['date_due'] = parsed_inv['date_due']
if parsed_inv.get('iban'):
+ company = invoice.company_id
partner_bank = bdio._match_partner_bank(
- partner, parsed_inv['iban'], parsed_inv.get('bic'),
- parsed_inv['chatter_msg'], create_if_not_found=True)
+ invoice.commercial_partner_id, parsed_inv['iban'],
+ parsed_inv.get('bic'), parsed_inv['chatter_msg'],
+ create_if_not_found=company.invoice_import_create_bank_account)
if partner_bank:
vals['partner_bank_id'] = partner_bank.id
return vals
@@ -870,7 +873,7 @@ def update_invoice(self):
"The currency of the imported invoice (%s) is different from "
"the currency of the existing invoice (%s)") % (
currency.name, invoice.currency_id.name))
- vals = self._prepare_update_invoice_vals(parsed_inv, partner)
+ vals = self._prepare_update_invoice_vals(parsed_inv, invoice)
logger.debug('Updating supplier invoice with vals=%s', vals)
self.invoice_id.write(vals)
if (