Skip to content

Commit

Permalink
[IMP] hr_expense_advance_clearing: fix unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
hongquangminh committed Jul 18, 2024
1 parent 0f1c36b commit 1f523b2
Show file tree
Hide file tree
Showing 5 changed files with 213 additions and 109 deletions.
9 changes: 4 additions & 5 deletions hr_expense_advance_clearing/models/hr_expense.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,12 @@ def onchange_advance(self):

def _get_move_line_src(self, move_line_name, partner_id):
self.ensure_one()
unit_amount = self.unit_amount or self.total_amount
quantity = self.quantity if self.unit_amount else 1
quantity = self.quantity if self.total_amount else 1
taxes = self.tax_ids.with_context(round=True).compute_all(
unit_amount, self.currency_id, quantity, self.product_id
self.total_amount, self.currency_id, quantity, self.product_id
)
amount_currency = self.total_amount - self.amount_tax
balance = self.total_amount_company - self.amount_tax_company
amount_currency = self.total_amount - self.tax_amount
balance = self.total_amount - self.tax_amount
ml_src_dict = {
"name": move_line_name,
"quantity": quantity,
Expand Down
16 changes: 8 additions & 8 deletions hr_expense_advance_clearing/models/hr_expense_sheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ def _check_advance_expense(self):
if advance_lines and len(advance_lines) != len(self.expense_line_ids):
raise ValidationError(_("Advance must contain only advance expense line"))

@api.depends("account_move_ids.payment_state")
def _compute_payment_state(self):
@api.depends("account_move_ids.payment_state", "account_move_ids.amount_residual")
def _compute_from_account_move_ids(self):
"""After clear advance. payment state will change to 'paid'"""
res = super()._compute_payment_state()
res = super()._compute_from_account_move_ids()
for sheet in self:
if sheet.advance_sheet_id and sheet.account_move_ids.state == "posted":
sheet.payment_state = "paid"
Expand Down Expand Up @@ -156,8 +156,8 @@ def _get_move_line_vals(self):
# source move line
move_line_src = expense._get_move_line_src(move_line_name, partner_id)
move_line_values = [move_line_src]
total_amount -= expense.total_amount_company
total_amount_currency -= expense.total_amount
total_amount -= expense.total_amount
total_amount_currency -= expense.total_amount_currency

# destination move line
move_line_dst = expense._get_move_line_dst(
Expand Down Expand Up @@ -191,7 +191,7 @@ def _get_move_line_vals(self):
payable_move_line["amount_currency"] = -remain_payable
payable_move_line[
"account_id"
] = expense._get_expense_account_destination()
] = self._get_expense_account_destination()
else:
advance_to_clear -= credit
# Add destination first (if credit is not zero)
Expand All @@ -202,10 +202,10 @@ def _get_move_line_vals(self):
move_line_vals.extend(move_line_values)
return move_line_vals

def _prepare_bill_vals(self):
def _prepare_bills_vals(self):
"""create journal entry instead of bills when clearing document"""
self.ensure_one()
res = super()._prepare_bill_vals()
res = super()._prepare_bills_vals()
if self.advance_sheet_id and self.payment_mode == "own_account":
if (
self.advance_sheet_residual <= 0.0
Expand Down
Loading

0 comments on commit 1f523b2

Please sign in to comment.