Skip to content

Commit

Permalink
FIX, track PIT in case not 150,000
Browse files Browse the repository at this point in the history
  • Loading branch information
kittiu committed Nov 4, 2021
1 parent 59a2943 commit 3e68d9d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
34 changes: 30 additions & 4 deletions l10n_th_account_tax/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,26 +474,52 @@ def _post(self, soft=True):
for move in self:
move.line_ids._checkout_tax_invoice_amount()

# Create account.withholding.move, for every withhlding tax line
# Withholding Tax:
# - Create account.withholding.move, for every withholding tax line
# - For case PIT, it is possible that there is no withholidng amount
# but still need to keep track the withholding.move base amount
for move in self:
# Normal case, create withholding.move only when withholding
wht_moves = move.line_ids.filtered("account_id.wht_account")
withholding_moves = [
(0, 0, self._prepare_withholding_move(wht_move))
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
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(
self.env.context.get("active_ids", [])
)
bill_wht_lines = bills.mapped("line_ids").filtered(
"wht_tax_id.is_pit"
)
bill_wht_moves = [
(0, 0, self._prepare_withholding_move(bill_wht_move))
for bill_wht_move in bill_wht_lines
]
move.write({"wht_move_ids": bill_wht_moves})
# When post, do remove the existing certs
self.mapped("wht_cert_ids").unlink()
return res

def _prepare_withholding_move(self, wht_move):
""" Prepare dict for account.withholding.move """
amount_income = wht_move.tax_base_amount
amount_wht = abs(wht_move.balance)
# In case, PIT is not withhold, but need to track from invoice
if wht_move.move_id.move_type == "in_invoice":
amount_income = abs(wht_move.balance)
amount_wht = 0.0
if wht_move.move_id.move_type == "in_refund":
amount_income = -abs(wht_move.balance)
amount_wht = 0.0
return {
"partner_id": wht_move.partner_id.id,
"amount_income": wht_move.tax_base_amount,
"amount_income": amount_income,
"wht_tax_id": wht_move.wht_tax_id.id,
"amount_wht": abs(wht_move.balance),
"payment_id": wht_move.move_id.payment_id.id,
"amount_wht": amount_wht,
}

def _get_tax_invoice_number(self, move, tax_invoice, tax):
Expand Down
10 changes: 7 additions & 3 deletions l10n_th_account_tax/models/account_withholding_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ class AccountWithholdingMove(models.Model):
index=True,
ondelete="cascade",
domain=[("state", "not in", ["draft", "cancel"])],
compute="_compute_move_data",
store=True,
readonly=False,
)
move_id = fields.Many2one(
comodel_name="account.move",
Expand All @@ -35,13 +38,13 @@ class AccountWithholdingMove(models.Model):
)
cancelled = fields.Boolean(readonly=True, help="For filtering cancelled payment")
date = fields.Date(
compute="_compute_date",
compute="_compute_move_data",
store=True,
readonly=False,
)
calendar_year = fields.Char(
string="Calendar Year",
compute="_compute_date",
compute="_compute_move_data",
store=True,
index=True,
)
Expand Down Expand Up @@ -74,7 +77,8 @@ class AccountWithholdingMove(models.Model):
)

@api.depends("move_id")
def _compute_date(self):
def _compute_move_data(self):
for rec in self:
rec.date = rec.move_id and rec.move_id.date or False
rec.calendar_year = rec.date and rec.date.strftime("%Y")
rec.payment_id = rec.move_id.payment_id

0 comments on commit 3e68d9d

Please sign in to comment.