mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-22 14:39:19 +00:00
Merge pull request #24162 from deepeshgarg007/template_update_v12_pre
fix(India): Taxation fixes
This commit is contained in:
@@ -9,6 +9,9 @@ erpnext.setup_auto_gst_taxation = (doctype) => {
|
|||||||
tax_category: function(frm) {
|
tax_category: function(frm) {
|
||||||
frm.trigger('get_tax_template');
|
frm.trigger('get_tax_template');
|
||||||
},
|
},
|
||||||
|
customer_address: function(frm) {
|
||||||
|
frm.trigger('get_tax_template');
|
||||||
|
},
|
||||||
get_tax_template: function(frm) {
|
get_tax_template: function(frm) {
|
||||||
if (!frm.doc.company) return;
|
if (!frm.doc.company) return;
|
||||||
|
|
||||||
@@ -16,6 +19,7 @@ erpnext.setup_auto_gst_taxation = (doctype) => {
|
|||||||
'shipping_address': frm.doc.shipping_address || '',
|
'shipping_address': frm.doc.shipping_address || '',
|
||||||
'shipping_address_name': frm.doc.shipping_address_name || '',
|
'shipping_address_name': frm.doc.shipping_address_name || '',
|
||||||
'customer_address': frm.doc.customer_address || '',
|
'customer_address': frm.doc.customer_address || '',
|
||||||
|
'supplier_address': frm.doc.supplier_address,
|
||||||
'customer': frm.doc.customer,
|
'customer': frm.doc.customer,
|
||||||
'supplier': frm.doc.supplier,
|
'supplier': frm.doc.supplier,
|
||||||
'supplier_gstin': frm.doc.supplier_gstin,
|
'supplier_gstin': frm.doc.supplier_gstin,
|
||||||
@@ -28,12 +32,15 @@ erpnext.setup_auto_gst_taxation = (doctype) => {
|
|||||||
args: {
|
args: {
|
||||||
party_details: JSON.stringify(party_details),
|
party_details: JSON.stringify(party_details),
|
||||||
doctype: frm.doc.doctype,
|
doctype: frm.doc.doctype,
|
||||||
company: frm.doc.company,
|
company: frm.doc.company
|
||||||
return_taxes: 1
|
|
||||||
},
|
},
|
||||||
callback: function(r) {
|
callback: function(r) {
|
||||||
if(r.message) {
|
if(r.message) {
|
||||||
frm.set_value('taxes_and_charges', r.message.taxes_and_charges);
|
frm.set_value('taxes_and_charges', r.message.taxes_and_charges);
|
||||||
|
frm.set_value('place_of_supply', r.message.place_of_supply);
|
||||||
|
} else if (frm.doc.is_internal_supplier || frm.doc.is_internal_customer) {
|
||||||
|
frm.set_value('taxes_and_charges', '');
|
||||||
|
frm.set_value('taxes', []);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ from erpnext.regional.india import number_state_mapping
|
|||||||
from six import string_types
|
from six import string_types
|
||||||
from erpnext.accounts.general_ledger import make_gl_entries
|
from erpnext.accounts.general_ledger import make_gl_entries
|
||||||
from erpnext.accounts.utils import get_account_currency
|
from erpnext.accounts.utils import get_account_currency
|
||||||
|
from frappe.model.utils import get_fetch_values
|
||||||
|
|
||||||
def validate_gstin_for_india(doc, method):
|
def validate_gstin_for_india(doc, method):
|
||||||
if hasattr(doc, 'gst_state') and doc.gst_state:
|
if hasattr(doc, 'gst_state') and doc.gst_state:
|
||||||
@@ -86,7 +87,7 @@ def validate_gstin_check_digit(gstin, label='GSTIN'):
|
|||||||
factor = 2 if factor == 1 else 1
|
factor = 2 if factor == 1 else 1
|
||||||
if gstin[-1] != code_point_chars[((mod - (total % mod)) % mod)]:
|
if gstin[-1] != code_point_chars[((mod - (total % mod)) % mod)]:
|
||||||
frappe.throw(_("""Invalid {0}! The check digit validation has failed.
|
frappe.throw(_("""Invalid {0}! The check digit validation has failed.
|
||||||
Please ensure you've typed the {0} correctly.""".format(label)))
|
Please ensure you've typed the {0} correctly.""").format(label))
|
||||||
|
|
||||||
def get_itemised_tax_breakup_header(item_doctype, tax_accounts):
|
def get_itemised_tax_breakup_header(item_doctype, tax_accounts):
|
||||||
if frappe.get_meta(item_doctype).has_field('gst_hsn_code'):
|
if frappe.get_meta(item_doctype).has_field('gst_hsn_code'):
|
||||||
@@ -149,24 +150,31 @@ def get_place_of_supply(party_details, doctype):
|
|||||||
return cstr(address.gst_state_number) + "-" + cstr(address.gst_state)
|
return cstr(address.gst_state_number) + "-" + cstr(address.gst_state)
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_regional_address_details(party_details, doctype, company, return_taxes=None):
|
def get_regional_address_details(party_details, doctype, company):
|
||||||
|
|
||||||
if isinstance(party_details, string_types):
|
if isinstance(party_details, string_types):
|
||||||
party_details = json.loads(party_details)
|
party_details = json.loads(party_details)
|
||||||
party_details = frappe._dict(party_details)
|
party_details = frappe._dict(party_details)
|
||||||
|
|
||||||
|
update_party_details(party_details, doctype)
|
||||||
|
|
||||||
party_details.place_of_supply = get_place_of_supply(party_details, doctype)
|
party_details.place_of_supply = get_place_of_supply(party_details, doctype)
|
||||||
|
|
||||||
|
if is_internal_transfer(party_details, doctype):
|
||||||
|
party_details.taxes_and_charges = ''
|
||||||
|
party_details.taxes = ''
|
||||||
|
return party_details
|
||||||
|
|
||||||
if doctype in ("Sales Invoice", "Delivery Note", "Sales Order"):
|
if doctype in ("Sales Invoice", "Delivery Note", "Sales Order"):
|
||||||
master_doctype = "Sales Taxes and Charges Template"
|
master_doctype = "Sales Taxes and Charges Template"
|
||||||
|
|
||||||
get_tax_template_for_sez(party_details, master_doctype, company, 'Customer')
|
get_tax_template_for_sez(party_details, master_doctype, company, 'Customer')
|
||||||
get_tax_template_based_on_category(master_doctype, company, party_details)
|
get_tax_template_based_on_category(master_doctype, company, party_details)
|
||||||
|
|
||||||
if party_details.get('taxes_and_charges') and return_taxes:
|
if party_details.get('taxes_and_charges'):
|
||||||
return party_details
|
return party_details
|
||||||
|
|
||||||
if not party_details.company_gstin:
|
if not party_details.company_gstin:
|
||||||
return
|
return party_details
|
||||||
|
|
||||||
elif doctype in ("Purchase Invoice", "Purchase Order", "Purchase Receipt"):
|
elif doctype in ("Purchase Invoice", "Purchase Order", "Purchase Receipt"):
|
||||||
master_doctype = "Purchase Taxes and Charges Template"
|
master_doctype = "Purchase Taxes and Charges Template"
|
||||||
@@ -174,15 +182,15 @@ def get_regional_address_details(party_details, doctype, company, return_taxes=N
|
|||||||
get_tax_template_for_sez(party_details, master_doctype, company, 'Supplier')
|
get_tax_template_for_sez(party_details, master_doctype, company, 'Supplier')
|
||||||
get_tax_template_based_on_category(master_doctype, company, party_details)
|
get_tax_template_based_on_category(master_doctype, company, party_details)
|
||||||
|
|
||||||
if party_details.get('taxes_and_charges') and return_taxes:
|
if party_details.get('taxes_and_charges'):
|
||||||
return party_details
|
return party_details
|
||||||
|
|
||||||
if not party_details.supplier_gstin:
|
if not party_details.supplier_gstin:
|
||||||
return
|
return party_details
|
||||||
|
|
||||||
if not party_details.place_of_supply: return
|
if not party_details.place_of_supply: return party_details
|
||||||
|
|
||||||
if not party_details.company_gstin: return
|
if not party_details.company_gstin: return party_details
|
||||||
|
|
||||||
if ((doctype in ("Sales Invoice", "Delivery Note", "Sales Order") and party_details.company_gstin
|
if ((doctype in ("Sales Invoice", "Delivery Note", "Sales Order") and party_details.company_gstin
|
||||||
and party_details.company_gstin[:2] != party_details.place_of_supply[:2]) or (doctype in ("Purchase Invoice",
|
and party_details.company_gstin[:2] != party_details.place_of_supply[:2]) or (doctype in ("Purchase Invoice",
|
||||||
@@ -192,12 +200,27 @@ def get_regional_address_details(party_details, doctype, company, return_taxes=N
|
|||||||
default_tax = get_tax_template(master_doctype, company, 0, party_details.company_gstin[:2])
|
default_tax = get_tax_template(master_doctype, company, 0, party_details.company_gstin[:2])
|
||||||
|
|
||||||
if not default_tax:
|
if not default_tax:
|
||||||
return
|
return party_details
|
||||||
party_details["taxes_and_charges"] = default_tax
|
party_details["taxes_and_charges"] = default_tax
|
||||||
party_details.taxes = get_taxes_and_charges(master_doctype, default_tax)
|
party_details.taxes = get_taxes_and_charges(master_doctype, default_tax)
|
||||||
|
|
||||||
if return_taxes:
|
return party_details
|
||||||
return party_details
|
|
||||||
|
def update_party_details(party_details, doctype):
|
||||||
|
for address_field in ['shipping_address', 'company_address', 'supplier_address', 'shipping_address_name', 'customer_address']:
|
||||||
|
if party_details.get(address_field):
|
||||||
|
party_details.update(get_fetch_values(doctype, address_field, party_details.get(address_field)))
|
||||||
|
|
||||||
|
def is_internal_transfer(party_details, doctype):
|
||||||
|
if doctype in ("Sales Invoice", "Delivery Note", "Sales Order"):
|
||||||
|
destination_gstin = party_details.company_gstin
|
||||||
|
elif doctype in ("Purchase Invoice", "Purchase Order", "Purchase Receipt"):
|
||||||
|
destination_gstin = party_details.supplier_gstin
|
||||||
|
|
||||||
|
if party_details.gstin == destination_gstin:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
False
|
||||||
|
|
||||||
def get_tax_template_based_on_category(master_doctype, company, party_details):
|
def get_tax_template_based_on_category(master_doctype, company, party_details):
|
||||||
if not party_details.get('tax_category'):
|
if not party_details.get('tax_category'):
|
||||||
@@ -504,6 +527,9 @@ def get_address_details(data, doc, company_address, billing_address):
|
|||||||
if doc.gst_category == 'SEZ':
|
if doc.gst_category == 'SEZ':
|
||||||
data.toStateCode = 99
|
data.toStateCode = 99
|
||||||
|
|
||||||
|
if doc.gst_category == 'SEZ':
|
||||||
|
data.toStateCode = 99
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def get_item_list(data, doc):
|
def get_item_list(data, doc):
|
||||||
|
|||||||
Reference in New Issue
Block a user