Beispiel #1
0
 def Populate(self):
     session = Session()
     if self.table == None:
         return
     query = session.query(self.table)
     for item in query:
         self.Append(item.name, item.id)
     self.SetSelection(0)
     session.close()
Beispiel #2
0
 def Post(name):
     exercise = ExerciseType.NullObject()
     if ExerciseType.Count(name) == 0:
         exercise = ExerciseType(name=name.lower())
         Session.add(exercise)
         Session.commit()
     else:
         exercise = ExerciseType.GetByName(name)
     return exercise
Beispiel #3
0
 def DeleteByName(name):
     item = ExerciseType.GetByName(name)
     Session.delete(item)
     result = Session.commit()
     print result
     return json.dumps({
         "data_type": "request_confirmation",
         "status": "FAILURE"
     })
Beispiel #4
0
def get_data():
    ses = Session()
    rs = ses.query(Car).all()
    # you have to serialize the data from data object to serail data here
    #rs is the data output in data object format,
    global data
    data = [{"car": Car.Name, "price": Car.Price} for Car in rs]
    #json.dump(rs)
    return jsonify([data])
Beispiel #5
0
 def GetByName(name):
     try:
         query = Session.query(ExerciseType).filter(
             ExerciseType.name == name.lower())
         ex = query.first()
         return ex
     except:
         return ExerciseType.NullObject()
Beispiel #6
0
def get_all_users():
    session = Session()

    listUsers = []
    users = session.query(User).all()

    for user in users:
        listUsers.append({"id": user.id,
                        "firstname": user.firstname,
                        "lastname": user.lastname,
                        "username": user.username,
                        "status": user.status,
                        "email": user.email,
                        "created_at" : user.created_at
                        })

    session.close()
    return listUsers
Beispiel #7
0
def home():
    ses = Session()
    ses.add_all([
        Car(Id=1, Name='Audi', Price=52642),
        Car(Id=2, Name='Mercedes', Price=57127),
        Car(Id=3, Name='Skoda', Price=9000),
        Car(Id=4, Name='Volvo', Price=29000),
        Car(Id=5, Name='Bentley', Price=350000),
        Car(Id=6, Name='Citroen', Price=21000),
        Car(Id=7, Name='Hummer', Price=41400),
        Car(Id=8, Name='Volkswagen', Price=21600)
    ])
    ses.commit()

    rs = ses.query(Car).all()
    for Car in rs:
        print(Car.Name, Car.Price)
    return rs
Beispiel #8
0
from Database import engine, Base, Session
from models import User

Base.metadata.create_all(engine)

session = Session()

session.commit()
session.close()
Beispiel #9
0
class PurchaseLogic(object):
    COL_ID = 0
    COL_ITEM_ID = 1
    COL_ITEM_BCODE = 2
    COL_ITEM_DESC = 3
    COL_QTY = 4
    COL_ITEM_UNIT = 5
    COL_COST = 6
    COL_ITEM_SELLING = 7
    COL_EXPIRY = 8
    #COL_ITEM_TAX_CAT = 9

    SetSupplierList = None
    SetTaxCategoryList = None
    GetSupplier = None
    GetTaxCategory = None
    SetSupplier = None
    SetTaxCategory = None
    SetListValue = None
    GetListValue = None
    SetRow = None
    Lock = None
    GetPurchaseBillId = None
    HasItems = None
    ShowNavBar = None
    HideNavBar = None
    PurchaseBillIdError = None

    def __init__(self, userSession, peripherals):
        self.userSession = userSession
        self.peripherals = peripherals

        self.session = Session()

    def __del__(self):
        self.session.close()

    def Start(self):
        self.SetSupplierList(Supplier)
        self.SetTaxCategoryList(TaxCategory)
        try:
            query = self.session.query(PurchaseBill)
            last = query[-1]
            self.PurchaseBill = last
            self.Display()
        except IndexError:
            self.PurchaseBill = None
            self.New()

    def OnBack(self, event):
        if self.PurchaseBill == None:
            try:
                query = self.session.query(PurchaseBill)
                last = query[-1]
                self.PurchaseBill = last
                self.Display()
            except IndexError:
                pass
        else:
            try:
                self.PurchaseBill = self.session.query(PurchaseBill).\
                                    filter(PurchaseBill.id == (self.PurchaseBill.id - 1)).one()
                self.Display()
            except NoResultFound:
                print "No more behind"

    def OnForward(self, event):
        if self.PurchaseBill != None:
            try:
                self.PurchaseBill = self.session.query(PurchaseBill).\
                                    filter(PurchaseBill.id == (self.PurchaseBill.id + 1)).one()
                self.Display()
            except NoResultFound:
                self.PurchaseBill = None
                self.New()

    def GoToPurchaseBill(self, billid):
        try:
            self.PurchaseBill = self.session.query(PurchaseBill).\
                                    filter(PurchaseBill.id == (billid)).one()
            self.Display()
        except NoResultFound:
            if self.PurchaseBill != None:
                self.SetPurchaseBillId(str(self.PurchaseBill.id))
            else:
                self.New()
            self.PurchaseBillIdError()

    def New(self):
        self.ClearAll()
        self.SetPurchaseBillId('New')
        self.SetDate(datetime.now())
        self.SetSupplier(0)
        self.SetTaxCategory(0)

    def Display(self):
        self.ClearAll()
        if self.PurchaseBill == None:
            return

        self.SetPurchaseBillId(str(self.PurchaseBill.id))
        self.SetDate(self.PurchaseBill.time)
        self.SetSupplier(self.PurchaseBill.supplier.id)

        for purchase in self.PurchaseBill.purchases:
            row = self.AppendRow()
            self.SetRow(row, [
                purchase.id, purchase.item.id, purchase.item.bcode,
                purchase.item.desc, purchase.qty, purchase.item.unit,
                purchase.cost, purchase.item.selling, purchase.expiry
            ])
            self.SetForExistingItem(row)
            self.SetTaxCategory(purchase.item.taxCategory.id)

    def Save(self, event):
        try:
            billId = int(self.GetPurchaseBillId())
        except ValueError:
            billId = 0

        if self.PurchaseBill == None:
            self.SaveNew()
        else:
            self.OverWrite()

    def AddNewItem(self, row):
        item = Item(bcode=self.GetListValue(row, self.COL_ITEM_BCODE),
                    desc=self.GetListValue(row, self.COL_ITEM_DESC),
                    unit=self.GetListValue(row, self.COL_ITEM_UNIT),
                    selling=self.GetListValue(row, self.COL_ITEM_SELLING),
                    stockStart=0,
                    stockIn=0,
                    stockOut=0,
                    taxCategory_id=self.GetTaxCategory())

        self.session.add(item)
        self.session.flush()

        if item.bcode == '':
            item.bcode = 'S' + (str(item.id)).upper().zfill(4)

        return item

    def OverWrite(self):
        print "OverWriting"
        try:
            self.PurchaseBill.time = self.GetDate()
            self.PurchaseBill.supplier_id = self.GetSupplier()
            self.PurchaseBill.user_id = self.userSession.user.id

            for row in range(self.GetRowCount()):
                purchaseid = self.GetListValue(row, self.COL_ID)
                if purchaseid == 0:
                    print "saving new"
                    self.SaveNewPurchase(row, self.PurchaseBill)
                else:
                    print "saving old"
                    self.OverWritePurchase(purchaseid, row, self.PurchaseBill)

        except Exception, err:
            self.session.rollback()
            print('ERROR: %s\n' % str(err))

            print "error bill not saved"
        else:
Beispiel #10
0
    def __init__(self, userSession, peripherals):
        self.userSession = userSession
        self.peripherals = peripherals

        self.session = Session()
Beispiel #11
0
 def GetAll():
     try:
         exercises = Session.query(ExerciseType).all()
         return exercises
     except:
         return []
Beispiel #12
0
 def Count(name):
     return Session.query(ExerciseType).filter(
         ExerciseType.name == name.lower()).count()
Beispiel #13
0
class InvoiceLogic(object):
    COL_ID = 0
    COL_BCODE = 1
    COL_DESC = 2
    COL_QTY = 3
    COL_UNIT = 4
    COL_AVAILABLE = 5
    COL_RATE = 6
    COL_GSTP = 7
    COL_GST = 8
    COL_DISC = 9
    COL_TOTAL = 10

    GetAddress = None #arg -, ret string
    SetAddress = None
    GetEnteredCode = None #arg -, ret string
    SetEnteredCode = None #arg str
    GetEnteredQty = None
    SetEnteredQty = None
    GetAllItems = None #arg -, ret 2dlist[][?what]
    GetListValue = None #arg row,col ret float
    SetListValue = None #arg row,col,float
    SetItemInteger = None
    GetColSum = None #arg col, ret float
    GetRowWith = None #arg col, search, ret row(int)
    ClearItems = None
    InsertRow = None #arg [?wh], ret bool
    SetTotal = None #arg str
    SetTax = None #arg str
    HasItems = None
    GetPayment = None #arg paymentMethod[][id, name], invoicetotal, taxtotal, ret paymentMethod, tendered, balance, approvalCode
    DeleteRow = None
    SetRow = None #arg row,[?wh], ret bool
    #GetListValue = None #arg row,col ret str
    #SetItemString = None #arg row,col,str
    #GetRow = None #arg row, ret list[?what]
    #GetCol = None #arg col, ret list[?what?]
    #SetRow = None #arg row,[?wh], ret bool
    #DisableUI = None
    #EnableUI = None

    InvoiceTotal = 0.0
    InvoiceTaxTotal = 0.0

    def __init__(self, usersession, peripherals):
        self.usersession = usersession
        self.peripherals = peripherals

        self.session = Session()


    def __del__(self):
        self.session.close()


    def Start(self):
        pass


    def AddItem(self, code, byitemid=False):
        if byitemid:
            item = self.session.query(Item).filter(Item.id == code).first()
            if item == None:
                print "item not  found"
                return
        else:
            try:
                item = self.session.query(Item).filter(Item.bcode == code).one()
            except (MultipleResultsFound, NoResultFound), e:
                print e
                return

        row = self.GetRowWith(self.COL_ID, item.id)

        try:
            enteredQty = float(self.GetEnteredQty())
        except ValueError:
            enteredQty = 1.0

        if enteredQty == 0:
            return

        self.SetEnteredQty("1")

        if row != None:
            qty = self.GetListValue(row, self.COL_QTY)
            qty += enteredQty
            self.SetListValue(row, self.COL_QTY, qty)
            self.SetListValue(row, self.COL_AVAILABLE, item.stockStart + item.stockIn - item.stockOut)
            self.UpdateRow(row)
        else:
            row = self.InsertRow([
                item.id,
                item.bcode,
                item.desc,
                enteredQty,
                item.unit,
                item.stockStart + item.stockIn - item.stockOut,
                item.selling,
                item.taxCategory.rate,
                0.0,
                0.0,
                0.0])
            self.UpdateRow(row)
Beispiel #14
0
 def __init__(self):
     self.dbsession = Session()
Beispiel #15
0
class SessionManager(object):
    user = None

    def __init__(self):
        self.dbsession = Session()

    def __del__(self):
        self.dbsession.close()

    def IsLoggedIn(self):
        if self.user == None:
            return False

        return True

    def Login(self, userid, password):
        user = self.dbsession.query(User).filter(User.id == userid).first()

        print userid
        print user

        if user != None:
            if user.password == password:
                if 'LOGIN' in user.privilages:
                    self.user = user
                    self.loginSession()
                    return True
        return False

    def Logout(self):
        self.logoutSession()
        self.user = None

    def loginSession(self):
        now = datetime.now()

        self.userSession = UserSession(user_id=self.user.id,
                                       time=now,
                                       host='127.0.0.1',
                                       port=0)

        self.dbsession.add(self.userSession)
        self.dbsession.commit()

        sessionlog = UserSessionLog(user_id=self.user.id,
                                    time=now,
                                    host=self.userSession.host,
                                    port=self.userSession.port,
                                    action='LOGIN')

        self.dbsession.add(sessionlog)
        self.dbsession.commit()

    def logoutSession(self):
        if self.userSession != None:
            now = datetime.now()

            sessionlog = UserSessionLog(user_id=self.user.id,
                                        time=now,
                                        host=self.userSession.host,
                                        port=self.userSession.port,
                                        action='LOGOUT')

            self.dbsession.add(sessionlog)

            self.dbsession.delete(self.userSession)

            self.dbsession.commit()

            self.userSession = None