[FIX] account: Take care of res.partner.bank owned by another company.
We need to take care of the `unique(sanitized_acc_number, partner_id)` constraint and avoid to create a new bank account if already exists in another company. closes odoo/odoo#130324 Task: 3432443 X-original-commit: bc4cbd0e129d7f9d417752e162397ece5e1bfc0f Related: odoo/enterprise#44903 Signed-off-by: Brice Bartoletti (bib) <bib@odoo.com> Signed-off-by: Laurent Smet (las) <las@odoo.com>
This commit is contained in:
@@ -436,7 +436,13 @@ class AccountBankStatementLine(models.Model):
|
||||
# -------------------------------------------------------------------------
|
||||
|
||||
def _find_or_create_bank_account(self):
|
||||
bank_account = self.env['res.partner.bank'].with_context(active_test=False).search([
|
||||
self.ensure_one()
|
||||
# There is a sql constraint on res.partner.bank ensuring an unique pair <partner, account number>.
|
||||
# Since it's not dependent of the company, we need to search on others company too to avoid the creation
|
||||
# of an extra res.partner.bank raising an error coming from this constraint.
|
||||
# However, at the end, we need to filter out the results to not trigger the check_company when trying to
|
||||
# assign a res.partner.bank owned by another company.
|
||||
bank_account = self.env['res.partner.bank'].sudo().with_context(active_test=False).search([
|
||||
('acc_number', '=', self.account_number),
|
||||
('partner_id', '=', self.partner_id.id),
|
||||
])
|
||||
@@ -446,7 +452,7 @@ class AccountBankStatementLine(models.Model):
|
||||
'partner_id': self.partner_id.id,
|
||||
'journal_id': None,
|
||||
})
|
||||
return bank_account
|
||||
return bank_account.filtered(lambda x: x.company_id in (False, self.company_id))
|
||||
|
||||
def _get_default_amls_matching_domain(self):
|
||||
return [
|
||||
|
||||
Reference in New Issue
Block a user