Skip to content

Commit

Permalink
/
Browse files Browse the repository at this point in the history
  • Loading branch information
kittiu committed Jul 30, 2023
1 parent 69feb16 commit 7fb5978
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 9 deletions.
38 changes: 31 additions & 7 deletions thai_tax/custom/custom_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,16 @@ def create_tax_invoice(doc, doctype, base_amount, tax_amount, voucher):
fields=["party"],
)
party = gl and gl[0].get("party")
# Case use Journal Entry
# Case Journal Entry
if not party and doc.voucher_type == "Journal Entry":
party = voucher.supplier
if doctype == "Sales Tax Invoice":
if not voucher.customer:
frappe.throw(_("Customer is required for Sales Tax Invoice"))
party = voucher.customer
if doctype == "Purchase Tax Invoice":
if not voucher.supplier:
frappe.throw(_("Supplier is required for Purchase Tax Invoice"))
party = voucher.supplier
je = frappe.get_doc(doc.voucher_type, doc.voucher_no)
if je.for_payment:
tinv_dict.update(
Expand Down Expand Up @@ -348,8 +355,11 @@ def get_uncleared_tax_amount(gl, payment_type):
return uncleared_tax


def is_tax_reset(doc, old_doc, tax_accounts):
def is_tax_reset(doc, tax_accounts):
# For new doc, or has tax changes, do the reset
if doc.docstatus != 0:
return False
old_doc = doc.get_doc_before_save()
if old_doc:
old_tax_lines = list(filter(lambda l: l.account in tax_accounts, old_doc.accounts))
new_tax_lines = list(filter(lambda l: l.account in tax_accounts, doc.accounts))
Expand All @@ -363,6 +373,10 @@ def is_tax_reset(doc, old_doc, tax_accounts):
old_line.tax_base_amount != new_line.tax_base_amount
or old_line.debit != new_line.debit
or old_line.credit != new_line.credit
or old_line.supplier != new_line.supplier
or old_line.customer != new_line.customer
or old_line.tax_invoice_number != new_line.tax_invoice_number
or str(old_line.tax_invoice_date) != str(new_line.tax_invoice_date)
):
return True
else:
Expand All @@ -376,11 +390,11 @@ def prepare_journal_entry_tax_invoice_detail(doc, method):
precision = get_field_precision(
frappe.get_meta("Journal Entry Tax Invoice Detail").get_field("tax_base_amount")
)
old_doc = doc.get_doc_before_save()
reset_tax = is_tax_reset(doc, old_doc, tax_accounts)
# Reset Tax Invoice Table
reset_tax = is_tax_reset(doc, tax_accounts)
if reset_tax:
for tax_invoice in doc.tax_invoice_details:
tax_invoice.delete()
for d in doc.tax_invoice_details:
d.delete()
for tax_line in filter(lambda l: l.account in tax_accounts, doc.accounts):
tax_rate = frappe.get_cached_value("Account", tax_line.account, "tax_rate")
tax_amount = abs(tax_line.debit - tax_line.credit)
Expand All @@ -391,13 +405,23 @@ def prepare_journal_entry_tax_invoice_detail(doc, method):
if not company_tax_address:
addrs = frappe.get_all("Address", {"is_your_company_address": 1}, pluck="name")
company_tax_address = len(addrs) == 1 and addrs[0] or ""
party_name = ""
if tax_line.customer:
party_name = frappe.get_doc("Customer", tax_line.customer).customer_name
if tax_line.supplier:
party_name = frappe.get_doc("Supplier", tax_line.supplier).supplier_name
tinv_detail = frappe.get_doc(
{
"doctype": "Journal Entry Tax Invoice Detail",
"parenttype": "Journal Entry",
"parentfield": "tax_invoice_details",
"parent": doc.name,
"company_tax_address": company_tax_address,
"supplier": tax_line.supplier,
"customer": tax_line.customer,
"party_name": party_name,
"tax_invoice_number": tax_line.tax_invoice_number,
"tax_invoice_date": tax_line.tax_invoice_date,
"tax_base_amount": flt(tax_base_amount, precision),
"tax_amount": flt(tax_amount, precision),
}
Expand Down
6 changes: 6 additions & 0 deletions thai_tax/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,13 @@
"Journal Entry-for_payment",
"Journal Entry-section_break_pxm0e",
"Journal Entry-tax_invoice_details",
"Journal Entry Account-overwrite_tax_invoice",
"Journal Entry Account-tax_base_amount",
"Journal Entry Account-tax_invoice_number",
"Journal Entry Account-tax_invoice_date",
"Journal Entry Account-column_break_cun7x",
"Journal Entry Account-supplier",
"Journal Entry Account-customer",
"Payment Entry-tax_invoice_date",
"Payment Entry-tax_invoice_number",
"Payment Entry-company_tax_address",
Expand Down
34 changes: 34 additions & 0 deletions thai_tax/public/js/journal_entry.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
frappe.ui.form.on("Journal Entry", {
setup(frm) {
frm.add_fetch("customer", "customer_name", "party_name");
frm.add_fetch("supplier", "supplier_name", "party_name");
},
refresh(frm) {
frm.set_query("company_tax_address", function () {
return {
Expand All @@ -16,3 +20,33 @@ frappe.ui.form.on("Journal Entry", {
});
},
});

frappe.ui.form.on("Journal Entry Tax Invoice Detail", {
customer(frm, cdt, cdn) {
let row = locals[cdt][cdn];
if (row.customer) {
frappe.model.set_value(cdt, cdn, "supplier", "");
}
},
supplier(frm, cdt, cdn) {
let row = locals[cdt][cdn];
if (row.supplier) {
frappe.model.set_value(cdt, cdn, "customer", "");
}
},
});

frappe.ui.form.on("Journal Entry Account", {
customer(frm, cdt, cdn) {
let row = locals[cdt][cdn];
if (row.customer) {
frappe.model.set_value(cdt, cdn, "supplier", "");
}
},
supplier(frm, cdt, cdn) {
let row = locals[cdt][cdn];
if (row.supplier) {
frappe.model.set_value(cdt, cdn, "customer", "");
}
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,16 @@
"engine": "InnoDB",
"field_order": [
"company_tax_address",
"column_break_gg3aa",
"party_name",
"section_break_gh6bu",
"supplier",
"column_break_b7ziy",
"customer",
"section_break_rpmxt",
"tax_invoice_number",
"tax_invoice_date",
"column_break_bxvza",
"tax_base_amount",
"tax_amount"
],
Expand All @@ -23,7 +30,6 @@
{
"fieldname": "supplier",
"fieldtype": "Link",
"in_list_view": 1,
"label": "Supplier",
"options": "Supplier"
},
Expand Down Expand Up @@ -57,12 +63,45 @@
"label": "Tax Amount",
"precision": "2",
"read_only": 1
},
{
"fieldname": "customer",
"fieldtype": "Link",
"label": "Customer",
"options": "Customer"
},
{
"fieldname": "party_name",
"fieldtype": "Data",
"in_list_view": 1,
"label": "Party Name",
"read_only": 1
},
{
"fieldname": "column_break_gg3aa",
"fieldtype": "Column Break"
},
{
"fieldname": "section_break_gh6bu",
"fieldtype": "Section Break"
},
{
"fieldname": "column_break_b7ziy",
"fieldtype": "Column Break"
},
{
"fieldname": "section_break_rpmxt",
"fieldtype": "Section Break"
},
{
"fieldname": "column_break_bxvza",
"fieldtype": "Column Break"
}
],
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2023-07-30 13:53:14.465463",
"modified": "2023-07-30 15:33:54.967313",
"modified_by": "Administrator",
"module": "Thai Tax",
"name": "Journal Entry Tax Invoice Detail",
Expand Down

0 comments on commit 7fb5978

Please sign in to comment.