From 7c28c97724d34f961c2cf271783fbca2fe485fc4 Mon Sep 17 00:00:00 2001 From: "Lucas Perais (lpe)" Date: Thu, 5 Sep 2019 09:22:20 +0000 Subject: [PATCH] [FIX] hr_expense: sheet multi expense partial payment Create two expense and put them into one sheet Post the sheet Make One partial payment with the wizard (Register Payment) Do it again for the residual amount Before this commit, it crashed because the second payment tried to reconcile itself with an already reconciled line After this commit, all the lines that need to be reconciled actually are without crash OPW 2065501 closes odoo/odoo#36454 Signed-off-by: Lucas Perais (lpe) --- addons/hr_expense/tests/test_expenses.py | 50 +++++++++++++++++++ .../hr_expense_sheet_register_payment.py | 2 +- 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/addons/hr_expense/tests/test_expenses.py b/addons/hr_expense/tests/test_expenses.py index d789f6e92be..e9cc5bf366d 100644 --- a/addons/hr_expense/tests/test_expenses.py +++ b/addons/hr_expense/tests/test_expenses.py @@ -53,6 +53,19 @@ class TestCheckJournalEntry(TransactionCase): 'company_id': company.id }) + self.bank_journal = self.env['account.journal'].create({ + 'name': 'Payment Journal', + 'code': 'PAY', + 'type': 'bank', + 'company_id': company.id + }) + + self.outbound_pay_method = self.env['account.payment.method'].create({ + 'name': 'outbound', + 'code': 'out', + 'payment_type': 'outbound', + }) + self.expense = self.env['hr.expense.sheet'].create({ 'name': 'Expense for John Smith', 'employee_id': self.employee.id, @@ -107,3 +120,40 @@ class TestCheckJournalEntry(TransactionCase): self.assertEquals(expense.tax_ids.ids, [self.tax.id]) self.assertEquals(expense.total_amount, 10863.60) self.assertTrue(expense.employee_id in user_demo.employee_ids) + + def test_partial_payment_multiexpense(self): + self.expense_line.unit_amount = 200 + expense_line2 = self.expense_line.copy({ + 'sheet_id': self.expense.id + }) + self.expense.approve_expense_sheets() + self.expense.action_sheet_move_create() + exp_move_lines = self.expense.account_move_id.line_ids + payable_move_lines = exp_move_lines.filtered(lambda l: l.account_id.internal_type == 'payable') + self.assertEquals(len(payable_move_lines), 2) + + WizardRegister = self.env['hr.expense.sheet.register.payment.wizard'].with_context(active_ids=self.expense.ids) + + register_pay1 = WizardRegister.create({ + 'journal_id': self.bank_journal.id, + 'payment_method_id': self.outbound_pay_method.id, + 'amount': 300, + }) + register_pay1.expense_post_payment() + + exp_move_lines = self.expense.account_move_id.line_ids + payable_move_lines = exp_move_lines.filtered(lambda l: l.account_id.internal_type == 'payable') + self.assertEquals(len(payable_move_lines.filtered(lambda l: l.reconciled)), 1) + + register_pay2 = WizardRegister.create({ + 'journal_id': self.bank_journal.id, + 'payment_method_id': self.outbound_pay_method.id, + 'amount': 100, + }) + register_pay2.expense_post_payment() + exp_move_lines = self.expense.account_move_id.line_ids + payable_move_lines = exp_move_lines.filtered(lambda l: l.account_id.internal_type == 'payable') + self.assertEquals(len(payable_move_lines.filtered(lambda l: l.reconciled)), 2) + + full_reconcile = payable_move_lines.mapped('full_reconcile_id') + self.assertEquals(len(full_reconcile), 1) diff --git a/addons/hr_expense/wizard/hr_expense_sheet_register_payment.py b/addons/hr_expense/wizard/hr_expense_sheet_register_payment.py index f378f15a471..54b8d816d14 100644 --- a/addons/hr_expense/wizard/hr_expense_sheet_register_payment.py +++ b/addons/hr_expense/wizard/hr_expense_sheet_register_payment.py @@ -86,7 +86,7 @@ class HrExpenseSheetRegisterPaymentWizard(models.TransientModel): # Reconcile the payment and the expense, i.e. lookup on the payable account move lines account_move_lines_to_reconcile = self.env['account.move.line'] for line in payment.move_line_ids + expense_sheet.account_move_id.line_ids: - if line.account_id.internal_type == 'payable': + if line.account_id.internal_type == 'payable' and not line.reconciled: account_move_lines_to_reconcile |= line account_move_lines_to_reconcile.reconcile()