[FIX] account: reconciliation widget: parent name targets partner without parent

Create a partner with a child *WITH THE SAME NAME*
Create an invoice for the child

Create bank statement and line, with the field partner_name equals
to the child's name (and to its parent)

Open the reconciliation wigdet for that statement

Before this commit, the widget searched lines for the child partner
because partner_name matches the child in priority
Hence the invoice just created was not present
This is because when validating an invoice or a payment
the journal entry's partner will be the commercial_partner_id of the child
By definition the commercial partner_id doesn't have a parent_id set

After this commit, the invoice is visible in the widget

OPW 2039768

closes odoo/odoo#36184

Signed-off-by: Lucas Perais (lpe) <lpe@odoo.com>
This commit is contained in:
Lucas Perais (lpe)
2019-08-28 12:14:27 +00:00
parent 412117c2a7
commit 3950702c86
3 changed files with 55 additions and 22 deletions
@@ -112,7 +112,8 @@ class AccountReconciliation(models.AbstractModel):
query += 'LEFT JOIN res_partner_bank bank ON bank.id = st_line.bank_account_id OR bank.acc_number = st_line.account_number %s\n' % (where_bank)
query += 'LEFT JOIN res_partner p1 ON st_line.partner_id=p1.id \n'
query += 'LEFT JOIN res_partner p2 ON bank.partner_id=p2.id \n'
query += 'LEFT JOIN res_partner p3 ON p3.name ILIKE st_line.partner_name %s\n' % (where_partner)
# By definition the commercial partner_id doesn't have a parent_id set
query += 'LEFT JOIN res_partner p3 ON p3.name ILIKE st_line.partner_name %s AND p3.parent_id is NULL \n' % (where_partner)
query += 'WHERE st_line.id IN %s'
params += [tuple(st_lines.ids)]
+21 -21
View File
@@ -129,6 +129,27 @@ class TestReconciliation(AccountingTestCase):
invoice.action_invoice_open()
return invoice
def create_invoice_partner(self, type='out_invoice', invoice_amount=50, currency_id=None, partner_id=False):
#we create an invoice in given currency
invoice = self.account_invoice_model.create({'partner_id': partner_id,
'currency_id': currency_id,
'name': type == 'out_invoice' and 'invoice to client' or 'invoice to vendor',
'account_id': self.account_rcv.id,
'type': type,
'date_invoice': time.strftime('%Y') + '-07-01',
})
self.account_invoice_line_model.create({'product_id': self.product.id,
'quantity': 1,
'price_unit': invoice_amount,
'invoice_id': invoice.id,
'name': 'product that cost ' + str(invoice_amount),
'account_id': self.env['account.account'].search([('user_type_id', '=', self.env.ref('account.data_account_type_revenue').id)], limit=1).id,
})
#validate invoice
invoice.action_invoice_open()
return invoice
def make_payment(self, invoice_record, bank_journal, amount=0.0, amount_currency=0.0, currency_id=None):
bank_stmt = self.acc_bank_stmt_model.create({
'journal_id': bank_journal.id,
@@ -890,27 +911,6 @@ class TestReconciliationExec(TestReconciliation):
self.assertEqual(reversed_bank_line.full_reconcile_id.id, bank_line.full_reconcile_id.id)
self.assertEqual(reversed_customer_line.full_reconcile_id.id, customer_line.full_reconcile_id.id)
def create_invoice_partner(self, type='out_invoice', invoice_amount=50, currency_id=None, partner_id=False):
#we create an invoice in given currency
invoice = self.account_invoice_model.create({'partner_id': partner_id,
'currency_id': currency_id,
'name': type == 'out_invoice' and 'invoice to client' or 'invoice to vendor',
'account_id': self.account_rcv.id,
'type': type,
'date_invoice': time.strftime('%Y') + '-07-01',
})
self.account_invoice_line_model.create({'product_id': self.product.id,
'quantity': 1,
'price_unit': invoice_amount,
'invoice_id': invoice.id,
'name': 'product that cost ' + str(invoice_amount),
'account_id': self.env['account.account'].search([('user_type_id', '=', self.env.ref('account.data_account_type_revenue').id)], limit=1).id,
})
#validate invoice
invoice.action_invoice_open()
return invoice
def test_aged_report(self):
AgedReport = self.env['report.account.report_agedpartnerbalance'].with_context(include_nullified_amount=True)
account_type = ['receivable']
@@ -95,3 +95,35 @@ class TestReconciliationWidget(TestReconciliation):
self.assertFalse(receivable1.id in mv_lines_ids)
self.assertTrue(receivable2.id in mv_lines_ids)
def test_partner_name_with_parent(self):
parent_partner = self.env['res.partner'].create({
'name': 'test',
})
child_partner = self.env['res.partner'].create({
'name': 'test',
'parent_id': parent_partner.id,
'type': 'delivery',
})
inv1 = self.create_invoice_partner(currency_id=self.currency_euro_id, partner_id=child_partner.id)
self.assertEqual(inv1.move_id.partner_id, parent_partner)
bank_stmt = self.acc_bank_stmt_model.create({
'company_id': self.env.ref('base.main_company').id,
'journal_id': self.bank_journal_euro.id,
'date': time.strftime('%Y-07-15'),
'name': 'test',
})
bank_stmt_line = self.acc_bank_stmt_line_model.create({
'name': 'testLine',
'statement_id': bank_stmt.id,
'amount': 100,
'date': time.strftime('%Y-07-15'),
'partner_name': 'test',
})
bkstmt_data = self.env['account.reconciliation.widget'].get_bank_statement_line_data(bank_stmt_line.ids)
self.assertEqual(len(bkstmt_data['lines']), 1)
self.assertEqual(bkstmt_data['lines'][0]['partner_id'], parent_partner.id)