Skip to content

Commit

Permalink
[14.0][IMP] l10n_th_withholding_tax, add base amount on payment register
Browse files Browse the repository at this point in the history
  • Loading branch information
kittiu committed Sep 28, 2021
1 parent b614f02 commit a35140f
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 14 deletions.
14 changes: 13 additions & 1 deletion l10n_th_withholding_tax/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ def _compute_wt_tax_id(self):
rec.wt_tax_id = rec.product_id.wt_tax_id
elif rec.move_id.move_type in ("in_invoice", "in_refund", "out_receipt"):
rec.wt_tax_id = rec.product_id.supplier_wt_tax_id
elif rec.payment_id:
elif (
rec.payment_id and rec.payment_id.wt_tax_id.account_id == rec.account_id
):
rec.wt_tax_id = rec.payment_id.wt_tax_id
else:
rec.wt_tax_id = False
Expand All @@ -42,3 +44,13 @@ def _get_wt_base_amount(self, currency, currency_date):
self.balance, currency, self.company_id, currency_date
)
return wt_base_amount

def _get_wt_amount(self, currency, currency_date):
""" Calculate withholding tax and base amount based on currency """
amount_base = 0
amount_wt = 0
for line in self:
base_amount = line._get_wt_base_amount(currency, currency_date)
amount_wt += line.wt_tax_id.amount / 100 * base_amount
amount_base += base_amount
return (amount_base, amount_wt)
26 changes: 18 additions & 8 deletions l10n_th_withholding_tax/wizard/account_payment_register.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ class AccountPaymentRegister(models.TransientModel):
string="Withholding Tax",
help="Optional hidden field to keep wt_tax. Useful for case 1 tax only",
)
wt_amount_base = fields.Monetary(
string="Withholding Base",
help="Based amount for the tax amount",
)

@api.onchange("wt_tax_id", "wt_amount_base")
def _onchange_wt_tax_id(self):
if self.wt_tax_id and self.wt_amount_base:
amount_wt = self.wt_tax_id.amount / 100 * self.wt_amount_base
self.amount = self.source_amount_currency - amount_wt
self.writeoff_account_id = self.wt_tax_id.account_id
self.writeoff_label = self.wt_tax_id.display_name

def _create_payment_vals_from_wizard(self):
payment_vals = super()._create_payment_vals_from_wizard()
Expand All @@ -20,9 +32,10 @@ def _create_payment_vals_from_wizard(self):
payment_vals.update({"wt_tax_id": self.wt_tax_id.id})
return payment_vals

def _update_payment_register(self, amount_wt, inv_lines):
def _update_payment_register(self, amount_base, amount_wt, inv_lines):
self.ensure_one()
self.amount -= amount_wt
self.wt_amount_base = amount_base
self.payment_difference_handling = "reconcile"
wt_tax = inv_lines.mapped("wt_tax_id")
if wt_tax and len(wt_tax) == 1:
Expand Down Expand Up @@ -50,14 +63,11 @@ def _compute_amount(self):
return res
# Case WHT only, ensure only 1 wizard
self.ensure_one()
amount_wt = 0
for line in move_lines:
base_amount = line._get_wt_base_amount(
self.currency_id, self.payment_date
)
amount_wt += line.wt_tax_id.amount / 100 * base_amount
amount_base, amount_wt = move_lines._get_wt_amount(
self.currency_id, self.payment_date
)
if amount_wt:
self._update_payment_register(amount_wt, move_lines)
self._update_payment_register(amount_base, amount_wt, move_lines)
return res

@api.model
Expand Down
24 changes: 19 additions & 5 deletions l10n_th_withholding_tax/wizard/account_payment_register_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,26 @@
<field name="inherit_id" ref="account.view_account_payment_register_form" />
<field name="arch" type="xml">
<field name="payment_difference_handling" position="after">
<field
name="wt_tax_id"
<div
attrs="{'invisible': [('payment_difference_handling', '!=', 'reconcile')]}"
placeholder="Withholding Tax"
options="{'no_create': True, 'no_open': True}"
/>
>
<label
for="wt_tax_id"
class="oe_edit_only"
string="Withholding Tax"
/>
<field
name="wt_tax_id"
placeholder="Withholding Tax"
options="{'no_create': True, 'no_open': True}"
/>
<label
for="wt_amount_base"
class="oe_edit_only"
string="Withholding Base"
/>
<field name="wt_amount_base" />
</div>
</field>
</field>
</record>
Expand Down

0 comments on commit a35140f

Please sign in to comment.