Skip to content
Snippets Groups Projects
Commit aea8536a authored by Nasreddin (bon)'s avatar Nasreddin (bon)
Browse files

[FIX] hr_expense: Update payment states after moves updated

Issue

	- Configure bank journal to post at bank reconciliation
	- Create 2 expenses paid by company
	- Create a report for the two expenses
	  (make sure bank journal configured in the first step is used)
	- Submit, approve and post journal entries

	Error message : "You cannot modify a journal entry linked to
	a posted payment."

Cause

	Since the payment state of expenses lines is updated one by one
	in related move, the first expense had already a 'posted'
	state when updating second expense line, who go against
	_validate_move_modification validation.

Solution

	Update payments state only after updating all moves lines.

opw-2275686

closes odoo/odoo#53080

Signed-off-by: default avatarSimon Goffin (sig) <sig@openerp.com>
parent 7c7275b8
No related branches found
No related tags found
No related merge requests found
......@@ -455,6 +455,8 @@ class HrExpense(models.Model):
move_to_keep_draft = self.env['account.move']
company_payments = self.env['account.payment']
for expense in self:
company_currency = expense.company_id.currency_id
different_currency = expense.currency_id != company_currency
......@@ -495,14 +497,15 @@ class HrExpense(models.Model):
expense.sheet_id.write({'account_move_id': move.id})
if expense.payment_mode == 'company_account':
if journal.post_at == 'pay_val':
payment.state = 'reconciled'
elif journal.post_at == 'bank_rec':
payment.state = 'posted'
company_payments |= payment
if journal.post_at == 'bank_rec':
move_to_keep_draft |= move
expense.sheet_id.paid_expense_sheets()
company_payments.filtered(lambda x: x.journal_id.post_at == 'pay_val').write({'state':'reconciled'})
company_payments.filtered(lambda x: x.journal_id.post_at == 'bank_rec').write({'state':'posted'})
# post the moves
for move in move_group_by_sheet.values():
if move in move_to_keep_draft:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment