[FIX] hr_expense: prepare method for move values
There was no way to inherit properly action_move_create method. opw:1974069 closes odoo/odoo#33488 Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
This commit is contained in:
committed by
Nicolas Martinelli
parent
c8b87f66f8
commit
01020e18e9
@@ -168,24 +168,33 @@ class HrExpense(models.Model):
|
||||
total_currency -= line['amount_currency'] or line['price']
|
||||
return total, total_currency, account_move_lines
|
||||
|
||||
@api.multi
|
||||
def _prepare_move_values(self):
|
||||
"""
|
||||
This function prepares move values related to an expense
|
||||
"""
|
||||
self.ensure_one()
|
||||
journal = self.sheet_id.bank_journal_id if self.payment_mode == 'company_account' else self.sheet_id.journal_id
|
||||
acc_date = self.sheet_id.accounting_date or self.date
|
||||
move_values = {
|
||||
'journal_id': journal.id,
|
||||
'company_id': self.env.user.company_id.id,
|
||||
'date': acc_date,
|
||||
'ref': self.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': '/',
|
||||
}
|
||||
return move_values
|
||||
|
||||
@api.multi
|
||||
def action_move_create(self):
|
||||
'''
|
||||
main function that is called when trying to create the accounting entries related to an expense
|
||||
'''
|
||||
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': '/',
|
||||
})
|
||||
# create the move that will contain the accounting entries
|
||||
move = self.env['account.move'].create(expense._prepare_move_values())
|
||||
company_currency = expense.company_id.currency_id
|
||||
diff_currency_p = expense.currency_id != company_currency
|
||||
#one account.move.line per expense (+taxes..)
|
||||
@@ -193,7 +202,7 @@ class HrExpense(models.Model):
|
||||
|
||||
#create one more move line, a counterline for the total on payable account
|
||||
payment_id = False
|
||||
total, total_currency, move_lines = expense._compute_expense_totals(company_currency, move_lines, acc_date)
|
||||
total, total_currency, move_lines = expense._compute_expense_totals(company_currency, move_lines, move.date)
|
||||
if expense.payment_mode == 'company_account':
|
||||
if not expense.sheet_id.bank_journal_id.default_credit_account_id:
|
||||
raise UserError(_("No credit account found for the %s journal, please configure one.") % (expense.sheet_id.bank_journal_id.name))
|
||||
@@ -226,7 +235,7 @@ class HrExpense(models.Model):
|
||||
'name': aml_name,
|
||||
'price': total,
|
||||
'account_id': emp_account,
|
||||
'date_maturity': acc_date,
|
||||
'date_maturity': move.date,
|
||||
'amount_currency': diff_currency_p and total_currency or False,
|
||||
'currency_id': diff_currency_p and expense.currency_id.id or False,
|
||||
'payment_id': payment_id,
|
||||
|
||||
Reference in New Issue
Block a user