Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0][IMP] l10n_th_withholding_tax_cert, add personal income tax #263

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions l10n_th_withholding_tax_cert/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
"security/account_security.xml",
"security/ir.model.access.csv",
"wizard/create_withholding_tax_cert.xml",
"wizard/create_pit_withholding_tax_cert.xml",
"views/withholding_tax_cert.xml",
"views/account_payment_view.xml",
"views/account_move_view.xml",
"views/res_partner_view.xml",
],
"installable": True,
"development_status": "Beta",
Expand Down
1 change: 1 addition & 0 deletions l10n_th_withholding_tax_cert/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
from . import withholding_tax_cert
from . import account_payment
from . import account_move
from . import res_partner
17 changes: 8 additions & 9 deletions l10n_th_withholding_tax_cert/models/account_move.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright 2019 Ecosoft Co., Ltd (https://ecosoft.co.th/)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)

from odoo import _, api, fields, models
from odoo import api, fields, models


class AccountMove(models.Model):
Expand Down Expand Up @@ -29,11 +29,10 @@ def _compute_wt_cert_cancel(self):
record.wt_cert_cancel = wt_cancel

def button_wt_certs(self):
return {
"name": _("Withholding Tax Certs."),
"view_mode": "tree,form",
"res_model": "withholding.tax.cert",
"view_id": False,
"type": "ir.actions.act_window",
"domain": [("id", "in", self.wt_cert_ids.ids)],
}
self.ensure_one()
action = self.env.ref(
"l10n_th_withholding_tax_cert.action_withholding_tax_cert_menu"
)
result = action.sudo().read()[0]
result["domain"] = [("id", "in", self.wt_cert_ids.ids)]
return result
18 changes: 8 additions & 10 deletions l10n_th_withholding_tax_cert/models/account_payment.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright 2019 Ecosoft Co., Ltd (https://ecosoft.co.th/)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)

from odoo import _, api, fields, models
from odoo import api, fields, models


class AccountPayment(models.Model):
Expand All @@ -13,7 +13,6 @@ class AccountPayment(models.Model):
string="Withholding Tax Cert.",
readonly=True,
)

wt_cert_cancel = fields.Boolean(
compute="_compute_wt_cert_cancel",
store=True,
Expand All @@ -30,11 +29,10 @@ def _compute_wt_cert_cancel(self):
record.wt_cert_cancel = wt_cancel

def button_wt_certs(self):
return {
"name": _("Withholding Tax Certs."),
"view_mode": "tree,form",
"res_model": "withholding.tax.cert",
"view_id": False,
"type": "ir.actions.act_window",
"domain": [("id", "in", self.wt_cert_ids.ids)],
}
self.ensure_one()
action = self.env.ref(
"l10n_th_withholding_tax_cert.action_withholding_tax_cert_menu"
)
result = action.sudo().read()[0]
result["domain"] = [("id", "in", self.wt_cert_ids.ids)]
return result
20 changes: 20 additions & 0 deletions l10n_th_withholding_tax_cert/models/res_partner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2021 Ecosoft Co., Ltd (https://ecosoft.co.th/)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)

from odoo import models


class ResPartner(models.Model):
_inherit = "res.partner"

def button_wt_certs(self):
self.ensure_one()
action = self.env.ref(
"l10n_th_withholding_tax_cert.action_withholding_tax_cert_menu"
)
result = action.sudo().read()[0]
certs = self.env["withholding.tax.cert"].search(
[("supplier_partner_id", "=", self.id)]
)
result["domain"] = [("id", "in", certs.ids)]
return result
12 changes: 12 additions & 0 deletions l10n_th_withholding_tax_cert/models/withholding_tax_cert.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,18 @@ def action_create_withholding_tax_cert(self):
"type": "ir.actions.act_window",
}

def action_create_pit_withholding_tax_cert(self):
view = "l10n_th_withholding_tax_cert.create_pit_withholding_tax_cert"
return {
"name": _("Create Withholding Tax Cert."),
"res_model": "create.pit.withholding.tax.cert",
"view_mode": "form",
"view_id": self.env.ref(view).id,
"context": self.env.context,
"target": "new",
"type": "ir.actions.act_window",
}


class WithholdingTaxCertLine(models.Model):
_name = "withholding.tax.cert.line"
Expand Down
2 changes: 2 additions & 0 deletions l10n_th_withholding_tax_cert/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
This module allow user to create Withholding Tax Certificate from any payment or journal entry document
that contain accounting entry on withholding tax.

For personal income tax, user can create Withholding Tax Certificate from Partner window (normally once a year)
2 changes: 1 addition & 1 deletion l10n_th_withholding_tax_cert/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
From supplier payment or journal entry that has already withheld tax,
From supplier payment, journal entry or partner (for persona tax) that has already withheld tax,

- Click action Create Withholding Tax Cert., this bring user to new Withholding Tax Certificate
- Fill in required information for Withholding Tax Certificate
Expand Down
1 change: 1 addition & 0 deletions l10n_th_withholding_tax_cert/security/ir.model.access.csv
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_withholding_tax_cert,withholding.tax.cert,model_withholding_tax_cert,account.group_account_invoice,1,1,1,1
access_withholding_tax_cert_line,withholding.tax.cert.line,model_withholding_tax_cert_line,account.group_account_invoice,1,1,1,1
access_create_withholding_tax_cert,access_create_withholding_tax_cert,model_create_withholding_tax_cert,account.group_account_invoice,1,1,1,1
access_create_pit_withholding_tax_cert,access_create_pit_withholding_tax_cert,model_create_pit_withholding_tax_cert,account.group_account_user,1,1,1,1
21 changes: 21 additions & 0 deletions l10n_th_withholding_tax_cert/views/res_partner_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="view_partner_form" model="ir.ui.view">
<field name="name">view.partner.form</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form" />
<field name="arch" type="xml">
<div name="button_box" position="inside">
<button
class="oe_stat_button"
name="button_wt_certs"
string="WT Certs"
type="object"
groups="account.group_account_invoice"
attrs="{'invisible':[('pit_move_ids','=',[])]}"
icon="fa-bars"
/>
</div>
</field>
</record>
</odoo>
1 change: 1 addition & 0 deletions l10n_th_withholding_tax_cert/wizard/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)

from . import create_withholding_tax_cert
from . import create_pit_withholding_tax_cert
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Copyright 2021 Ecosoft Co., Ltd (https://ecosoft.co.th/)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)

from odoo import _, fields, models
from odoo.exceptions import UserError

from ..models.withholding_tax_cert import INCOME_TAX_FORM, WHT_CERT_INCOME_TYPE


class CreatePITWithholdingTaxCert(models.TransientModel):
_name = "create.pit.withholding.tax.cert"
_description = "Create Withholding Tax Cert Wizard From PIT"

date_from = fields.Date(required=True)
date_to = fields.Date(required=True)
income_tax_form = fields.Selection(
selection=INCOME_TAX_FORM,
string="Income Tax Form",
required=True,
)
date = fields.Date(default=fields.Date.today(), required=True)

def _prepare_wt_line(self, cert, partner_id):
CertLine = self.env["withholding.tax.cert.line"]
select_dict = dict(WHT_CERT_INCOME_TYPE)
pit_moves = partner_id.pit_move_ids.filtered(
lambda l: self.date_from <= l.date <= self.date_to
and l.payment_state == "posted"
)
if pit_moves.filtered(lambda l: not l.wt_cert_income_type):
raise UserError(_("Type of Income is not set on some income/tax lines"))
for line in pit_moves:
cert.wt_line += CertLine.new(
{
"wt_cert_income_type": line.wt_cert_income_type,
"wt_cert_income_desc": select_dict[line.wt_cert_income_type],
"base": line.amount_income,
"amount": abs(line.amount_wt),
}
)

def create_pit_wt_cert(self):
self.ensure_one()
ctx = self._context.copy()
model = ctx.get("active_model", False)
active_id = ctx.get("active_id")
Cert = self.env["withholding.tax.cert"]
cert_ids = []
if model != "res.partner":
raise UserError(
_("You can create pit withholding tax from partner view only.")
)
partner_id = self.env[model].browse(active_id)
# Create new withholding.tax.cert
cert = Cert.new(
{
"supplier_partner_id": partner_id.id,
"income_tax_form": self.income_tax_form,
"date": self.date,
}
)
self._prepare_wt_line(cert, partner_id)
new_cert = Cert.create(cert._convert_to_write(cert._cache))
cert_ids.append(new_cert.id)
return {
"name": _("Create PIT Withholding Tax Cert."),
"view_mode": "tree,form",
"res_model": "withholding.tax.cert",
"view_id": False,
"type": "ir.actions.act_window",
"domain": [("id", "in", cert_ids)],
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="create_pit_withholding_tax_cert" model="ir.ui.view">
<field name="name">Create PIT Withholding Tax Cert.</field>
<field name="model">create.pit.withholding.tax.cert</field>
<field name="arch" type="xml">
<form>
<p>
Create new withholding tax cert. based on partner for withholding tax.
</p>
<group>
<group>
<field name="date_from" />
<field name="date_to" />
<field name="date" />
</group>
<group>
<field name="income_tax_form" />
</group>
</group>
<footer>
<button
string="Create"
name="create_pit_wt_cert"
type="object"
default_focus="1"
class="btn-primary"
/>
<button string="Cancel" class="btn-default" special="cancel" />
</footer>
</form>
</field>
</record>
<record id="action_partner_create_withholding_tax_cert" model="ir.actions.server">
<field name="name">Create Withholding Tax Cert.</field>
<field
name="model_id"
ref="l10n_th_withholding_tax_cert.model_create_pit_withholding_tax_cert"
/>
<field name="binding_model_id" ref="base.model_res_partner" />
<field name="binding_view_types">list,form</field>
<field name="state">code</field>
<field name="code">
action = env["withholding.tax.cert"].action_create_pit_withholding_tax_cert()
</field>
</record>
</odoo>