From 58ca0422b90f6b135c08a347569da16da582bc39 Mon Sep 17 00:00:00 2001 From: alt-odoo Date: Wed, 2 Jun 2021 08:44:15 +0000 Subject: [PATCH] [IMP] hr_expense: use bank account defined on employee in payment When registering a payment on an expense, we are currently using the first bank account set on the partner if no account is set on the account move. We should use the bank account defined on the employee instead, and fallback on the partner only if it is not set. closes odoo/odoo#72077 X-original-commit: e0335a71afbeb34c5fad9a71bd1b53d5d88d6fa6 Signed-off-by: oco-odoo Signed-off-by: Alex Tuyls --- addons/hr_expense/wizard/account_payment_register.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/addons/hr_expense/wizard/account_payment_register.py b/addons/hr_expense/wizard/account_payment_register.py index a44a23fbc8e..b8a0322ae41 100644 --- a/addons/hr_expense/wizard/account_payment_register.py +++ b/addons/hr_expense/wizard/account_payment_register.py @@ -10,6 +10,15 @@ class AccountPaymentRegister(models.TransientModel): # BUSINESS METHODS # ------------------------------------------------------------------------- + @api.model + def _get_line_batch_key(self, line): + # OVERRIDE to set the bank account defined on the employee + res = super()._get_line_batch_key(line) + expense_sheet = self.env['hr.expense.sheet'].search([('payment_mode', '=', 'own_account'), ('account_move_id', 'in', line.move_id.ids)]) + if expense_sheet.employee_id.bank_account_id and not line.move_id.partner_bank_id: + res['partner_bank_id'] = expense_sheet.employee_id.bank_account_id.id + return res + def _create_payments(self): # OVERRIDE to set the 'done' state on expense sheets. payments = super()._create_payments()