From 01020e18e911e582b4d93d029e90e2c2929bae2f Mon Sep 17 00:00:00 2001 From: Benoit Aimont Date: Wed, 24 Apr 2019 13:45:23 +0000 Subject: [PATCH] [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) --- addons/hr_expense/models/hr_expense.py | 37 ++++++++++++++++---------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/addons/hr_expense/models/hr_expense.py b/addons/hr_expense/models/hr_expense.py index 62326f734e4..a4dd234f9d4 100644 --- a/addons/hr_expense/models/hr_expense.py +++ b/addons/hr_expense/models/hr_expense.py @@ -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,