[REF] account: refactor bank statement reconciliation for adding bank account
When reconciling and the bank account is not found, the system wlll automatically create one. Here we refactor the method checking/creating this bank account in order to be able to inherit this functionality. In the meantime, we added the company_id for the newly created bank account in order to avoid problems when you are operating on multiple companies at the same time. X-original-commit: a63bd575166e4b07345fdcfa1c7d5bb9560821c8
This commit is contained in:
@@ -753,6 +753,17 @@ class AccountBankStatementLine(models.Model):
|
||||
'name': self.statement_id.name or _("Bank Statement %s") % self.date,
|
||||
}
|
||||
|
||||
def _find_or_create_bank_account(self):
|
||||
bank_account = self.env['res.partner.bank'].search(
|
||||
[('company_id', '=', self.company_id.id), ('acc_number', '=', self.account_number)])
|
||||
if not bank_account:
|
||||
bank_account = self.env['res.partner.bank'].create({
|
||||
'acc_number': self.account_number,
|
||||
'partner_id': self.partner_id.id,
|
||||
'company_id': self.company_id.id,
|
||||
})
|
||||
return bank_account
|
||||
|
||||
def process_reconciliation(self, counterpart_aml_dicts=None, payment_aml_rec=None, new_aml_dicts=None):
|
||||
""" Match statement lines with existing payments (eg. checks) and/or payables/receivables (eg. invoices and credit notes) and/or new move lines (eg. write-offs).
|
||||
If any new journal item needs to be created (via new_aml_dicts or counterpart_aml_dicts), a new journal entry will be created and will contain those
|
||||
@@ -911,12 +922,7 @@ class AccountBankStatementLine(models.Model):
|
||||
if self.account_number and self.partner_id and not self.bank_account_id:
|
||||
# Search bank account without partner to handle the case the res.partner.bank already exists but is set
|
||||
# on a different partner.
|
||||
bank_account = self.env['res.partner.bank'].search([('company_id', '=', self.company_id.id),('acc_number', '=', self.account_number)])
|
||||
if not bank_account:
|
||||
bank_account = self.env['res.partner.bank'].create({
|
||||
'acc_number': self.account_number, 'partner_id': self.partner_id.id
|
||||
})
|
||||
self.bank_account_id = bank_account
|
||||
self.bank_account_id = self._find_or_create_bank_account()
|
||||
|
||||
counterpart_moves._check_balanced()
|
||||
return counterpart_moves
|
||||
|
||||
Reference in New Issue
Block a user