-
-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ADD l10n_th_account_tax_advance_clearing
- Loading branch information
Showing
14 changed files
with
183 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
34
l10n_th_account_tax_advance_clearing/models/account_move.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
75
l10n_th_account_tax_advance_clearing/models/hr_expense_sheet.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* Kitti Upariphutthiphong. <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
27
l10n_th_account_tax_advance_clearing/views/hr_expense_view.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
setup/l10n_th_account_tax_advance_clearing/odoo/addons/l10n_th_account_tax_advance_clearing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../l10n_th_account_tax_advance_clearing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) |