Browse Source
* fix: RCM tax calculation * feat(India): ITC Reversal via Journal Entry * fix: Reverse Charge booking logic and validation * fix: Addd patch for availed ITC fields * fix: Hooks method to update availed ITC field * fix: Cleanup and fixes in GSTR3B report * fix: Update params in GSTR-1 report * fix: Debit note using Sales Invoice * fix: Setup and patch * fix: GSTR 3B report cleanup and updates * fix: Add method to get invoices liable to reverse charge * fix: Add taxable value in Purchase Invoice Item * fix: Inward supplies liable to reverse charge * fix: Linting issues * fix: GSTR3B report testdevelop
Deepesh Garg
3 years ago
committed by
GitHub
14 changed files with 811 additions and 662 deletions
@ -1,196 +1,82 @@ |
|||
{ |
|||
"allow_copy": 0, |
|||
"allow_guest_to_view": 0, |
|||
"allow_import": 0, |
|||
"allow_rename": 0, |
|||
"beta": 0, |
|||
"creation": "2018-01-02 15:48:58.768352", |
|||
"custom": 0, |
|||
"docstatus": 0, |
|||
"doctype": "DocType", |
|||
"document_type": "", |
|||
"editable_grid": 1, |
|||
"engine": "InnoDB", |
|||
"actions": [], |
|||
"creation": "2018-01-02 15:48:58.768352", |
|||
"doctype": "DocType", |
|||
"editable_grid": 1, |
|||
"engine": "InnoDB", |
|||
"field_order": [ |
|||
"company", |
|||
"cgst_account", |
|||
"sgst_account", |
|||
"igst_account", |
|||
"cess_account", |
|||
"is_reverse_charge_account" |
|||
], |
|||
"fields": [ |
|||
{ |
|||
"allow_bulk_edit": 0, |
|||
"allow_on_submit": 0, |
|||
"bold": 0, |
|||
"collapsible": 0, |
|||
"columns": 0, |
|||
"fieldname": "company", |
|||
"fieldtype": "Link", |
|||
"hidden": 0, |
|||
"ignore_user_permissions": 0, |
|||
"ignore_xss_filter": 0, |
|||
"in_filter": 0, |
|||
"in_global_search": 0, |
|||
"in_list_view": 1, |
|||
"in_standard_filter": 0, |
|||
"label": "Company", |
|||
"length": 0, |
|||
"no_copy": 0, |
|||
"options": "Company", |
|||
"permlevel": 0, |
|||
"precision": "", |
|||
"print_hide": 0, |
|||
"print_hide_if_no_value": 0, |
|||
"read_only": 0, |
|||
"remember_last_selected_value": 0, |
|||
"report_hide": 0, |
|||
"reqd": 1, |
|||
"search_index": 0, |
|||
"set_only_once": 0, |
|||
"unique": 0 |
|||
}, |
|||
"columns": 1, |
|||
"fieldname": "company", |
|||
"fieldtype": "Link", |
|||
"in_list_view": 1, |
|||
"label": "Company", |
|||
"options": "Company", |
|||
"reqd": 1 |
|||
}, |
|||
{ |
|||
"allow_bulk_edit": 0, |
|||
"allow_on_submit": 0, |
|||
"bold": 0, |
|||
"collapsible": 0, |
|||
"columns": 0, |
|||
"fieldname": "cgst_account", |
|||
"fieldtype": "Link", |
|||
"hidden": 0, |
|||
"ignore_user_permissions": 0, |
|||
"ignore_xss_filter": 0, |
|||
"in_filter": 0, |
|||
"in_global_search": 0, |
|||
"in_list_view": 1, |
|||
"in_standard_filter": 0, |
|||
"label": "CGST Account", |
|||
"length": 0, |
|||
"no_copy": 0, |
|||
"options": "Account", |
|||
"permlevel": 0, |
|||
"precision": "", |
|||
"print_hide": 0, |
|||
"print_hide_if_no_value": 0, |
|||
"read_only": 0, |
|||
"remember_last_selected_value": 0, |
|||
"report_hide": 0, |
|||
"reqd": 1, |
|||
"search_index": 0, |
|||
"set_only_once": 0, |
|||
"unique": 0 |
|||
}, |
|||
"columns": 2, |
|||
"fieldname": "cgst_account", |
|||
"fieldtype": "Link", |
|||
"in_list_view": 1, |
|||
"label": "CGST Account", |
|||
"options": "Account", |
|||
"reqd": 1 |
|||
}, |
|||
{ |
|||
"allow_bulk_edit": 0, |
|||
"allow_on_submit": 0, |
|||
"bold": 0, |
|||
"collapsible": 0, |
|||
"columns": 0, |
|||
"fieldname": "sgst_account", |
|||
"fieldtype": "Link", |
|||
"hidden": 0, |
|||
"ignore_user_permissions": 0, |
|||
"ignore_xss_filter": 0, |
|||
"in_filter": 0, |
|||
"in_global_search": 0, |
|||
"in_list_view": 1, |
|||
"in_standard_filter": 0, |
|||
"label": "SGST Account", |
|||
"length": 0, |
|||
"no_copy": 0, |
|||
"options": "Account", |
|||
"permlevel": 0, |
|||
"precision": "", |
|||
"print_hide": 0, |
|||
"print_hide_if_no_value": 0, |
|||
"read_only": 0, |
|||
"remember_last_selected_value": 0, |
|||
"report_hide": 0, |
|||
"reqd": 1, |
|||
"search_index": 0, |
|||
"set_only_once": 0, |
|||
"unique": 0 |
|||
}, |
|||
"columns": 2, |
|||
"fieldname": "sgst_account", |
|||
"fieldtype": "Link", |
|||
"in_list_view": 1, |
|||
"label": "SGST Account", |
|||
"options": "Account", |
|||
"reqd": 1 |
|||
}, |
|||
{ |
|||
"allow_bulk_edit": 0, |
|||
"allow_on_submit": 0, |
|||
"bold": 0, |
|||
"collapsible": 0, |
|||
"columns": 0, |
|||
"fieldname": "igst_account", |
|||
"fieldtype": "Link", |
|||
"hidden": 0, |
|||
"ignore_user_permissions": 0, |
|||
"ignore_xss_filter": 0, |
|||
"in_filter": 0, |
|||
"in_global_search": 0, |
|||
"in_list_view": 1, |
|||
"in_standard_filter": 0, |
|||
"label": "IGST Account", |
|||
"length": 0, |
|||
"no_copy": 0, |
|||
"options": "Account", |
|||
"permlevel": 0, |
|||
"precision": "", |
|||
"print_hide": 0, |
|||
"print_hide_if_no_value": 0, |
|||
"read_only": 0, |
|||
"remember_last_selected_value": 0, |
|||
"report_hide": 0, |
|||
"reqd": 1, |
|||
"search_index": 0, |
|||
"set_only_once": 0, |
|||
"unique": 0 |
|||
}, |
|||
"columns": 2, |
|||
"fieldname": "igst_account", |
|||
"fieldtype": "Link", |
|||
"in_list_view": 1, |
|||
"label": "IGST Account", |
|||
"options": "Account", |
|||
"reqd": 1 |
|||
}, |
|||
{ |
|||
"allow_bulk_edit": 0, |
|||
"allow_on_submit": 0, |
|||
"bold": 0, |
|||
"collapsible": 0, |
|||
"columns": 0, |
|||
"fieldname": "cess_account", |
|||
"fieldtype": "Link", |
|||
"hidden": 0, |
|||
"ignore_user_permissions": 0, |
|||
"ignore_xss_filter": 0, |
|||
"in_filter": 0, |
|||
"in_global_search": 0, |
|||
"in_list_view": 1, |
|||
"in_standard_filter": 0, |
|||
"label": "CESS Account", |
|||
"length": 0, |
|||
"no_copy": 0, |
|||
"options": "Account", |
|||
"permlevel": 0, |
|||
"precision": "", |
|||
"print_hide": 0, |
|||
"print_hide_if_no_value": 0, |
|||
"read_only": 0, |
|||
"remember_last_selected_value": 0, |
|||
"report_hide": 0, |
|||
"reqd": 0, |
|||
"search_index": 0, |
|||
"set_only_once": 0, |
|||
"unique": 0 |
|||
"columns": 2, |
|||
"fieldname": "cess_account", |
|||
"fieldtype": "Link", |
|||
"in_list_view": 1, |
|||
"label": "CESS Account", |
|||
"options": "Account" |
|||
}, |
|||
{ |
|||
"columns": 1, |
|||
"default": "0", |
|||
"fieldname": "is_reverse_charge_account", |
|||
"fieldtype": "Check", |
|||
"in_list_view": 1, |
|||
"label": "Is Reverse Charge Account" |
|||
} |
|||
], |
|||
"has_web_view": 0, |
|||
"hide_heading": 0, |
|||
"hide_toolbar": 0, |
|||
"idx": 0, |
|||
"image_view": 0, |
|||
"in_create": 0, |
|||
"is_submittable": 0, |
|||
"issingle": 0, |
|||
"istable": 1, |
|||
"max_attachments": 0, |
|||
"modified": "2018-01-02 15:52:22.335988", |
|||
"modified_by": "Administrator", |
|||
"module": "Accounts", |
|||
"name": "GST Account", |
|||
"name_case": "", |
|||
"owner": "Administrator", |
|||
"permissions": [], |
|||
"quick_entry": 1, |
|||
"read_only": 0, |
|||
"read_only_onload": 0, |
|||
"show_name_in_global_search": 0, |
|||
"sort_field": "modified", |
|||
"sort_order": "DESC", |
|||
"track_changes": 1, |
|||
"track_seen": 0 |
|||
], |
|||
"index_web_pages_for_search": 1, |
|||
"istable": 1, |
|||
"links": [], |
|||
"modified": "2021-04-09 12:30:25.889993", |
|||
"modified_by": "Administrator", |
|||
"module": "Accounts", |
|||
"name": "GST Account", |
|||
"owner": "Administrator", |
|||
"permissions": [], |
|||
"quick_entry": 1, |
|||
"sort_field": "modified", |
|||
"sort_order": "DESC", |
|||
"track_changes": 1 |
|||
} |
@ -0,0 +1,115 @@ |
|||
from __future__ import unicode_literals |
|||
import frappe |
|||
from frappe.custom.doctype.custom_field.custom_field import create_custom_fields |
|||
from frappe.custom.doctype.property_setter.property_setter import make_property_setter |
|||
from erpnext.regional.india.utils import get_gst_accounts |
|||
|
|||
def execute(): |
|||
company = frappe.get_all('Company', filters = {'country': 'India'}, fields=['name']) |
|||
if not company: |
|||
return |
|||
|
|||
frappe.reload_doc("regional", "doctype", "gst_settings") |
|||
frappe.reload_doc("accounts", "doctype", "gst_account") |
|||
|
|||
journal_entry_types = frappe.get_meta("Journal Entry").get_options("voucher_type").split("\n") + ['Reversal Of ITC'] |
|||
make_property_setter('Journal Entry', 'voucher_type', 'options', '\n'.join(journal_entry_types), '') |
|||
|
|||
custom_fields = { |
|||
'Journal Entry': [ |
|||
dict(fieldname='reversal_type', label='Reversal Type', |
|||
fieldtype='Select', insert_after='voucher_type', print_hide=1, |
|||
options="As per rules 42 & 43 of CGST Rules\nOthers", |
|||
depends_on="eval:doc.voucher_type=='Reversal Of ITC'", |
|||
mandatory_depends_on="eval:doc.voucher_type=='Reversal Of ITC'"), |
|||
dict(fieldname='company_address', label='Company Address', |
|||
fieldtype='Link', options='Address', insert_after='reversal_type', |
|||
print_hide=1, depends_on="eval:doc.voucher_type=='Reversal Of ITC'", |
|||
mandatory_depends_on="eval:doc.voucher_type=='Reversal Of ITC'"), |
|||
dict(fieldname='company_gstin', label='Company GSTIN', |
|||
fieldtype='Data', read_only=1, insert_after='company_address', print_hide=1, |
|||
fetch_from='company_address.gstin', |
|||
depends_on="eval:doc.voucher_type=='Reversal Of ITC'", |
|||
mandatory_depends_on="eval:doc.voucher_type=='Reversal Of ITC'") |
|||
], |
|||
'Purchase Invoice': [ |
|||
dict(fieldname='eligibility_for_itc', label='Eligibility For ITC', |
|||
fieldtype='Select', insert_after='reason_for_issuing_document', print_hide=1, |
|||
options='Input Service Distributor\nImport Of Service\nImport Of Capital Goods\nITC on Reverse Charge\nIneligible As Per Section 17(5)\nIneligible Others\nAll Other ITC', |
|||
default="All Other ITC") |
|||
], |
|||
'Purchase Invoice Item': [ |
|||
dict(fieldname='taxable_value', label='Taxable Value', |
|||
fieldtype='Currency', insert_after='base_net_amount', hidden=1, options="Company:company:default_currency", |
|||
print_hide=1) |
|||
] |
|||
} |
|||
|
|||
create_custom_fields(custom_fields, update=True) |
|||
|
|||
# Patch ITC Availed fields from Data to Currency |
|||
# Patch Availed ITC for current fiscal_year |
|||
|
|||
gst_accounts = get_gst_accounts(only_non_reverse_charge=1) |
|||
|
|||
frappe.db.sql(""" |
|||
UPDATE `tabCustom Field` SET fieldtype='Currency', options='Company:company:default_currency' |
|||
WHERE dt = 'Purchase Invoice' and fieldname in ('itc_integrated_tax', 'itc_state_tax', 'itc_central_tax', |
|||
'itc_cess_amount') |
|||
""") |
|||
|
|||
frappe.db.sql("""UPDATE `tabPurchase Invoice` set itc_integrated_tax = '0' |
|||
WHERE trim(coalesce(itc_integrated_tax, '')) = '' """) |
|||
|
|||
frappe.db.sql("""UPDATE `tabPurchase Invoice` set itc_state_tax = '0' |
|||
WHERE trim(coalesce(itc_state_tax, '')) = '' """) |
|||
|
|||
frappe.db.sql("""UPDATE `tabPurchase Invoice` set itc_central_tax = '0' |
|||
WHERE trim(coalesce(itc_central_tax, '')) = '' """) |
|||
|
|||
frappe.db.sql("""UPDATE `tabPurchase Invoice` set itc_cess_amount = '0' |
|||
WHERE trim(coalesce(itc_cess_amount, '')) = '' """) |
|||
|
|||
# Get purchase invoices |
|||
invoices = frappe.get_all('Purchase Invoice', |
|||
{'posting_date': ('>=', '2021-04-01'), 'eligibility_for_itc': ('!=', 'Ineligible')}, |
|||
['name']) |
|||
|
|||
amount_map = {} |
|||
|
|||
if invoices: |
|||
invoice_list = set([d.name for d in invoices]) |
|||
|
|||
# Get GST applied |
|||
amounts = frappe.db.sql(""" |
|||
SELECT parent, account_head, sum(base_tax_amount_after_discount_amount) as amount |
|||
FROM `tabPurchase Taxes and Charges` |
|||
where parent in %s |
|||
GROUP BY parent, account_head |
|||
""", (invoice_list), as_dict=1) |
|||
|
|||
for d in amounts: |
|||
amount_map.setdefault(d.parent, |
|||
{ |
|||
'itc_integrated_tax': 0, |
|||
'itc_state_tax': 0, |
|||
'itc_central_tax': 0, |
|||
'itc_cess_amount': 0 |
|||
}) |
|||
|
|||
if d.account_head in gst_accounts.get('igst_account'): |
|||
amount_map[d.parent]['itc_integrated_tax'] += d.amount |
|||
if d.account_head in gst_accounts.get('cgst_account'): |
|||
amount_map[d.parent]['itc_central_tax'] += d.amount |
|||
if d.account_head in gst_accounts.get('sgst_account'): |
|||
amount_map[d.parent]['itc_state_tax'] += d.amount |
|||
if d.account_head in gst_accounts.get('cess_account'): |
|||
amount_map[d.parent]['itc_cess_amount'] += d.amount |
|||
|
|||
for invoice, values in amount_map.items(): |
|||
frappe.db.set_value('Purchase Invoice', invoice, { |
|||
'itc_integrated_tax': values.get('itc_integrated_tax'), |
|||
'itc_central_tax': values.get('itc_central_tax'), |
|||
'itc_state_tax': values['itc_state_tax'], |
|||
'itc_cess_amount': values['itc_cess_amount'], |
|||
}) |
@ -0,0 +1,127 @@ |
|||
{ |
|||
"gstin": "", |
|||
"ret_period": "", |
|||
"inward_sup": { |
|||
"isup_details": [ |
|||
{ |
|||
"ty": "GST", |
|||
"intra": 0, |
|||
"inter": 0 |
|||
}, |
|||
{ |
|||
"ty": "NONGST", |
|||
"inter": 0, |
|||
"intra": 0 |
|||
} |
|||
] |
|||
}, |
|||
"sup_details": { |
|||
"osup_zero": { |
|||
"csamt": 0, |
|||
"txval": 0, |
|||
"iamt": 0 |
|||
}, |
|||
"osup_nil_exmp": { |
|||
"txval": 0 |
|||
}, |
|||
"osup_det": { |
|||
"samt": 0, |
|||
"csamt": 0, |
|||
"txval": 0, |
|||
"camt": 0, |
|||
"iamt": 0 |
|||
}, |
|||
"isup_rev": { |
|||
"samt": 0, |
|||
"csamt": 0, |
|||
"txval": 0, |
|||
"camt": 0, |
|||
"iamt": 0 |
|||
}, |
|||
"osup_nongst": { |
|||
"txval": 0 |
|||
} |
|||
}, |
|||
"inter_sup": { |
|||
"unreg_details": [], |
|||
"comp_details": [], |
|||
"uin_details": [] |
|||
}, |
|||
"itc_elg": { |
|||
"itc_avl": [ |
|||
{ |
|||
"csamt": 0, |
|||
"samt": 0, |
|||
"ty": "IMPG", |
|||
"camt": 0, |
|||
"iamt": 0 |
|||
}, |
|||
{ |
|||
"csamt": 0, |
|||
"samt": 0, |
|||
"ty": "IMPS", |
|||
"camt": 0, |
|||
"iamt": 0 |
|||
}, |
|||
{ |
|||
"samt": 0, |
|||
"csamt": 0, |
|||
"ty": "ISRC", |
|||
"camt": 0, |
|||
"iamt": 0 |
|||
}, |
|||
{ |
|||
"ty": "ISD", |
|||
"iamt": 0, |
|||
"camt": 0, |
|||
"samt": 0, |
|||
"csamt": 0 |
|||
}, |
|||
{ |
|||
"samt": 0, |
|||
"csamt": 0, |
|||
"ty": "OTH", |
|||
"camt": 0, |
|||
"iamt": 0 |
|||
} |
|||
], |
|||
"itc_rev": [ |
|||
{ |
|||
"ty": "RUL", |
|||
"iamt": 0, |
|||
"camt": 0, |
|||
"samt": 0, |
|||
"csamt": 0 |
|||
}, |
|||
{ |
|||
"ty": "OTH", |
|||
"iamt": 0, |
|||
"camt": 0, |
|||
"samt": 0, |
|||
"csamt": 0 |
|||
} |
|||
], |
|||
"itc_net": { |
|||
"samt": 0, |
|||
"csamt": 0, |
|||
"camt": 0, |
|||
"iamt": 0 |
|||
}, |
|||
"itc_inelg": [ |
|||
{ |
|||
"ty": "RUL", |
|||
"iamt": 0, |
|||
"camt": 0, |
|||
"samt": 0, |
|||
"csamt": 0 |
|||
}, |
|||
{ |
|||
"ty": "OTH", |
|||
"iamt": 0, |
|||
"camt": 0, |
|||
"samt": 0, |
|||
"csamt": 0 |
|||
} |
|||
] |
|||
} |
|||
} |
Loading…
Reference in new issue