def addEquivalence(self, inputs): equivalence = 1 if "equivalence" in inputs: equivalence = float(inputs["equivalence"]) self.code = CodeGen().GenCode({"table": "Equivalence", "column": "code"}) Equivalence(code=self.code, eq_name=inputs["eq_name"], from_eq=int(inputs["from_eq"]), to_eq=int(inputs["to_eq"]), equivalence=equivalence, optype="*", created_by=login().decLoginKey(inputs["key"]), created_date=general().date2julian()).save() self.reversecode = CodeGen().GenCode({"table": "Equivalence", "column": "code"}) Equivalence(code=self.reversecode, eq_name=inputs["eq_name"]+"(Reverso)", to_eq=int(inputs["from_eq"]), from_eq=int(inputs["to_eq"]), equivalence=equivalence, optype="/", created_by=login().decLoginKey(inputs["key"]), created_date=general().date2julian()).save() self.session.close() self.connORM.dispose() return {"status": 200, "value": {"code": self.code, "reversecode":self.reversecode}, 'type': 'application/json'}
def manCompany(self, inputs): if "company_code" not in inputs: self.code = CodeGen().GenCode({"table": company.__tablename__}) self.session.add( company(name=inputs["name"], code=self.code, address=inputs["address"], status=int(inputs["status"]), telephone=inputs["telephone"], owner=inputs["owner"], image=inputs["logopath"])) elif "company_code" in inputs: if inputs["company_code"] != '': self.code = int(inputs["company_code"]) self.session.query(company).\ filter_by(code=self.code).\ update({company.name:inputs["name"],company.image:inputs["logopath"], company.address:inputs["address"], company.telephone:inputs["telephone"], company.owner:inputs["owner"],company.status:int(inputs["status"])}) else: #Se que es un force, pero estaba rapido. self.code = CodeGen().GenCode({"table": company.__tablename__}) self.session.add( company(name=inputs["name"], code=self.code, address=inputs["address"], status=int(inputs["status"]), telephone=inputs["telephone"], owner=inputs["owner"], image=inputs["logopath"])) self.session.commit() self.session.close() if "__documentroot__" in inputs: dirlst = [] dirlst.append(inputs["__documentroot__"] + "/resources/plates/" + str(self.code)) dirlst.append(inputs["__documentroot__"] + "/resources/plates/categories/" + str(self.code)) dirlst.append(inputs["__documentroot__"] + "/resources/ads/" + str(self.code)) dirlst.append(inputs["__documentroot__"] + "/resources/company/" + str(self.code)) for directory in dirlst: if not os.path.exists(directory): os.makedirs(directory) return { "status": 200, "value": { "code": self.code }, "type": "application/json" }
def create(self, inputs): # This method will create an expense. self.code = CodeGen().GenCode({ "table": AccountsTbl.__tablename__, "column": AccountsTbl.code.name }) # Generating the code. start_amount = 0.00 if AccountsTbl.current_amount.name in inputs: start_amount = float(inputs[AccountsTbl.current_amount.name]) acc_type = 1481 if AccountsTbl.acc_type.name in inputs: acc_type = int(inputs[AccountsTbl.acc_type.name]) self.session.add( AccountsTbl(code=self.code, status=11, account_name=inputs[AccountsTbl.account_name.name], current_amount=start_amount, acc_type=acc_type)) # Saving self.session.commit() self.session.close() self.connORM.dispose() return { "status": 200, "value": { AccountsTbl.code.name: self.code }, 'type': 'application/json' }
def HandlegroupMenu(self, inputs): #Create a new menu item code = 0 userkey = self.decLoginKey(inputs["key"]) meta = {"db_alias": "default"} if "code" in inputs: code = int(inputs["code"]) gr_info = Group_module.objects(code=code).first() if gr_info != None: gr_name = gr_info.name if "name" in inputs: gr_name = inputs["name"] Group_module.objects(code=code).update( set__name=gr_name, set__created_by=userkey, set__created_date=general().date2julian()) else: code = CodeGen().GenCode({"table": "module", "column": "code"}) groupInfo = Group_module( code=code, name=inputs["name"], created_by=userkey, created_date=general().date2julian()).save() self.session.close() self.connORM.dispose() return { "status": 200, "value": { "code": code }, 'type': 'application/json' }
def addWaiter(self, inputs): usercode = None #The user that will have the key. if "user_code" in inputs: usercode = int(inputs["user_code"]) passwd = None # The user that will have the key. if "passwd" in inputs: passwd = inputs["passwd"] created_by = self.decLoginKey(inputs["key"]) code = CodeGen().GenCode({"table": "waiterKey", "column": "code"}) waiterKey(code=code, user_code=usercode, key=passwd, created_by=created_by, created_date=general().date2julian()).save() self.session.close() self.connORM.dispose() disconnect() return { "status": 200, "value": { "code": code }, 'type': 'application/json' }
def _type(self, inputs): code = 0 if Type.code.name not in inputs: code = CodeGen().GenCode({ "table": Type.__tablename__, "column": Type.code.name }) self.session.add( Type(level=int(inputs["level"]), code=code, name=inputs[Type.name.name])) else: code = int(inputs[Type.code.name]) self.session.query(Type).filter_by(code=code).update({ Type.name: inputs[Type.name.name], Type.level: int(inputs[Type.code.name]) }) self.session.commit() self.session.close() self.connORM.dispose() return { "status": 200, "value": { Type.code.name: code }, "type": "application/json" }
def addNCF(self, inputs): # Connecting terms with products. ncf_initial = int(inputs["ncf_initial"]) ncf_last = int(inputs["ncf_last"]) exp = str(inputs["exp"]) ncfLst = [] ncfRet = [] for ncf in range(ncf_initial, ncf_last): code = CodeGen().GenCode({"table": "ncf_codes", "column": "code"}) header = ncfType.objects( code=int(inputs["ncf_type"])).first().header ncfRet.append(header + str(ncf).zfill(8)) ncfLst.append( ncf_codes(code=code, secuence=str(ncf).zfill(8), exp=exp, ncf_type=int(inputs["ncf_type"]), status=11)) if len(ncfLst) > 0: ncf_codes.objects.insert(ncfLst) self.session.close() self.connORM.dispose() return {"status": 200, "value": ncfRet, 'type': 'application/json'}
def addTax(self, inputs): if tax.objects( name__icontains=str(inputs["name"]).upper()).first() != None: self.session.close() self.connORM.dispose() return { "status": 200, "value": { "error": "No puede crear un impuesto con el mismo nombre" }, 'type': 'application/json' } else: code = CodeGen().GenCode({"table": "tax", "column": "code"}) tax(name=str(inputs["name"]).upper(), percent=float(inputs["percent"]), code=code).save() self.session.close() self.connORM.dispose() return { "status": 200, "value": { "code": code }, 'type': 'application/json' }
def create(self, inputs): # This method will create an expense. self.code = CodeGen().GenCode({ "table": Type.__tablename__, "column": Type.code.name }) # Generating the code. level = None if Type.level.name in inputs: level = int(inputs[Type.level.name]) raw_code = str(level) + str(self.code) self.code = int(raw_code) tpname = "" if Type.tpname.name in inputs: tpname = inputs[Type.tpname.name] self.session.add(Type(code=self.code, tpname=tpname, level=level)) # Saving self.session.commit() self.session.close() self.connORM.dispose() return { "status": 200, "value": { Type.code.name: self.code }, 'type': 'application/json' }
def create(self, inputs): # This method will create an expense. if Status.code.name not in inputs: self.code = CodeGen().GenCode({ "table": Status.__tablename__, "column": Status.code.name }) else: self.code = int(inputs[Status.code.name]) name = "" if Status.description.name in inputs: name = inputs[Status.description.name] tpstatus = None if Status.tp_status.name in inputs: tpstatus = int(inputs[Status.tp_status.name]) # Generating the code. self.session.add(Status(code=self.code, name=name, tp_status=tpstatus)) # Saving self.session.commit() self.session.close() self.connORM.dispose() return { "status": 200, "value": { Status.code.name: self.code }, 'type': 'application/json' }
def transfer(self, inputs): account_from = None if "account_from" in inputs: account_from = int(inputs["account_from"]) account_to = int(inputs["account_to"]) notes = "" if "notes" in inputs: notes = str(inputs["notes"]) amount = float(inputs["amount"]) code = CodeGen().GenCode({ "table": "account_movement", "column": "code" }) acc_from_info = self.session.query(getaccounts). \ filter(getaccounts.code == account_from) acc_to_info = self.session.query(getaccounts). \ filter(getaccounts.code == account_to) account_movement(credit=account_from, debit=account_to, credit_name=acc_from_info.account_name, credit_code=int(acc_from_info.position_account), debit_name=acc_to_info.account_name, debit_code=int(acc_to_info.position_account), amount=amount, register_date=general().date2julian(), code=code, notes=notes).save() cur_amount = self.session.query(AccountsTbl.current_amount).\ filter(AccountsTbl.code == account_to) if (cur_amount != None): new_amount = amount + float(cur_amount.first()[0]) self.session.query(AccountsTbl).filter(AccountsTbl.code==account_to)\ .update({AccountsTbl.current_amount.name:new_amount}) self.session.commit() if account_from != None: cur_amount = float(self.session.query(AccountsTbl.current_amount). \ filter(AccountsTbl.code == account_from).first()[0]) cur_amount -= amount self.session.query(AccountsTbl).filter(AccountsTbl.code == account_from) \ .update({AccountsTbl.current_amount.name: cur_amount}) self.session.commit() self.session.close() self.connORM.dispose() return { "status": 200, "value": { "code": code }, 'type': 'application/json' }
def LoginRoot(self, inputs): #The login to verify if the owner of the account is this person. sessionID = 0 validation = {"status": 0} #When all the validations, are passed now the work. ###Close the session. if validation["status"] > 0: return { "status": 500, "value": validation['msg'], 'type': 'application/json' } userData = {} #This means that login with the system. getUserID = self.session.query(User.code, User.avatar, User.usrtype, Contact.email, Contact.contact_name, User.owner).\ filter(User.username == inputs["username"]).filter( User.passwd == hashlib. md5(inputs["passwd"].encode()).hexdigest()).\ filter(Contact.code == User.contact).\ filter(User.owner == True).\ first() if getUserID == None: return { "status": 200, "value": { "error": 0 }, 'type': 'application/json' } ###First Close the session self.closeAllSession(getUserID.code) meta = {"db_alias": "default"} sessionUserID = CodeGen().GenCode({"table": "SessionUser"}) UserSess = SessionUser(userCode=getUserID.code, code=sessionUserID, login=general().getJulian(), created_by=getUserID.code, created_date=general().getJulian()) UserSess.save() sessionID = str(UserSess.id) profile = self.getProfile({"key": sessionID}) profile["key"] = sessionID self.session.close() self.connORM.dispose() return {"status": 200, "value": profile, 'type': 'application/json'}
def RegisterMove(self, inputs): # This method register a move of product created = general().date2julian() inputs["created"] = created if ProductsMove.send_date.name in inputs: inputs[ProductsMove.send_date.name] = general().date2julian( inputs[ProductsMove.send_date.name]) item = int(inputs[ProductsMove.code.name]) storeDict = {} for column in DBProcess( ProductsMove.ProductsMove_tbl).getColumnDefinition: if column["name"] in inputs: storeDict[column["expr"]] = DBProcess(ProductsMove.ProductsMove_tbl).\ parse(column,inputs[column["name"]]) # Adding the product to the warehouse. for product in json.loads(inputs["products"]): connection = self.connORM.raw_connection() cursor = connection.cursor() code = CodeGen().GenCode({ "table": "Moveproducts", "column": "code" }) Moveproducts(code=code, give_by=int(inputs["from_warehouse"]), receive_by=int(inputs["to_warehouse"]), product=int(product["product"]), created_date=general().date2julian(), description=product["item_name"]).save() cursor.callproc('products_movement', [ int(product["product"]), Decimal(product["amount"]), int(inputs["from_warehouse"]), int(inputs["to_warehouse"]) ]) cursor.close() self.session.commit() self.session.close() self.connORM.dispose() return { "status": 200, "value": { ProductsMove.code.name: item }, 'type': 'application/json' }
def create_merma(self, inputs): self.code = CodeGen().GenCode({"table": Merma.__tablename__, "column": Merma.code.name}) # Generating the code. self.session.add(Merma(code=self.code, status=12, created_by=login().decLoginKey(inputs["key"]))) # Saving self.session.commit() self.session.close() self.connORM.dispose() return {"status": 200, "value": {"code": self.code}, 'type': 'application/json'}
def create(self, inputs): # This method will create an expense. self.code = CodeGen().GenCode({"table": buybills.__tablename__, "column": buybills.code.name}) # Generating the code. self.session.add(buybills(code=self.code, status=11)) # Saving self.session.commit() self.session.close() self.connORM.dispose() return {"status": 200, "value": {buybills.code.name: self.code}, 'type': 'application/json'}
class SessionUserSys(Document): # The sessions of the user that work with the system. id = ObjectIdField() login = DateTimeField(required=True) logout = DateTimeField(required=True) status = LongField(required=True) created_by = LongField(required=True) created_date = LongField(required=True) code = StringField(required=True, default=CodeGen().GenCode({"table": "SessionUserSys"})) meta = {"db_alias": "default"}
def modItem2Bill(self, inputs): self.code = CodeGen().GenCode({"table": "Buyitems", "column": "code"}) Buyitems.objects(code=self.code).update(set__item=int(inputs["product"]), set__total_item=float(inputs["total"]), set__total_tax=float(inputs["tax"]), set__other_costs=float(inputs["other_costs"]),set__discount=float(inputs["discount"]), set__unit=int(inputs["unit"]), set__equivalence=float(inputs["equivalence"]), set__created_by=login().decLoginKey(inputs["key"]), set__created_date=general().date2julian()) cur_amount = Items().Get({Item.code.name: inputs["product"]})["value"][0][Item.amount.name] self.session.close() self.connORM.dispose() return {"status": 200, "value": {"code": self.code}, 'type': 'application/json'}
def create(self, inputs): # This method will create an expense. if HappyHour.code.name not in inputs: self.code = CodeGen().GenCode({"table": HappyHour.__tablename__, "column": HappyHour.code.name}) else: self.code = int(inputs[HappyHour.code.name]) # Generating the code. self.session.add(HappyHour(code=self.code)) # Saving self.session.commit() self.session.close() self.connORM.dispose() return {"status": 200, "value": {HappyHour.code.name: self.code}, 'type': 'application/json'}
def addItem2Bill(self, inputs): self.code = CodeGen().GenCode({"table": "Buyitems", "column": "code"}) equivalence = 1 if "from_eq" in inputs: equivalence = int(str(inputs["from_eq"]).split(":")[0]) unit = 517 if "to_eq" in inputs: unit = int(inputs["to_eq"]) amount = float(inputs["amount"]) equivalence_data = Equivalence.objects(from_eq=unit, to_eq=equivalence) equivalence_info = equivalence_data.first() if equivalence_info!= None: if equivalence_info.optype == "*": amount = float(equivalence_info.equivalence) * float(inputs["amount"]) if equivalence_info.optype == "/": amount = float(equivalence_info.equivalence) / float(inputs["amount"]) Buyitems(code=self.code, product=int(inputs["product"]), amount=amount, total=float(inputs["total"]), tax=float(inputs["total_tax"]), bill=int(inputs["bill"]),unit=unit,term="",portion="",notes="", created_by=login().decLoginKey(inputs["key"]),created_date=general().date2julian()).save() cur_amount = self.session.query(Item.amount).filter_by(code=int(inputs["product"])).first()[0] if cur_amount == None or cur_amount=='None': cur_amount = 0.00 Items().Handle({Item.code.name: inputs["product"], Item.amount.name: float(cur_amount) + amount}) warehouse_info = self.session.query(WareHouse).filter_by(mainwarehouse=True) warehouse_info = self.session.query(WareHouse).filter_by(mainwarehouse=True) if warehouse_info != None and "amount" in inputs: warehose = warehouse_info[0] connection = self.connORM.raw_connection() cursor = connection.cursor() cursor.callproc('products_movement', [self.code, amount, warehose.code, 0]) cursor.close() self.session.close() self.connORM.dispose() return {"status": 200, "value": {"code":self.code}, 'type': 'application/json'}
def loadFromDGII(self, inputs): with open(inputs["path"], "r", encoding="ISO-8859-1") as file: rnclst = str(file.read()).split("\n")[2043122:] insertsLst=[] cont=0 for piece in rnclst: rnc_info = piece.split("|") insertsLst.append({Client.cl_name.name:rnc_info[1], Client.rnc.name:rnc_info[0], Client.status.name:11, Client.code.name:CodeGen().GenCode({"table": Client.__tablename__, "column": Client.code.name})}) print(rnc_info) print(insertsLst) self.session.bulk_insert_mappings(Client, insertsLst) self.session.commit() self.session.close() self.connORM.dispose()
def create(self, inputs): supplier_name = None if Supplier.sup_name.name in inputs: supplier_name = inputs[Supplier.sup_name.name] supplier = CodeGen().GenCode({ "table": Supplier.__tablename__, "column": Supplier.code.name }) self.session.add(Supplier(sup_name=supplier_name, code=supplier)) self.session.commit() self.session.close() self.connORM.dispose() self.type = "application/json" self.msg = {"code": supplier} self.status = 200 return {"status": self.status, "value": self.msg, "type": self.type}
def addGroupMenu(self, inputs): code = CodeGen().GenCode({"table": "Group_module", "column": "code"}) Group_module(code=code, name=inputs["group_name"], created_by=login().decLoginKey(inputs["key"]), created_date=general().date2julian()).save() self.session.close() self.connORM.dispose() return { "status": 200, "value": { "code": code }, 'type': 'application/json' }
def LoginWaiter(self, inputs): waiterinfo = waiterKey.objects(key=inputs["waiter_code"], status=11).first() if waiterinfo != None: ###First Close the session self.closeAllSession(waiterinfo.user_code) sessionUserID = CodeGen().GenCode({"table": "SessionUser"}) UserSess = SessionUser(userCode=waiterinfo.user_code, code=sessionUserID, login=general().getJulian(), created_by=waiterinfo.user_code, created_date=general().getJulian()) UserSess.save() sessionID = str(UserSess.id) profile = self.getProfile({"key": sessionID})["value"] profile["key"] = sessionID profile["orders"] = self.getOrdersByUser( {"usercode": waiterinfo.user_code})["value"] profile["modules"] = [] self.session.close() self.connORM.dispose() return { "status": 200, "value": profile, 'type': 'application/json' } else: self.session.close() self.connORM.dispose() return { "status": 200, "value": { "error": 0 }, 'type': 'application/json' }
def merma_addProd(self, inputs): self.code = inputs[Merma.code.name] # Generating the code. mermaprod_code= CodeGen().GenCode({"table": "MermaProd", "column": "code"}) product =int(inputs["product"]) MermaProd(code=mermaprod_code, product=product, amount=float(inputs["amount"]), merma=self.code).save() equivalence = 1 if "from_eq" in inputs: equivalence = int(str(inputs["from_eq"]).split(":")[0]) unit = 517 if "to_eq" in inputs: unit = int(inputs["to_eq"]) amount = float(inputs["amount"]) equivalence_data = Equivalence.objects(from_eq=equivalence, to_eq=unit) if equivalence_data != None: equivalence_info = equivalence_data.first() if equivalence_info.optype == "*": amount = float(equivalence_info.equivalence) * float(inputs["amount"]) if equivalence_info.optype == "/": amount = float(equivalence_info.equivalence) / float(inputs["amount"]) cur_amount = Items().Get({Item.code.name: inputs["product"]})["value"][0][Item.amount.name] if cur_amount == None or cur_amount == 'None': cur_amount = 0.00 self.session.close() self.connORM.dispose() if (float(cur_amount)-amount)>=0: Items().Handle( {Item.code.name: inputs["product"], Item.amount.name: float(cur_amount)-amount}) return {"status": 200, "value": {"code": mermaprod_code}, 'type': 'application/json'} else: return {"status": 200, "value": {"error": "Cantidad a mermar, " "no puede ser mayor a cantidad actual"}, 'type': 'application/json'}
def create(self, inputs): # This method will create an expense. self.code = CodeGen().GenCode({ "table": Tables.__tablename__, "column": Tables.code.name }) tblname = "" if Tables.tblname.name in inputs: tblname = inputs[Tables.tblname.name] table_area = None if Tables.area.name in inputs: table_area = int(inputs[Tables.area.name]) table_type = None if Tables.table_type.name in inputs: table_type = int(inputs[Tables.table_type.name]) status = None if Tables.status.name in inputs: if str(inputs[Tables.status.name]).lower() == "on": status = 11 # Generating the code. self.session.add( Tables(code=self.code, tblname=tblname, table_type=table_type, area=table_area, status=status)) # Saving with the name, at least. self.session.commit() self.session.close() self.connORM.dispose() return { "status": 200, "value": { Tables.code.name: self.code }, 'type': 'application/json' }
def create(self, inputs): # This method will create an expense. self.code = CodeGen().GenCode({ "table": WareHouse.__tablename__, "column": WareHouse.code.name }) # Generating the code. self.session.add(WareHouse(code=self.code, status=12, billDisc=False)) # Saving with the name, at least. self.session.commit() self.session.close() self.connORM.dispose() return { "status": 200, "value": { WareHouse.code.name: self.code }, 'type': 'application/json' }
def create(self, inputs): # Create a new ID for the contact contact_id = CodeGen().GenCode({ "table": Contact.__tablename__, "column": Contact.code.name }) # Generating the ID self.session.add(Contact(code=contact_id)) # Saving self.session.commit() self.session.close() self.connORM.dispose() return { "status": 200, "value": { Contact.code.name: contact_id }, 'type': 'application/json' }
def Handle(self, inputs): # This method will modify an expanse. item = int(inputs[User.code.name]) if User.passwd.name in inputs: #Just if the passwd inputs[User.passwd.name] = hashlib.md5( inputs[User.passwd.name].encode()).hexdigest() storeDict = {} for column in DBProcess(User.user_tbl).getColumnDefinition: if column["name"] in inputs: storeDict[column["expr"]] = DBProcess(User.user_tbl).parse( column, inputs[column["name"]]) self.session.query(User).filter_by(code=item).update(storeDict) self.session.commit() self.session.close() if "waiter_code" in inputs: if len(inputs["waiter_code"]) >= 4: # Means that the user will be created a key for the waiter. waiterKey.objects(user_code=item).update(set__status=12) waiterCode = CodeGen().GenCode({ "table": "waiterKey", "column": "code" }) waiterKey(code=waiterCode, user_code=item, status=11, key=inputs["waiter_code"], created_by=self.decLoginKey(inputs["key"]), created_date=general().date2julian()).save() return { "status": 200, "value": { User.code.name: item }, 'type': 'application/json' }
def addMovement(self, inputs): self.code = CodeGen().GenCode({ "table": ProductsMove.__tablename__, "column": ProductsMove.code.name }) # Generating the code. self.session.add(ProductsMove(code=self.code)) # Saving self.session.commit() self.session.close() self.connORM.dispose() return { "status": 200, "value": { ProductsMove.code.name: self.code }, 'type': 'application/json' }
def create(self, inputs): client_name="" if Client.cl_name.name in inputs: client_name = inputs[Client.cl_name.name] rnc = "" if Client.rnc.name in inputs: rnc= inputs[Client.rnc.name] _address = "" if Client._address.name in inputs: _address = inputs[Client._address.name] telephone = "" if Client.telephone.name in inputs: telephone = inputs[Client.telephone.name] # price = 0 # if Client.price.name in inputs: # price = int(inputs[Client.price.name]) ncf_type = 2 if Client.ncf_type.name in inputs: ncf_type = int(inputs[Client.ncf_type.name]) status=11 if Client.status.name in inputs: status=int(inputs[Client.status.name]) client = CodeGen().GenCode({"table": Client.__tablename__, "column": Client.code.name}) self.session.add(Client(cl_name=client_name, code=client,ncf_type=ncf_type, rnc=rnc, status=status, telephone=telephone,_address=_address, #price=price )) self.session.commit() self.session.close() self.connORM.dispose() self.type = "application/json" self.msg = {Client.code.name: client} self.status = 200 return {"status": self.status, "value": self.msg, "type": self.type}