Add module account_statement_import_base

The 2 modules account_statement_import_online and
account_statement_import depend on account_statement_import_base (and
not on each other) and share common code, in particular a hook to update
the statement line. So we can now have reconciliation modules that use
this hook and therefore work both on file import and online import. More
details on https://github.com/OCA/bank-statement-import/issues/481.

Improve bank statement line form view and journal form view.
This commit is contained in:
Alexis de Lattre
2022-08-08 00:05:18 +02:00
parent 84edaf5850
commit 6418bc396f
5 changed files with 6 additions and 83 deletions

View File

@@ -277,43 +277,15 @@ class AccountStatementImport(models.TransientModel):
)
return journal
@api.model
def _update_partner_from_account_number(self, lvals):
partner_bank = self.env["res.partner.bank"].search(
[("acc_number", "=", lvals["account_number"])], limit=1
)
if partner_bank:
lvals["partner_bank_id"] = partner_bank.id
lvals["partner_id"] = partner_bank.partner_id.id
def _complete_stmts_vals(self, stmts_vals, journal, account_number):
speeddict = journal._statement_line_import_speeddict()
for st_vals in stmts_vals:
st_vals["journal_id"] = journal.id
for lvals in st_vals["transactions"]:
unique_import_id = lvals.get("unique_import_id")
if unique_import_id:
sanitized_account_number = sanitize_account_number(account_number)
lvals["unique_import_id"] = (
(
sanitized_account_number
and sanitized_account_number + "-"
or ""
)
+ str(journal.id)
+ "-"
+ unique_import_id
)
if (
not lvals.get("partner_bank_id")
and lvals.get("account_number")
and not lvals.get("partner_id")
):
# Find the partner from his bank account number
# The partner selected during the
# reconciliation process will be linked to the bank account
# when the statement is closed (code in the account module)
self._update_partner_from_account_number(lvals)
journal._statement_line_import_update_unique_import_id(
lvals, account_number
)
journal._statement_line_import_update_hook(lvals, speeddict)
if not lvals.get("payment_ref"):
raise UserError(_("Missing payment_ref on a transaction."))
return stmts_vals