blob: 7980d0b9ffef79274398e7662925252af255916d [file] [log] [blame]
Aditya Hasef3c22f32019-01-22 18:22:20 +05301from __future__ import unicode_literals
Nabin Hait34c551d2019-07-03 10:34:31 +05302import frappe, re, json
Rushabh Mehtab3c8f442017-06-21 17:22:38 +05303from frappe import _
Deepesh Garg1c146062020-08-18 19:32:52 +05304import erpnext
Ankush Menata44df632021-03-01 17:12:53 +05305from frappe.utils import cstr, flt, date_diff, nowdate, round_based_on_smallest_currency_fraction, money_in_words, getdate
Rushabh Mehtab3c8f442017-06-21 17:22:38 +05306from erpnext.regional.india import states, state_numbers
Nabin Haitb962fc12017-07-17 18:02:31 +05307from erpnext.controllers.taxes_and_totals import get_itemised_tax, get_itemised_taxable_amount
Shreya Shah4fa600a2018-06-05 11:27:53 +05308from erpnext.controllers.accounts_controller import get_taxes_and_charges
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +05309from erpnext.hr.utils import get_salary_assignment
Anurag Mishra289c8222020-06-19 19:17:57 +053010from erpnext.payroll.doctype.salary_structure.salary_structure import make_salary_slip
Deepesh Garg6e2c13f2019-12-10 15:55:05 +053011from erpnext.regional.india import number_state_mapping
12from six import string_types
Deepesh Garg24f9a802020-06-03 10:59:37 +053013from erpnext.accounts.general_ledger import make_gl_entries
14from erpnext.accounts.utils import get_account_currency
Deepesh Garga7670852020-12-04 18:07:46 +053015from frappe.model.utils import get_fetch_values
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053016
17def validate_gstin_for_india(doc, method):
rushin2908a209b2019-03-15 15:28:50 +053018 if hasattr(doc, 'gst_state') and doc.gst_state:
19 doc.gst_state_number = state_numbers[doc.gst_state]
FinByz Tech Pvt. Ltd237a8712019-01-22 20:49:06 +053020 if not hasattr(doc, 'gstin') or not doc.gstin:
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053021 return
22
Deepesh Garg459155f2019-06-14 12:01:34 +053023 gst_category = []
24
25 if len(doc.links):
26 link_doctype = doc.links[0].get("link_doctype")
27 link_name = doc.links[0].get("link_name")
28
29 if link_doctype in ["Customer", "Supplier"]:
30 gst_category = frappe.db.get_value(link_doctype, {'name': link_name}, ['gst_category'])
31
Sagar Vorad75095b2019-01-23 14:40:01 +053032 doc.gstin = doc.gstin.upper().strip()
Sagar Vora07cf4e82019-01-10 11:07:51 +053033 if not doc.gstin or doc.gstin == 'NA':
34 return
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053035
Sagar Vora07cf4e82019-01-10 11:07:51 +053036 if len(doc.gstin) != 15:
37 frappe.throw(_("Invalid GSTIN! A GSTIN must have 15 characters."))
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053038
Deepesh Garg459155f2019-06-14 12:01:34 +053039 if gst_category and gst_category == 'UIN Holders':
40 p = re.compile("^[0-9]{4}[A-Z]{3}[0-9]{5}[0-9A-Z]{3}")
41 if not p.match(doc.gstin):
42 frappe.throw(_("Invalid GSTIN! The input you've entered doesn't match the GSTIN format for UIN Holders or Non-Resident OIDAR Service Providers"))
43 else:
44 p = re.compile("^[0-9]{2}[A-Z]{4}[0-9A-Z]{1}[0-9]{4}[A-Z]{1}[1-9A-Z]{1}[1-9A-Z]{1}[0-9A-Z]{1}$")
45 if not p.match(doc.gstin):
46 frappe.throw(_("Invalid GSTIN! The input you've entered doesn't match the format of GSTIN."))
Rushabh Mehta7231f292017-07-13 15:00:56 +053047
Deepesh Garg459155f2019-06-14 12:01:34 +053048 validate_gstin_check_digit(doc.gstin)
Nabin Hait34c551d2019-07-03 10:34:31 +053049 set_gst_state_and_state_number(doc)
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053050
Anurag Mishra1e396dc2021-01-13 14:01:57 +053051 if not doc.gst_state:
52 frappe.throw(_("Please Enter GST state"))
53
Deepesh Garg459155f2019-06-14 12:01:34 +053054 if doc.gst_state_number != doc.gstin[:2]:
55 frappe.throw(_("Invalid GSTIN! First 2 digits of GSTIN should match with State number {0}.")
56 .format(doc.gst_state_number))
Sagar Vora07cf4e82019-01-10 11:07:51 +053057
Deepesh Gargbb8cd1c2021-02-22 19:28:45 +053058def validate_pan_for_india(doc, method):
Nabin Hait866cf702021-02-22 21:35:00 +053059 if doc.get('country') != 'India' or not doc.pan:
Deepesh Gargbb8cd1c2021-02-22 19:28:45 +053060 return
61
62 p = re.compile("[A-Z]{5}[0-9]{4}[A-Z]{1}")
63 if not p.match(doc.pan):
64 frappe.throw(_("Invalid PAN No. The input you've entered doesn't match the format of PAN."))
65
Deepesh Gargd07447a2020-11-24 08:09:17 +053066def validate_tax_category(doc, method):
Deepesh Gargb0743342020-12-17 18:46:59 +053067 if doc.get('gst_state') and frappe.db.get_value('Tax Category', {'gst_state': doc.gst_state, 'is_inter_state': doc.is_inter_state}):
Deepesh Gargd07447a2020-11-24 08:09:17 +053068 if doc.is_inter_state:
69 frappe.throw(_("Inter State tax category for GST State {0} already exists").format(doc.gst_state))
70 else:
71 frappe.throw(_("Intra State tax category for GST State {0} already exists").format(doc.gst_state))
72
Deepesh Garg6e2c13f2019-12-10 15:55:05 +053073def update_gst_category(doc, method):
74 for link in doc.links:
75 if link.link_doctype in ['Customer', 'Supplier']:
76 if doc.get('gstin'):
77 frappe.db.sql("""
78 UPDATE `tab{0}` SET gst_category = %s WHERE name = %s AND gst_category = 'Unregistered'
79 """.format(link.link_doctype), ("Registered Regular", link.link_name)) #nosec
80
Nabin Hait34c551d2019-07-03 10:34:31 +053081def set_gst_state_and_state_number(doc):
82 if not doc.gst_state:
83 if not doc.state:
84 return
85 state = doc.state.lower()
86 states_lowercase = {s.lower():s for s in states}
87 if state in states_lowercase:
88 doc.gst_state = states_lowercase[state]
89 else:
90 return
91
92 doc.gst_state_number = state_numbers[doc.gst_state]
93
94def validate_gstin_check_digit(gstin, label='GSTIN'):
Sagar Vora07cf4e82019-01-10 11:07:51 +053095 ''' Function to validate the check digit of the GSTIN.'''
karthikeyan52825b922019-01-09 19:15:10 +053096 factor = 1
97 total = 0
98 code_point_chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
karthikeyan52825b922019-01-09 19:15:10 +053099 mod = len(code_point_chars)
Sagar Vora07cf4e82019-01-10 11:07:51 +0530100 input_chars = gstin[:-1]
karthikeyan52825b922019-01-09 19:15:10 +0530101 for char in input_chars:
102 digit = factor * code_point_chars.find(char)
Sagar Vora07cf4e82019-01-10 11:07:51 +0530103 digit = (digit // mod) + (digit % mod)
karthikeyan52825b922019-01-09 19:15:10 +0530104 total += digit
105 factor = 2 if factor == 1 else 1
Sagar Vora07cf4e82019-01-10 11:07:51 +0530106 if gstin[-1] != code_point_chars[((mod - (total % mod)) % mod)]:
Deepesh Gargd07447a2020-11-24 08:09:17 +0530107 frappe.throw(_("""Invalid {0}! The check digit validation has failed. Please ensure you've typed the {0} correctly.""").format(label))
Rushabh Mehta7231f292017-07-13 15:00:56 +0530108
Nabin Haitb962fc12017-07-17 18:02:31 +0530109def get_itemised_tax_breakup_header(item_doctype, tax_accounts):
110 if frappe.get_meta(item_doctype).has_field('gst_hsn_code'):
111 return [_("HSN/SAC"), _("Taxable Amount")] + tax_accounts
112 else:
113 return [_("Item"), _("Taxable Amount")] + tax_accounts
Nabin Haitb95ecd72018-02-16 13:19:04 +0530114
Nabin Hait34c551d2019-07-03 10:34:31 +0530115def get_itemised_tax_breakup_data(doc, account_wise=False):
116 itemised_tax = get_itemised_tax(doc.taxes, with_tax_account=account_wise)
Nabin Haitb962fc12017-07-17 18:02:31 +0530117
118 itemised_taxable_amount = get_itemised_taxable_amount(doc.items)
Nabin Haitb95ecd72018-02-16 13:19:04 +0530119
Nabin Haitb962fc12017-07-17 18:02:31 +0530120 if not frappe.get_meta(doc.doctype + " Item").has_field('gst_hsn_code'):
121 return itemised_tax, itemised_taxable_amount
122
123 item_hsn_map = frappe._dict()
124 for d in doc.items:
125 item_hsn_map.setdefault(d.item_code or d.item_name, d.get("gst_hsn_code"))
126
127 hsn_tax = {}
128 for item, taxes in itemised_tax.items():
129 hsn_code = item_hsn_map.get(item)
130 hsn_tax.setdefault(hsn_code, frappe._dict())
Nabin Hait34c551d2019-07-03 10:34:31 +0530131 for tax_desc, tax_detail in taxes.items():
132 key = tax_desc
133 if account_wise:
134 key = tax_detail.get('tax_account')
135 hsn_tax[hsn_code].setdefault(key, {"tax_rate": 0, "tax_amount": 0})
136 hsn_tax[hsn_code][key]["tax_rate"] = tax_detail.get("tax_rate")
137 hsn_tax[hsn_code][key]["tax_amount"] += tax_detail.get("tax_amount")
Nabin Haitb962fc12017-07-17 18:02:31 +0530138
139 # set taxable amount
140 hsn_taxable_amount = frappe._dict()
Nabin Hait34c551d2019-07-03 10:34:31 +0530141 for item in itemised_taxable_amount:
Nabin Haitb962fc12017-07-17 18:02:31 +0530142 hsn_code = item_hsn_map.get(item)
143 hsn_taxable_amount.setdefault(hsn_code, 0)
144 hsn_taxable_amount[hsn_code] += itemised_taxable_amount.get(item)
145
146 return hsn_tax, hsn_taxable_amount
147
Shreya Shah4fa600a2018-06-05 11:27:53 +0530148def set_place_of_supply(doc, method=None):
149 doc.place_of_supply = get_place_of_supply(doc, doc.doctype)
Nabin Haitb95ecd72018-02-16 13:19:04 +0530150
Ankush Menata44df632021-03-01 17:12:53 +0530151def validate_document_name(doc, method=None):
152 """Validate GST invoice number requirements."""
153 country = frappe.get_cached_value("Company", doc.company, "country")
154
155 if country != "India" or getdate(doc.posting_date) < getdate("2021-04-01"):
156 return
157
158 if len(doc.name) > 16:
159 frappe.throw(_("Maximum length of document number should be 16 characters as per GST rules. Please change the naming series."))
160
161 gst_doc_name_pattern = re.compile(r"^[a-zA-Z0-9\-/]+$")
162 if not gst_doc_name_pattern.match(doc.name):
163 frappe.throw(_("Document name should only contain alphanumeric values, dash(-) and slash(/) characters as per GST rules. Please change the naming series."))
164
Rushabh Mehta7231f292017-07-13 15:00:56 +0530165# don't remove this function it is used in tests
166def test_method():
167 '''test function'''
Nabin Haitb95ecd72018-02-16 13:19:04 +0530168 return 'overridden'
Shreya Shah4fa600a2018-06-05 11:27:53 +0530169
Deepesh Garg6e2c13f2019-12-10 15:55:05 +0530170def get_place_of_supply(party_details, doctype):
Shreya Shah4fa600a2018-06-05 11:27:53 +0530171 if not frappe.get_meta('Address').has_field('gst_state'): return
172
Deepesh Garg6e2c13f2019-12-10 15:55:05 +0530173 if doctype in ("Sales Invoice", "Delivery Note", "Sales Order"):
Deepesh Gargeacfd792020-10-30 22:12:24 +0530174 address_name = party_details.customer_address or party_details.shipping_address_name
Deepesh Garg6e2c13f2019-12-10 15:55:05 +0530175 elif doctype in ("Purchase Invoice", "Purchase Order", "Purchase Receipt"):
176 address_name = party_details.shipping_address or party_details.supplier_address
Shreya Shah4fa600a2018-06-05 11:27:53 +0530177
178 if address_name:
Deepesh Garg15ff6a52020-02-18 12:28:41 +0530179 address = frappe.db.get_value("Address", address_name, ["gst_state", "gst_state_number", "gstin"], as_dict=1)
Rohit Waghchaureb6a735e2018-10-11 10:40:34 +0530180 if address and address.gst_state and address.gst_state_number:
Deepesh Garg15ff6a52020-02-18 12:28:41 +0530181 party_details.gstin = address.gstin
Nabin Hait2390da62018-08-30 16:16:35 +0530182 return cstr(address.gst_state_number) + "-" + cstr(address.gst_state)
Shreya Shah4fa600a2018-06-05 11:27:53 +0530183
Deepesh Garg6e2c13f2019-12-10 15:55:05 +0530184@frappe.whitelist()
pateljannat1d5d8632020-11-19 20:11:45 +0530185def get_regional_address_details(party_details, doctype, company):
Deepesh Garg6e2c13f2019-12-10 15:55:05 +0530186 if isinstance(party_details, string_types):
187 party_details = json.loads(party_details)
188 party_details = frappe._dict(party_details)
Shreya Shah4fa600a2018-06-05 11:27:53 +0530189
Deepesh Garga7670852020-12-04 18:07:46 +0530190 update_party_details(party_details, doctype)
191
Deepesh Garg6e2c13f2019-12-10 15:55:05 +0530192 party_details.place_of_supply = get_place_of_supply(party_details, doctype)
Deepesh Garg15ff6a52020-02-18 12:28:41 +0530193
194 if is_internal_transfer(party_details, doctype):
195 party_details.taxes_and_charges = ''
Deepesh Gargb4be2922021-01-28 13:09:56 +0530196 party_details.taxes = []
pateljannatcd05b342020-11-19 11:37:08 +0530197 return party_details
Deepesh Garg15ff6a52020-02-18 12:28:41 +0530198
Deepesh Garg6e2c13f2019-12-10 15:55:05 +0530199 if doctype in ("Sales Invoice", "Delivery Note", "Sales Order"):
Shreya Shah4fa600a2018-06-05 11:27:53 +0530200 master_doctype = "Sales Taxes and Charges Template"
Deepesh Garg6e2c13f2019-12-10 15:55:05 +0530201
202 get_tax_template_for_sez(party_details, master_doctype, company, 'Customer')
203 get_tax_template_based_on_category(master_doctype, company, party_details)
204
pateljannatcd05b342020-11-19 11:37:08 +0530205 if party_details.get('taxes_and_charges'):
Deepesh Garg6e2c13f2019-12-10 15:55:05 +0530206 return party_details
207
208 if not party_details.company_gstin:
pateljannatcd05b342020-11-19 11:37:08 +0530209 return party_details
Shreya Shah4fa600a2018-06-05 11:27:53 +0530210
Deepesh Garg6e2c13f2019-12-10 15:55:05 +0530211 elif doctype in ("Purchase Invoice", "Purchase Order", "Purchase Receipt"):
212 master_doctype = "Purchase Taxes and Charges Template"
Deepesh Garg6e2c13f2019-12-10 15:55:05 +0530213 get_tax_template_for_sez(party_details, master_doctype, company, 'Supplier')
214 get_tax_template_based_on_category(master_doctype, company, party_details)
215
pateljannatcd05b342020-11-19 11:37:08 +0530216 if party_details.get('taxes_and_charges'):
Deepesh Garg6e2c13f2019-12-10 15:55:05 +0530217 return party_details
218
219 if not party_details.supplier_gstin:
pateljannatcd05b342020-11-19 11:37:08 +0530220 return party_details
Deepesh Garg6e2c13f2019-12-10 15:55:05 +0530221
pateljannatcd05b342020-11-19 11:37:08 +0530222 if not party_details.place_of_supply: return party_details
Deepesh Garg6e2c13f2019-12-10 15:55:05 +0530223
pateljannatcd05b342020-11-19 11:37:08 +0530224 if not party_details.company_gstin: return party_details
deepeshgarg007c58dc872019-12-12 14:55:57 +0530225
Deepesh Garg6e2c13f2019-12-10 15:55:05 +0530226 if ((doctype in ("Sales Invoice", "Delivery Note", "Sales Order") and party_details.company_gstin
227 and party_details.company_gstin[:2] != party_details.place_of_supply[:2]) or (doctype in ("Purchase Invoice",
228 "Purchase Order", "Purchase Receipt") and party_details.supplier_gstin and party_details.supplier_gstin[:2] != party_details.place_of_supply[:2])):
229 default_tax = get_tax_template(master_doctype, company, 1, party_details.company_gstin[:2])
Shreya Shah4fa600a2018-06-05 11:27:53 +0530230 else:
Deepesh Garg6e2c13f2019-12-10 15:55:05 +0530231 default_tax = get_tax_template(master_doctype, company, 0, party_details.company_gstin[:2])
Shreya Shah4fa600a2018-06-05 11:27:53 +0530232
233 if not default_tax:
pateljannatcd05b342020-11-19 11:37:08 +0530234 return party_details
Deepesh Garg6e2c13f2019-12-10 15:55:05 +0530235 party_details["taxes_and_charges"] = default_tax
236 party_details.taxes = get_taxes_and_charges(master_doctype, default_tax)
237
pateljannatcd05b342020-11-19 11:37:08 +0530238 return party_details
Deepesh Garg6e2c13f2019-12-10 15:55:05 +0530239
Deepesh Garga7670852020-12-04 18:07:46 +0530240def update_party_details(party_details, doctype):
241 for address_field in ['shipping_address', 'company_address', 'supplier_address', 'shipping_address_name', 'customer_address']:
242 if party_details.get(address_field):
243 party_details.update(get_fetch_values(doctype, address_field, party_details.get(address_field)))
244
Deepesh Garg15ff6a52020-02-18 12:28:41 +0530245def is_internal_transfer(party_details, doctype):
246 if doctype in ("Sales Invoice", "Delivery Note", "Sales Order"):
247 destination_gstin = party_details.company_gstin
248 elif doctype in ("Purchase Invoice", "Purchase Order", "Purchase Receipt"):
249 destination_gstin = party_details.supplier_gstin
250
251 if party_details.gstin == destination_gstin:
252 return True
253 else:
254 False
255
Deepesh Garg6e2c13f2019-12-10 15:55:05 +0530256def get_tax_template_based_on_category(master_doctype, company, party_details):
257 if not party_details.get('tax_category'):
258 return
259
260 default_tax = frappe.db.get_value(master_doctype, {'company': company, 'tax_category': party_details.get('tax_category')},
261 'name')
262
263 if default_tax:
264 party_details["taxes_and_charges"] = default_tax
265 party_details.taxes = get_taxes_and_charges(master_doctype, default_tax)
266
267def get_tax_template(master_doctype, company, is_inter_state, state_code):
268 tax_categories = frappe.get_all('Tax Category', fields = ['name', 'is_inter_state', 'gst_state'],
269 filters = {'is_inter_state': is_inter_state})
270
271 default_tax = ''
272
273 for tax_category in tax_categories:
274 if tax_category.gst_state == number_state_mapping[state_code] or \
275 (not default_tax and not tax_category.gst_state):
276 default_tax = frappe.db.get_value(master_doctype,
Deepesh Garg59ccb642020-11-05 16:29:34 +0530277 {'company': company, 'disabled': 0, 'tax_category': tax_category.name}, 'name')
Deepesh Garg6e2c13f2019-12-10 15:55:05 +0530278 return default_tax
279
280def get_tax_template_for_sez(party_details, master_doctype, company, party_type):
281
282 gst_details = frappe.db.get_value(party_type, {'name': party_details.get(frappe.scrub(party_type))},
283 ['gst_category', 'export_type'], as_dict=1)
284
285 if gst_details:
286 if gst_details.gst_category == 'SEZ' and gst_details.export_type == 'With Payment of Tax':
287 default_tax = frappe.db.get_value(master_doctype, {"company": company, "is_inter_state":1, "disabled":0,
288 "gst_state": number_state_mapping[party_details.company_gstin[:2]]})
289
290 party_details["taxes_and_charges"] = default_tax
291 party_details.taxes = get_taxes_and_charges(master_doctype, default_tax)
292
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530293
294def calculate_annual_eligible_hra_exemption(doc):
Nabin Hait10df3d52020-05-14 17:15:16 +0530295 basic_component, hra_component = frappe.db.get_value('Company', doc.company, ["basic_component", "hra_component"])
Nabin Hait04e7bf42019-04-25 18:44:10 +0530296 if not (basic_component and hra_component):
297 frappe.throw(_("Please mention Basic and HRA component in Company"))
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530298 annual_exemption, monthly_exemption, hra_amount = 0, 0, 0
Ranjith Kurungadamb1a756c2018-07-01 16:42:38 +0530299 if hra_component and basic_component:
Nabin Hait04e7bf42019-04-25 18:44:10 +0530300 assignment = get_salary_assignment(doc.employee, nowdate())
Nabin Hait04e7bf42019-04-25 18:44:10 +0530301 if assignment:
302 hra_component_exists = frappe.db.exists("Salary Detail", {
303 "parent": assignment.salary_structure,
304 "salary_component": hra_component,
305 "parentfield": "earnings",
306 "parenttype": "Salary Structure"
307 })
Nabin Hait6b9d64c2019-05-16 11:23:04 +0530308
Nabin Hait04e7bf42019-04-25 18:44:10 +0530309 if hra_component_exists:
310 basic_amount, hra_amount = get_component_amt_from_salary_slip(doc.employee,
311 assignment.salary_structure, basic_component, hra_component)
312 if hra_amount:
313 if doc.monthly_house_rent:
314 annual_exemption = calculate_hra_exemption(assignment.salary_structure,
Nabin Hait6b9d64c2019-05-16 11:23:04 +0530315 basic_amount, hra_amount, doc.monthly_house_rent, doc.rented_in_metro_city)
Nabin Hait04e7bf42019-04-25 18:44:10 +0530316 if annual_exemption > 0:
317 monthly_exemption = annual_exemption / 12
318 else:
319 annual_exemption = 0
Nabin Hait6b9d64c2019-05-16 11:23:04 +0530320
Nabin Hait04e7bf42019-04-25 18:44:10 +0530321 elif doc.docstatus == 1:
322 frappe.throw(_("Salary Structure must be submitted before submission of Tax Ememption Declaration"))
323
324 return frappe._dict({
325 "hra_amount": hra_amount,
326 "annual_exemption": annual_exemption,
327 "monthly_exemption": monthly_exemption
328 })
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530329
Ranjith Kurungadamb1a756c2018-07-01 16:42:38 +0530330def get_component_amt_from_salary_slip(employee, salary_structure, basic_component, hra_component):
Anurag Mishra33793d42020-04-29 11:48:41 +0530331 salary_slip = make_salary_slip(salary_structure, employee=employee, for_preview=1, ignore_permissions=True)
Ranjith Kurungadamb1a756c2018-07-01 16:42:38 +0530332 basic_amt, hra_amt = 0, 0
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530333 for earning in salary_slip.earnings:
Ranjith Kurungadamb1a756c2018-07-01 16:42:38 +0530334 if earning.salary_component == basic_component:
335 basic_amt = earning.amount
336 elif earning.salary_component == hra_component:
337 hra_amt = earning.amount
338 if basic_amt and hra_amt:
339 return basic_amt, hra_amt
Ranjith Kurungadam14e94f82018-07-16 16:12:46 +0530340 return basic_amt, hra_amt
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530341
Ranjith Kurungadamb1a756c2018-07-01 16:42:38 +0530342def calculate_hra_exemption(salary_structure, basic, monthly_hra, monthly_house_rent, rented_in_metro_city):
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530343 # TODO make this configurable
344 exemptions = []
345 frequency = frappe.get_value("Salary Structure", salary_structure, "payroll_frequency")
346 # case 1: The actual amount allotted by the employer as the HRA.
347 exemptions.append(get_annual_component_pay(frequency, monthly_hra))
Nabin Hait04e7bf42019-04-25 18:44:10 +0530348
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530349 actual_annual_rent = monthly_house_rent * 12
Ranjith Kurungadamb1a756c2018-07-01 16:42:38 +0530350 annual_basic = get_annual_component_pay(frequency, basic)
Nabin Hait04e7bf42019-04-25 18:44:10 +0530351
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530352 # case 2: Actual rent paid less 10% of the basic salary.
Ranjith Kurungadamb1a756c2018-07-01 16:42:38 +0530353 exemptions.append(flt(actual_annual_rent) - flt(annual_basic * 0.1))
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530354 # case 3: 50% of the basic salary, if the employee is staying in a metro city (40% for a non-metro city).
Ranjith Kurungadamb1a756c2018-07-01 16:42:38 +0530355 exemptions.append(annual_basic * 0.5 if rented_in_metro_city else annual_basic * 0.4)
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530356 # return minimum of 3 cases
357 return min(exemptions)
358
359def get_annual_component_pay(frequency, amount):
360 if frequency == "Daily":
361 return amount * 365
362 elif frequency == "Weekly":
363 return amount * 52
364 elif frequency == "Fortnightly":
365 return amount * 26
366 elif frequency == "Monthly":
367 return amount * 12
368 elif frequency == "Bimonthly":
369 return amount * 6
370
371def validate_house_rent_dates(doc):
372 if not doc.rented_to_date or not doc.rented_from_date:
373 frappe.throw(_("House rented dates required for exemption calculation"))
Nabin Hait04e7bf42019-04-25 18:44:10 +0530374
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530375 if date_diff(doc.rented_to_date, doc.rented_from_date) < 14:
376 frappe.throw(_("House rented dates should be atleast 15 days apart"))
Nabin Hait04e7bf42019-04-25 18:44:10 +0530377
378 proofs = frappe.db.sql("""
379 select name
380 from `tabEmployee Tax Exemption Proof Submission`
381 where
Nabin Hait49446ba2019-04-25 19:54:20 +0530382 docstatus=1 and employee=%(employee)s and payroll_period=%(payroll_period)s
383 and (rented_from_date between %(from_date)s and %(to_date)s or rented_to_date between %(from_date)s and %(to_date)s)
384 """, {
385 "employee": doc.employee,
386 "payroll_period": doc.payroll_period,
387 "from_date": doc.rented_from_date,
388 "to_date": doc.rented_to_date
389 })
Nabin Hait04e7bf42019-04-25 18:44:10 +0530390
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530391 if proofs:
Nabin Hait49446ba2019-04-25 19:54:20 +0530392 frappe.throw(_("House rent paid days overlapping with {0}").format(proofs[0][0]))
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530393
394def calculate_hra_exemption_for_period(doc):
395 monthly_rent, eligible_hra = 0, 0
396 if doc.house_rent_payment_amount:
397 validate_house_rent_dates(doc)
398 # TODO receive rented months or validate dates are start and end of months?
399 # Calc monthly rent, round to nearest .5
400 factor = flt(date_diff(doc.rented_to_date, doc.rented_from_date) + 1)/30
401 factor = round(factor * 2)/2
402 monthly_rent = doc.house_rent_payment_amount / factor
403 # update field used by calculate_annual_eligible_hra_exemption
404 doc.monthly_house_rent = monthly_rent
405 exemptions = calculate_annual_eligible_hra_exemption(doc)
406
407 if exemptions["monthly_exemption"]:
408 # calc total exemption amount
409 eligible_hra = exemptions["monthly_exemption"] * factor
Ranjith Kurungadam4f9744a2018-06-20 11:10:56 +0530410 exemptions["monthly_house_rent"] = monthly_rent
411 exemptions["total_eligible_hra_exemption"] = eligible_hra
412 return exemptions
Prasann Shah829172c2019-06-06 12:08:09 +0530413
Nabin Hait34c551d2019-07-03 10:34:31 +0530414def get_ewb_data(dt, dn):
Nabin Hait34c551d2019-07-03 10:34:31 +0530415
416 ewaybills = []
417 for doc_name in dn:
418 doc = frappe.get_doc(dt, doc_name)
419
Deepesh Garg15ff6a52020-02-18 12:28:41 +0530420 validate_doc(doc)
Nabin Hait34c551d2019-07-03 10:34:31 +0530421
422 data = frappe._dict({
423 "transporterId": "",
424 "TotNonAdvolVal": 0,
425 })
426
427 data.userGstin = data.fromGstin = doc.company_gstin
428 data.supplyType = 'O'
429
Deepesh Garg15ff6a52020-02-18 12:28:41 +0530430 if dt == 'Delivery Note':
431 data.subSupplyType = 1
432 elif doc.gst_category in ['Registered Regular', 'SEZ']:
Nabin Hait34c551d2019-07-03 10:34:31 +0530433 data.subSupplyType = 1
434 elif doc.gst_category in ['Overseas', 'Deemed Export']:
435 data.subSupplyType = 3
436 else:
Deepesh Gargcce3ac92020-02-02 21:25:58 +0530437 frappe.throw(_('Unsupported GST Category for E-Way Bill JSON generation'))
Nabin Hait34c551d2019-07-03 10:34:31 +0530438
439 data.docType = 'INV'
440 data.docDate = frappe.utils.formatdate(doc.posting_date, 'dd/mm/yyyy')
441
442 company_address = frappe.get_doc('Address', doc.company_address)
443 billing_address = frappe.get_doc('Address', doc.customer_address)
444
445 shipping_address = frappe.get_doc('Address', doc.shipping_address_name)
446
447 data = get_address_details(data, doc, company_address, billing_address)
448
449 data.itemList = []
450 data.totalValue = doc.total
451
452 data = get_item_list(data, doc)
453
454 disable_rounded = frappe.db.get_single_value('Global Defaults', 'disable_rounded_total')
455 data.totInvValue = doc.grand_total if disable_rounded else doc.rounded_total
456
457 data = get_transport_details(data, doc)
458
459 fields = {
460 "/. -": {
461 'docNo': doc.name,
462 'fromTrdName': doc.company,
463 'toTrdName': doc.customer_name,
464 'transDocNo': doc.lr_no,
465 },
466 "@#/,&. -": {
467 'fromAddr1': company_address.address_line1,
468 'fromAddr2': company_address.address_line2,
469 'fromPlace': company_address.city,
470 'toAddr1': shipping_address.address_line1,
471 'toAddr2': shipping_address.address_line2,
472 'toPlace': shipping_address.city,
473 'transporterName': doc.transporter_name
474 }
475 }
476
477 for allowed_chars, field_map in fields.items():
478 for key, value in field_map.items():
479 if not value:
480 data[key] = ''
481 else:
482 data[key] = re.sub(r'[^\w' + allowed_chars + ']', '', value)
483
484 ewaybills.append(data)
485
486 data = {
487 'version': '1.0.1118',
488 'billLists': ewaybills
489 }
490
491 return data
492
493@frappe.whitelist()
494def generate_ewb_json(dt, dn):
Deepesh Garg00ea59b2020-04-27 10:50:40 +0530495 dn = json.loads(dn)
496 return get_ewb_data(dt, dn)
Nabin Hait34c551d2019-07-03 10:34:31 +0530497
Deepesh Garg00ea59b2020-04-27 10:50:40 +0530498@frappe.whitelist()
499def download_ewb_json():
Sagar Vorac9b4ba62020-07-11 17:44:20 +0530500 data = json.loads(frappe.local.form_dict.data)
501 frappe.local.response.filecontent = json.dumps(data, indent=4, sort_keys=True)
Nabin Hait34c551d2019-07-03 10:34:31 +0530502 frappe.local.response.type = 'download'
503
Sagar Vorac9b4ba62020-07-11 17:44:20 +0530504 filename_prefix = 'Bulk'
505 docname = frappe.local.form_dict.docname
506 if docname:
507 if docname.startswith('['):
508 docname = json.loads(docname)
509 if len(docname) == 1:
510 docname = docname[0]
Deepesh Garg00ea59b2020-04-27 10:50:40 +0530511
Sagar Vorac9b4ba62020-07-11 17:44:20 +0530512 if not isinstance(docname, list):
513 # removes characters not allowed in a filename (https://stackoverflow.com/a/38766141/4767738)
514 filename_prefix = re.sub('[^\w_.)( -]', '', docname)
Nabin Hait34c551d2019-07-03 10:34:31 +0530515
Sagar Vorac9b4ba62020-07-11 17:44:20 +0530516 frappe.local.response.filename = '{0}_e-WayBill_Data_{1}.json'.format(filename_prefix, frappe.utils.random_string(5))
Nabin Hait34c551d2019-07-03 10:34:31 +0530517
Prasann Shah829172c2019-06-06 12:08:09 +0530518@frappe.whitelist()
519def get_gstins_for_company(company):
520 company_gstins =[]
521 if company:
522 company_gstins = frappe.db.sql("""select
523 distinct `tabAddress`.gstin
524 from
525 `tabAddress`, `tabDynamic Link`
526 where
527 `tabDynamic Link`.parent = `tabAddress`.name and
528 `tabDynamic Link`.parenttype = 'Address' and
529 `tabDynamic Link`.link_doctype = 'Company' and
Don-Leopardo2b6a20a2020-03-16 14:06:44 -0300530 `tabDynamic Link`.link_name = %(company)s""", {"company": company})
Prasann Shah829172c2019-06-06 12:08:09 +0530531 return company_gstins
532
Nabin Hait34c551d2019-07-03 10:34:31 +0530533def get_address_details(data, doc, company_address, billing_address):
534 data.fromPincode = validate_pincode(company_address.pincode, 'Company Address')
535 data.fromStateCode = data.actualFromStateCode = validate_state_code(
536 company_address.gst_state_number, 'Company Address')
537
538 if not doc.billing_address_gstin or len(doc.billing_address_gstin) < 15:
539 data.toGstin = 'URP'
540 set_gst_state_and_state_number(billing_address)
541 else:
542 data.toGstin = doc.billing_address_gstin
543
544 data.toPincode = validate_pincode(billing_address.pincode, 'Customer Address')
545 data.toStateCode = validate_state_code(billing_address.gst_state_number, 'Customer Address')
546
547 if doc.customer_address != doc.shipping_address_name:
548 data.transType = 2
549 shipping_address = frappe.get_doc('Address', doc.shipping_address_name)
550 set_gst_state_and_state_number(shipping_address)
551 data.toPincode = validate_pincode(shipping_address.pincode, 'Shipping Address')
552 data.actualToStateCode = validate_state_code(shipping_address.gst_state_number, 'Shipping Address')
553 else:
554 data.transType = 1
555 data.actualToStateCode = data.toStateCode
556 shipping_address = billing_address
Deepesh Gargd07447a2020-11-24 08:09:17 +0530557
Smit Vorabbe49332020-11-18 20:58:59 +0530558 if doc.gst_category == 'SEZ':
559 data.toStateCode = 99
Nabin Hait34c551d2019-07-03 10:34:31 +0530560
561 return data
562
563def get_item_list(data, doc):
564 for attr in ['cgstValue', 'sgstValue', 'igstValue', 'cessValue', 'OthValue']:
565 data[attr] = 0
566
567 gst_accounts = get_gst_accounts(doc.company, account_wise=True)
568 tax_map = {
569 'sgst_account': ['sgstRate', 'sgstValue'],
570 'cgst_account': ['cgstRate', 'cgstValue'],
571 'igst_account': ['igstRate', 'igstValue'],
572 'cess_account': ['cessRate', 'cessValue']
573 }
574 item_data_attrs = ['sgstRate', 'cgstRate', 'igstRate', 'cessRate', 'cessNonAdvol']
575 hsn_wise_charges, hsn_taxable_amount = get_itemised_tax_breakup_data(doc, account_wise=True)
576 for hsn_code, taxable_amount in hsn_taxable_amount.items():
577 item_data = frappe._dict()
578 if not hsn_code:
579 frappe.throw(_('GST HSN Code does not exist for one or more items'))
580 item_data.hsnCode = int(hsn_code)
581 item_data.taxableAmount = taxable_amount
582 item_data.qtyUnit = ""
583 for attr in item_data_attrs:
584 item_data[attr] = 0
585
586 for account, tax_detail in hsn_wise_charges.get(hsn_code, {}).items():
587 account_type = gst_accounts.get(account, '')
588 for tax_acc, attrs in tax_map.items():
589 if account_type == tax_acc:
590 item_data[attrs[0]] = tax_detail.get('tax_rate')
591 data[attrs[1]] += tax_detail.get('tax_amount')
592 break
593 else:
594 data.OthValue += tax_detail.get('tax_amount')
595
596 data.itemList.append(item_data)
597
598 # Tax amounts rounded to 2 decimals to avoid exceeding max character limit
599 for attr in ['sgstValue', 'cgstValue', 'igstValue', 'cessValue']:
600 data[attr] = flt(data[attr], 2)
601
602 return data
603
Deepesh Garg15ff6a52020-02-18 12:28:41 +0530604def validate_doc(doc):
Nabin Hait34c551d2019-07-03 10:34:31 +0530605 if doc.docstatus != 1:
Deepesh Gargcce3ac92020-02-02 21:25:58 +0530606 frappe.throw(_('E-Way Bill JSON can only be generated from submitted document'))
Nabin Hait34c551d2019-07-03 10:34:31 +0530607
608 if doc.is_return:
Deepesh Gargcce3ac92020-02-02 21:25:58 +0530609 frappe.throw(_('E-Way Bill JSON cannot be generated for Sales Return as of now'))
Nabin Hait34c551d2019-07-03 10:34:31 +0530610
611 if doc.ewaybill:
612 frappe.throw(_('e-Way Bill already exists for this document'))
613
614 reqd_fields = ['company_gstin', 'company_address', 'customer_address',
615 'shipping_address_name', 'mode_of_transport', 'distance']
616
617 for fieldname in reqd_fields:
618 if not doc.get(fieldname):
Deepesh Gargcce3ac92020-02-02 21:25:58 +0530619 frappe.throw(_('{} is required to generate E-Way Bill JSON').format(
Nabin Hait34c551d2019-07-03 10:34:31 +0530620 doc.meta.get_label(fieldname)
Suraj Shettyda2c69e2020-01-29 15:34:06 +0530621 ))
Nabin Hait34c551d2019-07-03 10:34:31 +0530622
623 if len(doc.company_gstin) < 15:
624 frappe.throw(_('You must be a registered supplier to generate e-Way Bill'))
625
626def get_transport_details(data, doc):
627 if doc.distance > 4000:
628 frappe.throw(_('Distance cannot be greater than 4000 kms'))
629
630 data.transDistance = int(round(doc.distance))
631
632 transport_modes = {
633 'Road': 1,
634 'Rail': 2,
635 'Air': 3,
636 'Ship': 4
637 }
638
639 vehicle_types = {
640 'Regular': 'R',
641 'Over Dimensional Cargo (ODC)': 'O'
642 }
643
644 data.transMode = transport_modes.get(doc.mode_of_transport)
645
646 if doc.mode_of_transport == 'Road':
647 if not doc.gst_transporter_id and not doc.vehicle_no:
648 frappe.throw(_('Either GST Transporter ID or Vehicle No is required if Mode of Transport is Road'))
649 if doc.vehicle_no:
650 data.vehicleNo = doc.vehicle_no.replace(' ', '')
651 if not doc.gst_vehicle_type:
652 frappe.throw(_('Vehicle Type is required if Mode of Transport is Road'))
653 else:
654 data.vehicleType = vehicle_types.get(doc.gst_vehicle_type)
655 else:
656 if not doc.lr_no or not doc.lr_date:
657 frappe.throw(_('Transport Receipt No and Date are mandatory for your chosen Mode of Transport'))
658
659 if doc.lr_no:
660 data.transDocNo = doc.lr_no
661
662 if doc.lr_date:
663 data.transDocDate = frappe.utils.formatdate(doc.lr_date, 'dd/mm/yyyy')
664
665 if doc.gst_transporter_id:
karthikeyan5ca46bed2020-05-30 15:00:56 +0530666 if doc.gst_transporter_id[0:2] != "88":
667 validate_gstin_check_digit(doc.gst_transporter_id, label='GST Transporter ID')
668 data.transporterId = doc.gst_transporter_id
Nabin Hait34c551d2019-07-03 10:34:31 +0530669
670 return data
671
672
673def validate_pincode(pincode, address):
674 pin_not_found = "Pin Code doesn't exist for {}"
675 incorrect_pin = "Pin Code for {} is incorrecty formatted. It must be 6 digits (without spaces)"
676
677 if not pincode:
678 frappe.throw(_(pin_not_found.format(address)))
679
680 pincode = pincode.replace(' ', '')
681 if not pincode.isdigit() or len(pincode) != 6:
682 frappe.throw(_(incorrect_pin.format(address)))
683 else:
684 return int(pincode)
685
686def validate_state_code(state_code, address):
687 no_state_code = "GST State Code not found for {0}. Please set GST State in {0}"
688 if not state_code:
689 frappe.throw(_(no_state_code.format(address)))
690 else:
691 return int(state_code)
692
Deepesh Garg3c004ad2020-07-02 21:18:29 +0530693@frappe.whitelist()
Nabin Hait34c551d2019-07-03 10:34:31 +0530694def get_gst_accounts(company, account_wise=False):
695 gst_accounts = frappe._dict()
696 gst_settings_accounts = frappe.get_all("GST Account",
697 filters={"parent": "GST Settings", "company": company},
698 fields=["cgst_account", "sgst_account", "igst_account", "cess_account"])
699
Deepesh Garg6e2c13f2019-12-10 15:55:05 +0530700 if not gst_settings_accounts and not frappe.flags.in_test:
Nabin Hait34c551d2019-07-03 10:34:31 +0530701 frappe.throw(_("Please set GST Accounts in GST Settings"))
702
703 for d in gst_settings_accounts:
704 for acc, val in d.items():
705 if not account_wise:
706 gst_accounts.setdefault(acc, []).append(val)
707 elif val:
708 gst_accounts[val] = acc
709
Nabin Hait34c551d2019-07-03 10:34:31 +0530710 return gst_accounts
Deepesh Garg24f9a802020-06-03 10:59:37 +0530711
Deepesh Garg3c004ad2020-07-02 21:18:29 +0530712def update_grand_total_for_rcm(doc, method):
Deepesh Garg52c319c2020-07-15 23:57:03 +0530713 country = frappe.get_cached_value('Company', doc.company, 'country')
714
715 if country != 'India':
716 return
717
Deepesh Garg8aed48f2020-08-19 18:30:18 +0530718 if not doc.total_taxes_and_charges:
719 return
720
Deepesh Garg3c004ad2020-07-02 21:18:29 +0530721 if doc.reverse_charge == 'Y':
722 gst_accounts = get_gst_accounts(doc.company)
723 gst_account_list = gst_accounts.get('cgst_account') + gst_accounts.get('sgst_account') \
724 + gst_accounts.get('igst_account')
725
Deepesh Garg1c146062020-08-18 19:32:52 +0530726 base_gst_tax = 0
Deepesh Garg3c004ad2020-07-02 21:18:29 +0530727 gst_tax = 0
Deepesh Garg1c146062020-08-18 19:32:52 +0530728
Deepesh Garg3c004ad2020-07-02 21:18:29 +0530729 for tax in doc.get('taxes'):
730 if tax.category not in ("Total", "Valuation and Total"):
731 continue
732
733 if flt(tax.base_tax_amount_after_discount_amount) and tax.account_head in gst_account_list:
Deepesh Garg1c146062020-08-18 19:32:52 +0530734 base_gst_tax += tax.base_tax_amount_after_discount_amount
735 gst_tax += tax.tax_amount_after_discount_amount
Deepesh Garg3c004ad2020-07-02 21:18:29 +0530736
737 doc.taxes_and_charges_added -= gst_tax
738 doc.total_taxes_and_charges -= gst_tax
Deepesh Garg1c146062020-08-18 19:32:52 +0530739 doc.base_taxes_and_charges_added -= base_gst_tax
740 doc.base_total_taxes_and_charges -= base_gst_tax
Deepesh Garg3c004ad2020-07-02 21:18:29 +0530741
Deepesh Garg1c146062020-08-18 19:32:52 +0530742 update_totals(gst_tax, base_gst_tax, doc)
Deepesh Garg3c004ad2020-07-02 21:18:29 +0530743
Deepesh Garg1c146062020-08-18 19:32:52 +0530744def update_totals(gst_tax, base_gst_tax, doc):
745 doc.base_grand_total -= base_gst_tax
Deepesh Garg3c004ad2020-07-02 21:18:29 +0530746 doc.grand_total -= gst_tax
747
748 if doc.meta.get_field("rounded_total"):
749 if doc.is_rounded_total_disabled():
750 doc.outstanding_amount = doc.grand_total
751 else:
752 doc.rounded_total = round_based_on_smallest_currency_fraction(doc.grand_total,
753 doc.currency, doc.precision("rounded_total"))
754
755 doc.rounding_adjustment += flt(doc.rounded_total - doc.grand_total,
756 doc.precision("rounding_adjustment"))
757
Deepesh Garg18827352020-07-17 11:31:15 +0530758 doc.outstanding_amount = doc.rounded_total or doc.grand_total
Deepesh Garg3c004ad2020-07-02 21:18:29 +0530759
760 doc.in_words = money_in_words(doc.grand_total, doc.currency)
Deepesh Garg1c146062020-08-18 19:32:52 +0530761 doc.base_in_words = money_in_words(doc.base_grand_total, erpnext.get_company_currency(doc.company))
Deepesh Garg18827352020-07-17 11:31:15 +0530762 doc.set_payment_schedule()
Deepesh Garg3c004ad2020-07-02 21:18:29 +0530763
764def make_regional_gl_entries(gl_entries, doc):
Deepesh Garg24f9a802020-06-03 10:59:37 +0530765 country = frappe.get_cached_value('Company', doc.company, 'country')
766
767 if country != 'India':
Deepesh Garg8aed48f2020-08-19 18:30:18 +0530768 return gl_entries
769
Deepesh Garg24f9a802020-06-03 10:59:37 +0530770 if doc.reverse_charge == 'Y':
Deepesh Garg24f9a802020-06-03 10:59:37 +0530771 gst_accounts = get_gst_accounts(doc.company)
772 gst_account_list = gst_accounts.get('cgst_account') + gst_accounts.get('sgst_account') \
773 + gst_accounts.get('igst_account')
774
775 for tax in doc.get('taxes'):
776 if tax.category not in ("Total", "Valuation and Total"):
777 continue
778
Deepesh Gargafd2dd32020-08-20 16:31:38 +0530779 dr_or_cr = "credit" if tax.add_deduct_tax == "Add" else "debit"
Deepesh Garg24f9a802020-06-03 10:59:37 +0530780 if flt(tax.base_tax_amount_after_discount_amount) and tax.account_head in gst_account_list:
781 account_currency = get_account_currency(tax.account_head)
782
783 gl_entries.append(doc.get_gl_dict(
784 {
785 "account": tax.account_head,
786 "cost_center": tax.cost_center,
787 "posting_date": doc.posting_date,
788 "against": doc.supplier,
Deepesh Gargafd2dd32020-08-20 16:31:38 +0530789 dr_or_cr: tax.base_tax_amount_after_discount_amount,
790 dr_or_cr + "_in_account_currency": tax.base_tax_amount_after_discount_amount \
Deepesh Garg24f9a802020-06-03 10:59:37 +0530791 if account_currency==doc.company_currency \
792 else tax.tax_amount_after_discount_amount
793 }, account_currency, item=tax)
794 )
795
Deepesh Gargd07447a2020-11-24 08:09:17 +0530796 return gl_entries
Deepesh Garg6a5ef262021-02-19 14:30:23 +0530797
798@frappe.whitelist()
799def get_regional_round_off_accounts(company, account_list):
800 country = frappe.get_cached_value('Company', company, 'country')
801
802 if country != 'India':
803 return
804
805 if isinstance(account_list, string_types):
806 account_list = json.loads(account_list)
807
808 if not frappe.db.get_single_value('GST Settings', 'round_off_gst_values'):
809 return
810
811 gst_accounts = get_gst_accounts(company)
812 gst_account_list = gst_accounts.get('cgst_account') + gst_accounts.get('sgst_account') \
813 + gst_accounts.get('igst_account')
814
815 account_list.extend(gst_account_list)
816
817 return account_list