def makerStock(): products = None if g.user.maker: products = Product.query.filter_by(active_flg=True)\ .filter_by(maker_id=g.user.maker_id)\ .all() if products: for p in products: if not p.price_unit: p.price_unit = 0 urls = getImgUrls(p.id) p.img_urls = [] p.img_thumb_urls = [] if urls: for u in urls: u = u.split('app')[1] p.img_urls.append(u) p.img_thumb_urls.append(getThumbUrls(u, height=80, width=80).split('app')[1]) else: p.img_urls.append(NO_PHOTO_URL.split('app')[1]) p.img_thumb_urls.append(NO_PHOTO_THUMB_URL.split('app')[1]) form = SimpleSubmitForm() if form.is_submitted(): string = request.form.getlist('product_data') if string: data_to_update = [] for s in string: raw = s.split(',') id = int(raw[0].split(':')[1]) code = raw[1].split(':')[1] str_qty = raw[2].split(':')[1] qty = 0 if str_qty: try: qty = int(str_qty) except ValueError: qty = 0; data_to_update.append({'id': id, 'code': code, 'qty': qty}) if data_to_update: for d in data_to_update: p = Product.query.get(d['id']) p.maker_code = d['code'] p.maker_qty_stock = d['qty'] db.session.add(p) db.session.commit() return render_template('maker/makerStock.html', title=gettext("My Stock"), products=products, form=form)
def shop(page=1): products = Product.query.filter_by(active_flg=True) curr_search = None if session['search_string']: curr_search = session['search_string'] products = products.filter(or_(Product.code.ilike('%' + session['search_string'] + '%'), (Product.desc_CS.ilike('%' + session['search_string'] + '%')), (Product.desc_JP.ilike('%' + session['search_string'] + '%')))) curr_catalog_terms = None if session['catalog_ids']: cps = CatalogedProducts.query.filter(CatalogedProducts.catalog_id.in_(session['catalog_ids'])).all() cataloged_product_ids = [] curr_catalog_terms = [] for cp in cps: cataloged_product_ids.append(cp.product_id) for id in session['catalog_ids']: curr_catalog_terms.append(Catalog.query.get(id).name_JP) products = products.filter(Product.id.in_(cataloged_product_ids)) if g.category_id: products = products.filter_by(category_id=int(g.category_id)) if session['available_only'] is True: products = products.filter(Product.available_qty > 0) products = products.order_by(Product.maker_id, Product.code) products = products.paginate(page, current_user.products_per_page, False) discount = 0 if current_user.role == USER_ROLES['ROLE_CUSTOMER'] and current_user.customer: discount = current_user.customer.base_discount for p in products.items: if not p.price_retail: p.price_retail = 0 unrounded_price = p.price_retail * (1.0 - discount) p.customer_price = int(5 * round(float(unrounded_price)/5)) urls = getImgUrls(p.id) p.img_urls = [] p.img_thumb_urls = [] if urls: for u in urls: u = u.split('app')[1] p.img_urls.append(u) p.img_thumb_urls.append(getThumbUrls(u).split('app')[1]) else: p.img_urls.append(NO_PHOTO_URL.split('app')[1]) p.img_thumb_urls.append(NO_PHOTO_THUMB_URL.split('app')[1]) form = ShopHeaderForm() categories = [(a.id, a.name_JP) for a in Category.query.all()] categories = [(0, gettext('All'))] + categories form.category.choices = categories catalog = prepare_catalog() return render_template('/shop/shop.html', title=gettext('AxiStore shop'), products=products, curr_category=g.category_id, axm_product_url=AXM_PRODUCT_URL_JA, curr_search=curr_search, curr_catalog_terms=curr_catalog_terms, catalog=catalog, form=form)