Skip to content

Commit

Permalink
[FIX] hr_expense_advance_clearing: hook advance product
Browse files Browse the repository at this point in the history
  • Loading branch information
Saran440 committed Nov 14, 2023
1 parent 6a32a6e commit 0847a83
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
9 changes: 5 additions & 4 deletions hr_expense_advance_clearing/models/hr_expense.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions hr_expense_advance_clearing/models/hr_expense_sheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 0847a83

Please sign in to comment.