[FIX] account: broken filter in reconciliation widget

From Accounting app under the kanban card "Bank" click on
"Reconcilile items". Select a line to reconcile with a selected partner
or counterpart (or input one) and then filter the underlying lines using
for example the name of the record

No filtering will occur, this is due to commit 900d89c997.
The domain used by the filtering function is matching all lines
from the current partner instead of restricting the search to
the filtered elements.

Reverting that commit and providing a fix for the original issue:
removing a check on the partner id make a logical separation between the
domain involving the partner_id and the one related to the search string,
so that they do not interfere with each other (at most they will overlap).

Preserving tests from the reverted commit and adding some more as well

opw-2070458

closes odoo/odoo#37179

X-original-commit: d434251f3350e033843d941b48cf84f7de28d20f
Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
This commit is contained in:
Andrea Grazioso (agr-odoo)
2019-09-20 08:45:33 +00:00
committed by fw-bot
parent 3ee3f7d497
commit 5e2ae036cf
2 changed files with 29 additions and 12 deletions
@@ -522,22 +522,16 @@ class AccountReconciliation(models.AbstractModel):
])
domain = expression.OR([domain_reconciliation, domain_matching])
partner_domain = []
if partner_id:
partner_domain = [('partner_id', '=', partner_id)]
domain = expression.AND([domain, partner_domain])
domain = expression.AND([domain, [('partner_id', '=', partner_id)]])
# Domain factorized for all reconciliation use cases
if search_str:
str_domain = self._domain_move_lines(search_str=search_str)
if not partner_id:
partner_domain = [('partner_id.name', 'ilike', search_str)]
str_domain = expression.OR([
str_domain,
partner_domain,
[('partner_id.name', 'ilike', search_str)]
])
domain = expression.AND([
domain,
str_domain
@@ -553,7 +547,6 @@ class AccountReconciliation(models.AbstractModel):
if st_line.company_id.account_bank_reconciliation_start:
domain = expression.AND([domain, [('date', '>=', st_line.company_id.account_bank_reconciliation_start)]])
return domain
@api.model
@@ -58,6 +58,7 @@ class TestReconciliationWidget(TestReconciliation):
def test_filter_partner1(self):
inv1 = self.create_invoice(currency_id=self.currency_euro_id)
inv2 = self.create_invoice(currency_id=self.currency_euro_id)
partner = inv1.partner_id
receivable1 = inv1.move_id.line_ids.filtered(lambda l: l.account_id.internal_type == 'receivable')
receivable2 = inv2.move_id.line_ids.filtered(lambda l: l.account_id.internal_type == 'receivable')
@@ -76,7 +77,31 @@ class TestReconciliationWidget(TestReconciliation):
'date': time.strftime('%Y-07-15'),
})
# This is like opening the widget, and type "deco" in the filter
# This is like input a partner in the widget
mv_lines_rec = self.env['account.reconciliation.widget'].get_move_lines_for_bank_statement_line(
bank_stmt_line.id,
partner_id=partner.id,
excluded_ids=[],
search_str=False
)
mv_lines_ids = [l['id'] for l in mv_lines_rec]
self.assertTrue(receivable1.id in mv_lines_ids)
self.assertTrue(receivable2.id in mv_lines_ids)
# With a partner set, type the invoice reference in the filter
mv_lines_rec = self.env['account.reconciliation.widget'].get_move_lines_for_bank_statement_line(
bank_stmt_line.id,
partner_id=partner.id,
excluded_ids=[],
search_str=inv1.reference
)
mv_lines_ids = [l['id'] for l in mv_lines_rec]
self.assertTrue(receivable1.id in mv_lines_ids)
self.assertFalse(receivable2.id in mv_lines_ids)
# Without a partner set, type "deco" in the filter
mv_lines_rec = self.env['account.reconciliation.widget'].get_move_lines_for_bank_statement_line(
bank_stmt_line.id,
partner_id=False,
@@ -88,8 +113,7 @@ class TestReconciliationWidget(TestReconciliation):
self.assertTrue(receivable1.id in mv_lines_ids)
self.assertTrue(receivable2.id in mv_lines_ids)
# This is like clicking on the first receivable
partner = inv1.partner_id
# With a partner set, type "deco" in the filter and click on the first receivable
mv_lines_rec = self.env['account.reconciliation.widget'].get_move_lines_for_bank_statement_line(
bank_stmt_line.id,
partner_id=partner.id,