diff --git a/AUTHORS b/AUTHORS index 89b1591bb31bf4930e89b37a3309ae2847983b59..8519d97357fe561e1fa4489e27eaacb5e65a3e75 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1,7 +1,7 @@ Active Contributors "Abhijith Balan" -"Mohd. Talha Pawaty" +"Nitesh Chaughule" "Prajkta Patkar" "Reshma Bhatawadekar" @@ -15,7 +15,7 @@ Past contributers Abhijeet Mote, Abhishek Alai, Aditi Patil, Akshay Puradkar, Amit Chaugule, Ankita Shanbhag, Aparna Kokirkar, Ashwini Jogdand, Ashwini Shinde, Ashutosh Paralikar Avinash Pathak,Bhavesh Bawadhane,Dinesh Sutar, Ganesh Mashram, Girish Joshi, Girish Mane, Ishan Masdekar -Kanchan Kayande, Kanchan Palatane,Namita Dubey,Navin Karkera ,Nutan Nivate, Payal Mamidwar, +Kanchan Kayande, Kanchan Palatane, Mohd. Talha Pawat,Namita Dubey,Navin Karkera ,Nutan Nivate, Payal Mamidwar, Parabjyot Singh,, Poonam Dhane, Pornima Kolte,Prasad Shegokar, Priyali Mhetre,Radhika Vadegaonkar kulkarni, Rahul Chaurasiya ,Ravindra Lakal, Rupali Markad,Rohini Baraskar,Sachin Patil,Sadhana Bagal,Sayali Yawle, Snehal Nighut, Shruti Surve, Shweta Pawar, Sundeep Padmanabh,Trupti Kini, Ujwala Pawde, Vaibhav Kurhe,Vaishali Kamble,Vanita Rajpurohit, Vinayak Kusumkar and Vishakha Divekar. diff --git a/CHANGELOG b/CHANGELOG index 016d1376d94e1d883c94986bcc416de76712ef09..5b47bdc7feeb76e24a2bbd87826c1f966e6f6bbc 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,15 @@ +[10-January-2018 Release 4.50] +* Refinement in Transaction API +* Function in Transaction API to auto generate Voucher No. +* Function in Bill Wise API that returns all unpaid invoices. +* Function in Bill Wise API that returns both unpaid and partially paid invoices. +* Function in User API that returns list of users having same role and their role. +* Function in User API that returns all data of a user(accessible only to admin). +* All details of a user can be edited by admin. +* Consignee details can be added in Delivery Note. +* Function in Godowns API to return name and address of all godowns that contain products. +* Modified PUT of Invoice API. + [10-November-2017 Release 4.25 Update] * Permissions to Godown In Charge modified. * CESS field added in invoice and cash memo. diff --git a/gkcore/__init__.py b/gkcore/__init__.py index 3c7fded07aae07fa4c9bfa7d1665b159a0ed28b0..3e2cae4b7414e3adc8d3d82582714ecfe8055514 100644 --- a/gkcore/__init__.py +++ b/gkcore/__init__.py @@ -1,6 +1,7 @@ """ Copyright (C) 2013, 2014, 2015, 2016 Digital Freedom Foundation +Copyright (C) 2017, 2018 Digital Freedom Foundation & Accion Labs This file is part of GNUKhata:A modular,robust and Free Accounting System. GNUKhata is Free Software; you can redistribute it and/or modify diff --git a/gkcore/models/gkdb.py b/gkcore/models/gkdb.py index 4c0d9821ee853defedff5af87bf5bdec28792264..b49a1e3ca2b353ffb912e0d63e153d73f9916119 100644 --- a/gkcore/models/gkdb.py +++ b/gkcore/models/gkdb.py @@ -1,6 +1,7 @@ """ Copyright (C) 2013, 2014, 2015, 2016 Digital Freedom Foundation +Copyright (C) 2017, 2018 Digital Freedom Foundation & Accion Labs Pvt. Ltd. This file is part of GNUKhata:A modular,robust and Free Accounting System. GNUKhata is Free Software; you can redistribute it and/or modify @@ -361,6 +362,7 @@ delchal = Table('delchal',metadata, Column('noofpackages', Integer, nullable=False), Column('modeoftransport', UnicodeText), Column('attachment',JSON), + Column('consignee',JSONB), Column('attachmentcount',Integer,default=0), Column('orgcode',Integer, ForeignKey('organisation.orgcode',ondelete="CASCADE"), nullable=False), Column('custid',Integer, ForeignKey('customerandsupplier.custid')), diff --git a/gkcore/models/meta.py b/gkcore/models/meta.py index d367ae9ef835e3461104f5b5d9d2a04ff3abc2ed..883b3bbeacbd157cd82270f6090712bb3563a722 100644 --- a/gkcore/models/meta.py +++ b/gkcore/models/meta.py @@ -1,6 +1,7 @@ """ Copyright (C) 2013, 2014, 2015, 2016 Digital Freedom Foundation +Copyright (C) 2017, 2018 Digital Freedom Foundation & Accion Labs This file is part of GNUKhata:A modular,robust and Free Accounting System. GNUKhata is Free Software; you can redistribute it and/or modify diff --git a/gkcore/tests/test_account.py b/gkcore/tests/test_account.py index 33ad80705a2fb2139a4af129e1744e87d97e5807..78234182b8488c882febee26e28bcfb5f8ac3a9d 100644 --- a/gkcore/tests/test_account.py +++ b/gkcore/tests/test_account.py @@ -1,5 +1,6 @@ """ Copyright (C) 2013, 2014, 2015, 2016 Digital Freedom Foundation +Copyright (C) 2017, 2018 Digital Freedom Foundation & Accion Labs This file is part of GNUKhata:A modular,robust and Free Accounting System. GNUKhata is Free Software; you can redistribute it and/or modify diff --git a/gkcore/tests/test_accountsbyrule.py b/gkcore/tests/test_accountsbyrule.py index 8babb03575b4275178932a2461303bd0f8098d2a..971d50e88823c84560a461bc67570ced142efbba 100644 --- a/gkcore/tests/test_accountsbyrule.py +++ b/gkcore/tests/test_accountsbyrule.py @@ -1,5 +1,6 @@ """ Copyright (C) 2013, 2014, 2015, 2016 Digital Freedom Foundation +Copyright (C) 2017, 2018 Digital Freedom Foundation & Accion Labs This file is part of GNUKhata:A modular,robust and Free Accounting System. GNUKhata is Free Software; you can redistribute it and/or modify diff --git a/gkcore/tests/test_backuprestore.py b/gkcore/tests/test_backuprestore.py index 2e82e8fd75c91558cebdaa7dd01295b1baf094d0..810a9818511e18013701128f5f398089cf4fd968 100644 --- a/gkcore/tests/test_backuprestore.py +++ b/gkcore/tests/test_backuprestore.py @@ -1,5 +1,6 @@ """ Copyright (C) 2013, 2014, 2015, 2016 Digital Freedom Foundation +Copyright (C) 2017, 2018 Digital Freedom Foundation & Accion Labs This file is part of GNUKhata:A modular,robust and Free Accounting System. GNUKhata is Free Software; you can redistribute it and/or modify diff --git a/gkcore/tests/test_category.py b/gkcore/tests/test_category.py index 773fd159fcc50964a0a59cc6847c51ffb40b69ae..6537acc995b819506535094d66820cca1d52b3ef 100644 --- a/gkcore/tests/test_category.py +++ b/gkcore/tests/test_category.py @@ -1,5 +1,6 @@ """ Copyright (C) 2013, 2014, 2015, 2016 Digital Freedom Foundation +Copyright (C) 2017, 2018 Digital Freedom Foundation & Accion Labs This file is part of GNUKhata:A modular,robust and Free Accounting System. GNUKhata is Free Software; you can redistribute it and/or modify diff --git a/gkcore/tests/test_categoryspecs.py b/gkcore/tests/test_categoryspecs.py index 5a29fce69c6332e0e722b297275f87374e3e38b9..8778f480f387d7aaf923d767f481d1daefdf419f 100644 --- a/gkcore/tests/test_categoryspecs.py +++ b/gkcore/tests/test_categoryspecs.py @@ -1,5 +1,6 @@ """ Copyright (C) 2013, 2014, 2015, 2016 Digital Freedom Foundation +Copyright (C) 2017, 2018 Digital Freedom Foundation & Accion Labs This file is part of GNUKhata:A modular,robust and Free Accounting System. GNUKhata is Free Software; you can redistribute it and/or modify diff --git a/gkcore/tests/test_customer.py b/gkcore/tests/test_customer.py index ee77d531b38dfd3e3feb12f16992787fa7b90790..00c5772103669da6ca5e21daaac165a37f7fc879 100644 --- a/gkcore/tests/test_customer.py +++ b/gkcore/tests/test_customer.py @@ -1,5 +1,6 @@ """ Copyright (C) 2013, 2014, 2015, 2016 Digital Freedom Foundation +Copyright (C) 2017, 2018 Digital Freedom Foundation & Accion Labs This file is part of GNUKhata:A modular,robust and Free Accounting System. GNUKhata is Free Software; you can redistribute it and/or modify diff --git a/gkcore/tests/test_delchal.py b/gkcore/tests/test_delchal.py index bed1e91fa4d36edd92b7a2b8c481ca11971d9f60..5e1fb9e2c1cca92e06963ad0ad36b0cebbcea545 100644 --- a/gkcore/tests/test_delchal.py +++ b/gkcore/tests/test_delchal.py @@ -1,5 +1,6 @@ """ Copyright (C) 2013, 2014, 2015, 2016 Digital Freedom Foundation +Copyright (C) 2017, 2018 Digital Freedom Foundation & Accion Labs This file is part of GNUKhata:A modular,robust and Free Accounting System. GNUKhata is Free Software; you can redistribute it and/or modify diff --git a/gkcore/tests/test_godown.py b/gkcore/tests/test_godown.py index 57d497c0b338e524210ab352847f3fc2a8fcf153..665cb4e4bf3c77ad01df6cf0f72466e4c56a1319 100644 --- a/gkcore/tests/test_godown.py +++ b/gkcore/tests/test_godown.py @@ -1,5 +1,6 @@ """ Copyright (C) 2013, 2014, 2015, 2016 Digital Freedom Foundation +Copyright (C) 2017, 2018 Digital Freedom Foundation & Accion Labs This file is part of GNUKhata:A modular,robust and Free Accounting System. GNUKhata is Free Software; you can redistribute it and/or modify diff --git a/gkcore/tests/test_groupssubgroups.py b/gkcore/tests/test_groupssubgroups.py index 0c59cd3ddd4e618104f90df2a3b721f32ae109b6..ad6803c2b29a0835ac577bd6e399f5d58964c24e 100644 --- a/gkcore/tests/test_groupssubgroups.py +++ b/gkcore/tests/test_groupssubgroups.py @@ -1,5 +1,6 @@ """ Copyright (C) 2013, 2014, 2015, 2016 Digital Freedom Foundation +Copyright (C) 2017, 2018 Digital Freedom Foundation & Accion Labs This file is part of GNUKhata:A modular,robust and Free Accounting System. GNUKhata is Free Software; you can redistribute it and/or modify diff --git a/gkcore/tests/test_invoice.py b/gkcore/tests/test_invoice.py index fba14970e3b64b1047275ae804c89b1a47d7f9e1..1ddd7b5b4306d329898dee3adba9caf2c6d974b5 100644 --- a/gkcore/tests/test_invoice.py +++ b/gkcore/tests/test_invoice.py @@ -1,5 +1,6 @@ """ Copyright (C) 2013, 2014, 2015, 2016 Digital Freedom Foundation +Copyright (C) 2017, 2018 Digital Freedom Foundation & Accion Labs This file is part of GNUKhata:A modular,robust and Free Accounting System. GNUKhata is Free Software; you can redistribute it and/or modify diff --git a/gkcore/tests/test_log.py b/gkcore/tests/test_log.py index 7cfea75318dc866dbb820687d3f5c337add9b78e..eccccebd47a21e70a250b1bd18f4b345df3eaacb 100644 --- a/gkcore/tests/test_log.py +++ b/gkcore/tests/test_log.py @@ -1,5 +1,6 @@ """ Copyright (C) 2013, 2014, 2015, 2016 Digital Freedom Foundation +Copyright (C) 2017, 2018 Digital Freedom Foundation & Accion Labs This file is part of GNUKhata:A modular,robust and Free Accounting System. GNUKhata is Free Software; you can redistribute it and/or modify diff --git a/gkcore/tests/test_login.py b/gkcore/tests/test_login.py index 4aaa892d9c81fe42f3933614449165f55ffb6f98..ce3326cc3a039701bc3101b969e18045069af96d 100644 --- a/gkcore/tests/test_login.py +++ b/gkcore/tests/test_login.py @@ -1,5 +1,6 @@ """ Copyright (C) 2013, 2014, 2015, 2016 Digital Freedom Foundation +Copyright (C) 2017, 2018 Digital Freedom Foundation & Accion Labs This file is part of GNUKhata:A modular,robust and Free Accounting System. GNUKhata is Free Software; you can redistribute it and/or modify diff --git a/gkcore/tests/test_organisation.py b/gkcore/tests/test_organisation.py index b7e9d9f4ecc01e5b0e95ac76bb2ace9d743ac042..fa74b3707fb3132b7564bf18134b701962a29a24 100644 --- a/gkcore/tests/test_organisation.py +++ b/gkcore/tests/test_organisation.py @@ -1,5 +1,6 @@ """ Copyright (C) 2013, 2014, 2015, 2016 Digital Freedom Foundation +Copyright (C) 2017, 2018 Digital Freedom Foundation & Accion Labs This file is part of GNUKhata:A modular,robust and Free Accounting System. GNUKhata is Free Software; you can redistribute it and/or modify diff --git a/gkcore/tests/test_product.py b/gkcore/tests/test_product.py index 91df28d8bb489e5faa74942e5248e11f623e2d12..2d7d6154f409f8d38aa9d9baf8eda39cdf94db25 100644 --- a/gkcore/tests/test_product.py +++ b/gkcore/tests/test_product.py @@ -1,5 +1,6 @@ """ Copyright (C) 2013, 2014, 2015, 2016 Digital Freedom Foundation +Copyright (C) 2017, 2018 Digital Freedom Foundation & Accion Labs This file is part of GNUKhata:A modular,robust and Free Accounting System. GNUKhata is Free Software; you can redistribute it and/or modify diff --git a/gkcore/tests/test_project.py b/gkcore/tests/test_project.py index 56a1f6b9a195bf02116ade7abfa7f075aa7545d5..c2ca350aac30b931f6c81e76696040bd84ced269 100644 --- a/gkcore/tests/test_project.py +++ b/gkcore/tests/test_project.py @@ -1,5 +1,6 @@ """ Copyright (C) 2013, 2014, 2015, 2016 Digital Freedom Foundation +Copyright (C) 2017, 2018 Digital Freedom Foundation & Accion Labs This file is part of GNUKhata:A modular,robust and Free Accounting System. GNUKhata is Free Software; you can redistribute it and/or modify diff --git a/gkcore/tests/test_reports.py b/gkcore/tests/test_reports.py index e5f953b9d2accb6f3e0c0c757f461733be823c23..578e55e6ed03a0fb46686a1456c91a2b6a1a9688 100644 --- a/gkcore/tests/test_reports.py +++ b/gkcore/tests/test_reports.py @@ -1,5 +1,6 @@ """ Copyright (C) 2013, 2014, 2015, 2016 Digital Freedom Foundation +Copyright (C) 2017, 2018 Digital Freedom Foundation & Accion Labs This file is part of GNUKhata:A modular,robust and Free Accounting System. GNUKhata is Free Software; you can redistribute it and/or modify diff --git a/gkcore/tests/test_rollclose.py b/gkcore/tests/test_rollclose.py index 1ef38ac291ded9d1a0b631ced84443a0c5a42e06..6da8ea0957ce2cc8aa7c3668cd797e92b75bf968 100644 --- a/gkcore/tests/test_rollclose.py +++ b/gkcore/tests/test_rollclose.py @@ -1,5 +1,6 @@ """ Copyright (C) 2013, 2014, 2015, 2016 Digital Freedom Foundation +Copyright (C) 2017, 2018 Digital Freedom Foundation & Accion Labs This file is part of GNUKhata:A modular,robust and Free Accounting System. GNUKhata is Free Software; you can redistribute it and/or modify diff --git a/gkcore/tests/test_supplier.py b/gkcore/tests/test_supplier.py index 7ac4cef5267de98b429af887aab310392244d46f..e16fbb265cade6539ced33f18ee9e92d6e5ca880 100644 --- a/gkcore/tests/test_supplier.py +++ b/gkcore/tests/test_supplier.py @@ -1,5 +1,6 @@ """ Copyright (C) 2013, 2014, 2015, 2016 Digital Freedom Foundation +Copyright (C) 2017, 2018 Digital Freedom Foundation & Accion Labs This file is part of GNUKhata:A modular,robust and Free Accounting System. GNUKhata is Free Software; you can redistribute it and/or modify diff --git a/gkcore/tests/test_tax.py b/gkcore/tests/test_tax.py index e1e7f1ea0ca1e57a0cd0630843657289423dbd78..1b66761e4c939165d1e759f418d2399793479749 100644 --- a/gkcore/tests/test_tax.py +++ b/gkcore/tests/test_tax.py @@ -1,5 +1,6 @@ """ Copyright (C) 2013, 2014, 2015, 2016 Digital Freedom Foundation +Copyright (C) 2017, 2018 Digital Freedom Foundation & Accion Labs This file is part of GNUKhata:A modular,robust and Free Accounting System. GNUKhata is Free Software; you can redistribute it and/or modify diff --git a/gkcore/tests/test_transaction.py b/gkcore/tests/test_transaction.py index b6aeb5344ab8e775acf3a8f261751c2a43fd311b..b75de2b3aabe5bda5be3e5e9bac05adb2adfb853 100644 --- a/gkcore/tests/test_transaction.py +++ b/gkcore/tests/test_transaction.py @@ -1,5 +1,6 @@ """ Copyright (C) 2013, 2014, 2015, 2016 Digital Freedom Foundation +Copyright (C) 2017, 2018 Digital Freedom Foundation & Accion Labs This file is part of GNUKhata:A modular,robust and Free Accounting System. GNUKhata is Free Software; you can redistribute it and/or modify diff --git a/gkcore/tests/test_transfernote.py b/gkcore/tests/test_transfernote.py index 050783a4a215dfee761a631ab31f0e043aca288e..d5cee35823ed2d3a3f7970070be3a724dd6ef7d4 100644 --- a/gkcore/tests/test_transfernote.py +++ b/gkcore/tests/test_transfernote.py @@ -1,5 +1,6 @@ """ Copyright (C) 2013, 2014, 2015, 2016 Digital Freedom Foundation +Copyright (C) 2017, 2018 Digital Freedom Foundation & Accion Labs This file is part of GNUKhata:A modular,robust and Free Accounting System. GNUKhata is Free Software; you can redistribute it and/or modify diff --git a/gkcore/tests/test_unit.py b/gkcore/tests/test_unit.py index d3c18ad4c2596d268c9c71b83708f6d59759d9d9..4ade9f366db5a514199dc0c9582af4703bd222ae 100644 --- a/gkcore/tests/test_unit.py +++ b/gkcore/tests/test_unit.py @@ -1,5 +1,6 @@ """ Copyright (C) 2013, 2014, 2015, 2016 Digital Freedom Foundation +Copyright (C) 2017, 2018 Digital Freedom Foundation & Accion Labs This file is part of GNUKhata:A modular,robust and Free Accounting System. GNUKhata is Free Software; you can redistribute it and/or modify diff --git a/gkcore/tests/test_user.py b/gkcore/tests/test_user.py index d27818943f7f7e1da30d23e1456ca0821291376a..8522a4fa4f6ccaa9c194ebe78e865beb7fb44ae0 100644 --- a/gkcore/tests/test_user.py +++ b/gkcore/tests/test_user.py @@ -1,5 +1,6 @@ """ Copyright (C) 2013, 2014, 2015, 2016 Digital Freedom Foundation +Copyright (C) 2017, 2018 Digital Freedom Foundation & Accion Labs This file is part of GNUKhata:A modular,robust and Free Accounting System. GNUKhata is Free Software; you can redistribute it and/or modify diff --git a/gkcore/views/api_account.py b/gkcore/views/api_account.py index d50ca7b8bcf7c6490450d7348564187b5a677349..9322299e0535c33857e581156dc47cc576f38fff 100644 --- a/gkcore/views/api_account.py +++ b/gkcore/views/api_account.py @@ -1,6 +1,7 @@ """ -Copyright (C) 2013, 2014, 2015, 2016 Digital Freedom Foundation +Copyright (C) 2013, 2014, 2015, 2016, Digital Freedom Foundation +Copyright (C) 2017, 2018 Digital Freedom Foundation & Accion Labs This file is part of GNUKhata:A modular,robust and Free Accounting System. GNUKhata is Free Software; you can redistribute it and/or modify @@ -23,7 +24,8 @@ Contributors: "Krishnakant Mane" "Ishan Masdekar " "Navin Karkera" -Prajkta Patkar" +"Prajkta Patkar" +"Prajkta Patkar" """ from gkcore import eng, enumdict @@ -58,240 +60,243 @@ refer to the __init__.py of main gkcore package for details on routing url """ @view_defaults(route_name='accounts') class api_account(object): - #constructor will initialise request. - def __init__(self,request): - self.request = Request - self.request = request - self.con = Connection - print "accounts initialized" + #constructor will initialise request. + def __init__(self,request): + self.request = Request + self.request = request + self.con = Connection + print "accounts initialized" - @view_config(request_method='POST',renderer='json') - def addAccount(self): - """ - purpose: - Adds an account under either a group or it's subgroup. - Request_method is post which means adding a resource. - returns a json object containing success result as true if account is created. - Alchemy expression language will be used for inserting into accounts table. - The data is fetched from request.json_body. - Expects accountname,groupsubgroupcode and opening balance. - Function will only proceed if auth check is successful, because orgcode needed as a common parameter can be procured only through the said method. - """ - 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() - dataset = self.request.json_body - dataset["orgcode"] = authDetails["orgcode"] - result = self.con.execute(gkdb.accounts.insert(),[dataset]) - self.con.close() - return {"gkstatus":enumdict["Success"]} - except exc.IntegrityError: - self.con.close() - return {"gkstatus":enumdict["DuplicateEntry"]} - except: - self.con.close() - return {"gkstatus":enumdict["ConnectionFailed"]} + @view_config(request_method='POST',renderer='json') + def addAccount(self): + """ + purpose: + Adds an account under either a group or it's subgroup. + Request_method is post which means adding a resource. + returns a json object containing success result as true if account is created. + Alchemy expression language will be used for inserting into accounts table. + The data is fetched from request.json_body. + Expects accountname,groupsubgroupcode and opening balance. + Function will only proceed if auth check is successful, because orgcode needed as a common parameter can be procured only through the said method. + """ + 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() + dataset = self.request.json_body + dataset["orgcode"] = authDetails["orgcode"] + result = self.con.execute(gkdb.accounts.insert(),[dataset]) + self.con.close() + return {"gkstatus":enumdict["Success"]} + except exc.IntegrityError: + self.con.close() + return {"gkstatus":enumdict["DuplicateEntry"]} + except: + self.con.close() + return {"gkstatus":enumdict["ConnectionFailed"]} - @view_config(route_name='account', request_method='GET',renderer='json') - def getAccount(self): - """ - Purpose: - Returns an account given it's account code. - Returns a json object containing: - *accountcode - *accountname - *openingbal as float - *groupsubgroupcode - The request_method is get meaning retriving data. - The route_name has been override here to make a special call which does not come under view_default. - parameter will be taken from request.matchdict in a get request. - Function will only proceed if auth check is successful, because orgcode needed as a common parameter can be procured only through the said method. - """ - 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() - result = self.con.execute(select([gkdb.accounts]).where(gkdb.accounts.c.accountcode==self.request.matchdict["accountcode"])) - row = result.fetchone() - acc={"accountcode":row["accountcode"], "accountname":row["accountname"], "openingbal":"%.2f"%float(row["openingbal"]),"groupcode":row["groupcode"]} - self.con.close() - return {"gkstatus": enumdict["Success"], "gkresult":acc} - except: - self.con.close() - return {"gkstatus":enumdict["ConnectionFailed"] } + @view_config(route_name='account', request_method='GET',renderer='json') + def getAccount(self): + """ + Purpose: + Returns an account given it's account code. + Returns a json object containing: + *accountcode + *accountname + *openingbal as float + *groupsubgroupcode + The request_method is get meaning retriving data. + The route_name has been override here to make a special call which does not come under view_default. + parameter will be taken from request.matchdict in a get request. + Function will only proceed if auth check is successful, because orgcode needed as a common parameter can be procured only through the said method. + """ + 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() + result = self.con.execute(select([gkdb.accounts]).where(gkdb.accounts.c.accountcode==self.request.matchdict["accountcode"])) + row = result.fetchone() + acc={"accountcode":row["accountcode"], "accountname":row["accountname"], "openingbal":"%.2f"%float(row["openingbal"]),"groupcode":row["groupcode"]} + self.con.close() + return {"gkstatus": enumdict["Success"], "gkresult":acc} + except: + self.con.close() + return {"gkstatus":enumdict["ConnectionFailed"] } - @view_config(request_method='GET', renderer ='json') - def getAllAccounts(self): - 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() - result = self.con.execute(select([gkdb.accounts]).where(gkdb.accounts.c.orgcode==authDetails["orgcode"]).order_by(gkdb.accounts.c.accountname)) - accs = [] - srno=1 - for accrow in result: - g = gkdb.groupsubgroups.alias("g") - sg = gkdb.groupsubgroups.alias("sg") + @view_config(request_method='GET', renderer ='json') + def getAllAccounts(self): + 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() + result = self.con.execute(select([gkdb.accounts]).where(gkdb.accounts.c.orgcode==authDetails["orgcode"]).order_by(gkdb.accounts.c.accountname)) + accs = [] + srno=1 + for accrow in result: + g = gkdb.groupsubgroups.alias("g") + sg = gkdb.groupsubgroups.alias("sg") - resultset = self.con.execute(select([(g.c.groupcode).label('groupcode'),(g.c.groupname).label('groupname'),(sg.c.groupcode).label('subgroupcode'),(sg.c.groupname).label('subgroupname')]).where(or_(and_(g.c.groupcode==int(accrow["groupcode"]),g.c.subgroupof==null(),sg.c.groupcode==int(accrow["groupcode"]),sg.c.subgroupof==null()),and_(g.c.groupcode==sg.c.subgroupof,sg.c.groupcode==int(accrow["groupcode"]))))) - grprow = resultset.fetchone() - if grprow["groupcode"]==grprow["subgroupcode"]: - accs.append({"srno":srno,"accountcode":accrow["accountcode"], "accountname":accrow["accountname"], "openingbal":"%.2f"%float(accrow["openingbal"]),"groupcode":grprow["groupcode"],"groupname":grprow["groupname"],"subgroupcode":"","subgroupname":""}) - else: - accs.append({"srno":srno,"accountcode":accrow["accountcode"], "accountname":accrow["accountname"], "openingbal":"%.2f"%float(accrow["openingbal"]),"groupcode":grprow["groupcode"],"groupname":grprow["groupname"],"subgroupcode":grprow["subgroupcode"],"subgroupname":grprow["subgroupname"]}) - srno = srno+1 - self.con.close() - return {"gkstatus": enumdict["Success"], "gkresult":accs} - except: - self.con.close() - return {"gkstatus":enumdict["ConnectionFailed"] } + resultset = self.con.execute(select([(g.c.groupcode).label('groupcode'),(g.c.groupname).label('groupname'),(sg.c.groupcode).label('subgroupcode'),(sg.c.groupname).label('subgroupname')]).where(or_(and_(g.c.groupcode==int(accrow["groupcode"]),g.c.subgroupof==null(),sg.c.groupcode==int(accrow["groupcode"]),sg.c.subgroupof==null()),and_(g.c.groupcode==sg.c.subgroupof,sg.c.groupcode==int(accrow["groupcode"]))))) + grprow = resultset.fetchone() + if grprow["groupcode"]==grprow["subgroupcode"]: + accs.append({"srno":srno,"accountcode":accrow["accountcode"], "accountname":accrow["accountname"], "openingbal":"%.2f"%float(accrow["openingbal"]),"groupcode":grprow["groupcode"],"groupname":grprow["groupname"],"subgroupcode":"","subgroupname":""}) + else: + accs.append({"srno":srno,"accountcode":accrow["accountcode"], "accountname":accrow["accountname"], "openingbal":"%.2f"%float(accrow["openingbal"]),"groupcode":grprow["groupcode"],"groupname":grprow["groupname"],"subgroupcode":grprow["subgroupcode"],"subgroupname":grprow["subgroupname"]}) + srno = srno+1 + self.con.close() + return {"gkstatus": enumdict["Success"], "gkresult":accs} + except: + self.con.close() + return {"gkstatus":enumdict["ConnectionFailed"] } - @view_config(request_method='GET',request_param='accbygrp', renderer ='json') - def getAllAccountsByGroup(self): - """ - Purpose: - This function returns accountcode , accountname and openingbalance for a certain groupcode (group) which has been provided. - """ - 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() - result = self.con.execute(select([accounts.c.accountcode,accounts.c.accountname,accounts.c.openingbal]).where(and_(accounts.c.orgcode==authDetails["orgcode"],accounts.c.groupcode==self.request.params["groupcode"]))) - accData = result.fetchall() - allAcc = [] - for row in accData: - allAcc.append({"accountcode":row["accountcode"], "accountname":row["accountname"],"openingbal":"%.2f"%float(row["openingbal"])}) - self.con.close() - return {"gkstatus": enumdict["Success"], "gkresult":allAcc} - except: - self.con.close() - return {"gkstatus":enumdict["ConnectionFailed"] } + @view_config(request_method='GET',request_param='accbygrp', renderer ='json') + def getAllAccountsByGroup(self): + """ + Purpose: + This function returns accountcode , accountname and openingbalance for a certain groupcode (group) which has been provided. + """ + 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() + result = self.con.execute(select([accounts.c.accountcode,accounts.c.accountname,accounts.c.openingbal]).where(and_(accounts.c.orgcode==authDetails["orgcode"],accounts.c.groupcode==self.request.params["groupcode"]))) + accData = result.fetchall() + allAcc = [] + for row in accData: + allAcc.append({"accountcode":row["accountcode"], "accountname":row["accountname"],"openingbal":"%.2f"%float(row["openingbal"])}) + self.con.close() + return {"gkstatus": enumdict["Success"], "gkresult":allAcc} + except: + self.con.close() + return {"gkstatus":enumdict["ConnectionFailed"] } - @view_config(request_method='GET',request_param='acclist', renderer ='json') - def getAccountslist(self): - 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() - accData = self.con.execute(select([accounts.c.accountcode,accounts.c.accountname]).where(accounts.c.orgcode == authDetails["orgcode"])) - accRows = accData.fetchall() - accList = {} - for row in accRows: - accList[row["accountname"]]= row["accountcode"] - - return {"gkstatus": enumdict["Success"], "gkresult":accList} - except: - self.con.close() - return {"gkstatus":enumdict["ConnectionFailed"] } - finally: - self.con.close() + @view_config(request_method='GET',request_param='acclist', renderer ='json') + def getAccountslist(self): + 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() + accData = self.con.execute(select([accounts.c.accountcode,accounts.c.accountname]).where(accounts.c.orgcode == authDetails["orgcode"])) + accRows = accData.fetchall() + accList = {} + for row in accRows: + accList[row["accountname"]]= row["accountcode"] + + return {"gkstatus": enumdict["Success"], "gkresult":accList} + except: + self.con.close() + return {"gkstatus":enumdict["ConnectionFailed"] } + finally: + self.con.close() - @view_config(request_method='GET',request_param='find=exists', renderer ='json') - def accountExists(self): - 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() - accountname = self.request.params["accountname"] - result = self.con.execute(select([func.count(gkdb.accounts.c.accountname).label('acc')]).where(and_(gkdb.accounts.c.accountname==accountname,gkdb.accounts.c.orgcode==authDetails["orgcode"]))) - acccount = result.fetchone() - if acccount["acc"]>0: - self.con.close() - return {"gkstatus": enumdict["DuplicateEntry"]} - else: - self.con.close() - return {"gkstatus": enumdict["Success"]} - except: - self.con.close() - return {"gkstatus":enumdict["ConnectionFailed"] } + @view_config(request_method='GET',request_param='find=exists', renderer ='json') + def accountExists(self): + 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() + accountname = self.request.params["accountname"] + result = self.con.execute(select([func.count(gkdb.accounts.c.accountname).label('acc')]).where(and_(gkdb.accounts.c.accountname==accountname,gkdb.accounts.c.orgcode==authDetails["orgcode"]))) + acccount = result.fetchone() + if acccount["acc"]>0: + self.con.close() + return {"gkstatus": enumdict["DuplicateEntry"]} + else: + self.con.close() + return {"gkstatus": enumdict["Success"]} + except: + self.con.close() + return {"gkstatus":enumdict["ConnectionFailed"] } - @view_config(request_method='PUT', renderer='json') - def editAccount(self): - 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() - dataset = self.request.json_body - result = self.con.execute(gkdb.accounts.update().where(gkdb.accounts.c.accountcode==dataset["accountcode"]).values(dataset)) - self.con.close() - return {"gkstatus":enumdict["Success"]} - except: - self.con.close() - return {"gkstatus":enumdict["ConnectionFailed"]} + @view_config(request_method='PUT', renderer='json') + def editAccount(self): + 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() + dataset = self.request.json_body + result = self.con.execute(gkdb.accounts.update().where(gkdb.accounts.c.accountcode==dataset["accountcode"]).values(dataset)) + self.con.close() + return {"gkstatus":enumdict["Success"]} + except exc.IntegrityError: + self.con.close() + return {"gkstatus":enumdict["DuplicateEntry"]} + except: + self.con.close() + return {"gkstatus":enumdict["ConnectionFailed"]} - @view_config(request_method='DELETE', renderer ='json') - def deleteAccount(self): - 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([gkdb.users.c.userrole]).where(gkdb.users.c.userid == authDetails["userid"] )) - userRole = user.fetchone() - dataset = self.request.json_body - if userRole[0]==-1: - vouchercountdata = self.con.execute(select([gkdb.accounts.c.vouchercount]).where(gkdb.accounts.c.accountcode==dataset["accountcode"])) - vouchercountrow = vouchercountdata.fetchone() - if vouchercountrow["vouchercount"]!=0: - self.con.close() - return {"gkstatus":enumdict["ActionDisallowed"]} - else: - result = self.con.execute(gkdb.accounts.delete().where(gkdb.accounts.c.accountcode==dataset["accountcode"])) - self.con.close() - return {"gkstatus":enumdict["Success"]} - else: - self.con.close() - return {"gkstatus": enumdict["BadPrivilege"]} - except: - self.con.close() - return {"gkstatus":enumdict["ConnectionFailed"] } + @view_config(request_method='DELETE', renderer ='json') + def deleteAccount(self): + 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([gkdb.users.c.userrole]).where(gkdb.users.c.userid == authDetails["userid"] )) + userRole = user.fetchone() + dataset = self.request.json_body + if userRole[0]==-1: + vouchercountdata = self.con.execute(select([gkdb.accounts.c.vouchercount]).where(gkdb.accounts.c.accountcode==dataset["accountcode"])) + vouchercountrow = vouchercountdata.fetchone() + if vouchercountrow["vouchercount"]!=0: + self.con.close() + return {"gkstatus":enumdict["ActionDisallowed"]} + else: + result = self.con.execute(gkdb.accounts.delete().where(gkdb.accounts.c.accountcode==dataset["accountcode"])) + self.con.close() + return {"gkstatus":enumdict["Success"]} + else: + self.con.close() + return {"gkstatus": enumdict["BadPrivilege"]} + except: + self.con.close() + return {"gkstatus":enumdict["ConnectionFailed"] } diff --git a/gkcore/views/api_accountsbyrule.py b/gkcore/views/api_accountsbyrule.py index 09a7f939e3b37cc0dea6d9fdbcc20105d646b537..a82ee7f615e71a61d37ffbbbdecf942603ecda09 100644 --- a/gkcore/views/api_accountsbyrule.py +++ b/gkcore/views/api_accountsbyrule.py @@ -1,6 +1,8 @@ """ Copyright (C) 2013, 2014, 2015, 2016 Digital Freedom Foundation +Copyright (C) 2017, 2018 Digital Freedom Foundation & Accion Labs Pvt. Ltd. + This file is part of GNUKhata:A modular,robust and Free Accounting System. GNUKhata is Free Software; you can redistribute it and/or modify diff --git a/gkcore/views/api_bankrecon.py b/gkcore/views/api_bankrecon.py index 3dbdc2b55d064d2de3ed1c13c45cec3e3f6ce680..b1ae6ca02462db6befe126180a217683c07f4410 100644 --- a/gkcore/views/api_bankrecon.py +++ b/gkcore/views/api_bankrecon.py @@ -1,6 +1,7 @@ """ Copyright (C) 2013, 2014, 2015, 2016 Digital Freedom Foundation +Copyright (C) 2017, 2018 Digital Freedom Foundation & Accion Labs Pvt. Ltd. This file is part of GNUKhata:A modular,robust and Free Accounting System. GNUKhata is Free Software; you can redistribute it and/or modify diff --git a/gkcore/views/api_billwise.py b/gkcore/views/api_billwise.py index 79c16ced0edbb5ef332b0cf7d0b526ceb2f8da77..a5c0689bb88bdc708f16d87aa10d2d788c861bd4 100644 --- a/gkcore/views/api_billwise.py +++ b/gkcore/views/api_billwise.py @@ -1,5 +1,6 @@ """ -Copyright (C) 2013, 2014, 2015, 2016 Digital Freedom Foundation +Copyright (C) 2013, 2014, 2015, 2016, 2017 Digital Freedom Foundation +Copyright (C) 2017, 2018 Digital Freedom Foundation & Accion Labs Pvt. Ltd. This file is part of GNUKhata:A modular,robust and Free Accounting System. GNUKhata is Free Software; you can redistribute it and/or modify @@ -147,7 +148,81 @@ It will be used for creating entries in the billwise table and updating it as ne return{"gkstatus":enumdict["Success"],"vouchers":unAdjReceipts,"invoices":unAdjInvoices} except: return{"gkstatus":enumdict["ConnectionFailed"]} - - - + @view_config(request_method='GET',renderer='json', request_param="type=all") + def getallUnadjustedBills(self): + """ + Purpose: + Gets the list of unadjusted invoices. + Description: + An invoice is considered unadjusted if it has not been paid or payment for it has not been received completely. + These are adjusted either while creating vouchers or while doing bill wise accounting. + This function returns a list of all unadjusted or partially adjusted bills of an 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() + # An empty list into which unadjusted invoices shall be appended. + unAdjInvoices = [] + # Fetching id, number, date, total amount and amount paid of all unpaid invoices. + # It is unadjusted if invoice total is greater that amount paid. + invoices = self.con.execute(select([invoice.c.invid,invoice.c.invoiceno,invoice.c.invoicedate,invoice.c.invoicetotal,invoice.c.amountpaid, invoice.c.custid]).where(and_(invoice.c.invoicetotal > invoice.c.amountpaid, invoice.c.icflag == 9, invoice.c.orgcode == authDetails["orgcode"]))) + invoicesData = invoices.fetchall() + # Appending dictionaries into empty list. + # Each dictionary has details of an invoice viz. id, number, date, total amount, amount paid and balance. + for inv in invoicesData: + custData = self.con.execute(select([customerandsupplier.c.custname, customerandsupplier.c.csflag, customerandsupplier.c.custid]).where(customerandsupplier.c.custid == inv["custid"])) + customerdata = custData.fetchone() + unAdjInvoices.append({"invid":inv["invid"],"invoiceno":inv["invoiceno"],"invoicedate":datetime.strftime(inv["invoicedate"],'%d-%m-%Y'),"invoicetotal":"%.2f"%(float(inv["invoicetotal"])),"balanceamount":"%.2f"%(float(inv["invoicetotal"]-inv["amountpaid"])), "custname":customerdata["custname"], "custid":customerdata["custid"], "csflag": customerdata["csflag"]}) + return{"gkstatus":enumdict["Success"],"invoices":unAdjInvoices} + except: + return{"gkstatus":enumdict["ConnectionFailed"]} + @view_config(request_method='GET',renderer='json', request_param="type=pending") + def getallPendingBills(self): + """ + Purpose: + Gets the list of pending invoices. + Description: + An invoice is considered pending if it has not been paid or no payment for it has been received. + These are adjusted either while creating vouchers or while doing bill wise accounting. + This function returns a list of all pending bills of an 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() + # An empty list into which pending invoices shall be appended. + unAdjInvoices = [] + # Fetching id, number, date, total amount and amount paid of all unpaid invoices. + # It is pending if invoice total is greater that amount paid. + invoices = self.con.execute(select([invoice.c.invid,invoice.c.invoiceno,invoice.c.invoicedate,invoice.c.invoicetotal,invoice.c.amountpaid, invoice.c.custid]).where(and_(invoice.c.amountpaid == 0, invoice.c.icflag == 9, invoice.c.orgcode == authDetails["orgcode"]))) + invoicesData = invoices.fetchall() + # Appending dictionaries into empty list. + # Each dictionary has details of an invoice viz. id, number, date, total amount, amount paid and balance. + for inv in invoicesData: + custData = self.con.execute(select([customerandsupplier.c.custname, customerandsupplier.c.csflag, customerandsupplier.c.custid]).where(customerandsupplier.c.custid == inv["custid"])) + customerdata = custData.fetchone() + # If there is a invtype parameter then only sale/purchase invoices are returned depending on the value of type. + if self.request.params.has_key('invtype'): + if str(self.request.params["invtype"]) == 'sale' and int(customerdata['csflag']) == 3: + unAdjInvoices.append({"invid":inv["invid"],"invoiceno":inv["invoiceno"],"invoicedate":datetime.strftime(inv["invoicedate"],'%d-%m-%Y'),"invoicetotal":"%.2f"%(float(inv["invoicetotal"])),"balanceamount":"%.2f"%(float(inv["invoicetotal"]-inv["amountpaid"])), "custname":customerdata["custname"], "custid":customerdata["custid"], "csflag": customerdata["csflag"]}) + elif str(self.request.params["invtype"]) == 'purchase' and int(customerdata['csflag']) == 19: + unAdjInvoices.append({"invid":inv["invid"],"invoiceno":inv["invoiceno"],"invoicedate":datetime.strftime(inv["invoicedate"],'%d-%m-%Y'),"invoicetotal":"%.2f"%(float(inv["invoicetotal"])),"balanceamount":"%.2f"%(float(inv["invoicetotal"]-inv["amountpaid"])), "custname":customerdata["custname"], "custid":customerdata["custid"], "csflag": customerdata["csflag"]}) + else: + unAdjInvoices.append({"invid":inv["invid"],"invoiceno":inv["invoiceno"],"invoicedate":datetime.strftime(inv["invoicedate"],'%d-%m-%Y'),"invoicetotal":"%.2f"%(float(inv["invoicetotal"])),"balanceamount":"%.2f"%(float(inv["invoicetotal"]-inv["amountpaid"])), "custname":customerdata["custname"], "custid":customerdata["custid"], "csflag": customerdata["csflag"]}) + return{"gkstatus":enumdict["Success"],"invoices":unAdjInvoices} + except: + return{"gkstatus":enumdict["ConnectionFailed"]} diff --git a/gkcore/views/api_category.py b/gkcore/views/api_category.py index 2acbc866aeae3473bff12e38aab673df15b8e338..cd9f8a55a81fdccb7b150e13842e622ce9001363 100644 --- a/gkcore/views/api_category.py +++ b/gkcore/views/api_category.py @@ -1,5 +1,6 @@ """ Copyright (C) 2013, 2014, 2015, 2016 Digital Freedom Foundation +Copyright (C) 2017, 2018 Digital Freedom Foundation & Accion Labs Pvt. Ltd. This file is part of GNUKhata:A modular,robust and Free Accounting System. GNUKhata is Free Software; you can redistribute it and/or modify diff --git a/gkcore/views/api_categoryspecs.py b/gkcore/views/api_categoryspecs.py index ea84bf169afeb16f0ea90626c0fefcafef58f302..f3fdc37c8bf929484c2532b5e316839d82a1028b 100644 --- a/gkcore/views/api_categoryspecs.py +++ b/gkcore/views/api_categoryspecs.py @@ -1,6 +1,7 @@ """ Copyright (C) 2013, 2014, 2015, 2016 Digital Freedom Foundation +Copyright (C) 2017, 2018 Digital Freedom Foundation & Accion Labs Pvt. Ltd. This file is part of GNUKhata:A modular,robust and Free Accounting System. GNUKhata is Free Software; you can redistribute it and/or modify diff --git a/gkcore/views/api_customer.py b/gkcore/views/api_customer.py index 87ea7d7efa6d803f54834f76649abd98b0dc7c6b..8a0bceb2843db1ad5c15866b5ae5070d3af16483 100644 --- a/gkcore/views/api_customer.py +++ b/gkcore/views/api_customer.py @@ -1,6 +1,7 @@ """ Copyright (C) 2013, 2014, 2015, 2016 Digital Freedom Foundation +Copyright (C) 2017, 2018 Digital Freedom Foundation & Accion Labs Pvt. Ltd. This file is part of GNUKhata:A modular,robust and Free Accounting System. GNUKhata is Free Software; you can redistribute it and/or modify diff --git a/gkcore/views/api_delchal.py b/gkcore/views/api_delchal.py index e7fddcf23b35fb5124e4845bc028037b35852f94..0d59be0ecf275368084a70ad45fc7a8c2aa000dc 100644 --- a/gkcore/views/api_delchal.py +++ b/gkcore/views/api_delchal.py @@ -1,6 +1,7 @@ """ Copyright (C) 2013, 2014, 2015, 2016 Digital Freedom Foundation +Copyright (C) 2017, 2018 Digital Freedom Foundation & Accion Labs Pvt. Ltd. This file is part of GNUKhata:A modular,robust and Free Accounting System. GNUKhata is Free Software; you can redistribute it and/or modify @@ -23,6 +24,8 @@ Contributors: "Krishnakant Mane" "Ishan Masdekar " "Navin Karkera" +"Reshma Bhatawade" + """ @@ -231,6 +234,7 @@ class api_delchal(object): "dcflag":delchaldata["dcflag"], "issuername":delchaldata["issuername"], "designation":delchaldata["designation"], + "consignee":delchaldata["consignee"], "dcdate":datetime.strftime(delchaldata["dcdate"],'%d-%m-%Y'), "custid":delchaldata["custid"],"custname":custname["custname"], "custstate":custname["state"], diff --git a/gkcore/views/api_godown.py b/gkcore/views/api_godown.py index 6b67c78aaa90c69c260357b21b35c16c0b3326bb..d0441451a34a2968c23c6dba38bde23002557a39 100644 --- a/gkcore/views/api_godown.py +++ b/gkcore/views/api_godown.py @@ -1,6 +1,7 @@ """ Copyright (C) 2013, 2014, 2015, 2016 Digital Freedom Foundation +Copyright (C) 2017, 2018 Digital Freedom Foundation & Accion Labs Pvt. Ltd. This file is part of GNUKhata:A modular,robust and Free Accounting System. GNUKhata is Free Software; you can redistribute it and/or modify @@ -44,257 +45,288 @@ from gkcore.views.api_login import authCheck from gkcore.views.api_user import getUserRole def getusergodowns(userid): - try: - con = Connection - con = eng.connect() - uid=userid - godowns=con.execute(select([godown]).where(godown.c.goid.in_(select([usergodown.c.goid]).where(usergodown.c.userid == uid)))) - usergo = [] - srno=1 - for row in godowns: - godownstock = con.execute(select([func.count(stock.c.goid).label("godownstockstatus") ]).where(stock.c.goid==row["goid"])) - godownstockcount = godownstock.fetchone() - godownstatus = godownstockcount["godownstockstatus"] - if godownstatus > 0: - status = "Active" - else: - status = "Inactive" - usergo.append({"godownstatus":status, "srno":srno, "goid": row["goid"], "goname": row["goname"], "goaddr": row["goaddr"], "gocontact": row["gocontact"],"state":row["state"],"contactname":row["contactname"],"designation":row["designation"]}) - srno = srno+1 - return {"gkstatus": gkcore.enumdict["Success"], "gkresult":usergo } - except: - return {"gkstatus":gkcore.enumdict["ConnectionFailed"] } - finally: - con.close(); + try: + con = Connection + con = eng.connect() + uid=userid + godowns=con.execute(select([godown]).where(godown.c.goid.in_(select([usergodown.c.goid]).where(usergodown.c.userid == uid)))) + usergo = [] + srno=1 + for row in godowns: + godownstock = con.execute(select([func.count(stock.c.goid).label("godownstockstatus") ]).where(stock.c.goid==row["goid"])) + godownstockcount = godownstock.fetchone() + godownstatus = godownstockcount["godownstockstatus"] + if godownstatus > 0: + status = "Active" + else: + status = "Inactive" + usergo.append({"godownstatus":status, "srno":srno, "goid": row["goid"], "goname": row["goname"], "goaddr": row["goaddr"], "gocontact": row["gocontact"],"state":row["state"],"contactname":row["contactname"],"designation":row["designation"]}) + srno = srno+1 + return {"gkstatus": gkcore.enumdict["Success"], "gkresult":usergo } + except: + return {"gkstatus":gkcore.enumdict["ConnectionFailed"] } + finally: + con.close(); @view_defaults(route_name='godown') class api_godown(object): - def __init__(self,request): - self.request = Request - self.request = request - self.con = Connection + def __init__(self,request): + self.request = Request + self.request = request + self.con = Connection - @view_config(request_method='POST',renderer='json') - def addGodown(self): - 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() - dataset = self.request.json_body - dataset["orgcode"] = authDetails["orgcode"] - result = self.con.execute(godown.insert(),[dataset]) - return {"gkstatus":enumdict["Success"]} - except exc.IntegrityError: - return {"gkstatus":enumdict["DuplicateEntry"]} - except: - return {"gkstatus":gkcore.enumdict["ConnectionFailed"] } - finally: - self.con.close() + @view_config(request_method='POST',renderer='json') + def addGodown(self): + 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() + dataset = self.request.json_body + dataset["orgcode"] = authDetails["orgcode"] + result = self.con.execute(godown.insert(),[dataset]) + return {"gkstatus":enumdict["Success"]} + except exc.IntegrityError: + return {"gkstatus":enumdict["DuplicateEntry"]} + except: + return {"gkstatus":gkcore.enumdict["ConnectionFailed"] } + finally: + self.con.close() - @view_config(request_method='PUT', renderer='json') - def editGodown(self): - 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() - dataset = self.request.json_body - result = self.con.execute(godown.update().where(godown.c.goid==dataset["goid"]).values(dataset)) - return {"gkstatus":enumdict["Success"]} - except: - return {"gkstatus":gkcore.enumdict["ConnectionFailed"] } - finally: - self.con.close() + @view_config(request_method='PUT', renderer='json') + def editGodown(self): + 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() + dataset = self.request.json_body + result = self.con.execute(godown.update().where(godown.c.goid==dataset["goid"]).values(dataset)) + return {"gkstatus":enumdict["Success"]} + except: + return {"gkstatus":gkcore.enumdict["ConnectionFailed"] } + finally: + self.con.close() - @view_config(request_method='GET', renderer ='json') - def getAllGodowns(self): - try: - token = self.request.headers["gktoken"] - except: - return {"gkstatus": gkcore.enumdict["UnauthorisedAccess"]} - authDetails = authCheck(token) - if authDetails["auth"] == False: - return {"gkstatus": gkcore.enumdict["UnauthorisedAccess"]} - else: - try: - self.con = eng.connect() - userrole = getUserRole(authDetails["userid"]) - gorole = userrole["gkresult"] - if (gorole["userrole"]==3): - try: - result = getusergodowns(authDetails["userid"]) - return {"gkstatus": gkcore.enumdict["Success"], "gkresult":result["gkresult"]} - except: - return {"gkstatus":gkcore.enumdict["ConnectionFailed"] } - if (gorole["userrole"]!=3): - result = self.con.execute(select([godown]).where(godown.c.orgcode==authDetails["orgcode"]).order_by(godown.c.goname)) - godowns = [] - srno=1 - for row in result: - godownstock = self.con.execute(select([func.count(stock.c.goid).label("godownstockstatus") ]).where(stock.c.goid==row["goid"])) - godownstockcount = godownstock.fetchone() - godownstatus = godownstockcount["godownstockstatus"] - if godownstatus > 0: - status = "Active" - else: - status = "Inactive" - godowns.append({"godownstatus":status, "srno":srno, "goid": row["goid"], "goname": row["goname"], "goaddr": row["goaddr"], "gocontact": row["gocontact"],"state":row["state"],"contactname":row["contactname"],"designation":row["designation"]}) - srno = srno+1 - return {"gkstatus": gkcore.enumdict["Success"], "gkresult":godowns } - except: - return {"gkstatus":gkcore.enumdict["ConnectionFailed"] } - finally: - self.con.close() + @view_config(request_method='GET', renderer ='json') + def getAllGodowns(self): + try: + token = self.request.headers["gktoken"] + except: + return {"gkstatus": gkcore.enumdict["UnauthorisedAccess"]} + authDetails = authCheck(token) + if authDetails["auth"] == False: + return {"gkstatus": gkcore.enumdict["UnauthorisedAccess"]} + else: + try: + self.con = eng.connect() + userrole = getUserRole(authDetails["userid"]) + gorole = userrole["gkresult"] + if (gorole["userrole"]==3): + try: + result = getusergodowns(authDetails["userid"]) + return {"gkstatus": gkcore.enumdict["Success"], "gkresult":result["gkresult"]} + except: + return {"gkstatus":gkcore.enumdict["ConnectionFailed"] } + if (gorole["userrole"]!=3): + result = self.con.execute(select([godown]).where(godown.c.orgcode==authDetails["orgcode"]).order_by(godown.c.goname)) + godowns = [] + srno=1 + for row in result: + godownstock = self.con.execute(select([func.count(stock.c.goid).label("godownstockstatus") ]).where(stock.c.goid==row["goid"])) + godownstockcount = godownstock.fetchone() + godownstatus = godownstockcount["godownstockstatus"] + if godownstatus > 0: + status = "Active" + else: + status = "Inactive" + godowns.append({"godownstatus":status, "srno":srno, "goid": row["goid"], "goname": row["goname"], "goaddr": row["goaddr"], "gocontact": row["gocontact"],"state":row["state"],"contactname":row["contactname"],"designation":row["designation"]}) + srno = srno+1 + return {"gkstatus": gkcore.enumdict["Success"], "gkresult":godowns } + except: + return {"gkstatus":gkcore.enumdict["ConnectionFailed"] } + finally: + self.con.close() - @view_config(request_method='GET', request_param='type=togodown', renderer ='json') - def togodowns(self): - try: - token = self.request.headers["gktoken"] - except: - return {"gkstatus": gkcore.enumdict["UnauthorisedAccess"]} - authDetails = authCheck(token) - if authDetails["auth"] == False: - return {"gkstatus": gkcore.enumdict["UnauthorisedAccess"]} - else: - try: - self.con = eng.connect() - result = self.con.execute(select([godown]).where(godown.c.orgcode==authDetails["orgcode"])) - godowns = [] - for row in result: - godowns.append({"goid": row["goid"], "goname": row["goname"], "goaddr": row["goaddr"]}) - return {"gkstatus": gkcore.enumdict["Success"], "gkresult":godowns } - except: - return {"gkstatus":gkcore.enumdict["ConnectionFailed"] } - finally: - self.con.close() + @view_config(request_method='GET', request_param='type=togodown', renderer ='json') + def togodowns(self): + try: + token = self.request.headers["gktoken"] + except: + return {"gkstatus": gkcore.enumdict["UnauthorisedAccess"]} + authDetails = authCheck(token) + if authDetails["auth"] == False: + return {"gkstatus": gkcore.enumdict["UnauthorisedAccess"]} + else: + try: + self.con = eng.connect() + result = self.con.execute(select([godown]).where(godown.c.orgcode==authDetails["orgcode"])) + godowns = [] + for row in result: + godowns.append({"goid": row["goid"], "goname": row["goname"], "goaddr": row["goaddr"]}) + return {"gkstatus": gkcore.enumdict["Success"], "gkresult":godowns } + except: + return {"gkstatus":gkcore.enumdict["ConnectionFailed"] } + finally: + self.con.close() - @view_config(request_param='qty=single', request_method='GET',renderer='json') - def getGodown(self): - 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() - result = self.con.execute(select([godown]).where(godown.c.goid == self.request.params["goid"])) - row = result.fetchone() - godownDetails={"goid": row["goid"], "goname": row["goname"], "goaddr": row["goaddr"], "gocontact": row["gocontact"],"state":row["state"],"contactname":row["contactname"],"designation":row["designation"]} - self.con.close() - return {"gkstatus":enumdict["Success"],"gkresult":godownDetails} - except: - return {"gkstatus":enumdict["ConnectionFailed"]} - finally: - self.con.close() + @view_config(request_param='qty=single', request_method='GET',renderer='json') + def getGodown(self): + 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() + result = self.con.execute(select([godown]).where(godown.c.goid == self.request.params["goid"])) + row = result.fetchone() + godownDetails={"goid": row["goid"], "goname": row["goname"], "goaddr": row["goaddr"], "gocontact": row["gocontact"],"state":row["state"],"contactname":row["contactname"],"designation":row["designation"]} + self.con.close() + return {"gkstatus":enumdict["Success"],"gkresult":godownDetails} + except: + return {"gkstatus":enumdict["ConnectionFailed"]} + finally: + self.con.close() - '''This function returns all godowns associated with godown in charge. - It takes user id as a input''' - @view_config(request_method='GET', request_param='type=byuser', renderer ='json') - def getGodownsByUser(self): - try: - token = self.request.headers["gktoken"] - except: - return {"gkstatus": gkcore.enumdict["UnauthorisedAccess"]} - authDetails = authCheck(token) - if authDetails["auth"] == False: - return {"gkstatus": gkcore.enumdict["UnauthorisedAccess"]} - else: - try: - self.con = eng.connect() - result = getusergodowns(self.request.params["userid"]) - return {"gkstatus": gkcore.enumdict["Success"], "gkresult":result["gkresult"]} - except: - return {"gkstatus":gkcore.enumdict["ConnectionFailed"] } - finally: - self.con.close() + '''This function returns all godowns associated with godown in charge. + It takes user id as a input''' + @view_config(request_method='GET', request_param='type=byuser', renderer ='json') + def getGodownsByUser(self): + try: + token = self.request.headers["gktoken"] + except: + return {"gkstatus": gkcore.enumdict["UnauthorisedAccess"]} + authDetails = authCheck(token) + if authDetails["auth"] == False: + return {"gkstatus": gkcore.enumdict["UnauthorisedAccess"]} + else: + try: + self.con = eng.connect() + result = getusergodowns(self.request.params["userid"]) + return {"gkstatus": gkcore.enumdict["Success"], "gkresult":result["gkresult"]} + except: + return {"gkstatus":gkcore.enumdict["ConnectionFailed"] } + finally: + self.con.close() + """ + The below function "getNumberOfProductInGodown" will be called when user select a + godown for deletetion, it will return number of products a selected godown content. + """ + + @view_config(request_method='GET', request_param='type=goproduct',renderer='json') + def getNumberOfProductInGodown(self): + 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() + goid = self.request.params["goid"] + result = self.con.execute(select([func.count(goprod.c.productcode)]).where(goprod.c.goid == goid)) + row = result.fetchone() + return {"gkstatus":enumdict["Success"],"gkresult":row[0]} + except: + self.con.close() + return {"gkstatus":enumdict["ConnectionFailed"]} + finally: + self.con.close() + """ - The below function "getNumberOfProductInGodown" will be called when user select a - godown for deletetion, it will return number of products a selected godown content. + The below function "getGodownProd" will be called when user select Dispatched From for Transfer Note, it will return Godown Name with Address containing products. """ + @view_config(request_method='GET', request_param='value=1',renderer='json') + def getGodownProd(self): + 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() + result = self.con.execute(select([goprod.c.goid]).distinct().where(goprod.c.orgcode == authDetails["orgcode"])) + grow = result.fetchall() + godownList = [] + for g in grow : + godownData = self.con.execute(select([godown.c.goid, godown.c.goname, godown.c.goaddr]).where(godown.c.goid == g["goid"])) + row = godownData.fetchone() + godownList.append({"goid": row["goid"], "goname": row["goname"], "goaddr": row["goaddr"]}) + self.con.close() + return {"gkstatus":enumdict["Success"],"gkresult":godownList} + except: + self.con.close() + return {"gkstatus":enumdict["ConnectionFailed"]} + finally: + self.con.close() + - @view_config(request_method='GET', request_param='type=goproduct',renderer='json') - def getNumberOfProductInGodown(self): - 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() - goid = self.request.params["goid"] - result = self.con.execute(select([func.count(goprod.c.productcode)]).where(goprod.c.goid == goid)) - row = result.fetchone() - return {"gkstatus":enumdict["Success"],"gkresult":row[0]} - except: - self.con.close() - return {"gkstatus":enumdict["ConnectionFailed"]} - finally: - self.con.close() - - @view_config(request_method='DELETE', renderer ='json') - def deleteGodown(self): - 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() - dataset = self.request.json_body - result = self.con.execute(godown.delete().where(godown.c.goid==dataset["goid"])) - return {"gkstatus":enumdict["Success"]} - except exc.IntegrityError: - return {"gkstatus":enumdict["ActionDisallowed"]} - except: - return {"gkstatus":enumdict["ConnectionFailed"] } - finally: - self.con.close() + @view_config(request_method='DELETE', renderer ='json') + def deleteGodown(self): + 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() + dataset = self.request.json_body + result = self.con.execute(godown.delete().where(godown.c.goid==dataset["goid"])) + return {"gkstatus":enumdict["Success"]} + except exc.IntegrityError: + return {"gkstatus":enumdict["ActionDisallowed"]} + except: + return {"gkstatus":enumdict["ConnectionFailed"] } + finally: + self.con.close() - @view_config(request_method='GET', request_param='type=lastfivegodown', renderer ='json') - def lastfivegodata(self): - try: - token = self.request.headers["gktoken"] - except: - return {"gkstatus": gkcore.enumdict["UnauthorisedAccess"]} - authDetails = authCheck(token) - if authDetails["auth"] == False: - return {"gkstatus": gkcore.enumdict["UnauthorisedAccess"]} - else: - try: - self.con = eng.connect() - result = self.con.execute(select([godown]).where(godown.c.orgcode==authDetails["orgcode"]).order_by(godown.c.goid.desc()).limit(5)) - godowns = [] - srno=1 - for row in result: - godowns.append({"goname": row["goname"], "goaddr": row["goaddr"], "state":row["state"]}) - srno = srno+1 - return {"gkstatus": gkcore.enumdict["Success"], "gkresult":godowns } - except: - return {"gkstatus":gkcore.enumdict["ConnectionFailed"] } - finally: - self.con.close() + @view_config(request_method='GET', request_param='type=lastfivegodown', renderer ='json') + def lastfivegodata(self): + try: + token = self.request.headers["gktoken"] + except: + return {"gkstatus": gkcore.enumdict["UnauthorisedAccess"]} + authDetails = authCheck(token) + if authDetails["auth"] == False: + return {"gkstatus": gkcore.enumdict["UnauthorisedAccess"]} + else: + try: + self.con = eng.connect() + result = self.con.execute(select([godown]).where(godown.c.orgcode==authDetails["orgcode"]).order_by(godown.c.goid.desc()).limit(5)) + godowns = [] + srno=1 + for row in result: + godowns.append({"goname": row["goname"], "goaddr": row["goaddr"], "state":row["state"]}) + srno = srno+1 + return {"gkstatus": gkcore.enumdict["Success"], "gkresult":godowns } + except: + return {"gkstatus":gkcore.enumdict["ConnectionFailed"] } + finally: + self.con.close() diff --git a/gkcore/views/api_groupssubgroups.py b/gkcore/views/api_groupssubgroups.py index a40744c4dcf344a473a84c01501e357acd64d15f..2ab45a652a3e4ab1fa8964c63910589c5f92857c 100644 --- a/gkcore/views/api_groupssubgroups.py +++ b/gkcore/views/api_groupssubgroups.py @@ -1,6 +1,7 @@ """ Copyright (C) 2013, 2014, 2015, 2016 Digital Freedom Foundation +Copyright (C) 2017, 2018 Digital Freedom Foundation & Accion Labs Pvt. Ltd. This file is part of GNUKhata:A modular,robust and Free Accounting System. GNUKhata is Free Software; you can redistribute it and/or modify diff --git a/gkcore/views/api_invoice.py b/gkcore/views/api_invoice.py index 923bc93eb4685686b817db824c9b60687eeed46c..dcc5422ac6b319a376acc1bb6804fa7b150cc0c1 100644 --- a/gkcore/views/api_invoice.py +++ b/gkcore/views/api_invoice.py @@ -1,5 +1,6 @@ """ Copyright (C) 2013, 2014, 2015, 2016 Digital Freedom Foundation +Copyright (C) 2017, 2018 Digital Freedom Foundation & Accion Labs Pvt. Ltd. This file is part of GNUKhata:A modular,robust and Free Accounting System. GNUKhata is Free Software; you can redistribute it and/or modify @@ -134,6 +135,12 @@ class api_invoice(object): return {"gkstatus":gkcore.enumdict["ConnectionFailed"] } finally: self.con.close() + + ''' + This is a function to update an invoice. + This function is primarily used to enable editing of invoices. + It receives a dictionary with information regarding an invoice, changes to be made in stock if any and delivery notes linked if any. + ''' @view_config(request_method='PUT', renderer='json') def editInvoice(self): try: @@ -146,48 +153,56 @@ class api_invoice(object): else: try: self.con = eng.connect() + # Data is stored in a variable dtset. dtset = self.request.json_body + # Empty dictionary to store details of delivery challan linked if any. dcinvdataset={} + # Details of invoice and stock are stored in separate variables. invdataset = dtset["invoice"] stockdataset = dtset["stock"] items = invdataset["contents"] invdataset["orgcode"] = authDetails["orgcode"] stockdataset["orgcode"] = authDetails["orgcode"] - result = self.con.execute(stock.delete().where(and_(stock.c.dcinvtnid==invdataset["invid"],stock.c.dcinvtnflag==9))) - result = self.con.execute(dcinv.delete().where(dcinv.c.invid==invdataset["invid"])) + # Entries in dcinv and stock tables are deleted to avoid duplicate entries. + try: + deletestock = self.con.execute(stock.delete().where(and_(stock.c.dcinvtnid==invdataset["invid"],stock.c.dcinvtnflag==9))) + except: + pass + try: + deletedcinv = self.con.execute(dcinv.delete().where(dcinv.c.invid==invdataset["invid"])) + except: + pass + # If delivery chalan is linked details of invoice are updated and a new entry is made in the dcinv table. if invdataset.has_key("dcid"): - dcid = invdataset.pop("dcid") - result = self.con.execute(invoice.update().where(invoice.c.invid==invdataset["invid"]).values(invdataset)) - invdataset["dcid"] = dcid - if result.rowcount == 1: - dcinvdataset["dcid"]=invdataset["dcid"] - dcinvdataset["orgcode"]=invdataset["orgcode"] - dcinvdataset["invid"]=invdataset["invid"] + dcinvdataset["dcid"]=invdataset.pop("dcid") + dcinvdataset["orgcode"]=invdataset["orgcode"] + dcinvdataset["invid"]=invdataset["invid"] + dcinvdataset["invprods"] = stockdataset["items"] + try: + updateinvoice = self.con.execute(invoice.update().where(invoice.c.invid==invdataset["invid"]).values(invdataset)) result = self.con.execute(dcinv.insert(),[dcinvdataset]) return {"gkstatus":enumdict["Success"]} - else: + except: return {"gkstatus":gkcore.enumdict["ConnectionFailed"] } + # If no delivery challan is linked an entry is made in stock table after invoice details are updated. else: try: - result = self.con.execute(invoice.update().where(invoice.c.invid==invdataset["invid"]).values(invdataset)) + updateinvoice = self.con.execute(invoice.update().where(invoice.c.invid==invdataset["invid"]).values(invdataset)) result = self.con.execute(select([invoice.c.invid,invoice.c.invoicedate]).where(and_(invoice.c.custid==invdataset["custid"], invoice.c.invoiceno==invdataset["invoiceno"]))) invoiceid = result.fetchone() stockdataset["dcinvtnid"] = invoiceid["invid"] stockdataset["stockdate"] = invoiceid["invoicedate"] + stockdataset["dcinvtnflag"] = "9" for item in items.keys(): stockdataset["productcode"] = item stockdataset["qty"] = items[item].values()[0] - stockdataset["dcinvtnflag"] = "9" result = self.con.execute(stock.insert(),[stockdataset]) return {"gkstatus":enumdict["Success"]} except: - result = self.con.execute(stock.delete().where(and_(stock.c.dcinvtnid==invoiceid["invid"],stock.c.dcinvtnflag==9))) - result = self.con.execute(invoice.delete().where(invoice.c.invid==invoiceid["invid"])) return {"gkstatus":gkcore.enumdict["ConnectionFailed"] } except exc.IntegrityError: return {"gkstatus":enumdict["DuplicateEntry"]} except: - result = self.con.execute(invoice.delete().where(invoice.c.invid==invdataset["invid"])) return {"gkstatus":gkcore.enumdict["ConnectionFailed"] } finally: self.con.close() @@ -285,7 +300,7 @@ There will be an icFlag which will determine if it's an incrementing or decreme inv["transportationmode"] = invrow["transportationmode"] inv["vehicleno"] = invrow["vehicleno"] inv["reversecharge"] = invrow["reversecharge"] - inOut = self.con.execute(select([stock.c.inout]).where(stock.c.dcinvtnid==self.request.params["invid"])) + inOut = self.con.execute(select([stock.c.inout]).where(and_(stock.c.dcinvtnid==self.request.params["invid"], stock.c.dcinvtnflag==9))) inOutData = inOut.fetchone() if inOutData != None: inv["inoutflag"] = int(inOutData["inout"]) @@ -298,17 +313,19 @@ There will be an icFlag which will determine if it's an incrementing or decreme result =self.con.execute(select([dcinv.c.dcid]).where(dcinv.c.invid==invrow["invid"])) dcid = result.fetchone() if result.rowcount>0: - dc = self.con.execute(select([delchal.c.dcno]).where(delchal.c.dcid==dcid["dcid"])) + dc = self.con.execute(select([delchal.c.dcno, delchal.c.dcdate]).where(delchal.c.dcid==dcid["dcid"])) delchalData = dc.fetchone() inv["dcid"]=dcid["dcid"] inv["dcno"]=delchalData["dcno"] + inv["dcdate"] = datetime.strftime(delchalData["dcdate"],"%d-%m-%Y") inOut = self.con.execute(select([stock.c.inout]).where(and_(stock.c.dcinvtnid==dcid["dcid"], stock.c.dcinvtnflag==4))) inOutData = inOut.fetchone() if inOutData != None: inv["inoutflag"] = int(inOutData["inout"]) custandsup = self.con.execute(select([customerandsupplier.c.custname,customerandsupplier.c.state, customerandsupplier.c.custaddr, customerandsupplier.c.custtan,customerandsupplier.c.gstin, customerandsupplier.c.csflag]).where(customerandsupplier.c.custid==invrow["custid"])) custData = custandsup.fetchone() - custSupDetails = {"custname":custData["custname"],"custsupstate":custData["state"],"custaddr":custData["custaddr"],"csflag":custData["csflag"]} + custsupstatecode = getStateCode(custData["state"],self.con)["statecode"] + custSupDetails = {"custname":custData["custname"],"custsupstate":custData["state"],"custaddr":custData["custaddr"],"csflag":custData["csflag"],"custsupstatecode":custsupstatecode} if custData["custtan"] != None: custSupDetails["custtin"] = custData["custtan"] if custData["gstin"] != None: @@ -323,7 +340,6 @@ There will be an icFlag which will determine if it's an incrementing or decreme except: custSupDetails["custgstin"] = None - inv["custSupDetails"] = custSupDetails #contents is a nested dictionary from invoice table. #It contains productcode as the key with a value as a dictionary. diff --git a/gkcore/views/api_log.py b/gkcore/views/api_log.py index f710e9ad50241bfeb3b03fc0aed36916dfed565f..f79ed0863b263ec5323b455935dc7042165d888a 100644 --- a/gkcore/views/api_log.py +++ b/gkcore/views/api_log.py @@ -1,6 +1,7 @@ """ Copyright (C) 2013, 2014, 2015, 2016 Digital Freedom Foundation +Copyright (C) 2017, 2018 Digital Freedom Foundation & Accion Labs Pvt. Ltd. This file is part of GNUKhata:A modular,robust and Free Accounting System. GNUKhata is Free Software; you can redistribute it and/or modify diff --git a/gkcore/views/api_login.py b/gkcore/views/api_login.py index 5deee2e1babf1b4c70ceadb86f84842bb253711f..f4073db7dcdf0dfc4a8ec012fd8a3cb8e5f98b81 100644 --- a/gkcore/views/api_login.py +++ b/gkcore/views/api_login.py @@ -1,6 +1,7 @@ """ Copyright (C) 2013, 2014, 2015, 2016 Digital Freedom Foundation +Copyright (C) 2017, 2018 Digital Freedom Foundation & Accion Labs Pvt. Ltd. This file is part of GNUKhata:A modular,robust and Free Accounting System. GNUKhata is Free Software; you can redistribute it and/or modify diff --git a/gkcore/views/api_organisation.py b/gkcore/views/api_organisation.py index 890f472ae41640a9e749fe21cc4d5be91d7d9df8..0f6c1acabd65a92ccd4dfae1fc116fab9901863a 100644 --- a/gkcore/views/api_organisation.py +++ b/gkcore/views/api_organisation.py @@ -1,6 +1,7 @@ """ Copyright (C) 2013, 2014, 2015, 2016 Digital Freedom Foundation +Copyright (C) 2017, 2018 Digital Freedom Foundation & Accion Labs Pvt. Ltd. This file is part of GNUKhata:A modular,robust and Free Accounting System. GNUKhata is Free Software; you can redistribute it and/or modify @@ -60,10 +61,14 @@ class api_organisation(object): """ self.con = eng.connect() try: + self.con.execute(select([func.count(gkdb.delchal.c.consignee)])) self.con.execute(select([func.count(gkdb.invoice.c.orgstategstin)])) self.con.execute(select([func.count(gkdb.invoice.c.cess)])) self.con.execute(select([func.count(gkdb.state.c.statecode)])) - self.con.execute(select([func.count(gkdb.invoice.c.reversecharge)])) + countResult = self.con.execute(select([func.count(gkdb.invoice.c.reversecharge).label('revcount')])) + countData = countResult.fetchone() + if int(countData["revcount"]) > 0: + self.con.execute("update invoice set reversecharge = '0'" ) self.con.execute(select(gkdb.organisation.c.gstin)) self.con.execute(select([func.count(gkdb.invoice.c.consignee)])) self.con.execute(select([func.count(gkdb.customerandsupplier.c.gstin)])) @@ -80,7 +85,7 @@ class api_organisation(object): self.con.execute(select(gkdb.organisation.c.billflag)) self.con.execute(select([func.count(gkdb.billwise.c.billid)])) except: - self.con.execute("update invoice set reversecharge = '0'" ) + self.con.execute("alter table delchal add consignee jsonb") self.con.execute("alter table invoice add orgstategstin text") self.con.execute("alter table invoice add cess jsonb") self.con.execute("alter table product add UNIQUE(productdesc,orgcode)") diff --git a/gkcore/views/api_product.py b/gkcore/views/api_product.py index a4b3123f5078b5bcaa81c19eb46635a6d4c1c156..120cdd77a5524c548767629d27ef092c32b389a3 100644 --- a/gkcore/views/api_product.py +++ b/gkcore/views/api_product.py @@ -1,6 +1,7 @@ """ Copyright (C) 2013, 2014, 2015, 2016 Digital Freedom Foundation +Copyright (C) 2017, 2018 Digital Freedom Foundation & Accion Labs Pvt. Ltd. This file is part of GNUKhata:A modular,robust and Free Accounting System. GNUKhata is Free Software; you can redistribute it and/or modify diff --git a/gkcore/views/api_project.py b/gkcore/views/api_project.py index e53dc9f54190964921709d1e7b8435031969c887..c737c1f5f9a64fbb86aaf46ab743a967635cbfb1 100644 --- a/gkcore/views/api_project.py +++ b/gkcore/views/api_project.py @@ -1,6 +1,7 @@ """ Copyright (C) 2013, 2014, 2015, 2016 Digital Freedom Foundation +Copyright (C) 2017, 2018 Digital Freedom Foundation & Accion Labs Pvt. Ltd. This file is part of GNUKhata:A modular,robust and Free Accounting System. GNUKhata is Free Software; you can redistribute it and/or modify diff --git a/gkcore/views/api_purchaseorder.py b/gkcore/views/api_purchaseorder.py index f551df5bfcbc2e1930ba89611370ed82d29b5bf6..5980c06c3d0799e0104d6164118d07c282a00a86 100644 --- a/gkcore/views/api_purchaseorder.py +++ b/gkcore/views/api_purchaseorder.py @@ -1,6 +1,7 @@ """ Copyright (C) 2013, 2014, 2015, 2016 Digital Freedom Foundation +Copyright (C) 2017, 2018 Digital Freedom Foundation & Accion Labs Pvt. Ltd. This file is part of GNUKhata:A modular,robust and Free Accounting System. GNUKhata is Free Software; you can redistribute it and/or modify diff --git a/gkcore/views/api_reports.py b/gkcore/views/api_reports.py index f06d6b1f4604f166f5b6bf267f28ea07be0b1caf..cb147260683e92d6329e8628eb97f7ec5ec0830e 100644 --- a/gkcore/views/api_reports.py +++ b/gkcore/views/api_reports.py @@ -1,6 +1,7 @@ """ Copyright (C) 2013, 2014, 2015, 2016 Digital Freedom Foundation +Copyright (C) 2017, 2018 Digital Freedom Foundation & Accion Labs Pvt. Ltd. This file is part of GNUKhata:A modular,robust and Free Accounting System. GNUKhata is Free Software; you can redistribute it and/or modify diff --git a/gkcore/views/api_rollclose.py b/gkcore/views/api_rollclose.py index d0ccabfa016da9e3823c62c391b2f24c8075cf59..9a252a30c3ee6ae2b40a78644741add030531b06 100644 --- a/gkcore/views/api_rollclose.py +++ b/gkcore/views/api_rollclose.py @@ -1,6 +1,7 @@ """ Copyright (C) 2013, 2014, 2015, 2016 Digital Freedom Foundation +Copyright (C) 2017, 2018 Digital Freedom Foundation & Accion Labs Pvt. Ltd. This file is part of GNUKhata:A modular,robust and Free Accounting System. GNUKhata is Free Software; you can redistribute it and/or modify diff --git a/gkcore/views/api_state.py b/gkcore/views/api_state.py index 6660db033accc8e5b203ed47484e7a6bb0de5d8f..0ea9fdb729c5e14d762f9e207696264bbfa1a652 100644 --- a/gkcore/views/api_state.py +++ b/gkcore/views/api_state.py @@ -1,5 +1,6 @@ """ Copyright (C) 2013, 2014, 2015, 2016 Digital Freedom Foundation +Copyright (C) 2017, 2018 Digital Freedom Foundation & Accion Labs Pvt. Ltd. This file is part of GNUKhata:A modular,robust and Free Accounting System. GNUKhata is Free Software; you can redistribute it and/or modify diff --git a/gkcore/views/api_tax.py b/gkcore/views/api_tax.py index 23ecc4956983b329c837e5af5c8f823e712e0b6c..f1093373acd5280b7dace5818a27b177f07e3f06 100644 --- a/gkcore/views/api_tax.py +++ b/gkcore/views/api_tax.py @@ -1,6 +1,7 @@ """ Copyright (C) 2013, 2014, 2015, 2016 Digital Freedom Foundation +Copyright (C) 2017, 2018 Digital Freedom Foundation & Accion Labs Pvt. Ltd. This file is part of GNUKhata:A modular,robust and Free Accounting System. GNUKhata is Free Software; you can redistribute it and/or modify diff --git a/gkcore/views/api_transaction.py b/gkcore/views/api_transaction.py index 3de4076361105b6da8087e2327088ec76abee661..413f590f0d4d21c64ee6625b6528768674268478 100644 --- a/gkcore/views/api_transaction.py +++ b/gkcore/views/api_transaction.py @@ -1,6 +1,7 @@ """ Copyright (C) 2013, 2014, 2015, 2016 Digital Freedom Foundation +Copyright (C) 2017, 2018 Digital Freedom Foundation & Accion Labs Pvt. Ltd. This file is part of GNUKhata:A modular,robust and Free Accounting System. GNUKhata is Free Software; you can redistribute it and/or modify @@ -24,6 +25,7 @@ Contributors: "Ishan Masdekar " "Navin Karkera" "Vanita Rajpurohit" +'Prajkta Patkar' """ @@ -67,11 +69,48 @@ class api_transaction(object): self.request = Request self.request = request self.con = Connection + def __genVoucherNumber(self,con,voucherType,orgcode): + """ + Purpose: + Generates a new vouchernumber based on vouchertype and max count for that type. + """ + initialType = "" + if voucherType == "journal": + initialType = "jr" + if voucherType == "contra": + initialType = "cr" + if voucherType == "payment": + initialType = "pt" + if voucherType == "receipt": + initialType = "rt" + if voucherType == "sales": + initialType = "sl" + if voucherType == "purchase": + initialType = "pu" + if voucherType == "creditnote": + initialType = "cn" + if voucherType == "debitnote": + initialType = "dn" + if voucherType == "salereturn": + initialType = "sr" + if voucherType == "purchasereturn": + initialType = "pr" + + vchCountResult = self.con.execute("select count(vouchercode) as vcount from vouchers where orgcode = %d"%(int(orgcode))) + vchCount = vchCountResult.fetchone() + if vchCount["vcount"] == 0: + initialType = initialType + "1" + else: + vchCodeResult = self.con.execute("select max(vouchercode) as vcode from vouchers") + vchCode = vchCodeResult.fetchone() + initialType = initialType + str(vchCode["vcode"]) + return initialType - + @view_config(request_method='POST',renderer='json') def addVoucher(self): """ + Purpose: adds a new voucher for given organisation and returns success as gkstatus if adding is successful. Description: @@ -113,6 +152,12 @@ class api_transaction(object): if dataset.has_key("instrumentdate"): instrumentdate=dataset["instrumentdate"] dataset["instrumentdate"] = datetime.strptime(instrumentdate, "%Y-%m-%d") + # generate voucher number if it is not sent. + if dataset.has_key("vouchernumber") == False: + voucherType = dataset["vouchertype"] + vchNo = self.__genVoucherNumber(self.con,voucherType,dataset["orgcode"]) + dataset["vouchernumber"] = vchNo + result = self.con.execute(vouchers.insert(),[dataset]) for drkeys in drs.keys(): self.con.execute("update accounts set vouchercount = vouchercount +1 where accountcode = %d"%(int(drkeys))) diff --git a/gkcore/views/api_transfernote.py b/gkcore/views/api_transfernote.py index fa86760679a9d86918bf450b19eb717cb8f79388..259174a04ae889311b5598a51fa6abd9550b899d 100644 --- a/gkcore/views/api_transfernote.py +++ b/gkcore/views/api_transfernote.py @@ -1,5 +1,6 @@ """ Copyright (C) 2013, 2014, 2015, 2016 Digital Freedom Foundation +Copyright (C) 2017, 2018 Digital Freedom Foundation & Accion Labs Pvt. Ltd. This file is part of GNUKhata:A modular,robust and Free Accounting System. GNUKhata is Free Software; you can redistribute it and/or modify diff --git a/gkcore/views/api_unitofmeasurement.py b/gkcore/views/api_unitofmeasurement.py index b2846a7e7a796f26da9bc3ddb760534f42685d00..47e3b9e6cee4483cdd9b3e94a67e4668e9a5a2ff 100644 --- a/gkcore/views/api_unitofmeasurement.py +++ b/gkcore/views/api_unitofmeasurement.py @@ -1,6 +1,7 @@ """ Copyright (C) 2013, 2014, 2015, 2016 Digital Freedom Foundation +Copyright (C) 2017, 2018 Digital Freedom Foundation & Accion Labs Pvt. Ltd. This file is part of GNUKhata:A modular,robust and Free Accounting System. GNUKhata is Free Software; you can redistribute it and/or modify diff --git a/gkcore/views/api_user.py b/gkcore/views/api_user.py index 9bd222fc740ab76cf01972a3f3f548b76db8e534..73b813fb4180b3764f1d4a1ba68ce66db39d3214 100644 --- a/gkcore/views/api_user.py +++ b/gkcore/views/api_user.py @@ -1,6 +1,7 @@ """ Copyright (C) 2013, 2014, 2015, 2016 Digital Freedom Foundation +Copyright (C) 2017, 2018 Digital Freedom Foundation & Accion Labs Pvt. Ltd. This file is part of GNUKhata:A modular,robust and Free Accounting System. GNUKhata is Free Software; you can redistribute it and/or modify @@ -24,6 +25,9 @@ Contributors: "Ishan Masdekar " "Navin Karkera" "Mohd. Talha Pawaty" +"Prajkta Patkar" +"Nitesh Chaughule" + """ @@ -109,8 +113,11 @@ class api_user(object): return {"gkstatus":gkcore.enumdict["ConnectionFailed"] } finally: self.con.close() - @view_config(route_name='user', request_method='GET',renderer='json') - def getUser(self): + """ + Following function is to retrive user data.It needs userid & only admin can view data of other users. + """ + @view_config(route_name='user', request_method='GET', request_param = "userAllData",renderer='json') + def getUserAllData(self): try: token = self.request.headers["gktoken"] except: @@ -121,25 +128,106 @@ class api_user(object): else: try: self.con = eng.connect() - result = self.con.execute(select([gkdb.users]).where(gkdb.users.c.userid == authDetails["userid"] )) - row = result.fetchone() - User = {"userid":row["userid"], "username":row["username"], "userrole":row["userrole"], "userquestion":row["userquestion"], "useranswer":row["useranswer"], "userpassword":row["userpassword"]} - if User["userrole"] == 3: - usgo = self.con.execute(select([gkdb.usergodown.c.goid]).where(gkdb.users.c.userid == authDetails["userid"])) - goids = usgo.fetchall() - userGodowns = {} - for g in goids: - godownid = g["goid"] - godownData = self.con.execute(select([gkdb.godown.c.goname]).where(gkdb.godown.c.goid == godownid)) - gNameRow = godownData.fetchone() - userGodowns[godownid] = gNameRow["goname"] - User["godowns"] = userGodowns + # get necessary user data by comparing userid + user=self.con.execute(select([gkdb.users.c.userrole]).where(gkdb.users.c.userid == authDetails["userid"] )) + userRole = user.fetchone() + if userRole[0]==-1: + result = self.con.execute(select([gkdb.users]).where(gkdb.users.c.userid == self.request.params["userid"] )) + row = result.fetchone() + User = {"userid":row["userid"], "username":row["username"], "userrole":row["userrole"], "userquestion":row["userquestion"], "useranswer":row["useranswer"]} + if(row["userrole"] == -1): + User["userroleName"]= "Admin" + elif(row["userrole"] == 0): + User["userroleName"] = "Manager" + elif(row["userrole"] == 1): + User["userroleName"] = "Operator" + elif(row["userrole"] == 2): + User["userroleName"] = "Internal Auditor" + + # -1 = admin,1 = operator,2 = manager , 3 = godown in charge + # if user is godown in-charge we need to retrive associated godown/s + if User["userrole"] == 3: + User["userroleName"] = "Godown In Charge" + usgo = self.con.execute(select([gkdb.usergodown.c.goid]).where(gkdb.usergodown.c.userid == self.request.params["userid"])) + goids = usgo.fetchall() + userGodowns = {} + for g in goids: + godownid = g["goid"] + # now we have associated godown ids, by which we can get godown name + godownData = self.con.execute(select([gkdb.godown.c.goname]).where(gkdb.godown.c.goid == godownid)) + gNameRow = godownData.fetchone() + userGodowns[godownid] = gNameRow["goname"] + User["godowns"] = userGodowns - return {"gkstatus": gkcore.enumdict["Success"], "gkresult":User} + return {"gkstatus": gkcore.enumdict["Success"], "gkresult":User} + else: + return {"gkstatus":gkcore.enumdict["ActionDisallowed"]} + except: return {"gkstatus":gkcore.enumdict["ConnectionFailed"] } finally: self.con.close() + + """ + Following function is to get all users data having same user role .It needs userrole & only admin can view data of other users. + """ + @view_config(route_name='user', request_method='GET', request_param = "sameRoleUsers",renderer='json') + def getAllUsersData(self): + 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() + # get user role to validate. + # only admin can view all users entire data + user=self.con.execute(select([gkdb.users.c.userrole]).where(gkdb.users.c.userid == authDetails["userid"] )) + userRole = user.fetchone() + if userRole[0]==-1: + # get all users having same user role. + result = self.con.execute(select([gkdb.users.c.username,gkdb.users.c.userid,gkdb.users.c.userquestion,gkdb.users.c.useranswer]).where(and_(gkdb.users.c.userrole == self.request.params["userrole"] , gkdb.users.c.orgcode == authDetails["orgcode"]))) + userData = result.fetchall() + usersList = [] + for row in userData : + User = {"userid":row["userid"], "username":row["username"], "userrole":self.request.params["userrole"], "userquestion":row["userquestion"], "useranswer":row["useranswer"]} + # -1 = admin, 0 = Manager ,1 = operator,2 = Internal Auditor , 3 = godown in charge + if int(self.request.params["userrole"]) == -1: + User["userroleName"]= "Admin" + elif int(self.request.params["userrole"] == 0): + User["userroleName"] = "Manager" + elif int(self.request.params["userrole"] == 1): + User["userroleName"] = "Operator" + elif int(self.request.params["userrole"] == 2): + User["userroleName"] = "Internal Auditor" + # if user is godown in-charge we need to retrive associated godown/s + + elif int(self.request.params["userrole"]) == 3: + User["userroleName"] = "Godown In Charge" + usgo = self.con.execute(select([gkdb.usergodown.c.goid]).where(gkdb.users.c.userid == row["userid"])) + goids = usgo.fetchall() + userGodowns = {} + for g in goids: + godownid = g["goid"] + # now we have associated godown ids, by which we can get godown name + godownData = self.con.execute(select([gkdb.godown.c.goname]).where(gkdb.godown.c.goid == godownid)) + gNameRow = godownData.fetchone() + userGodowns[godownid] = gNameRow["goname"] + User["godowns"] = userGodowns + usersList.append(User) + + return {"gkstatus": gkcore.enumdict["Success"], "gkresult":usersList} + else: + return {"gkstatus":gkcore.enumdict["ActionDisallowed"]} + + except: + return {"gkstatus":gkcore.enumdict["ConnectionFailed"] } + finally: + self.con.close() + @view_config(request_method='PUT', renderer='json') def editUser(self): try: @@ -164,6 +252,83 @@ class api_user(object): return {"gkstatus":gkcore.enumdict["ConnectionFailed"] } finally: self.con.close() + """ + Following function check status (i.e valid or not) of field current password in edituser. +""" + + @view_config(request_method='POST', request_param="userloginstatus", renderer='json') + def userLoginstatus(self): + try: + self.con = eng.connect() + token = self.request.headers["gktoken"] + except: + return {"gkstatus": gkcore.enumdict["UnauthorisedAccess"]} + authDetails = authCheck(token) + if authDetails["auth"] == False: + return {"gkstatus": enumdict["UnauthorisedAcces"]} + else: + try: + dataset = self.request.json_body + result = self.con.execute(select([gkdb.users.c.userid]).where(and_(gkdb.users.c.username==dataset["username"], gkdb.users.c.userpassword== dataset["userpassword"], gkdb.users.c.orgcode==authDetails["orgcode"])) ) + if result.rowcount == 1: + return {"gkstatus":enumdict["Success"]} + else: + return {"gkstatus": enumdict["BadPrivilege"]} + except: + return {"gkstatus":enumdict["ConnectionFailed"]} + finally: + self.con.close() + + """ + Following function update user, in the users table. + It may also have a list of goids for the godowns associated with this user. + The frontend must send the role as Godown In Charge for this. +""" + @view_config(request_method='PUT', request_param='editdata' ,renderer='json') + def updateuser(self): + try: + token = self.request.headers["gktoken"] + except: + return {"gkstatus": gkcore.enumdict["UnauthorisedAccess"]} + authDetails = authCheck(token) + if authDetails["auth"] == False: + return {"gkstatus": enumdict["UnauthorisedAcces"]} + else: + try: + self.con =eng.connect() + userRole = getUserRole(authDetails["userid"]) + dataset = self.request.json_body + if userRole["gkresult"]["userrole"] == -1: + dataset["orgcode"] = authDetails["orgcode"] + # "originalrole" gives userrole of old user + originalrole = getUserRole(dataset["userid"]) + if int(originalrole["gkresult"]["userrole"]==3): + result = self.con.execute(gkdb.usergodown.delete().where(gkdb.usergodown.c.userid==dataset["userid"])) + #dataset["userrole"] gives userrole of new user + if dataset.has_key("userrole"): + if int(dataset["userrole"])== 3: + golists = tuple(dataset.pop("golist")) + result = self.con.execute(gkdb.users.update().where(gkdb.users.c.userid==dataset["userid"]).values(dataset)) + currentid = dataset["userid"] + for goid in golists: + godata = {"userid":currentid,"goid":goid,"orgcode":dataset["orgcode"]} + result = self.con.execute(gkdb.usergodown.insert(),[godata]) + return {"gkstatus":enumdict["Success"]} + else: + result = self.con.execute(gkdb.users.update().where(gkdb.users.c.userid==dataset["userid"]).values(dataset)) + return {"gkstatus":enumdict["Success"]} + else: + result = self.con.execute(gkdb.users.update().where(gkdb.users.c.userid==dataset["userid"]).values(dataset)) + return {"gkstatus":enumdict["Success"]} + else: + return {"gkstatus":gkcore.enumdict["ActionDisallowed"]} + except exc.IntegrityError: + return {"gkstatus":enumdict["DuplicateEntry"]} + except: + return {"gkstatus":gkcore.enumdict["ConnectionFailed"] } + finally: + self.con.close() + @view_config(request_method='GET', renderer ='json') def getAllUsers(self): try: @@ -180,7 +345,18 @@ class api_user(object): result = self.con.execute(select([gkdb.users.c.username,gkdb.users.c.userid,gkdb.users.c.userrole]).where(gkdb.users.c.orgcode==authDetails["orgcode"]).order_by(gkdb.users.c.username)) users = [] for row in result: - users.append({"userid":row["userid"], "username":row["username"], "userrole":row["userrole"]}) + # Specify user role + if(row["userrole"] == -1): + userroleName = "Admin" + elif(row["userrole"] == 0): + userroleName = "Manager" + elif(row["userrole"] == 1): + userroleName = "Operator" + elif(row["userrole"] == 2): + userroleName = "Internal Auditor" + elif(row["userrole"] == 3): + userroleName = "Godown In Charge" + users.append({"userid":row["userid"], "username":row["username"], "userrole":row["userrole"],"userrolename": userroleName}) return {"gkstatus": gkcore.enumdict["Success"], "gkresult":users } except: return {"gkstatus":gkcore.enumdict["ConnectionFailed"] } @@ -373,3 +549,38 @@ class api_user(object): except: return {"gkstatus": enumdict["ConnectionFailed"]} + + """This function sends basic data of user like username ,userrole """ + @view_config(request_method='GET',request_param = "user=single" ,renderer ='json') + def getDataofUser(self): + try: + token = self.request.headers["gktoken"] + except: + return {"gkstatus": gkcore.enumdict["UnauthorisedAccess"]} + authDetails = authCheck(token) + if authDetails["auth"] == False: + return {"gkstatus": gkcore.enumdict["UnauthorisedAccess"]} + else: + try: + self.con = eng.connect() + #there is only one possibility for a catch which is failed connection to db. + #Retrieve data of that user whose userid is sent + result = self.con.execute(select([gkdb.users.c.username,gkdb.users.c.userrole, gkdb.users.c.userid]).where(gkdb.users.c.userid==authDetails["userid"])) + row = result.fetchone() + userData = {"username":row["username"],"userrole":row["userrole"],"userid":row["userid"]} + if(row["userrole"] == -1): + userData["userroleName"]= "Admin" + elif(row["userrole"] == 0): + userData["userroleName"] = "Manager" + elif(row["userrole"] == 1): + userData["userroleName"] = "Operator" + elif(row["userrole"] == 2): + userData["userroleName"] = "Internal Auditor" + elif(row["userrole"] == 3): + userData["userroleName"] = "Godown In Charge" + return {"gkstatus": gkcore.enumdict["Success"], "gkresult":userData } + except: + return {"gkstatus":gkcore.enumdict["ConnectionFailed"] } + finally: + self.con.close() + diff --git a/gkutil.sh b/gkutil.sh index 4112c704b5cd686ed44f84d8ffc9b895422b275a..1ab56219283db8b4c5b7c3a878cfc8815f53c14d 100755 --- a/gkutil.sh +++ b/gkutil.sh @@ -1,6 +1,7 @@ #!/bin/bash # Copyright (C) 2013, 2014, 2015, 2016 Digital Freedom Foundation +# Copyright (C) 2017, 2018 Digital Freedom Foundation & Accion Labs # This file is part of GNUKhata:A modular,robust and Free Accounting System. # GNUKhata is Free Software; you can redistribute it and/or modify diff --git a/initdb.py b/initdb.py index 726fa721a41181889bcc04f8cb95ee3fd03af74b..bef27e73fb69382d15c6dfd29aa6b71a1c431812 100644 --- a/initdb.py +++ b/initdb.py @@ -1,6 +1,7 @@ """ Copyright (C) 2013, 2014, 2015, 2016 Digital Freedom Foundation +Copyright (C) 2017, 2018 Digital Freedom Foundation & Accion Labs This file is part of GNUKhata:A modular,robust and Free Accounting System. GNUKhata is Free Software; you can redistribute it and/or modify