[IMP] account: reconciliation models: match amls whose partner's name is contained in payment reference

Invoice matching rules now also match account.move.lines based on their partner's name : if the statement line's payment reference contains the first name and last name of its patner (in any order, at any position), we match the move line.

closes odoo/odoo#50083

Related: odoo/enterprise#10166
Related: odoo/upgrade#1317
Signed-off-by: Quentin De Paoli (qdp) <qdp@openerp.com>
This commit is contained in:
oco-odoo
2020-06-12 16:26:48 +00:00
parent faed88d209
commit d49d1e4437
2 changed files with 21 additions and 0 deletions
@@ -626,6 +626,15 @@ class AccountReconcileModel(models.Model):
)
)
)
OR
(
/* We also match statement lines without partners with amls
whose partner's name's parts (splitting on space) are all present
within the payment_ref, in any order, with any characters between them. */
aml_partner.name IS NOT NULL
AND st_line.payment_ref ~* concat('(?=.*', array_to_string(regexp_split_to_array(lower(aml_partner.name), ' '),'.*)(?=.*'), '.*)')
)
"""
st_lines_queries.append(r"st_line.id = %s AND (%s)" % (st_line.id, st_line_subquery))
@@ -499,3 +499,15 @@ class TestReconciliationMatchingRules(AccountTestInvoicingCommon):
self.bank_line_1.id: {'aml_ids': [self.invoice_line_1.id], 'model': self.rule_1},
self.bank_line_2.id: {'aml_ids': []},
}, self.bank_st)
def test_partner_name_in_communication(self):
self.invoice_line_1.partner_id.write({'name': "Archibald Haddock"})
self.bank_line_1.write({'partner_id': None, 'payment_ref': '1234//HADDOCK-Archibald'})
self.bank_line_2.write({'partner_id': None})
self.rule_1.write({'match_partner': False})
# bank_line_1 should match, as its communication contains the invoice's partner name
self._check_statement_matching(self.rule_1, {
self.bank_line_1.id: {'aml_ids': [self.invoice_line_1.id], 'model': self.rule_1},
self.bank_line_2.id: {'aml_ids': []},
}, self.bank_st)