Skip to content

Commit

Permalink
Merge l10n_th_account_advance_clearing to l10n_th_account_expense_tax
Browse files Browse the repository at this point in the history
  • Loading branch information
kittiu committed Oct 31, 2021
1 parent 7b98f24 commit 2ef1eba
Show file tree
Hide file tree
Showing 16 changed files with 97 additions and 121 deletions.
1 change: 1 addition & 0 deletions l10n_th_account_tax/security/ir.model.access.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ access_account_move_tax_invoice_portal,account.move.tax.invoice portal,model_acc
access_account_move_tax_invoice_manager,account.move.tax.invoice manager,model_account_move_tax_invoice,account.group_account_manager,1,0,0,0
access_account_move_tax_invoice_user,account.move.tax.invoice user,model_account_move_tax_invoice,base.group_user,1,1,1,0
access_account_withholding_tax,account.withholding.tax,model_account_withholding_tax,account.group_account_invoice,1,1,1,1
access_account_withholding_tax_user,account.withholding.tax.user,model_account_withholding_tax,base.group_user,1,0,0,0
access_personal_income_tax,access_personal_income_tax,model_personal_income_tax,account.group_account_user,1,1,1,1
access_personal_income_tax_user,access_personal_income_tax_user,model_personal_income_tax,,1,0,0,0
access_personal_income_tax_rate,access_personal_income_tax_rate,model_personal_income_tax_rate,account.group_account_user,1,1,1,1
Expand Down
3 changes: 0 additions & 3 deletions l10n_th_account_tax_advance_clearing/__init__.py

This file was deleted.

19 changes: 0 additions & 19 deletions l10n_th_account_tax_advance_clearing/__manifest__.py

This file was deleted.

4 changes: 0 additions & 4 deletions l10n_th_account_tax_advance_clearing/models/__init__.py

This file was deleted.

34 changes: 0 additions & 34 deletions l10n_th_account_tax_advance_clearing/models/account_move.py

This file was deleted.

This file was deleted.

This file was deleted.

Binary file not shown.
27 changes: 0 additions & 27 deletions l10n_th_account_tax_advance_clearing/views/hr_expense_view.xml

This file was deleted.

1 change: 1 addition & 0 deletions l10n_th_account_tax_expense/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@

from . import account_move
from . import hr_expense
from . import hr_expense_sheet
33 changes: 31 additions & 2 deletions l10n_th_account_tax_expense/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,38 @@ class AccountMove(models.Model):
_inherit = "account.move"

def _post(self, soft=True):
res = super()._post(soft)
self._assign_tax_invoice()
self._reconcile_withholding_tax_entry()
return res

def _reconcile_withholding_tax_entry(self):
""" Re-Reconciliation, ensure the wht_move is taken into account """
for move in self:
clearing = self.env["hr.expense.sheet"].search(
[("wht_move_id", "=", move.id)]
)
if not clearing:
continue
clearing.ensure_one()
move_lines = clearing.account_move_id.line_ids
accounts = move_lines.mapped("account_id").filtered("reconcile")
# Find clearing and advance moves to unreconcile first
r_lines = clearing.account_move_id.line_ids.filtered(
lambda l: l.account_id.id in accounts.ids
)
md_lines = r_lines.mapped("matched_debit_ids.debit_move_id")
mc_lines = r_lines.mapped("matched_credit_ids.credit_move_id")
# Removes reconcile
(r_lines + md_lines + mc_lines).remove_move_reconcile()
# Re-reconcile again this time with the wht_tax JV
wht_lines = move.line_ids.filtered(
lambda l: l.account_id.id in accounts.ids
)
(r_lines + wht_lines + md_lines + mc_lines).reconcile()

def _assign_tax_invoice(self):
""" Use Bill Reference and Date from Expense Line as Tax Invoice """
# Expense Taxes
for move in self:
for tax_invoice in move.tax_invoice_ids.filtered(
lambda l: l.tax_line_id.type_tax_use == "purchase"
Expand All @@ -25,4 +55,3 @@ def _post(self, soft=True):
bill_partner = tax_invoice.move_line_id.expense_id.bill_partner_id
if bill_partner:
tax_invoice.write({"partner_id": bill_partner.id})
return super()._post(soft)
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# 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
from odoo import _, fields, models
from odoo.exceptions import UserError


class HrExpenseSheet(models.Model):
Expand All @@ -9,7 +10,7 @@ class HrExpenseSheet(models.Model):
wht_move_id = fields.Many2one(
comodel_name="account.move",
string="Withholding Tax JV",
ondelete="restrict",
ondelete="set null",
copy=False,
readonly=True,
help="For case clear advance, a JV can be created to record withholding tax",
Expand All @@ -25,15 +26,33 @@ def _compute_has_wht(self):
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()
active_id = self.env.context.get("active_id")
sheet = self.env["hr.expense.sheet"].browse(active_id)
sheet.ensure_one()
# Validation
if sheet.state not in ("done", "post"):
raise UserError(_("Only posted or paid expense report can create JV"))
if sheet.wht_move_id:
raise UserError(_("Already created withholding tax JV"))
# Window action
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")]
# Create wht JV
move_vals = sheet._prepare_withholding_tax_entry()
move = self.env["account.move"].create(move_vals)
sheet.wht_move_id = move
result["res_id"] = move.id
return result

def _prepare_withholding_tax_entry(self):
self.ensure_one()
# Prepare Dr. Advance, Cr. WHT lines
line_vals_list = []
move_lines = self.account_move_id.mapped("line_ids")
# Cr. WHT Lines
wht_move_lines = self.account_move_id.mapped("line_ids").filtered("wht_tax_id")
wht_move_lines = move_lines.filtered("wht_tax_id")
currency = self.env.company.currency_id
deduction_list, amount_deduct = wht_move_lines._prepare_deduction_list(
currency=currency
Expand All @@ -48,28 +67,30 @@ def action_create_withholding_tax_entry(self):
"credit": deduction["amount"],
"partner_id": deduction["partner_id"],
"account_id": deduction["account_id"],
"wht_tax_id": deduction["wht_tax_id"],
"tax_base_amount": deduction["wht_amount_base"],
}
)
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,
}
)
accounts = move_lines.mapped("account_id").filtered("reconcile")
# Dr. Reconcilable Account (i.e., AP, Advance)
partner_id = self.employee_id.sudo().address_home_id.commercial_partner_id.id
for account in accounts:
line_vals_list.append(
{
"name": account.name,
"amount_currency": amount_deduct,
"currency_id": currency.id,
"debit": amount_deduct, # Sum of all credit
"credit": 0.0,
"partner_id": partner_id,
"account_id": account.id,
}
)
amount_deduct = 0.0
# Create JV
move_vals = {
"move_type": "entry",
"ref": self.account_move_id.display_name,
"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
return move_vals
4 changes: 3 additions & 1 deletion l10n_th_account_tax_expense/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
This module make sure that Expense will also comply with Tax Invoice concept of l10n_th_tax.
This module make sure that Expense will also comply with Tax Invoice concept of l10n_th_account_tax.

In case expense has VAT,

* Expense's Bill Reference and Date will be used as Tax Invoice Number and Tax Invoice Date
* Without Bill Reference, Post Journal Entry is not allowed

This module also provide addition step to create withholding tax journal entry.
18 changes: 18 additions & 0 deletions l10n_th_account_tax_expense/views/hr_expense_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@
<field name="model">hr.expense.sheet</field>
<field name="inherit_id" ref="hr_expense.view_hr_expense_sheet_form" />
<field name="arch" type="xml">
<field name="account_move_id" position="after">
<field
name="wht_move_id"
attrs="{'invisible': [('wht_move_id', '=', False)]}"
/>
</field>
<xpath
expr="//field[@name='expense_line_ids']/tree/field[@name='tax_ids']"
position="after"
Expand Down Expand Up @@ -64,4 +70,16 @@
</xpath>
</field>
</record>

<record id="action_create_withholding_entry" model="ir.actions.server">
<field name="name">Create Withholding Tax JV</field>
<field name="model_id" ref="hr_expense.model_hr_expense_sheet" />
<field name="binding_model_id" ref="hr_expense.model_hr_expense_sheet" />
<field name="binding_view_types">form</field>
<field name="state">code</field>
<field name="code">
action = env['hr.expense.sheet'].action_create_withholding_tax_entry()
</field>
</record>

</odoo>

This file was deleted.

6 changes: 0 additions & 6 deletions setup/l10n_th_account_tax_advance_clearing/setup.py

This file was deleted.

0 comments on commit 2ef1eba

Please sign in to comment.