From 0847a833610a6392ace221aa4f390c06128249be Mon Sep 17 00:00:00 2001 From: Saran440 Date: Tue, 14 Nov 2023 15:49:09 +0700 Subject: [PATCH] [FIX] hr_expense_advance_clearing: hook advance product --- hr_expense_advance_clearing/models/hr_expense.py | 9 +++++---- hr_expense_advance_clearing/models/hr_expense_sheet.py | 6 ++---- .../wizard/account_payment_register.py | 5 ++++- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/hr_expense_advance_clearing/models/hr_expense.py b/hr_expense_advance_clearing/models/hr_expense.py index f6d262368..b6bdf224b 100644 --- a/hr_expense_advance_clearing/models/hr_expense.py +++ b/hr_expense_advance_clearing/models/hr_expense.py @@ -26,12 +26,13 @@ class HrExpense(models.Model): help="Expense created from this advance expense line", ) + def _get_product_advance(self): + return self.env.ref("hr_expense_advance_clearing.product_emp_advance") + @api.constrains("advance") def _check_advance(self): for expense in self.filtered("advance"): - emp_advance = self.env.ref( - "hr_expense_advance_clearing.product_emp_advance" - ) + emp_advance = expense._get_product_advance() if not emp_advance.property_account_expense_id: raise ValidationError( _("Employee advance product has no payable account") @@ -61,7 +62,7 @@ def onchange_advance(self): def _get_account_move_line_values(self): move_line_values_by_expense = super()._get_account_move_line_values() # Only when do the clearing, change cr payable to cr advance - emp_advance = self.env.ref("hr_expense_advance_clearing.product_emp_advance") + emp_advance = self._get_product_advance() sheets = self.mapped("sheet_id").filtered("advance_sheet_id") for sheet in sheets: advance_to_clear = sheet.advance_sheet_residual diff --git a/hr_expense_advance_clearing/models/hr_expense_sheet.py b/hr_expense_advance_clearing/models/hr_expense_sheet.py index ea759eec7..dd3ae66b1 100644 --- a/hr_expense_advance_clearing/models/hr_expense_sheet.py +++ b/hr_expense_advance_clearing/models/hr_expense_sheet.py @@ -79,10 +79,8 @@ def _check_constraint_clearing_amount(self): @api.depends("account_move_id.line_ids.amount_residual") def _compute_clearing_residual(self): - emp_advance = self.env.ref( - "hr_expense_advance_clearing.product_emp_advance", False - ) for sheet in self: + emp_advance = sheet._get_product_advance() residual_company = 0.0 if emp_advance: for line in sheet.sudo().account_move_id.line_ids: @@ -102,7 +100,7 @@ def _compute_clearing_count(self): sheet.clearing_count = len(sheet.clearing_sheet_ids) def _get_product_advance(self): - return self.env.ref("hr_expense_advance_clearing.product_emp_advance") + return self.env.ref("hr_expense_advance_clearing.product_emp_advance", False) def action_sheet_move_create(self): res = super().action_sheet_move_create() diff --git a/hr_expense_advance_clearing/wizard/account_payment_register.py b/hr_expense_advance_clearing/wizard/account_payment_register.py index 79cdc88c1..b90a65113 100644 --- a/hr_expense_advance_clearing/wizard/account_payment_register.py +++ b/hr_expense_advance_clearing/wizard/account_payment_register.py @@ -127,6 +127,9 @@ def _create_payment_return_advance(self, ctx, advance_account): ) return payment + def _get_product_advance(self): + return self.env.ref("hr_expense_advance_clearing.product_emp_advance") + def expense_post_return_advance(self): """This is opposite operation of action_create_payments(), it return remaining advance from employee back to company @@ -138,7 +141,7 @@ def expense_post_return_advance(self): ctx = self._context.copy() ctx.update({"skip_account_move_synchronization": True}) expense_sheet = move_ids.line_ids.expense_id.sheet_id - emp_advance = self.env.ref("hr_expense_advance_clearing.product_emp_advance") + emp_advance = self._get_product_advance() advance_account = emp_advance.property_account_expense_id # Create return advance and post it payment = self._create_payment_return_advance(ctx, advance_account)