[FIX] hr_expense: doesn't post if journal.post_at == 'bank_rec'

Steps to reproduce:
- Create a bank journal, with "post at" = "Bank reconciliation"
- Create a new expense paid by "Company"
- Create a report and confirm

Current behavior:
- the bank move is posted

Expected behavior:
- the bank move is not posted (and i will posted during the bank reconciliation"

closes odoo/odoo#52260

X-original-commit: 0b45a8317f1e4538ad93aa169b8be08f5403340a
Signed-off-by: Simon Goffin (sig) <sig@openerp.com>
This commit is contained in:
Florent de Labarre
2020-06-03 06:23:53 +00:00
committed by Goffin Simon
parent 8ac95195fc
commit accfe5e089
+11 -1
View File
@@ -480,6 +480,8 @@ class HrExpense(models.Model):
move_line_values_by_expense = self._get_account_move_line_values()
move_to_keep_draft = self.env['account.move']
for expense in self:
company_currency = expense.company_id.currency_id
different_currency = expense.currency_id != company_currency
@@ -508,7 +510,7 @@ class HrExpense(models.Model):
'partner_type': 'supplier',
'journal_id': journal.id,
'date': expense.date,
'state': 'reconciled',
'state': 'draft',
'currency_id': expense.currency_id.id if different_currency else journal_currency.id,
'amount': abs(total_amount_currency) if different_currency else abs(total_amount),
'name': expense.name,
@@ -520,10 +522,18 @@ 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'
move_to_keep_draft |= move
expense.sheet_id.paid_expense_sheets()
# post the moves
for move in move_group_by_sheet.values():
if move in move_to_keep_draft:
continue
move.post()
return move_group_by_sheet