Commit a6bf5a52 authored by Krishnakant Mane's avatar Krishnakant Mane
Browse files

Merge branch 'autovchno' into 'devel'

A function to generate voucher no.

While importing data voucher no is to be created by software.
A function is written which creates voucher no with initial appended of respective voucher type e.g. For voucher type "sale"auto generated voucher no. would be "sl12".

See merge request !28
parents 4a807141 2b5cdaf2
......@@ -67,11 +67,48 @@ class api_transaction(object):
self.request = Request
self.request = request
self.con = Connection
def __genVoucherNumber(self,con,voucherType,orgcode):
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 == "credit Note":
initialType = "cn"
if voucherType == "debit Note":
initialType = "dn"
if voucherType == "sale Return":
initialType = "sr"
if voucherType == "purchase Return":
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"
vchCodeResult = self.con.execute("select max(vouchercode) as vcode from vouchers")
vchCode = vchCodeResult.fetchone()
initialType = initialType + str(vchCode["vcode"])
return initialType
def addVoucher(self):
adds a new voucher for given organisation and returns success as gkstatus if adding is successful.
......@@ -113,6 +150,12 @@ class api_transaction(object):
if dataset.has_key("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)))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment