Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions addons/hr_expense/models/hr_expense.py
Original file line number Diff line number Diff line change
Expand Up @@ -1010,6 +1010,30 @@ def _get_base_account(self):

return account

def _prepare_company_bill_vals(self):
# NOTE: Similar to `_prepare_bills_vals` in sheet, but to do it per expense for the vendors
self.ensure_one()
# move_vals = self.sheet_id._prepare_move_vals()
# if self.employee_id.sudo().bank_account_id:
# move_vals['partner_bank_id'] = self.employee_id.sudo().bank_account_id.id
return {
**self.sheet_id._prepare_move_vals(),
"journal_id": self.sheet_id.journal_id.id,
"move_type": "in_invoice",
"ref": self.name,
"date": self.date,
"partner_id": self.vendor_id.id,
"commercial_partner_id": self.vendor_id.commercial_partner_id.id,
"currency_id": self.currency_id.id,
"line_ids": [Command.create(self._prepare_move_lines_vals())],
"attachment_ids": [
Command.create(
attachment.copy_data({"res_model": "account.move", "res_id": False, "raw": attachment.raw})[0]
)
for attachment in self.message_main_attachment_id
],
}

def _prepare_move_lines_vals(self):
self.ensure_one()
account = self._get_base_account()
Expand Down
33 changes: 8 additions & 25 deletions addons/hr_expense/models/hr_expense_sheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,12 +647,8 @@ def action_open_expense_view(self):

def action_open_account_moves(self):
self.ensure_one()
if self.payment_mode == 'own_account':
res_model = 'account.move'
record_ids = self.account_move_ids
else:
res_model = 'account.payment'
record_ids = self.account_move_ids.origin_payment_id
res_model = 'account.move'
record_ids = self.account_move_ids

action = {'type': 'ir.actions.act_window', 'res_model': res_model}
if len(self.account_move_ids) == 1:
Expand Down Expand Up @@ -768,26 +764,13 @@ def _do_create_moves(self):
moves_sudo = self.env['account.move'].sudo().create([sheet._prepare_bills_vals() for sheet in own_account_sheets])
for move_sudo in moves_sudo:
move_sudo._message_set_main_attachment_id(move_sudo.attachment_ids, force=True, filter_xml=False)
if company_account_sheets:
move_vals_list, payment_vals_list = zip(*[
expense._prepare_payments_vals()

moves_sudo |= self.env["account.move"].sudo().create(
[
expense._prepare_company_bill_vals()
for expense in company_account_sheets.expense_line_ids
])

payment_moves_sudo = self.env['account.move'].sudo().create(move_vals_list)
for payment_vals, move in zip(payment_vals_list, payment_moves_sudo):
payment_vals['move_id'] = move.id

payments_sudo = self.env['account.payment'].sudo().create(payment_vals_list)
for payment_sudo, move_sudo in zip(payments_sudo, payment_moves_sudo):
move_sudo.update({
'origin_payment_id': payment_sudo.id,
# We need to put the journal_id because editing origin_payment_id triggers a re-computation chain
# that voids the company_currency_id of the lines
'journal_id': move_sudo.journal_id.id,
})

moves_sudo |= payment_moves_sudo
]
)

# returning the move with the super user flag set back as it was at the origin of the call
return moves_sudo.sudo(self.env.su)
Expand Down