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

Add Sign eTax option in account.payment #158

Merged
merged 1 commit into from
Nov 19, 2023
Merged
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
1 change: 1 addition & 0 deletions frappe_etax_service/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"wizards/account_debit_note_view.xml",
"wizards/wizard_select_replacement_purpose.xml",
"views/account_move_views.xml",
"views/account_payment_views.xml",
"views/res_config_settings.xml",
"views/purpose_code_views.xml",
"views/doctype_views.xml",
Expand Down
70 changes: 70 additions & 0 deletions frappe_etax_service/inet/inet_data_template.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
def prepare_data(doc):
if doc._name == "account.move": # Invoice
return prepare_data_invoice(doc)
if doc._name == "account.payment":
return prepare_data_payment(doc)


def prepare_data_invoice(doc):
d = {}
d["currency_code"] = doc.currency_id.name
d["document_type_code"] = doc.etax_doctype
Expand Down Expand Up @@ -59,3 +66,66 @@ def prepare_data(doc):
d["final_amount_untaxed"] = doc._get_additional_amount()[2]
d["adjust_amount_untaxed"] = doc._get_additional_amount()[2]
return d


def prepare_data_payment(doc):
d = {}
d["currency_code"] = doc.currency_id.name
d["document_type_code"] = doc.etax_doctype
d["document_id"] = doc.name
d["document_issue_dtm"] = doc.date and doc.date.strftime("%Y-%m-%dT%H:%M:%S")
# As of now, no use for payment
d["create_purpose_code"] = ""
d["create_purpose"] = ""
d["ref_document_id"] = ""
d["ref_document_issue_dtm"] = ""
d["ref_document_type_code"] = ""
# --
d["buyer_ref_document"] = doc.ref
d["seller_branch_id"] = doc._get_branch_id() or doc.company_id.branch
d["source_system"] = doc.env["ir.config_parameter"].sudo().get_param("web.base.url", "")
d["send_mail"] = (
"Y"
if doc.env["ir.config_parameter"]
.sudo()
.get_param("frappe_etax_service.is_send_etax_email")
else "N"
)
d["seller_tax_id"] = doc.company_id.vat
d["buyer_name"] = doc.partner_id.name
d["buyer_type"] = "TXID" # TXID, NIDN, CCPT, OTHR (no taxid)
d["buyer_tax_id"] = doc.partner_id.vat
d["buyer_branch_id"] = doc.partner_id.branch or "00000"
d["buyer_email"] = doc.partner_id.email
d["buyer_zip"] = doc.partner_id.zip
d["buyer_building_name"] = ""
d["buyer_building_no"] = ""
d["buyer_address_line1"] = doc.partner_id.street
d["buyer_address_line2"] = doc.partner_id.street2
d["buyer_address_line3"] = ""
d["buyer_address_line4"] = ""
d["buyer_address_line5"] = ""
d["buyer_city_name"] = doc.partner_id.city
d["buyer_country_code"] = doc.partner_id.country_id and doc.partner_id.country_id.code or ""
doc_lines = []
for line in doc.tax_invoice_ids:
doc_lines.append(
{
"product_code": line.tax_invoice_number,
"product_name": line.tax_invoice_number,
"product_price": line.tax_base_amount,
"product_quantity": 1,
"line_tax_type_code": line.tax_line_id.name and "VAT" or "FRE",
"line_tax_rate": line.tax_line_id.amount,
"line_base_amount": line.tax_base_amount,
"line_tax_amount": line.balance,
"line_total_amount": line.tax_base_amount + line.balance,
}
)
d["line_item_information"] = doc_lines
# As of now, no use for payment
d["original_amount_untaxed"] = False
d["final_amount_untaxed"] = False
d["adjust_amount_untaxed"] = False
# --
return d
1 change: 1 addition & 0 deletions frappe_etax_service/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from . import etax_th
from . import account_move
from . import account_payment
from . import res_config_settings
from . import purpose_code
from . import doctype
18 changes: 9 additions & 9 deletions frappe_etax_service/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ class AccountMove(models.Model):
_name = "account.move"
_inherit = ["account.move", "etax.th"]

def button_etax_invoices(self):
self.ensure_one()
return {
"name": _("Sign e-Tax Invoice"),
"type": "ir.actions.act_window",
"view_mode": "form",
"res_model": "wizard.select.etax.doctype",
"target": "new",
}
# def button_etax_invoices(self):
# self.ensure_one()
# return {
# "name": _("Sign e-Tax Invoice"),
# "type": "ir.actions.act_window",
# "view_mode": "form",
# "res_model": "wizard.select.etax.doctype",
# "target": "new",
# }

def _get_branch_id(self):
"""
Expand Down
29 changes: 29 additions & 0 deletions frappe_etax_service/models/account_payment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright 2023 Kitti U.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import _, api, fields, models
from odoo.exceptions import ValidationError


class AccountMove(models.Model):
_name = "account.payment"
_inherit = ["account.payment", "etax.th"]

def action_draft(self):
if self.filtered(lambda l: l.etax_status in ("success", "processing", "to_process")):
raise ValidationError(_(
"Cannot reset to draft, eTax submission already started or succeeded.\n"
"You should do the refund process instead."
))
return super().action_draft()

def _get_branch_id(self):
"""
By default, core odoo do not provide branch_id field in
account.move and account.payment.
This method will check if branch_id is exist in model and return branch_id
"""
if self.reconciled_invoice_ids:
if "branch_id" in self.env["account.move"]._fields:
return self.reconciled_invoice_ids[0].branch_id.name
else:
return False
11 changes: 5 additions & 6 deletions frappe_etax_service/models/doctype.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,19 @@ class DocType(models.Model):
),
]

name = fields.Char(required=True)
name = fields.Char(
string="Form Name",
required=True,
)
move_type = fields.Selection(
[
("out_invoice", "Customer Invoice"),
("out_refund", "Customer Credit Note"),
("out_invoice_debit", "Customer Debit Note"),
("entry", "Customer Payment")
],
string="Type",
)
report_template_id = fields.Many2one(
string="Invoice template",
comodel_name="ir.actions.report",
domain=[("model", "=", "account.move"), ("binding_model_id", "!=", False)],
)
doc_source_template = fields.Selection(
string="Invoice template source",
selection=[
Expand Down
20 changes: 15 additions & 5 deletions frappe_etax_service/models/etax_th.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class ETaxTH(models.AbstractModel):
string="Replaced Document",
readonly=True,
copy=False,
help="Currently this field only support invoice and not payment"
)
is_send_frappe = fields.Boolean(
copy=False,
Expand Down Expand Up @@ -107,7 +108,7 @@ def update_processing_document(self):
"name": "%s_signed.pdf" % self.name,
"datas": base64.b64encode(requests.get(pdf_url).content),
"type": "binary",
"res_model": "account.move",
"res_model": self._name,
"res_id": self.id,
}
)
Expand All @@ -117,7 +118,7 @@ def update_processing_document(self):
"name": "%s_signed.xml" % self.name,
"datas": base64.b64encode(requests.get(xml_url).content),
"type": "binary",
"res_model": "account.move",
"res_model": self._name,
"res_id": self.id,
}
)
Expand Down Expand Up @@ -187,7 +188,7 @@ def _get_odoo_form(self, form_type, form_name):
if form_type == "odoo":
report = self.env["ir.actions.report"].search([("name", "=", form_name)])
if len(report) != 1:
raise ValidationError(_("Cannot find form - %s") % form_name)
raise ValidationError(_("Cannot find form - %s\nOr > 1 form with the same name)") % form_name)
content, content_type = report._render_qweb_pdf(self.id)
return base64.b64encode(content).decode()
return ""
Expand Down Expand Up @@ -225,7 +226,7 @@ def _send_to_frappe(self, doc_data, form_type, form_name, pdf_content):
"name": "%s_signed.pdf" % self.name,
"datas": base64.b64encode(requests.get(pdf_url).content),
"type": "binary",
"res_model": "account.move",
"res_model": self._name,
"res_id": self.id,
}
)
Expand All @@ -235,11 +236,20 @@ def _send_to_frappe(self, doc_data, form_type, form_name, pdf_content):
"name": "%s_signed.xml" % self.name,
"datas": base64.b64encode(requests.get(xml_url).content),
"type": "binary",
"res_model": "account.move",
"res_model": self._name,
"res_id": self.id,
}
)
except Exception as e:
self.etax_status = "error"
self.etax_error_message = str(e)

def button_etax_invoices(self):
self.ensure_one()
return {
"name": _("Sign e-Tax Invoice"),
"type": "ir.actions.act_window",
"view_mode": "form",
"res_model": "wizard.select.etax.doctype",
"target": "new",
}
1 change: 0 additions & 1 deletion frappe_etax_service/views/account_move_views.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>

<!--
decoration-info
decoration-success
Expand Down
123 changes: 123 additions & 0 deletions frappe_etax_service/views/account_payment_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>

<record id="view_account_payment_tree" model="ir.ui.view">
<field name="name">account.view.account.payment.tree</field>
<field name="model">account.payment</field>
<field name="inherit_id" ref="account.view_account_payment_tree" />
<field name="arch" type="xml">
<xpath expr="//field[@name='state']" position="after">
<field
name="etax_status"
widget="badge"
decoration-success="etax_status=='success'"
decoration-danger="etax_status=='error'"
decoration-warning="etax_status in ['processing', 'to_process']"
optional="show"
/>
</xpath>
</field>
</record>

<record id="view_account_payment_form" model="ir.ui.view">
<field name="name">view.account.payment.form</field>
<field name="model">account.payment</field>
<field name="inherit_id" ref="l10n_th_account_tax.view_account_payment_form" />
<field name="arch" type="xml">
<xpath expr="//header" position="after">
<field name="etax_status" invisible="1" />
<div
groups="account.group_account_invoice,account.group_account_readonly"
class="text-right alert alert-success"
role="alert"
attrs="{'invisible': [('etax_status', 'not in', ('success'))]}"
>
Digitally signed eTax invoice
</div>
</xpath>
<xpath expr="//button[@name='mark_as_sent']" position="after">
<button
string='e-Tax Invoice'
name="button_etax_invoices"
type="object"
class="btn-info"
attrs="{
'invisible': ['|', '|',
('etax_status', 'in', ['success']),
('state', 'not in', ('posted')),
('tax_invoice_ids', '=', [])
]
}"
/>
<!-- <button
string='Create Replacement e-Tax'
name="frappe_etax_service.action_select_replacement_purpose_view"
type="action"
attrs="{'invisible': ['|', ('etax_status', '!=', 'success'), ('state', '!=', 'posted')]}"
/> -->
</xpath>
<xpath expr="//page[@name='tax_invoice']" position="after">
<page
id="frappe_etax_service"
string="e-Tax Info"
attrs="{'invisible': [('tax_invoice_ids', '=', [])]}"
>
<group>
<group string="e-Tax">
<field
name="etax_doctype"
string="Doctype"
readonly="1"
force_save="1"
/>
<field
name="etax_status"
string="Status"
widget="badge"
decoration-success="etax_status=='success'"
decoration-danger="etax_status=='error'"
decoration-warning="etax_status in ['processing', 'to_process']"
readonly="1"
force_save="1"
/>
<field
name="etax_transaction_code"
string="Transaction code"
readonly="1"
force_save="1"
/>
<field
name="etax_error_code"
string="Error code"
readonly="1"
force_save="1"
/>
<field
name="etax_error_message"
string="Error message"
readonly="1"
force_save="1"
/>
</group>
<group>
</group>
<!-- <group string="Additional Information">
<field
name="replaced_entry_id"
attrs="{'invisible': [('replaced_entry_id', '=', False)]}"
/>
<field
name="create_purpose_code"
attrs="{'required': [('replaced_entry_id', '!=', False)]}"
/>
<field
name="create_purpose"
attrs="{'required': [('replaced_entry_id', '!=', False)]}"
/>
</group> -->
</group>
</page>
</xpath>
</field>
</record>
</odoo>
7 changes: 0 additions & 7 deletions frappe_etax_service/views/doctype_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@
<group>
<group>
<field name="name" />
<field
name="report_template_id"
options="{'no_create': True, 'no_open': True,
'exclusive_selection': True}"
attrs="{'invisible': [('doc_source_template','!=', 'odoo')]}"
/>
<field name="move_type" />
<field name="doctype_code" />
</group>
Expand All @@ -32,7 +26,6 @@
<field name="arch" type="xml">
<tree>
<field name="name" />
<field name="report_template_id" />
<field name="doc_source_template" />
<field name="doctype_code" />
</tree>
Expand Down
Loading