From 163b20ce8302b4dbac166ca601c7d397e90c1e40 Mon Sep 17 00:00:00 2001 From: Kitti U Date: Mon, 29 Jan 2024 18:46:33 +0700 Subject: [PATCH] FIX: create tax invoice from Journal Entry, use override party --- thai_tax/custom/custom_api.py | 16 ++-- thai_tax/fixtures/custom_field.json | 132 ++++++++++++++-------------- 2 files changed, 75 insertions(+), 73 deletions(-) diff --git a/thai_tax/custom/custom_api.py b/thai_tax/custom/custom_api.py index 74018b1..bc7e2aa 100644 --- a/thai_tax/custom/custom_api.py +++ b/thai_tax/custom/custom_api.py @@ -19,6 +19,8 @@ def create_tax_invoice_on_gl_tax(doc, method): is_return = False if doc.voucher_type in ["Sales Invoice", "Purchase Invoice"]: is_return = voucher.is_return # Case Debit/Credit Note + if doc.voucher_type == "Journal Entry": + is_return = voucher.reversal_of and True or False sign = is_return and -1 or 1 # Tax amount, use Dr/Cr to ensure it support every case if doc.account in [setting.sales_tax_account, setting.purchase_tax_account]: @@ -70,19 +72,19 @@ def create_tax_invoice(doc, doctype, base_amount, tax_amount, voucher): "voucher_no": doc.voucher_no, "party": ["!=", ""], }, - fields=["party"], + fields=["party", "party_type"], ) party = gl and gl[0].get("party") - # Case Journal Entry - if not party and doc.voucher_type == "Journal Entry": + party_type = gl and gl[0].get("party_type") + if doc.voucher_type == "Journal Entry": if doctype == "Sales Tax Invoice": - if not voucher.customer: + party = voucher.customer or party + if not party: frappe.throw(_("Customer is required for Sales Tax Invoice")) - party = voucher.customer if doctype == "Purchase Tax Invoice": - if not voucher.supplier: + party = voucher.supplier or party + if not party: 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( diff --git a/thai_tax/fixtures/custom_field.json b/thai_tax/fixtures/custom_field.json index 39a7a03..3054662 100644 --- a/thai_tax/fixtures/custom_field.json +++ b/thai_tax/fixtures/custom_field.json @@ -1945,21 +1945,21 @@ }, { "allow_in_quick_entry": 0, - "allow_on_submit": 0, + "allow_on_submit": 1, "bold": 0, "collapsible": 0, "collapsible_depends_on": null, "columns": 0, "default": null, - "depends_on": null, + "depends_on": "eval:doc.party_type=='Employee'", "description": null, "docstatus": 0, "doctype": "Custom Field", - "dt": "Sales Invoice", - "fetch_from": null, + "dt": "Payment Entry", + "fetch_from": "supplier.supplier_name", "fetch_if_empty": 0, - "fieldname": "tax_invoice", - "fieldtype": "Tab Break", + "fieldname": "supplier_name", + "fieldtype": "Data", "hidden": 0, "hide_border": 0, "hide_days": 0, @@ -1970,18 +1970,18 @@ "in_list_view": 0, "in_preview": 0, "in_standard_filter": 0, - "insert_after": "total_billing_amount", + "insert_after": "tax_invoice_date", "is_system_generated": 0, "is_virtual": 0, - "label": "Tax Invoice", + "label": "Supplier Name", "length": 0, "mandatory_depends_on": null, - "modified": "2023-03-04 12:30:55.408440", + "modified": "2023-04-30 15:46:05.824582", "module": null, - "name": "Sales Invoice-tax_invoice", - "no_copy": 0, + "name": "Payment Entry-supplier_name", + "no_copy": 1, "non_negative": 0, - "options": null, + "options": "", "permlevel": 0, "precision": "", "print_hide": 0, @@ -1993,27 +1993,27 @@ "reqd": 0, "search_index": 0, "sort_options": 0, - "translatable": 0, + "translatable": 1, "unique": 0, "width": null }, { "allow_in_quick_entry": 0, - "allow_on_submit": 1, + "allow_on_submit": 0, "bold": 0, "collapsible": 0, "collapsible_depends_on": null, "columns": 0, "default": null, - "depends_on": "eval:doc.party_type=='Employee'", + "depends_on": null, "description": null, "docstatus": 0, "doctype": "Custom Field", - "dt": "Payment Entry", - "fetch_from": "supplier.supplier_name", + "dt": "Sales Invoice", + "fetch_from": null, "fetch_if_empty": 0, - "fieldname": "supplier_name", - "fieldtype": "Data", + "fieldname": "tax_invoice", + "fieldtype": "Tab Break", "hidden": 0, "hide_border": 0, "hide_days": 0, @@ -2024,18 +2024,18 @@ "in_list_view": 0, "in_preview": 0, "in_standard_filter": 0, - "insert_after": "tax_invoice_date", + "insert_after": "total_billing_amount", "is_system_generated": 0, "is_virtual": 0, - "label": "Supplier Name", + "label": "Tax Invoice", "length": 0, "mandatory_depends_on": null, - "modified": "2023-04-30 15:46:05.824582", + "modified": "2023-03-04 12:30:55.408440", "module": null, - "name": "Payment Entry-supplier_name", - "no_copy": 1, + "name": "Sales Invoice-tax_invoice", + "no_copy": 0, "non_negative": 0, - "options": "", + "options": null, "permlevel": 0, "precision": "", "print_hide": 0, @@ -2047,7 +2047,7 @@ "reqd": 0, "search_index": 0, "sort_options": 0, - "translatable": 1, + "translatable": 0, "unique": 0, "width": null }, @@ -2110,18 +2110,18 @@ "allow_on_submit": 0, "bold": 0, "collapsible": 0, - "collapsible_depends_on": "", + "collapsible_depends_on": null, "columns": 0, "default": null, "depends_on": null, "description": null, "docstatus": 0, "doctype": "Custom Field", - "dt": "Sales Invoice", + "dt": "Purchase Invoice", "fetch_from": null, "fetch_if_empty": 0, - "fieldname": "column_break_cijbv", - "fieldtype": "Column Break", + "fieldname": "tax_invoice", + "fieldtype": "Tab Break", "hidden": 0, "hide_border": 0, "hide_days": 0, @@ -2132,15 +2132,15 @@ "in_list_view": 0, "in_preview": 0, "in_standard_filter": 0, - "insert_after": "tax_invoice_number", + "insert_after": "supplied_items", "is_system_generated": 0, "is_virtual": 0, - "label": "", + "label": "Tax Invoice", "length": 0, "mandatory_depends_on": null, - "modified": "2023-03-04 12:33:18.257218", + "modified": "2023-03-04 12:19:58.948151", "module": null, - "name": "Sales Invoice-column_break_cijbv", + "name": "Purchase Invoice-tax_invoice", "no_copy": 0, "non_negative": 0, "options": null, @@ -2150,7 +2150,7 @@ "print_hide_if_no_value": 0, "print_width": null, "read_only": 0, - "read_only_depends_on": null, + "read_only_depends_on": "", "report_hide": 0, "reqd": 0, "search_index": 0, @@ -2164,18 +2164,18 @@ "allow_on_submit": 0, "bold": 0, "collapsible": 0, - "collapsible_depends_on": null, + "collapsible_depends_on": "", "columns": 0, "default": null, "depends_on": null, "description": null, "docstatus": 0, "doctype": "Custom Field", - "dt": "Purchase Invoice", + "dt": "Sales Invoice", "fetch_from": null, "fetch_if_empty": 0, - "fieldname": "tax_invoice", - "fieldtype": "Tab Break", + "fieldname": "column_break_cijbv", + "fieldtype": "Column Break", "hidden": 0, "hide_border": 0, "hide_days": 0, @@ -2186,15 +2186,15 @@ "in_list_view": 0, "in_preview": 0, "in_standard_filter": 0, - "insert_after": "supplied_items", + "insert_after": "tax_invoice_number", "is_system_generated": 0, "is_virtual": 0, - "label": "Tax Invoice", + "label": "", "length": 0, "mandatory_depends_on": null, - "modified": "2023-03-04 12:19:58.948151", + "modified": "2023-03-04 12:33:18.257218", "module": null, - "name": "Purchase Invoice-tax_invoice", + "name": "Sales Invoice-column_break_cijbv", "no_copy": 0, "non_negative": 0, "options": null, @@ -2204,7 +2204,7 @@ "print_hide_if_no_value": 0, "print_width": null, "read_only": 0, - "read_only_depends_on": "", + "read_only_depends_on": null, "report_hide": 0, "reqd": 0, "search_index": 0, @@ -2225,11 +2225,11 @@ "description": null, "docstatus": 0, "doctype": "Custom Field", - "dt": "Sales Invoice", + "dt": "Purchase Invoice", "fetch_from": null, "fetch_if_empty": 0, - "fieldname": "tax_invoice_date", - "fieldtype": "Date", + "fieldname": "tax_invoice_number", + "fieldtype": "Data", "hidden": 0, "hide_border": 0, "hide_days": 0, @@ -2237,18 +2237,18 @@ "ignore_user_permissions": 0, "ignore_xss_filter": 0, "in_global_search": 0, - "in_list_view": 0, + "in_list_view": 1, "in_preview": 0, - "in_standard_filter": 0, - "insert_after": "column_break_cijbv", + "in_standard_filter": 1, + "insert_after": "tax_invoice", "is_system_generated": 0, "is_virtual": 0, - "label": "Tax Invoice Date", + "label": "Tax Invoice Number", "length": 0, "mandatory_depends_on": null, - "modified": "2023-03-19 19:48:52.251588", + "modified": "2023-03-04 12:24:47.559568", "module": null, - "name": "Sales Invoice-tax_invoice_date", + "name": "Purchase Invoice-tax_invoice_number", "no_copy": 1, "non_negative": 0, "options": null, @@ -2257,8 +2257,8 @@ "print_hide": 0, "print_hide_if_no_value": 0, "print_width": null, - "read_only": 1, - "read_only_depends_on": null, + "read_only": 0, + "read_only_depends_on": "eval:doc.docstatus!=0", "report_hide": 0, "reqd": 0, "search_index": 0, @@ -2279,11 +2279,11 @@ "description": null, "docstatus": 0, "doctype": "Custom Field", - "dt": "Purchase Invoice", + "dt": "Sales Invoice", "fetch_from": null, "fetch_if_empty": 0, - "fieldname": "tax_invoice_number", - "fieldtype": "Data", + "fieldname": "tax_invoice_date", + "fieldtype": "Date", "hidden": 0, "hide_border": 0, "hide_days": 0, @@ -2291,18 +2291,18 @@ "ignore_user_permissions": 0, "ignore_xss_filter": 0, "in_global_search": 0, - "in_list_view": 1, + "in_list_view": 0, "in_preview": 0, - "in_standard_filter": 1, - "insert_after": "tax_invoice", + "in_standard_filter": 0, + "insert_after": "column_break_cijbv", "is_system_generated": 0, "is_virtual": 0, - "label": "Tax Invoice Number", + "label": "Tax Invoice Date", "length": 0, "mandatory_depends_on": null, - "modified": "2023-03-04 12:24:47.559568", + "modified": "2023-03-19 19:48:52.251588", "module": null, - "name": "Purchase Invoice-tax_invoice_number", + "name": "Sales Invoice-tax_invoice_date", "no_copy": 1, "non_negative": 0, "options": null, @@ -2311,8 +2311,8 @@ "print_hide": 0, "print_hide_if_no_value": 0, "print_width": null, - "read_only": 0, - "read_only_depends_on": "eval:doc.docstatus!=0", + "read_only": 1, + "read_only_depends_on": null, "report_hide": 0, "reqd": 0, "search_index": 0,