Subversion Repositories SmartDukaan

Rev

Rev 14094 | Blame | Compare with Previous | Last modification | View Log | RSS feed

import MySQLdb

db = MySQLdb.connect('localhost',"root","shop2020","warehouse" )
cursor = db.cursor()

def processPurchaseOrdersClosure():
    sql = "select id, poValidityLimit from supplier"
    print sql
    
    cursor.execute(sql)
    result = cursor.fetchall()
    
    for rec in result:
        updateSql = "update purchaseorder set status = 3 where supplierId = %d and DATE(createdAt) < DATE(SUBDATE(NOW(), %d))"%(rec[0],rec[1])
        print updateSql
        try:
            # Execute the update SQL command
            cursor.execute(updateSql)
            # Commit your changes in the database
            db.commit()
        except:
            # Rollback in case there is any error
            db.rollback()

def main():
    processPurchaseOrdersClosure()


if __name__=='__main__':
    main()