Exemplo n.º 1
0
def stock_transfer():
    """ """

    bag = bag_utils.is_modifiable_bag(session.current_bag)

    # check if all the bag items are consistent
    bag_items = db(db.bag_item.id_bag == bag.id).select()
    # delete the bag if there are no items
    if not bag_items:
        session.flash = T('There are no items in the bag')
        redirection()

    # counts services, since services cant be transfered
    count = 0
    for bag_item in bag_items:
        if not bag_item.id_item.has_inventory:
            count += 1

    # the bag contains services
    if count:
        session.flash = T('You should not be transfering services')
        bag_utils.auto_bag_selection()
        redirect(URL('default', 'index'))

    bag_utils.check_bag_items_integrity(bag_items)

    # create stock transfer record
    new_stock_transfer_id = db.stock_transfer.insert(id_store_from=bag.id_store.id, id_bag=bag.id)
    bag.status = BAG_COMPLETE
    bag.update_record()
    item_utils.remove_stocks(bag_items)

    redirect(URL('stock_transfer', 'ticket', args=new_stock_transfer_id))
Exemplo n.º 2
0
def stock_transfer():
    """ """

    bag = bag_utils.is_modifiable_bag(session.current_bag)

    # check if all the bag items are consistent
    bag_items = db(db.bag_item.id_bag == bag.id).select()
    # delete the bag if there are no items
    if not bag_items:
        session.flash = T('There are no items in the bag')
        redirection()

    # counts services, since services cant be transfered
    count = 0
    for bag_item in bag_items:
        if not bag_item.id_item.has_inventory:
            count += 1

    # the bag contains services
    if count:
        session.flash = T('You should not be transfering services')
        bag_utils.auto_bag_selection()
        redirect(URL('default', 'index'))

    bag_utils.check_bag_items_integrity(bag_items)

    # create stock transfer record
    new_stock_transfer_id = db.stock_transfer.insert(id_store_from=bag.id_store.id, id_bag=bag.id)
    bag.status = BAG_COMPLETE
    bag.update_record()
    item_utils.remove_stocks(bag_items)

    redirect(URL('stock_transfer', 'ticket', args=new_stock_transfer_id))
Exemplo n.º 3
0
def discard_bag():
    bag = bag_utils.is_modifiable_bag(session.current_bag)
    removed_bag = session.current_bag
    db(db.bag_item.id_bag == bag.id).delete()
    db(db.bag.id == bag.id).delete()

    bag_utils.auto_bag_selection()

    return dict(other_bag=db.bag(session.current_bag), removed=removed_bag)
Exemplo n.º 4
0
def discard_bag():
    bag = bag_utils.is_modifiable_bag(session.current_bag)
    removed_bag = session.current_bag
    db(db.bag_item.id_bag == bag.id).delete()
    db(db.bag.id == bag.id).delete()

    bag_utils.auto_bag_selection()

    return dict(other_bag=db.bag(session.current_bag), removed=removed_bag)
Exemplo n.º 5
0
def post_login():
    if not auth.has_membership('Clients') or auth.user.is_client:
        common_utils.select_store(True)

    bag_utils.auto_bag_selection()
    if request.vars.__next:
        request.vars._next = request.vars.__next
        del request.vars.__next

    redirection()
Exemplo n.º 6
0
def post_login():
    if not auth.has_membership('Clients') or auth.user.is_client:
        common_utils.select_store(True)

    bag_utils.auto_bag_selection()
    if request.vars.__next:
        request.vars._next = request.vars.__next
        del request.vars.__next

    redirection()
Exemplo n.º 7
0
def store_selection():
    """ """

    if not auth.has_membership('Employee') or session.store:
        redirect(URL('default', 'index'))

    user_stores_query = (db.store.id < 0)
    if auth.has_membership('Admin'):
        user_stores_query = (db.store.is_active == True)
    else:
        user_stores_query = (db.store.is_active == True)
        user_store_groups = db((db.auth_membership.group_id == db.auth_group.id)
                             & (db.auth_group.role.contains('Store '))
                             & (db.auth_membership.user_id == auth.user.id)
                             ).select(db.auth_group.role)
        extra_query = (db.store.id < 0)
        for user_store_group in user_store_groups:
            store_id = int(user_store_group.role.split(' ')[1])
            extra_query |= (db.store.id == store_id)
        user_stores_query = (user_stores_query & (extra_query))

    stores = db(user_stores_query).select()
    if len(stores) == 1:
        session.store = stores.first().id
        bag_utils.auto_bag_selection()
        redirection()

    form = SQLFORM.factory(
        Field('store', "reference store", label=T('Store'), requires=IS_IN_DB(db(user_stores_query), 'store.id', '%(name)s'))
    )

    if form.process().accepted:
        session.store = form.vars.store
        response.flash = T("You are in store") + " %s" % db.store(form.vars.store).name

        bag_utils.auto_bag_selection()

        redirection()
    elif form.errors:
        response.flash = T('form has errors')
    return dict(form=form)
Exemplo n.º 8
0
def store_selection():
    """ """

    if not auth.has_membership('Employee') or session.store:
        redirect(URL('default', 'index'))

    user_stores_query = (db.store.id < 0)
    if auth.has_membership('Admin'):
        user_stores_query = (db.store.is_active == True)
    else:
        user_stores_query = (db.store.is_active == True)
        user_store_groups = db((db.auth_membership.group_id == db.auth_group.id)
                             & (db.auth_group.role.contains('Store '))
                             & (db.auth_membership.user_id == auth.user.id)
                             ).select(db.auth_group.role)
        extra_query = (db.store.id < 0)
        for user_store_group in user_store_groups:
            store_id = int(user_store_group.role.split(' ')[1])
            extra_query |= (db.store.id == store_id)
        user_stores_query = (user_stores_query & (extra_query))

    stores = db(user_stores_query).select()
    if len(stores) == 1:
        session.store = stores.first().id
        bag_utils.auto_bag_selection()
        redirection()

    form = SQLFORM.factory(
        Field('store', "reference store", label=T('Store'), requires=IS_IN_DB(db(user_stores_query), 'store.id', '%(name)s'))
    )

    if form.process().accepted:
        session.store = form.vars.store
        response.flash = T("You are in store") + " %s" % db.store(form.vars.store).name

        bag_utils.auto_bag_selection()

        redirection()
    elif form.errors:
        response.flash = T('form has errors')
    return dict(form=form)
Exemplo n.º 9
0
def complete():
    """ Check bag consistency and set its status based on the user role """

    from cp_errors import CP_EmptyBagError

    bag = bag_utils.is_modifiable_bag(session.current_bag)

    try:
        bag_utils.complete(bag)
        bag_utils.auto_bag_selection()

    except CP_EmptyBagError:
        bag_utils.auto_bag_selection()
        redirection()

    if auth.has_membership(None, bag.created_by.id, 'Clients'):
        redirect(URL('sale_order', 'create', args=bag.id))

    if auth.has_membership('Sales checkout'):
        redirect(URL('sale', 'create', args=bag.id))
    else:
        redirect(URL('ticket', args=bag.id))
Exemplo n.º 10
0
def complete():
    """ Check bag consistency and set its status based on the user role """

    from cp_errors import CP_EmptyBagError

    bag = bag_utils.is_modifiable_bag(session.current_bag)

    try:
        bag_utils.complete(bag)
        bag_utils.auto_bag_selection()

    except CP_EmptyBagError:
        bag_utils.auto_bag_selection()
        redirection()

    if auth.has_membership(None, bag.created_by.id, 'Clients'):
        redirect(URL('sale_order', 'create', args=bag.id))

    if auth.has_membership('Sales checkout'):
        redirect(URL('sale', 'create', args=bag.id))
    else:
        redirect(URL('ticket', args=bag.id))
Exemplo n.º 11
0
def select_bag():
    """ Set the specified bag as the current bag. The current bag will be available as session.current_bag

        args: [bag_id]
    """
    bag = None
    try:
        bag = bag_utils.is_modifiable_bag(request.args(0))
    except:
        bag = bag_utils.auto_bag_selection()
    if not bag:
        raise HTTP(404)
    session.current_bag = bag.id
    return bag_utils.bag_selection_return_format(bag)
Exemplo n.º 12
0
def select_bag():
    """ Set the specified bag as the current bag. The current bag will be available as session.current_bag

        args: [bag_id]
    """
    bag = None
    try:
        bag = bag_utils.is_modifiable_bag(request.args(0))
    except:
        bag = bag_utils.auto_bag_selection()
    if not bag:
        raise HTTP(404)
    session.current_bag = bag.id
    return bag_utils.bag_selection_return_format(bag)