Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[10.0] Auto-creation of bank accounts upon invoice import is now optional #78

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions account_invoice_import/models/account_config_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ class AccountConfigSettings(models.TransientModel):
related='company_id.adjustment_debit_account_id')
invoice_import_email = fields.Char(
related='company_id.invoice_import_email')
invoice_import_create_bank_account = fields.Boolean(
related='company_id.invoice_import_create_bank_account')
2 changes: 2 additions & 0 deletions account_invoice_import/models/company.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,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',
Expand Down
4 changes: 4 additions & 0 deletions account_invoice_import/views/account_config_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
<label for="adjustment_credit_account_id"/>
<field name="adjustment_credit_account_id" class="oe_inline"/>
</div>
<div name="invoice_import_create_bank_account">
<field name="invoice_import_create_bank_account"/>
<label for="invoice_import_create_bank_account" class="oe_inline"/>
</div>
<div name="invoice_import_email">
<label for="invoice_import_email"/>
<field name="invoice_import_email" class="oe_inline"/>
Expand Down
21 changes: 12 additions & 9 deletions account_invoice_import/wizard/account_invoice_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -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._context.get('force_company') or\
self.env.user.company_id.id
company = self.env['res.company'].browse(
self._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'):
Expand All @@ -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'),
Expand All @@ -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
Expand Down Expand Up @@ -819,7 +820,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'),
Expand All @@ -828,9 +829,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
Expand Down Expand Up @@ -871,7 +874,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 (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,16 @@ def _match_partner_bank(
chatter_msg.append(_(
"The bank account <b>IBAN %s</b> has been automatically "
"added on the supplier <b>%s</b>") % (
iban, partner.name))
iban, partner.display_name))
return partner_bank
else:
chatter_msg.append(_(
"The analysis of the business document returned "
"<b>IBAN %s</b> as bank account, but there is no such "
"bank account in Odoo linked to partner <b>%s</b> and "
"the option to automatically create bank "
"accounts upon import is disabled.")
% (iban, partner.display_name))

@api.model
def _match_product(self, product_dict, chatter_msg, seller=False):
Expand Down