From 8100ee0a99cb4b92c7c1844e1bae30f1a63fc781 Mon Sep 17 00:00:00 2001 From: kk Date: Thu, 26 Oct 2017 12:08:16 +0530 Subject: [PATCH 1/8] made standard dictionary for VAT --- gkcore/views/api_tax.py | 374 ++++++++++++++++++++-------------------- 1 file changed, 188 insertions(+), 186 deletions(-) diff --git a/gkcore/views/api_tax.py b/gkcore/views/api_tax.py index efe80e8..f5f4153 100644 --- a/gkcore/views/api_tax.py +++ b/gkcore/views/api_tax.py @@ -41,15 +41,17 @@ from sqlalchemy.sql.expression import null def calTax(taxflag,source,destination,productcode,con): """ Purpose: - Takes the product code and returns tax rate based on inter or intra state basis. + Takes the product code and returns tax rate based on inter or intra state basis either GST or VAT depending on what is asked for. Description: This function takes product code, custermer and supplier states and taxflag as parameters and returns the tax rate (either GST or VAT). + Also returns Cess rate if GST is selected. The function searches the tax table for the tax rate given the productcode. If GST is sent as taxflag then IGST is returned for inter state sales. For this the 2 states provided as parameters must be different. If it is intra state then IGST is divided by 2 and the values are sent as CGST and SGST. - Returns the taxname and tax rate as dictionary in gkresult. + In both cases (CGST and IGST) CESS is returned if available in the tax table for the given product code. + Returns the taxnames as keys (CESS and GST in cases of GST) and their respective rates as values in dictionary in gkresult. """ try: if taxflag == 22: @@ -57,11 +59,11 @@ def calTax(taxflag,source,destination,productcode,con): if source == destination: taxResult = con.execute(select([tax.c.taxrate]).where(and_(tax.c.taxname == 'VAT',tax.c.productcode == productcode,tax.c.state == source))) taxData = taxResult.fetchone() - return{"gkstatus":enumdict["Success"],"gkresult":{"taxname":"VAT","taxrate":"%.2f"%float(taxData["taxrate"])}} + return{"gkstatus":enumdict["Success"],"gkresult":{"VAT":"%.2f"%float(taxData["taxrate"])}} else: taxResult = con.execute(select([tax.c.taxrate]).where(and_(tax.c.taxname == 'CVAT',tax.c.productcode == productcode))) taxData = taxResult.fetchone() - return{"gkstatus":enumdict["Success"],"gkresult":{"taxname":"CVAT","taxrate":"%.2f"%float(taxData["taxrate"])}} + return{"gkstatus":enumdict["Success"],"gkresult":{"CVAT":"%.2f"%float(taxData["taxrate"])}} else: #since it is not 22 means it is 7 = "GST". if source == destination: @@ -85,204 +87,204 @@ def calTax(taxflag,source,destination,productcode,con): @view_defaults(route_name='tax') class api_tax(object): - def __init__(self,request): - self.request = Request - self.request = request - self.con = Connection - print "tax initialized" + def __init__(self,request): + self.request = Request + self.request = request + self.con = Connection + print "tax initialized" - @view_config(request_method='POST',renderer='json') - def addtax(self): - """ This method creates tax - First it checks the user role if the user is admin then only user can add new tax """ - try: - token = self.request.headers["gktoken"] - except: - return {"gkstatus": gkcore.enumdict["UnauthorisedAccess"]} + @view_config(request_method='POST',renderer='json') + def addtax(self): + """ This method creates tax + First it checks the user role if the user is admin then only user can add new tax """ + try: + token = self.request.headers["gktoken"] + except: + return {"gkstatus": gkcore.enumdict["UnauthorisedAccess"]} - authDetails = authCheck(token) - if authDetails["auth"] == False: - return {"gkstatus": enumdict["UnauthorisedAccess"]} - else: - try: + authDetails = authCheck(token) + if authDetails["auth"] == False: + return {"gkstatus": enumdict["UnauthorisedAccess"]} + else: + try: - self.con = eng.connect() - user=self.con.execute(select([users.c.userrole]).where(users.c.userid == authDetails["userid"] )) - userRole = user.fetchone() - dataset = self.request.json_body - if userRole["userrole"]==-1 or userRole["userrole"]==1 or userRole["userrole"]==0: - dataset["orgcode"] = authDetails["orgcode"] + self.con = eng.connect() + user=self.con.execute(select([users.c.userrole]).where(users.c.userid == authDetails["userid"] )) + userRole = user.fetchone() + dataset = self.request.json_body + if userRole["userrole"]==-1 or userRole["userrole"]==1 or userRole["userrole"]==0: + dataset["orgcode"] = authDetails["orgcode"] - result = self.con.execute(tax.insert(),[dataset]) - return {"gkstatus":enumdict["Success"]} - else: - return {"gkstatus": enumdict["BadPrivilege"]} - except exc.IntegrityError: - return {"gkstatus":enumdict["DuplicateEntry"]} - except: - return {"gkstatus":gkcore.enumdict["ConnectionFailed"]} - finally: - self.con.close() + result = self.con.execute(tax.insert(),[dataset]) + return {"gkstatus":enumdict["Success"]} + else: + return {"gkstatus": enumdict["BadPrivilege"]} + except exc.IntegrityError: + return {"gkstatus":enumdict["DuplicateEntry"]} + except: + return {"gkstatus":gkcore.enumdict["ConnectionFailed"]} + finally: + self.con.close() - @view_config(request_method='GET',request_param='pscflag',renderer='json') - def getprodtax(self): - """ - This method will return the list of taxes for a product or a category. - The tax will be either returned for a given product or a category, or with the combination of product and state (Specially for VAT). - Takes in a parameter for productcode or categorycode, optionally statecode. - If the flag is p then all the taxes for that product will be returned. - If it is s then for that product for that state will be returned. - If it is c then for that category will be returned. - returns a list of JSON objects. - """ - try: - token = self.request.headers["gktoken"] - except: - return {"gkstatus": enumdict["UnauthorisedAccess"]} - authDetails = authCheck(token) - if authDetails["auth"] == False: - return {"gkstatus":enumdict["UnauthorisedAccess"]} - else: - try: - self.con = eng.connect() - if(self.request.params["pscflag"]=="p"): - result = self.con.execute(select([tax.c.taxid,tax.c.taxname,tax.c.taxrate,tax.c.state]).where(tax.c.productcode==self.request.params["productcode"])) - tx =[] - for row in result: - tx.append({"taxid":row["taxid"],"taxname":row["taxname"], "taxrate":"%.2f"%float(row["taxrate"]),"state":row["state"]}) - return {"gkstatus":enumdict["Success"],"gkresult":tx} + @view_config(request_method='GET',request_param='pscflag',renderer='json') + def getprodtax(self): + """ + This method will return the list of taxes for a product or a category. + The tax will be either returned for a given product or a category, or with the combination of product and state (Specially for VAT). + Takes in a parameter for productcode or categorycode, optionally statecode. + If the flag is p then all the taxes for that product will be returned. + If it is s then for that product for that state will be returned. + If it is c then for that category will be returned. + returns a list of JSON objects. + """ + try: + token = self.request.headers["gktoken"] + except: + return {"gkstatus": enumdict["UnauthorisedAccess"]} + authDetails = authCheck(token) + if authDetails["auth"] == False: + return {"gkstatus":enumdict["UnauthorisedAccess"]} + else: + try: + self.con = eng.connect() + if(self.request.params["pscflag"]=="p"): + result = self.con.execute(select([tax.c.taxid,tax.c.taxname,tax.c.taxrate,tax.c.state]).where(tax.c.productcode==self.request.params["productcode"])) + tx =[] + for row in result: + tx.append({"taxid":row["taxid"],"taxname":row["taxname"], "taxrate":"%.2f"%float(row["taxrate"]),"state":row["state"]}) + return {"gkstatus":enumdict["Success"],"gkresult":tx} - if(self.request.params["pscflag"]=="s"): - result = self.con.execute(select([tax.c.taxid,tax.c.taxname,tax.c.taxrate]).where(and_(tax.c.productcode==self.request.params["productcode"],tax.c.state==self.request.params["state"]))) - tx =[] - for row in result: - tx.append({"taxid":row["taxid"],"taxname":row["taxname"], "taxrate":"%.2f"%float(row["taxrate"])}) - return {"gkstatus":enumdict["Success"], "gkresult":tx} - self.con.close() + if(self.request.params["pscflag"]=="s"): + result = self.con.execute(select([tax.c.taxid,tax.c.taxname,tax.c.taxrate]).where(and_(tax.c.productcode==self.request.params["productcode"],tax.c.state==self.request.params["state"]))) + tx =[] + for row in result: + tx.append({"taxid":row["taxid"],"taxname":row["taxname"], "taxrate":"%.2f"%float(row["taxrate"])}) + return {"gkstatus":enumdict["Success"], "gkresult":tx} + self.con.close() - if(self.request.params["pscflag"]=="c"): - result = self.con.execute(select([tax.c.taxid,tax.c.taxname,tax.c.taxrate,tax.c.state]).where(tax.c.categorycode==self.request.params["categorycode"])) - tx =[] - for row in result: - tx.append({"taxid":row["taxid"],"taxname":row["taxname"], "taxrate":"%.2f"%float(row["taxrate"]),"state":row["state"]}) - return {"gkstatus":enumdict["Success"],"gkresult":tx} - if(self.request.params["pscflag"]=="i"): - result = self.con.execute(select([product.c.categorycode]).where(product.c.productcode==self.request.params["productcode"])) - catcoderow = result.fetchone() - tx = 0.00 - if catcoderow["categorycode"]!=None: - if(self.request.params.has_key("state")): - result = self.con.execute(select([tax.c.taxrate]).where(and_(tax.c.categorycode==catcoderow["categorycode"],tax.c.state==self.request.params["state"]))) - if result.rowcount>0: - taxrow = result.fetchone() - tx = taxrow["taxrate"] - else: - result = self.con.execute(select([tax.c.taxrate]).where(and_(tax.c.categorycode==catcoderow["categorycode"],tax.c.state==null()))) - if result.rowcount>0: - taxrow = result.fetchone() - tx = taxrow["taxrate"] - else: - if(self.request.params.has_key("state")): - result = self.con.execute(select([tax.c.taxrate]).where(and_(tax.c.productcode==self.request.params["productcode"],tax.c.state==self.request.params["state"]))) - if result.rowcount>0: - taxrow = result.fetchone() - tx = taxrow["taxrate"] - else: - result = self.con.execute(select([tax.c.taxrate]).where(and_(tax.c.productcode==self.request.params["productcode"],tax.c.state==null()))) - if result.rowcount>0: - taxrow = result.fetchone() - tx = taxrow["taxrate"] - return {"gkstatus":enumdict["Success"],"gkresult":"%.2f"%float(tx)} - except: - self.con.close() - return {"gkstatus":enumdict["ConnectionFailed"]} - finally: - self.con.close() + if(self.request.params["pscflag"]=="c"): + result = self.con.execute(select([tax.c.taxid,tax.c.taxname,tax.c.taxrate,tax.c.state]).where(tax.c.categorycode==self.request.params["categorycode"])) + tx =[] + for row in result: + tx.append({"taxid":row["taxid"],"taxname":row["taxname"], "taxrate":"%.2f"%float(row["taxrate"]),"state":row["state"]}) + return {"gkstatus":enumdict["Success"],"gkresult":tx} + if(self.request.params["pscflag"]=="i"): + result = self.con.execute(select([product.c.categorycode]).where(product.c.productcode==self.request.params["productcode"])) + catcoderow = result.fetchone() + tx = 0.00 + if catcoderow["categorycode"]!=None: + if(self.request.params.has_key("state")): + result = self.con.execute(select([tax.c.taxrate]).where(and_(tax.c.categorycode==catcoderow["categorycode"],tax.c.state==self.request.params["state"]))) + if result.rowcount>0: + taxrow = result.fetchone() + tx = taxrow["taxrate"] + else: + result = self.con.execute(select([tax.c.taxrate]).where(and_(tax.c.categorycode==catcoderow["categorycode"],tax.c.state==null()))) + if result.rowcount>0: + taxrow = result.fetchone() + tx = taxrow["taxrate"] + else: + if(self.request.params.has_key("state")): + result = self.con.execute(select([tax.c.taxrate]).where(and_(tax.c.productcode==self.request.params["productcode"],tax.c.state==self.request.params["state"]))) + if result.rowcount>0: + taxrow = result.fetchone() + tx = taxrow["taxrate"] + else: + result = self.con.execute(select([tax.c.taxrate]).where(and_(tax.c.productcode==self.request.params["productcode"],tax.c.state==null()))) + if result.rowcount>0: + taxrow = result.fetchone() + tx = taxrow["taxrate"] + return {"gkstatus":enumdict["Success"],"gkresult":"%.2f"%float(tx)} + except: + self.con.close() + return {"gkstatus":enumdict["ConnectionFailed"]} + finally: + self.con.close() - @view_config(request_method='GET',renderer='json') - def getAllTax(self): - """This method returns all existing data about taxes for current organisation """ - try: + @view_config(request_method='GET',renderer='json') + def getAllTax(self): + """This method returns all existing data about taxes for current organisation """ + try: - token = self.request.headers["gktoken"] - except: - return {"gkstatus": enumdict["UnauthorisedAccess"]} - authDetails = authCheck(token) - if authDetails["auth"] == False: - return {"gkstatus":enumdict["UnauthorisedAccess"]} - else: - try: - self.con = eng.connect() + token = self.request.headers["gktoken"] + except: + return {"gkstatus": enumdict["UnauthorisedAccess"]} + authDetails = authCheck(token) + if authDetails["auth"] == False: + return {"gkstatus":enumdict["UnauthorisedAccess"]} + else: + try: + self.con = eng.connect() - result = self.con.execute(select([tax]).where(tax.c.orgcode==authDetails["orgcode"])) - tx = [] - for row in result: - tx.append({"taxid": row["taxid"], "taxname":row["taxname"], "taxrate":"%.2f"%float(row["taxrate"]),"state":row["state"], "categorycode": row["categorycode"], "productcode": row["productcode"], "orgcode": row["orgcode"] }) + result = self.con.execute(select([tax]).where(tax.c.orgcode==authDetails["orgcode"])) + tx = [] + for row in result: + tx.append({"taxid": row["taxid"], "taxname":row["taxname"], "taxrate":"%.2f"%float(row["taxrate"]),"state":row["state"], "categorycode": row["categorycode"], "productcode": row["productcode"], "orgcode": row["orgcode"] }) - self.con.close() - return {"gkstatus":enumdict["Success"], "gkdata":tx} - except: - self.con.close() - return {"gkstatus":enumdict["ConnectionFailed"]} - finally: - self.con.close() + self.con.close() + return {"gkstatus":enumdict["Success"], "gkdata":tx} + except: + self.con.close() + return {"gkstatus":enumdict["ConnectionFailed"]} + finally: + self.con.close() - @view_config(request_method='PUT', renderer='json') - def edittaxdata(self): - """ This method updates the taxdata """ - try: - token = self.request.headers["gktoken"] - except: - return {"gkstatus": gkcore.enumdict["UnauthorisedAccess"]} + @view_config(request_method='PUT', renderer='json') + def edittaxdata(self): + """ This method updates the taxdata """ + try: + token = self.request.headers["gktoken"] + except: + return {"gkstatus": gkcore.enumdict["UnauthorisedAccess"]} - authDetails = authCheck(token) - if authDetails["auth"] == False: - return {"gkstatus": enumdict["UnauthorisedAccess"]} - else: - try: - self.con = eng.connect() - user=self.con.execute(select([users.c.userrole]).where(users.c.userid == authDetails["userid"] )) - userRole = user.fetchone() - dataset = self.request.json_body + authDetails = authCheck(token) + if authDetails["auth"] == False: + return {"gkstatus": enumdict["UnauthorisedAccess"]} + else: + try: + self.con = eng.connect() + user=self.con.execute(select([users.c.userrole]).where(users.c.userid == authDetails["userid"] )) + userRole = user.fetchone() + dataset = self.request.json_body - if userRole["userrole"]==-1 or userRole["userrole"]==1 or userRole["userrole"]==0: + if userRole["userrole"]==-1 or userRole["userrole"]==1 or userRole["userrole"]==0: - result = self.con.execute(tax.update().where(tax.c.taxid == dataset["taxid"]).values(dataset)) - return {"gkstatus":enumdict["Success"]} - else: - return {"gkstatus": enumdict["BadPrivilege"]} - except: - return {"gkstatus":gkcore.enumdict["ConnectionFailed"] } - finally: - self.con.close() + result = self.con.execute(tax.update().where(tax.c.taxid == dataset["taxid"]).values(dataset)) + return {"gkstatus":enumdict["Success"]} + else: + return {"gkstatus": enumdict["BadPrivilege"]} + except: + return {"gkstatus":gkcore.enumdict["ConnectionFailed"] } + finally: + self.con.close() - @view_config(request_method='DELETE', renderer ='json') - def deletetaxdata(self): - """ This method delets the tax data by matching taxid """ - try: - token = self.request.headers["gktoken"] - except: - return {"gkstatus": enumdict["UnauthorisedAccess"]} - authDetails = authCheck(token) - if authDetails["auth"]==False: - return {"gkstatus":enumdict["UnauthorisedAccess"]} - else: - try: - self.con = eng.connect() - user=self.con.execute(select([users.c.userrole]).where(users.c.userid == authDetails["userid"] )) - userRole = user.fetchone() - dataset = self.request.json_body - if userRole["userrole"]==-1 or userRole["userrole"]==1 or userRole["userrole"]==0: - result = self.con.execute(tax.delete().where(tax.c.taxid==dataset["taxid"])) - return {"gkstatus":enumdict["Success"]} - else: - {"gkstatus": enumdict["BadPrivilege"]} - except exc.IntegrityError: - return {"gkstatus":enumdict["ActionDisallowed"]} - except: - return {"gkstatus":enumdict["ConnectionFailed"] } - finally: - self.con.close() + @view_config(request_method='DELETE', renderer ='json') + def deletetaxdata(self): + """ This method delets the tax data by matching taxid """ + try: + token = self.request.headers["gktoken"] + except: + return {"gkstatus": enumdict["UnauthorisedAccess"]} + authDetails = authCheck(token) + if authDetails["auth"]==False: + return {"gkstatus":enumdict["UnauthorisedAccess"]} + else: + try: + self.con = eng.connect() + user=self.con.execute(select([users.c.userrole]).where(users.c.userid == authDetails["userid"] )) + userRole = user.fetchone() + dataset = self.request.json_body + if userRole["userrole"]==-1 or userRole["userrole"]==1 or userRole["userrole"]==0: + result = self.con.execute(tax.delete().where(tax.c.taxid==dataset["taxid"])) + return {"gkstatus":enumdict["Success"]} + else: + {"gkstatus": enumdict["BadPrivilege"]} + except exc.IntegrityError: + return {"gkstatus":enumdict["ActionDisallowed"]} + except: + return {"gkstatus":enumdict["ConnectionFailed"] } + finally: + self.con.close() -- GitLab From dead124c52ac559f6830246c1ac2393f4d38394c Mon Sep 17 00:00:00 2001 From: kk Date: Thu, 26 Oct 2017 12:45:53 +0530 Subject: [PATCH 2/8] Added Cess with GST. --- gkcore/views/api_tax.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/gkcore/views/api_tax.py b/gkcore/views/api_tax.py index f5f4153..408da85 100644 --- a/gkcore/views/api_tax.py +++ b/gkcore/views/api_tax.py @@ -66,6 +66,12 @@ def calTax(taxflag,source,destination,productcode,con): return{"gkstatus":enumdict["Success"],"gkresult":{"CVAT":"%.2f"%float(taxData["taxrate"])}} else: #since it is not 22 means it is 7 = "GST". + #Also we will need CESS in Both Inter and Intra State GST. + CESSResult = con.execute(select([tax.c.taxrate]).where(and_(tax.c.taxname == "CESS",tax.c.productcode == productcode))) + if CESSResult.rowcount > 0: + cessRow = CESSResult.fetchone() + cessData ="%.2f"%float(cessRow["taxrate"]) + if source == destination: #this is SGST and CGST. @@ -75,12 +81,12 @@ def calTax(taxflag,source,destination,productcode,con): gst = float(taxData["taxrate"]) /2 #note although we are returning only SGST, same rate applies to CGST. #so when u see taxname is sgst then cgst with same rate is asumed. - return{"gkstatus":enumdict["Success"],"gkresult":{"taxname":"SGST","taxrate":"%.2f"%float(gst)}} + return{"gkstatus":enumdict["Success"],"gkresult":{"SGST":"%.2f"%float(gst),"CESS":cessData}} else: #this is IGST. taxResult = con.execute(select([tax.c.taxrate]).where(and_(tax.c.taxname == 'IGST',tax.c.productcode == productcode))) taxData = taxResult.fetchone() - return{"gkstatus":enumdict["Success"],"gkresult":{"taxname":"IGST","taxrate":"%.2f"%float(taxData["taxrate"])}} + return{"gkstatus":enumdict["Success"],"gkresult":{"IGST":"%.2f"%float(taxData["taxrate"]),"CESS":cessData}} except: return {"gkstatus":gkcore.enumdict["ConnectionFailed"]} -- GitLab From 4432f2f56559a95c924507948376b81b7914f062 Mon Sep 17 00:00:00 2001 From: kk Date: Thu, 26 Oct 2017 13:34:41 +0530 Subject: [PATCH 3/8] Solved the flaw which could come with CESS not available. --- gkcore/views/api_invoice.py | 7 ++++--- gkcore/views/api_tax.py | 10 +++++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/gkcore/views/api_invoice.py b/gkcore/views/api_invoice.py index 2ae6ea1..6947cbc 100644 --- a/gkcore/views/api_invoice.py +++ b/gkcore/views/api_invoice.py @@ -378,9 +378,10 @@ There will be an icFlag which will determine if it's an incrementing or decreme else: TaxData = calTax(7,invrow["sourcestate"],invrow["taxstate"],pc,self.con) taxResult = TaxData["gkresult"] - taxRate = float(taxResult["taxrate"]) - inv["taxname"] = taxResult["taxname"] - if taxResult["taxname"] == "IGST": + + if taxResult.has_key(IGST): + taxRate = float(taxResult["IGST"]) + cessRate = float(ta) taxAmount = (taxableAmount * (taxRate/100)) totalAmount = taxableAmount + (taxableAmount * (taxRate/100)) else: diff --git a/gkcore/views/api_tax.py b/gkcore/views/api_tax.py index 408da85..ada15e3 100644 --- a/gkcore/views/api_tax.py +++ b/gkcore/views/api_tax.py @@ -67,10 +67,12 @@ def calTax(taxflag,source,destination,productcode,con): else: #since it is not 22 means it is 7 = "GST". #Also we will need CESS in Both Inter and Intra State GST. + taxDict = {} CESSResult = con.execute(select([tax.c.taxrate]).where(and_(tax.c.taxname == "CESS",tax.c.productcode == productcode))) if CESSResult.rowcount > 0: cessRow = CESSResult.fetchone() cessData ="%.2f"%float(cessRow["taxrate"]) + taxDict["CESS"] = cessData if source == destination: @@ -80,13 +82,15 @@ def calTax(taxflag,source,destination,productcode,con): taxData = taxResult.fetchone() gst = float(taxData["taxrate"]) /2 #note although we are returning only SGST, same rate applies to CGST. - #so when u see taxname is sgst then cgst with same rate is asumed. - return{"gkstatus":enumdict["Success"],"gkresult":{"SGST":"%.2f"%float(gst),"CESS":cessData}} + #so when u see taxname is sgst then cgst with same rate is asumed. + taxDict["SGST"] = gst + return{"gkstatus":enumdict["Success"],"gkresult":taxDict}} else: #this is IGST. taxResult = con.execute(select([tax.c.taxrate]).where(and_(tax.c.taxname == 'IGST',tax.c.productcode == productcode))) taxData = taxResult.fetchone() - return{"gkstatus":enumdict["Success"],"gkresult":{"IGST":"%.2f"%float(taxData["taxrate"]),"CESS":cessData}} + taxDict["IGST"] ="%.2f"%float(taxData["taxrate"]) + return{"gkstatus":enumdict["Success"],"gkresult":taxDict} except: return {"gkstatus":gkcore.enumdict["ConnectionFailed"]} -- GitLab From 079ae474f0f233cdb7033bce5516ae3542074dac Mon Sep 17 00:00:00 2001 From: kk Date: Thu, 26 Oct 2017 15:09:59 +0530 Subject: [PATCH 4/8] Completed modifications invoice for CESS. --- gkcore/views/api_invoice.py | 17 ++++++++++++----- gkcore/views/api_tax.py | 2 +- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/gkcore/views/api_invoice.py b/gkcore/views/api_invoice.py index 6947cbc..09340ae 100644 --- a/gkcore/views/api_invoice.py +++ b/gkcore/views/api_invoice.py @@ -378,22 +378,29 @@ There will be an icFlag which will determine if it's an incrementing or decreme else: TaxData = calTax(7,invrow["sourcestate"],invrow["taxstate"],pc,self.con) taxResult = TaxData["gkresult"] - + cessRate = 0.00 + cessAmount = 0.00 + taxname = "" + if taxResult.has_key(CESS): + cessVal = float(taxResult["CESS"]) + cessAmount = (taxableAmount * (taxRate/100)) + if taxResult.has_key(IGST): + taxname = IGST taxRate = float(taxResult["IGST"]) - cessRate = float(ta) taxAmount = (taxableAmount * (taxRate/100)) - totalAmount = taxableAmount + (taxableAmount * (taxRate/100)) + totalAmount = taxableAmount + taxAmount + cessAmount else: + taxname = SGST taxAmount = (taxableAmount * (taxRate/100)) - totalAmount = taxableAmount + (taxableAmount * ((taxRate * 2)/100)) + totalAmount = taxableAmount + (taxableAmount * ((taxRate * 2)/100)) + cessAmount totalDisc = totalDisc + float(discount) totalTaxableVal = totalTaxableVal + taxableAmount totalTaxAmt = totalTaxAmt + taxAmount - invContents[pc] = {"proddesc":prodrow["productdesc"],"gscode":prodrow["gscode"],"uom":unitofMeasurement,"qty":"%.2f"% (float(contentsData[pc][contentsData[pc].keys()[0]])),"freeqty":"%.2f"% (float(freeqty)),"priceperunit":"%.2f"% (float(contentsData[pc].keys()[0])),"discount":"%.2f"% (float(discount)),"taxableamount":"%.2f"%(float(taxableAmount)),"totalAmount":"%.2f"% (float(totalAmount)),"taxname":taxResult["taxname"],"taxrate":"%.2f"% (float(taxRate)),"taxamount":"%.2f"% (float(taxAmount))} + invContents[pc] = {"proddesc":prodrow["productdesc"],"gscode":prodrow["gscode"],"uom":unitofMeasurement,"qty":"%.2f"% (float(contentsData[pc][contentsData[pc].keys()[0]])),"freeqty":"%.2f"% (float(freeqty)),"priceperunit":"%.2f"% (float(contentsData[pc].keys()[0])),"discount":"%.2f"% (float(discount)),"taxableamount":"%.2f"%(float(taxableAmount)),"totalAmount":"%.2f"% (float(totalAmount)),"taxname":taxname,"taxrate":"%.2f"% (float(taxRate)),"taxamount":"%.2f"% (float(taxAmount)),"cess":float(cessAmount)} inv["totaldiscount"] = "%.2f"% (float(totalDisc)) inv["totaltaxablevalue"] = "%.2f"% (float(totalTaxableVal)) inv["totaltaxamt"] = "%.2f"% (float(totalTaxAmt)) diff --git a/gkcore/views/api_tax.py b/gkcore/views/api_tax.py index ada15e3..27e0274 100644 --- a/gkcore/views/api_tax.py +++ b/gkcore/views/api_tax.py @@ -21,7 +21,7 @@ Copyright (C) 2013, 2014, 2015, 2016 Digital Freedom Foundation Contributors: "Krishnakant Mane" -"Prajkta Patkar" +"Prajkta Patkar" "Bhagyashree Pandhare" """ -- GitLab From 4c9868b89e4428088a3c1a6cd2905277c3b4e2d7 Mon Sep 17 00:00:00 2001 From: Prajkta_Patkar Date: Thu, 26 Oct 2017 16:17:05 +0530 Subject: [PATCH 5/8] mistakes corrected and cess formula corrected --- gkcore/views/api_invoice.py | 24 +++++++++++++----------- gkcore/views/api_tax.py | 2 +- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/gkcore/views/api_invoice.py b/gkcore/views/api_invoice.py index 09340ae..cd264be 100644 --- a/gkcore/views/api_invoice.py +++ b/gkcore/views/api_invoice.py @@ -264,7 +264,7 @@ There will be an icFlag which will determine if it's an incrementing or decreme if authDetails["auth"] == False: return {"gkstatus": gkcore.enumdict["UnauthorisedAccess"]} else: - try: + # try: self.con = eng.connect() result = self.con.execute(select([invoice]).where(invoice.c.invid==self.request.params["invid"])) invrow = result.fetchone() @@ -381,17 +381,19 @@ There will be an icFlag which will determine if it's an incrementing or decreme cessRate = 0.00 cessAmount = 0.00 taxname = "" - if taxResult.has_key(CESS): + if taxResult.has_key('CESS'): cessVal = float(taxResult["CESS"]) - cessAmount = (taxableAmount * (taxRate/100)) + cessAmount = (taxableAmount * (cessVal/100)) - if taxResult.has_key(IGST): - taxname = IGST + if taxResult.has_key('IGST'): + taxname = "IGST" taxRate = float(taxResult["IGST"]) + print taxRate taxAmount = (taxableAmount * (taxRate/100)) totalAmount = taxableAmount + taxAmount + cessAmount + print totalAmount else: - taxname = SGST + taxname = "SGST" taxAmount = (taxableAmount * (taxRate/100)) totalAmount = taxableAmount + (taxableAmount * ((taxRate * 2)/100)) + cessAmount @@ -400,16 +402,16 @@ There will be an icFlag which will determine if it's an incrementing or decreme totalTaxAmt = totalTaxAmt + taxAmount - invContents[pc] = {"proddesc":prodrow["productdesc"],"gscode":prodrow["gscode"],"uom":unitofMeasurement,"qty":"%.2f"% (float(contentsData[pc][contentsData[pc].keys()[0]])),"freeqty":"%.2f"% (float(freeqty)),"priceperunit":"%.2f"% (float(contentsData[pc].keys()[0])),"discount":"%.2f"% (float(discount)),"taxableamount":"%.2f"%(float(taxableAmount)),"totalAmount":"%.2f"% (float(totalAmount)),"taxname":taxname,"taxrate":"%.2f"% (float(taxRate)),"taxamount":"%.2f"% (float(taxAmount)),"cess":float(cessAmount)} + invContents[pc] = {"proddesc":prodrow["productdesc"],"gscode":prodrow["gscode"],"uom":unitofMeasurement,"qty":"%.2f"% (float(contentsData[pc][contentsData[pc].keys()[0]])),"freeqty":"%.2f"% (float(freeqty)),"priceperunit":"%.2f"% (float(contentsData[pc].keys()[0])),"discount":"%.2f"% (float(discount)),"taxableamount":"%.2f"%(float(taxableAmount)),"totalAmount":"%.2f"% (float(totalAmount)),"taxname":taxname,"taxrate":"%.2f"% (float(taxRate)),"taxamount":"%.2f"% (float(taxAmount)),"cess":"%.2f"%(float(cessAmount))} inv["totaldiscount"] = "%.2f"% (float(totalDisc)) inv["totaltaxablevalue"] = "%.2f"% (float(totalTaxableVal)) inv["totaltaxamt"] = "%.2f"% (float(totalTaxAmt)) inv["invcontents"] = invContents return {"gkstatus":gkcore.enumdict["Success"],"gkresult":inv} - except: - return {"gkstatus":gkcore.enumdict["ConnectionFailed"]} - finally: - self.con.close() + # except: + # return {"gkstatus":gkcore.enumdict["ConnectionFailed"]} + # finally: + # self.con.close() @view_config(request_method='GET',request_param="type=bwa", renderer ='json') def getCSUPBills(self): diff --git a/gkcore/views/api_tax.py b/gkcore/views/api_tax.py index 27e0274..23ecc49 100644 --- a/gkcore/views/api_tax.py +++ b/gkcore/views/api_tax.py @@ -84,7 +84,7 @@ def calTax(taxflag,source,destination,productcode,con): #note although we are returning only SGST, same rate applies to CGST. #so when u see taxname is sgst then cgst with same rate is asumed. taxDict["SGST"] = gst - return{"gkstatus":enumdict["Success"],"gkresult":taxDict}} + return{"gkstatus":enumdict["Success"],"gkresult":taxDict} else: #this is IGST. taxResult = con.execute(select([tax.c.taxrate]).where(and_(tax.c.taxname == 'IGST',tax.c.productcode == productcode))) -- GitLab From 9eb1e27c98873fd379b76c10baea87325f62a199 Mon Sep 17 00:00:00 2001 From: Prajkta_Patkar Date: Thu, 26 Oct 2017 16:30:08 +0530 Subject: [PATCH 6/8] taxResult variable added wj=hic was missed --- gkcore/views/api_invoice.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gkcore/views/api_invoice.py b/gkcore/views/api_invoice.py index cd264be..e0ec063 100644 --- a/gkcore/views/api_invoice.py +++ b/gkcore/views/api_invoice.py @@ -388,12 +388,12 @@ There will be an icFlag which will determine if it's an incrementing or decreme if taxResult.has_key('IGST'): taxname = "IGST" taxRate = float(taxResult["IGST"]) - print taxRate taxAmount = (taxableAmount * (taxRate/100)) totalAmount = taxableAmount + taxAmount + cessAmount - print totalAmount else: + print "SGST" taxname = "SGST" + taxRate = float(taxResult["SGST"]) taxAmount = (taxableAmount * (taxRate/100)) totalAmount = taxableAmount + (taxableAmount * ((taxRate * 2)/100)) + cessAmount -- GitLab From 647f523931ecd2f477d8ffabedbecd4feca9235b Mon Sep 17 00:00:00 2001 From: kk Date: Fri, 27 Oct 2017 11:46:16 +0530 Subject: [PATCH 7/8] Removed commented try except block and corrected indentation. --- gkcore/views/api_invoice.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gkcore/views/api_invoice.py b/gkcore/views/api_invoice.py index e0ec063..fad188e 100644 --- a/gkcore/views/api_invoice.py +++ b/gkcore/views/api_invoice.py @@ -264,7 +264,7 @@ There will be an icFlag which will determine if it's an incrementing or decreme if authDetails["auth"] == False: return {"gkstatus": gkcore.enumdict["UnauthorisedAccess"]} else: - # try: + try: self.con = eng.connect() result = self.con.execute(select([invoice]).where(invoice.c.invid==self.request.params["invid"])) invrow = result.fetchone() @@ -408,7 +408,7 @@ There will be an icFlag which will determine if it's an incrementing or decreme inv["totaltaxamt"] = "%.2f"% (float(totalTaxAmt)) inv["invcontents"] = invContents return {"gkstatus":gkcore.enumdict["Success"],"gkresult":inv} - # except: + except: # return {"gkstatus":gkcore.enumdict["ConnectionFailed"]} # finally: # self.con.close() -- GitLab From 77f4cd0be93810791941e1f5694e781b47076a54 Mon Sep 17 00:00:00 2001 From: kk Date: Fri, 27 Oct 2017 11:48:23 +0530 Subject: [PATCH 8/8] all code final. --- gkcore/views/api_invoice.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gkcore/views/api_invoice.py b/gkcore/views/api_invoice.py index fad188e..1761024 100644 --- a/gkcore/views/api_invoice.py +++ b/gkcore/views/api_invoice.py @@ -409,9 +409,9 @@ There will be an icFlag which will determine if it's an incrementing or decreme inv["invcontents"] = invContents return {"gkstatus":gkcore.enumdict["Success"],"gkresult":inv} except: - # return {"gkstatus":gkcore.enumdict["ConnectionFailed"]} - # finally: - # self.con.close() + return {"gkstatus":gkcore.enumdict["ConnectionFailed"]} + finally: + self.con.close() @view_config(request_method='GET',request_param="type=bwa", renderer ='json') def getCSUPBills(self): -- GitLab