Skip to content

Commit

Permalink
ADD l10n_th_account_tax_advance_clearing
Browse files Browse the repository at this point in the history
  • Loading branch information
kittiu committed Oct 30, 2021
1 parent 689d7eb commit 5a54d63
Show file tree
Hide file tree
Showing 14 changed files with 183 additions and 6 deletions.
14 changes: 10 additions & 4 deletions l10n_th_account_tax/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ def write(self, vals):
self.mapped("tax_invoice_ids").unlink()
return super().write(vals)

def _prepare_deduction_list(self, currency, date):
def _prepare_deduction_list(self, currency=False, date=False):
def add_deduction(
wht_lines, wht_tax, partner_id, amount_deduct, currency, date
):
Expand All @@ -288,6 +288,11 @@ def add_deduction(
deductions.append(deduct)
return amount_deduct

if not currency:
currency = self.env.company.currency_id
if not date:
date = fields.Date.context_today(self)

deductions = []
amount_deduct = 0
wht_taxes = self.mapped("wht_tax_id")
Expand All @@ -298,10 +303,11 @@ def add_deduction(
"expense_id"
): # From expense, group by bill_partner_id of expense, or default partner
partner_ids = list(
{
x.bill_partner_id.id or x.partner_id.id
[
x.bill_partner_id.id
or x.employee_id.sudo().address_home_id.commercial_partner_id.id
for x in wht_tax_lines.mapped("expense_id")
}
]
)
for partner_id in partner_ids:
partner_wht_lines = wht_tax_lines.filtered(
Expand Down
2 changes: 1 addition & 1 deletion l10n_th_account_tax/wizard/account_payment_register.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def _compute_amount(self):
# Case WHT only, ensure only 1 wizard
self.ensure_one()
deduction_list, _ = wht_move_lines._prepare_deduction_list(
self.currency_id, self.payment_date
currency=self.currency_id, date=self.payment_date
)
# Support only case single WHT line in this module
# Use l10n_th_account_tax_mult if there are mixed lines
Expand Down
3 changes: 3 additions & 0 deletions l10n_th_account_tax_advance_clearing/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)

from . import models
19 changes: 19 additions & 0 deletions l10n_th_account_tax_advance_clearing/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2020 Ecosoft Co., Ltd (http://ecosoft.co.th/)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)

{
"name": "Thai Localization - Advance Clearing Withholding Tax",
"version": "14.0.1.0.0",
"author": "Ecosoft,Odoo Community Association (OCA)",
"license": "AGPL-3",
"website": "https://github.com/OCA/l10n-thailand",
"category": "Localization / Accounting",
"depends": ["l10n_th_account_tax_expense", "hr_expense_advance_clearing"],
"data": [
"views/hr_expense_view.xml",
],
"installable": True,
"auto_install": True,
"development_status": "Beta",
"maintainers": ["kittiu"],
}
4 changes: 4 additions & 0 deletions l10n_th_account_tax_advance_clearing/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)

from . import hr_expense_sheet
from . import account_move
34 changes: 34 additions & 0 deletions l10n_th_account_tax_advance_clearing/models/account_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright 2021 Ecosoft Co., Ltd (http://ecosoft.co.th/)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)
from odoo import models


class AccountMove(models.Model):
_inherit = "account.move"

def _post(self, soft=True):
"""After post, for wht_tax JV case only, recompute the reconciliation
to ensure that the wht_tax JV is taken into account first"""
res = super()._post(soft=soft)
for move in self:
clearing = self.env["hr.expense.sheet"].search(
[("wht_move_id", "=", move.id)]
)
if not clearing:
continue
clearing.ensure_one()
emp_advance = self.env.ref(
"hr_expense_advance_clearing.product_emp_advance"
)
adv_account = emp_advance.property_account_expense_id
# Find clearing and advance moves to reconcile
cl_lines = clearing.account_move_id.line_ids.filtered(
lambda l: l.account_id == adv_account
)
av_lines = cl_lines.mapped("matched_debit_ids.debit_move_id")
# Removes reconcile
res = (cl_lines + av_lines).remove_move_reconcile()
# reconcile again this time with the wht_tax JV
wht_lines = move.line_ids.filtered(lambda l: l.account_id == adv_account)
res = (cl_lines + wht_lines + av_lines).reconcile()
return res
75 changes: 75 additions & 0 deletions l10n_th_account_tax_advance_clearing/models/hr_expense_sheet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Copyright 2021 Ecosoft Co., Ltd (http://ecosoft.co.th/)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)
from odoo import fields, models


class HrExpenseSheet(models.Model):
_inherit = "hr.expense.sheet"

wht_move_id = fields.Many2one(
comodel_name="account.move",
string="Withholding Tax JV",
ondelete="restrict",
copy=False,
readonly=True,
help="For case clear advance, a JV can be created to record withholding tax",
)
has_wht = fields.Boolean(
compute="_compute_has_wht",
)

def _compute_has_wht(self):
for rec in self:
rec.has_wht = len(rec.expense_line_ids.mapped("wht_tax_id")) > 0

def action_create_withholding_tax_entry(self):
"""From expense sheet with WHT lines, this action
helps create new JV with default withholding entries"""
self.ensure_one()
action = self.env.ref("account.action_move_journal_line")
result = action.sudo().read()[0]
view = self.env.ref("account.view_move_form", False)
result["views"] = [(view and view.id or False, "form")]
# Prepare Dr. Advance, Cr. WHT lines
line_vals_list = []
# Cr. WHT Lines
wht_move_lines = self.account_move_id.mapped("line_ids").filtered("wht_tax_id")
currency = self.env.company.currency_id
deduction_list, amount_deduct = wht_move_lines._prepare_deduction_list(
currency=currency
)
for deduction in deduction_list:
line_vals_list.append(
{
"name": deduction["name"],
"amount_currency": -deduction["amount"],
"currency_id": currency.id,
"debit": 0.0,
"credit": deduction["amount"],
"partner_id": deduction["partner_id"],
"account_id": deduction["account_id"],
}
)
emp_advance = self.env.ref("hr_expense_advance_clearing.product_emp_advance")
adv_account = emp_advance.property_account_expense_id
# Dr. Advance
line_vals_list.append(
{
"name": adv_account.name,
"amount_currency": amount_deduct,
"currency_id": currency.id,
"debit": amount_deduct, # Sum of all credit
"credit": 0.0,
"partner_id": self.employee_id.sudo().address_home_id.commercial_partner_id.id,
"account_id": adv_account.id,
}
)
# Create JV
move_vals = {
"move_type": "entry",
"line_ids": [(0, 0, line_vals) for line_vals in line_vals_list],
}
move = self.env["account.move"].create(move_vals)
self.wht_move_id = move
result["res_id"] = move.id
return result
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Kitti Upariphutthiphong. <[email protected]>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This module provide addition step to create withholding tax journal entry.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions l10n_th_account_tax_advance_clearing/views/hr_expense_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!-- Copyright 2021 Ecosoft Co., Ltd (http://ecosoft.co.th/)
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) -->
<odoo>
<record id="view_hr_expense_sheet_form" model="ir.ui.view">
<field name="name">view.hr.expense.sheet.form</field>
<field name="model">hr.expense.sheet</field>
<field name="inherit_id" ref="hr_expense.view_hr_expense_sheet_form" />
<field name="arch" type="xml">
<button name="reset_expense_sheets" position="after">
<field name="has_wht" invisible="1" />
<button
name="action_create_withholding_tax_entry"
string="Create Withholding JV"
type="object"
groups="account.group_account_user"
attrs="{'invisible': ['|', '|', '|', ('state', '!=', 'done'), ('has_wht', '=', False), ('wht_move_id', '!=', False), ('advance_sheet_id', '=', False)]}"
/>
</button>
<field name="account_move_id" position="after">
<field
name="wht_move_id"
attrs="{'invisible': [('wht_move_id', '=', False)]}"
/>
</field>
</field>
</record>
</odoo>
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def _onchange_payment_difference_handling(self):
# Case WHT only, ensure only 1 wizard
self.ensure_one()
(deduction_list, amount_deduct) = move_lines._prepare_deduction_list(
self.currency_id, self.payment_date
currency=self.currency_id, date=self.payment_date
)
deductions = [(5, 0, 0)]
for deduct in deduction_list:
Expand Down
6 changes: 6 additions & 0 deletions setup/l10n_th_account_tax_advance_clearing/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

0 comments on commit 5a54d63

Please sign in to comment.