Skip to content

Commit

Permalink
FIX, track PIT in case not 150,000, on Exp
Browse files Browse the repository at this point in the history
  • Loading branch information
kittiu committed Nov 5, 2021
1 parent 7d8ec16 commit 1f27c7a
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
10 changes: 8 additions & 2 deletions l10n_th_account_tax/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,14 @@ class AccountMove(models.Model):
)

def _compute_has_wht(self):
"""Has WHT when
1. Has wht_tax_id
2. Is not invoice (move_type == 'entry')
"""
for rec in self:
rec.has_wht = len(rec.line_ids.mapped("wht_tax_id")) > 0
wht_tax = True if rec.line_ids.mapped("wht_tax_id") else False
not_inv = rec.move_type == "entry"
rec.has_wht = wht_tax and not_inv

@api.depends("wht_cert_ids.state")
def _compute_wht_cert_status(self):
Expand Down Expand Up @@ -486,7 +492,7 @@ def _post(self, soft=True):
for wht_move in wht_moves
]
move.write({"wht_move_ids": [(5, 0, 0)] + withholding_moves})
# On payment JE, keep track of move when PIT not withheld, use date from vendor bill
# On payment JE, keep track of move when PIT not withheld, use data from vendor bill
if move.payment_id and not move.payment_id.wht_move_ids.mapped("is_pit"):
if self.env.context.get("active_model") == "account.move":
bills = self.env["account.move"].browse(
Expand Down
2 changes: 1 addition & 1 deletion l10n_th_account_tax/views/account_move_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
class="alert alert-warning"
role="alert"
style="margin-bottom:0px;"
attrs="{'invisible': ['|', '|', ('move_type', '!=', 'entry'), ('wht_cert_status', '!=', 'none'), ('state', '!=', 'posted')]}"
attrs="{'invisible': ['|', ('wht_cert_status', '!=', 'none'), ('state', '!=', 'posted')]}"
>
This entry containg withholding tax, but no withholding tax certs. created yet.
<button
Expand Down
2 changes: 1 addition & 1 deletion l10n_th_account_tax/views/account_payment_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
class="alert alert-warning"
role="alert"
style="margin-bottom:0px;"
attrs="{'invisible': ['|', '|', ('move_type', '!=', 'entry'), ('wht_cert_status', '!=', 'none'), ('state', '!=', 'posted')]}"
attrs="{'invisible': ['|', ('wht_cert_status', '!=', 'none'), ('state', '!=', 'posted')]}"
>
This entry containg withholding tax, but no withholding tax certs. created yet.
<button
Expand Down
32 changes: 32 additions & 0 deletions l10n_th_account_tax_expense/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,35 @@ def _assign_tax_invoice(self):
bill_partner = tax_invoice.move_line_id.expense_id.bill_partner_id
if bill_partner:
tax_invoice.write({"partner_id": bill_partner.id})

def _compute_has_wht(self):
"""Has WHT when
Is expense's JE when (
move_type == 'entry'
and lines with expense_id
and not lines with payment_id
)
"""
super()._compute_has_wht()
for rec in self.filtered("has_wht"):
exp_move = (
rec.move_type == "entry"
and rec.line_ids.filtered("expense_id")
and not rec.line_ids.filtered("payment_id")
)
if exp_move:
rec.has_wht = False

def _prepare_withholding_move(self, wht_move):
""" Prepare dict for account.withholding.move on Expense"""
res = super()._prepare_withholding_move(wht_move)
# Is this an expense's journal entry?
is_expense = wht_move.expense_id and not wht_move.payment_id
if is_expense:
res.update(
{
"amount_income": abs(wht_move.balance),
"amount_wht": 0.0,
}
)
return res

0 comments on commit 1f27c7a

Please sign in to comment.