Skip to content

Commit

Permalink
[MIG] account_invoice_import_facturx to v12
Browse files Browse the repository at this point in the history
Update technical name of module to remove '-'
Up-port PR OCA#78 Auto-creation of bank accounts upon invoice import is now optional
Fix returned action when using the import wizard
  • Loading branch information
alexis-via authored and acsonefho committed Apr 24, 2023
1 parent cf4cb93 commit 0f38698
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
2 changes: 2 additions & 0 deletions account_invoice_import/models/company.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
3 changes: 3 additions & 0 deletions account_invoice_import/models/res_config_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 4 additions & 0 deletions account_invoice_import/views/res_config_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
<label class="o_form_label col-md-6 o_light_label" for="invoice_import_email"/>
<field name="invoice_import_email" class="oe_inline"/>
</div>
<div class="row">
<label class="o_form_label col-md-6 o_light_label" for="invoice_import_create_bank_account"/>
<field name="invoice_import_create_bank_account" class="oe_inline"/>
</div>
</div>
</div>
</div>
Expand Down
23 changes: 13 additions & 10 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.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'):
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 @@ -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,
Expand Down Expand Up @@ -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'),
Expand All @@ -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
Expand Down Expand Up @@ -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 (
Expand Down

0 comments on commit 0f38698

Please sign in to comment.