def set_data_for(self, main_date): try: on, end = main_date.current.current except: on, end = main_date.current on = datetime(on.year, on.month, on.day, 0, 0, 0) end = datetime(end.year, end.month, end.day, 23, 59, 59) reports = [] this_periode_rpt = Reports.select().where(Reports.date >= on, Reports.date <= end) for store in Store.select().order_by(Store.name): if ([(i) for i in this_periode_rpt.where(Reports.store << [store, ])] == []): continue cpt = 0 for prod in Product.select().order_by(Product.name): if ([(i) for i in this_periode_rpt.where(Reports.store == store, Reports.product << [prod, ])] == []): continue dict_store = {} repts = this_periode_rpt.where( Reports.store == store, Reports.product == prod) dict_store["store"] = store.name if cpt < 1 else "" dict_store["product"] = prod.name dict_store["sum_qty_in"] = repts.select( peewee.fn.SUM(Reports.qty_use)).where(Reports.type_ == Reports.E).scalar() dict_store["sum_qty_out"] = repts.select( peewee.fn.SUM(Reports.qty_use)).where(Reports.type_ == Reports.S).scalar() cpt += 1 reports.append(dict_store) self.data = [(rep.get('store'), rep.get('product'), rep.get('sum_qty_in'), rep.get('sum_qty_out')) for rep in reports]
def stores_list(): # create column called 'num' to count how many warehouse is under the given store stores = Store.select(Store.name, Store.store_id, fn.COUNT(Warehouse.store_id).alias('count')).join( Warehouse, JOIN.LEFT_OUTER).group_by( Store.store_id).order_by(Store.name) return render_template('stores.html', stores=stores)
def destroy_store(store_id): store_list = Store.select() if request.method == "POST": store = Store.get_by_id(store_id) flash(f"Closed {store.name}.") store.delete_instance() return redirect(url_for('index_stores')) else: return render_template('stores.html', store_list=store_list)
def store_info(store_number): if request.method == 'POST': new_store_name = request.form['new_store_name'] Store.update({Store.name: new_store_name}).where(Store.id == store_number) return redirect(url_for('store/index')) else: store_id = Store.select().where(Store.id == store_number) num_of_wh = True for store in store_id: num_of_wh = len(list(store.warehouses)) return render_template('store_page.html', store_id=store_id, num_of_wh=num_of_wh)
def warehouse_create(): warehouse_location = request.form.get('warehouse_location') store_id = request.form.get('store_id') warehouse = Warehouse(location=warehouse_location, store=store_id) if warehouse.save(): flash(f"Added Warehouse: {warehouse_location}") return redirect(url_for('warehouse_new')) #redirect back to the GET app.route('warehouse/new/) to re-render the whole form again# else: flash('Store already has a warehouse') return render_template('warehouse.html', stores=Store.select())
def lastes_reports(): list_rep = [] for store in Store.select(): for prod in Product.select(): try: list_rep.append(Reports.filter(deleted=False, store=store, product=prod) .order_by(Reports.date.desc()).get()) except Exception as e: # print(e) pass return list_rep
def refresh_(self, idd): self.prod = Product.get(id=idd) rest_by_store = "" for store in Store.select(): remaining, nbr_parts = store.get_remaining_and_nb_parts(self.prod) if remaining < 10: color_style = 'color: DarkGreen' if remaining <= 5: color_style = 'color: LightCoral' if remaining <= 2: color_style = 'color: red; text-decoration: blink' if remaining >= 10: color_style = 'color: LimeGreen;' color_style = color_style + \ "; border:3px solid green; font-size: 15px" if Store.select().count() == 1: rest_by_store += """ <p><strong style='{color_style}'> {remaining} </strong><i>pièces</i></p> """.format(color_style=color_style, remaining=remaining) else: rest_by_store += """<li> {store}: <strong style='{color_style}'> {nbr_parts} </strong><i>pièces</i> <b>{remaining} </b><i>carton</i> </li>""".format(store=store.name, color_style=color_style, remaining=remaining, nbr_parts=nbr_parts * remaining) width = height = 50 if self.prod.image_link: self.image_btt.setText("Zoom") width = 200 height = 100 self.info_box.setText(u"""<h2>{name}</h2> <h4>Quantité restante:</h4> <ul>{remaining}</ul> """.format(name=self.prod.name, remaining=rest_by_store)) self.image.setText("""<img src="{image}" width='{width}' height='{height}'>""".format(image=self.prod.image_link, width=width, height=height))
def warehouse(): if request.method == 'POST': store = request.form['store_list'] location = request.form['warehouse_location'] new_warehouse = Warehouse.create(location=location, store=store) new_warehouse.save() flash("Warehouse created", "success") return redirect(url_for('warehouse')) else: # result = Store.select(Store.name, fn.COUNT(Warehouse.store.id == Store.id)).join(Warehouse).group_by(Store.name).where(Store.id == Warehouse.store.id) warehouse_list = Warehouse.select() store_list = Store.select() return render_template('warehouse.html', warehouse_list=warehouse_list, store_list=store_list)
def popup(self, pos): row = self.selectionModel().selection().indexes()[0].row() if (len(self.data) - 1) < row: return False self.store = Store.select().where( Store.name == self.data[row][0]).get() menu = QMenu() menu.addAction(QIcon(u"{}edit.png".format(Config.img_cmedia)), u"modifier", lambda: self.prod_edit(self.store)) menu.addAction(QIcon("{}del.png".format(Config.img_cmedia)), u"supprimer", lambda: self.prod_del(self.store)) self.action = menu.exec_(self.mapToGlobal(pos))
def store(): # form = forms.Store() # store_list = Store.select() store_list = Store.select() payload = [] for store in store_list: new_object = { "store_name": store.name, "num": len(list(store.warehouses)) } payload.append(new_object) if request.method == 'POST': # How to post a success message from form submission if not using flash but using bootstrap under 'store.html' line 5 # breakpoint() new_store = Store(name=request.form['store_name']) new_store.save() flash("Store created", "success") return redirect(url_for('store'), store_list) else: return render_template('store.html', payload=payload)
def shop_index(): all_stores = Store.select() # store_names = [] # store_warehouse = [] # store_details = [] # store_id = [] # for i in all_stores: # arr = [0] # # store_names.append(i.name) # stores_instance = Store.get_by_id(i.id) # for j in stores_instance.warehouses: # arr.append(j) # store_warehouse.append(len(arr)-1) # for j in range(len(store_names)): # store_details.append({store_names[j]: store_warehouse[j]}) # for k in all_stores: # store_id.append(k.id) return render_template('view_all.html', all_stores = all_stores)
def refresh_(self, idd): self.prod = Product.get(id=idd) self.nameLabel.setText((u"<h4>Article:</h4>")) self.name.setText(u"<h6>{name}</h6>".format(name=self.prod.name.title())) rest_by_store = "" for store in Store.select(): remaining, nbr_parts = store.get_remaining_and_nb_parts(self.prod) if remaining < 10: color_style = 'color: DarkGreen' if remaining <= 5: color_style = 'color: LightCoral' if remaining <= 2: color_style = 'color: red; text-decoration: blink' if remaining >= 10: color_style = 'color: LimeGreen;' color_style = color_style + "; border:3px solid green; font-size: 15px" rest_by_store += u"<div> {store}: <strong style='{color_style}'>" \ u" {remaining} </strong> ({nbr_parts} pièces)"\ u"</div>".format(store=store.name, color_style=color_style, remaining=remaining, nbr_parts=nbr_parts) self.store.setText(u"<h4><u>Quantité restante</u>:</h4> \ {remaining}</ul>".format(remaining=rest_by_store)) self.imagelabel.setText(u"<b>Pas d'image<b>") self.image.setStyleSheet("") if self.prod.image_link: self.imagelabel.setText(u"<b><u>Image</u></b>") self.image.setStyleSheet("background: url({image})" " no-repeat scroll 20px 110px #CCCCCC;" "width: 55px".format(image=self.prod.image_link))
def warehouse_new(): stores = Store.select() # to render all store in select options return render_template("warehouse_new.html", stores=stores)
def multi_store(self): return Store.select().count() > 1
def index_stores(): sname = Store.select() return render_template('index_stores.html', sname=sname)
def warehouse(): store = Store.select() return render_template('warehouse.html',store=store)
def store_show(): stores = Store.select() warehouses = Warehouse.select() return render_template('stores.html', stores=stores, warehouses = warehouses)
def warehouse_new(): stores = Store.select( ) # PUT IN HERE AS NEED TO RENDER TEMPLATE, NOT IN WAREHOUSE HTML return render_template('warehouse.html', stores=stores)
def store_select(): stores = Store.select() warehouse = Warehouse.select() return render_template('list_stores.html', stores=stores, warehouse=warehouse)
def stores(): return render_template('liststores.html', stores=Store.select(), warehouse=Warehouse.select())
def set_data_for(self): self.data = [(mag.name, mag.stock_maxi) for mag in Store.select().order_by(Store.id.desc())]
def warehouse_new(): stores = Store.select() return render_template('warehouse.html', stores=stores)
def show(): stores = Store.select() # stores= Store.select(Store, Warehouse, pw.fn.COUNT(Warehouse.id).filter(Warehouse.store_id == Store.id).alias("w_count")).join(Warehouse, join_type="left outer").group_by(Warehouse.id, Store.id).order_by(Store.id) return render_template('store.html', stores=stores)
def index(): all_stores = Store.select() return render_template('home.html', stores=all_stores)
def show_warehouse(): stores = Store.select() return render_template('warehouse.html', stores=stores)
def store_display(): stores = Store.select() return render_template('stores.html', stores=stores)
def new_warehouse(): sname = Store.select() # JUST RENDERS WAREHOUSE>HTML # pass down sname variable that contains all store names to warehouse.html return render_template('warehouse.html', sname=sname)
def store(): store_list = Store.select() return render_template('store.html', store_list=store_list)
def stores(): stores = Store.select().order_by(Store.id) return render_template('stores.html', stores=stores)
def warehouse(): query = Store.select() return render_template('warehouse.html', stores = query )
def warehouse(): stores = Store.select() #passing stores from the database into the site return render_template('warehouse.html', stores=stores)
def index_stores(): store_list = Store.select().order_by(Store.id.asc()) return render_template('stores.html', store_list=store_list)
def show_stores(): stores = Store.select() #passing stores from the database into warehouses = Warehouse.select() return render_template('stores.html', stores=stores, warehouses=warehouses)
def new_warehouse(): store_list = Store.select() return render_template('warehouse.html', store_list=store_list)
def show_store_list(): all_store = Store.select() return render_template('all-store.html', all_store=all_store)
def stores(): stores = Store.select().order_by(Store.id) warehouses = Warehouse.get() return render_template('stores.html', stores=stores, warehouses=warehouses)
def store_index(): stores = Store.select() return render_template('store_index.html', stores=stores)