Пример #1
0
def cancelrequest(id):
    req = Request.query.get(id)
    if not req:
        flash(gettext('Order not found!'))
        return redirect('requests')
    products = req.products
    form = SimpleSubmitForm()

    if form.validate_on_submit():
        req = Request.query.get(int(flask.request.form['request_id']))
        products = req.products
        for rp in products:
            db.session.delete(rp)
            pass
        db.session.delete(req)

        target = 'requests'
        # Axis Mart order: delete the customer too
        if req.customer.customer_type == CUSTOMER_TYPES['TYPE_AXM']:
            cust = Customer.query.get(req.customer.id)
            db.session.delete(cust)
            target = 'axm_' + target    # redirect to AxM orders

        db.session.commit()
        flash('Order was sucessfully cancelled and deleted.')
        return redirect(target)

    return render_template('requests/cancelrequest.html',
                           title=gettext("Cancel order from customer"),
                           request=req,
                           products=products,
                           CUSTOMER_TYPES=CUSTOMER_TYPES,
                           form=form)
Пример #2
0
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)
Пример #3
0
def csvDownloadCustomer():
    categories = Category.query.all()
    form = SimpleSubmitForm()
    if form.validate_on_submit():
        category_ids = request.form.getlist('csv_cat_id')
        data_type = request.form['data-type']
        if data_type == 'availability':
            return redirect(url_for('download_file', filename=generate_available_stock_csv(category_ids)))
        elif data_type == 'details':
            return redirect(url_for('download_file', filename=generate_product_details_csv(category_ids)))

    return render_template('/shop/csvdownloadcustomer.html',
                           title=gettext('Data download'),
                           categories=categories,
                           form=form)
Пример #4
0
def cancelorder(id):
    order = Order.query.get(id)
    if not order:
        flash(gettext('Order not found!'))
        return redirect('requests')
    products = order.products
    form = SimpleSubmitForm()

    if form.validate_on_submit():
        order = Order.query.get(int(flask.request.form['order_id']))
        products = order.products
        for op in products:
            db.session.delete(op)
            pass
        db.session.delete(order)
        db.session.commit()
        flash('Order was sucessfully cancelled and deleted.')
        return redirect('orders')

    return render_template('orders/cancelorder.html',
                           title=gettext("Cancel order to maker"),
                           order=order,
                           products=products,
                           form=form)
Пример #5
0
def unsuppliedProducts(id=None):

    form = SimpleSubmitForm()

    if form.is_submitted():
        if 'checked-items-ids-hid' in request.form:
            cust_id = request.form['curr-customer-id-hid']
            data = request.form['checked-items-ids-hid']
            return redirect(url_for('supplyProducts', cust_id=cust_id, deliver_items_data=data))

    unsupplied_requests = Request.query.filter_by(active_flg=True).all()
    customer_ids = []
    for ur in unsupplied_requests:
        if ur.customer_id not in customer_ids:
            customer_ids.append(ur.customer_id)
    unsupplied_customers = db.session.query(Customer)\
        .filter(Customer.id.in_(customer_ids)).order_by(Customer.id)\
        .all()

    for uc in unsupplied_customers:
        uc.unsupplied_products_count = 0
        for ur in unsupplied_requests:
            if ur.customer_id == uc.id:
                for product in ur.products:
                    if product.quantity > product.qty_supplied:
                        uc.unsupplied_products_count += (product.quantity - product.qty_supplied)

    if not id:
        id = unsupplied_customers[0].id
    cust = Customer.query.filter_by(id=id).first()
    requests = cust.requests.all()
    products = []
    for r in requests:
        for rp in r.products:
            if rp.product not in products:
                rp.product.cust_request_qty = rp.product.customer_request_qty(cust.id)
                if rp.product.cust_request_qty > 0:
                    products.append(rp.product)

    # Load number of products reserved earlier by other customers
    for p in products:
        stock = p.qty_stock
        cust_earliest_request_dt = RequestedProducts.query.filter_by(product_id=p.id)\
            .filter(RequestedProducts.quantity - RequestedProducts.qty_supplied > 0)\
            .join(Request).order_by(Request.created_dt)\
            .join(Customer).filter(Customer.id == cust.id)\
            .first().request.created_dt
        earlier_requests = RequestedProducts.query.filter_by(product_id=p.id)\
            .filter(RequestedProducts.quantity - RequestedProducts.qty_supplied > 0)\
            .join(Request).filter(Request.created_dt < cust_earliest_request_dt)\
            .join(Customer).filter(Customer.id != cust.id)\
            .all()
        p.reserved_earlier_qty = 0
        for er in earlier_requests:
            p.reserved_earlier_qty += er.quantity - er.qty_supplied

        temp = p.qty_stock - p.reserved_earlier_qty
        if temp <= 0:
            p.deliverable_qty = 0
        elif temp > p.cust_request_qty:
            p.deliverable_qty = p.cust_request_qty
        else:
            p.deliverable_qty = temp

    products = sorted(products, key=lambda k: (k.maker_id, k.code))
    for p in products:
        urls = getImgUrls(p.id)
        if urls:
            p.img_url = urls[0]

    # If AxM customer, is the order paid for_
    curr_paid = True
    if cust.customer_type == CUSTOMER_TYPES['TYPE_AXM']:
        curr_req = cust.requests.all()[0]
        if curr_req:
            curr_paid = curr_req.paid_for_flg

    return render_template('supplies/unsuppliedproducts.html',
                           title=gettext("Unsupplied products"),
                           form=form,
                           unsupplied_customers=unsupplied_customers,
                           products=products,
                           CUSTOMER_TYPES=CUSTOMER_TYPES,
                           curr_id=id,
                           curr_paid=curr_paid)