Skip to content

Commit

Permalink
[FIX] hr_expense: Update payment states after moves updated
Browse files Browse the repository at this point in the history
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#53080

Signed-off-by: Simon Goffin (sig) <[email protected]>
  • Loading branch information
nboulif committed Jun 17, 2020
1 parent 7c7275b commit aea8536
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions addons/hr_expense/models/hr_expense.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,8 @@ def action_move_create(self):

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
Expand Down Expand Up @@ -495,14 +497,15 @@ def action_move_create(self):
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:
Expand Down

0 comments on commit aea8536

Please sign in to comment.