diff --git a/addons/account/models/account_partial_reconcile.py b/addons/account/models/account_partial_reconcile.py index c3b43ccc714..e32c9727f96 100644 --- a/addons/account/models/account_partial_reconcile.py +++ b/addons/account/models/account_partial_reconcile.py @@ -503,13 +503,20 @@ class AccountPartialReconcile(models.Model): moves._post(soft=False) # Reconcile the tax lines being on a reconcile tax basis transfer account. - for line, move_index, sequence in to_reconcile_after: + for lines, move_index, sequence in to_reconcile_after: + + # In expenses, all move lines are created manually without any grouping on tax lines. + # In that case, 'lines' could be already reconciled. + lines = lines.filtered(lambda x: not x.reconciled) + if not lines: + continue + counterpart_line = moves[move_index].line_ids.filtered(lambda line: line.sequence == sequence) # When dealing with tiny amounts, the line could have a zero amount and then, be already reconciled. if counterpart_line.reconciled: continue - (line + counterpart_line).reconcile() + (lines + counterpart_line).reconcile() return moves diff --git a/addons/hr_expense/tests/test_expenses.py b/addons/hr_expense/tests/test_expenses.py index 9ba6e66fd33..77f8250271e 100644 --- a/addons/hr_expense/tests/test_expenses.py +++ b/addons/hr_expense/tests/test_expenses.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. from odoo.addons.hr_expense.tests.common import TestExpenseCommon -from odoo.tests import tagged +from odoo.tests import tagged, Form from odoo import fields @@ -223,3 +223,57 @@ class TestExpenses(TestExpenseCommon): # Assert not "Cannot create unbalanced journal entry" error. expense.action_sheet_move_create() + + def test_reconcile_payment(self): + tax = self.env['account.tax'].create({ + 'name': 'tax abc', + 'type_tax_use': 'purchase', + 'amount_type': 'percent', + 'amount': 15, + 'price_include': False, + 'include_base_amount': False, + 'tax_exigibility': 'on_payment' + }) + current_assets_type = self.env.ref('account.data_account_type_current_assets') + company = self.env.company.id + tax.cash_basis_transition_account_id = self.env['account.account'].create({ + 'name': "test", + 'code': 999991, + 'reconcile': True, + 'user_type_id': current_assets_type.id, + 'company_id': company, + }).id + + sheet = self.env['hr.expense.sheet'].create({ + 'company_id': company, + 'employee_id': self.expense_employee.id, + 'name': 'test sheet', + 'expense_line_ids': [ + (0, 0, { + 'name': 'expense_1', + 'date': '2016-01-01', + 'product_id': self.product_a.id, + 'unit_amount': 10.0, + 'employee_id': self.expense_employee.id, + 'tax_ids': tax + }), + (0, 0, { + 'name': 'expense_2', + 'date': '2016-01-01', + 'product_id': self.product_a.id, + 'unit_amount': 1.0, + 'employee_id': self.expense_employee.id, + 'tax_ids': tax + }), + ], + }) + + + #actions + sheet.action_submit_sheet() + sheet.approve_expense_sheets() + sheet.action_sheet_move_create() + action_data = sheet.action_register_payment() + wizard = Form(self.env['account.payment.register'].with_context(action_data['context'])).save() + wizard.action_create_payments() + self.assertEqual(sheet.state, 'done', 'all account.move.line linked to expenses must be reconciled after payment')