Skip to content

Commit

Permalink
[FIX] hr_expense: Creation of entries from several expense lines
Browse files Browse the repository at this point in the history
When posting journal entries for an hr.expense.sheet with several expense lines
(by clicking on the button "Post journal entries"), all the account move lines
created for the same sheet must be linked to the same account move because
the model hr.expense.sheet has just a field "account_move_id" to access all the entries
(by clicking on button "Accounting Entries")

opw:715523,709930,725798,716239
  • Loading branch information
simongoffin committed Mar 27, 2017
1 parent 5c0901b commit f97eb0a
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions addons/hr_expense/models/hr_expense.py
Expand Up @@ -172,19 +172,24 @@ def action_move_create(self):
'''
main function that is called when trying to create the accounting entries related to an expense
'''
move_group_by_sheet = {}
for expense in self:
journal = expense.sheet_id.bank_journal_id if expense.payment_mode == 'company_account' else expense.sheet_id.journal_id
#create the move that will contain the accounting entries
acc_date = expense.sheet_id.accounting_date or expense.date
move = self.env['account.move'].create({
'journal_id': journal.id,
'company_id': self.env.user.company_id.id,
'date': acc_date,
'ref': expense.sheet_id.name,
# force the name to the default value, to avoid an eventual 'default_name' in the context
# to set it to '' which cause no number to be given to the account.move when posted.
'name': '/',
})
if not expense.sheet_id.id in move_group_by_sheet:
move = self.env['account.move'].create({
'journal_id': journal.id,
'company_id': self.env.user.company_id.id,
'date': acc_date,
'ref': expense.sheet_id.name,
# force the name to the default value, to avoid an eventual 'default_name' in the context
# to set it to '' which cause no number to be given to the account.move when posted.
'name': '/',
})
move_group_by_sheet[expense.sheet_id.id] = move
else:
move = move_group_by_sheet[expense.sheet_id.id]
company_currency = expense.company_id.currency_id
diff_currency_p = expense.currency_id != company_currency
#one account.move.line per expense (+taxes..)
Expand Down Expand Up @@ -235,9 +240,10 @@ def action_move_create(self):
lines = map(lambda x: (0, 0, expense._prepare_move_line(x)), move_lines)
move.with_context(dont_create_taxes=True).write({'line_ids': lines})
expense.sheet_id.write({'account_move_id': move.id})
move.post()
if expense.payment_mode == 'company_account':
expense.sheet_id.paid_expense_sheets()
for move in move_group_by_sheet.values():
move.post()
return True

@api.multi
Expand Down

0 comments on commit f97eb0a

Please sign in to comment.