Esempio n. 1
0
def create_new_stock_item(purchase, item):
    """ Create and settup stock item """

    price = 0
    if item.id_brand and item.id_brand.earnp_base:
        price = item.base_price / (1 + item.id_brand.earnp_base / 100)

    if not price:
        # get prices from the last stock items
        last_stock_item = db( db.stock_item.id_item == item.id ).select(
            db.stock_item.price
        ).last()
        price = last_stock_item.price if last_stock_item else item.base_price

    price = D(price or 1.0)

    taxes = item_utils.item_taxes(item, 1)
    price /= 1 + taxes

    stock_item = db.stock_item.insert(
        id_purchase=purchase.id, id_item=item.id, purchase_qty=1,
        price=price,
        taxes=price * taxes,
        base_price=item.base_price,
        price2=item.price2 or 0,
        price3=item.price3 or 0
    )

    purchase.items_subtotal += price
    purchase.items_total = purchase.items_total or 0
    purchase.items_total += price + price * taxes
    purchase.update_record()

    return stock_item
Esempio n. 2
0
def create_new_stock_item(purchase, item):
    """ Create and settup stock item """

    price = 0
    if item.id_brand and item.id_brand.earnp_base:
        price = item.base_price / (1 + item.id_brand.earnp_base / 100)

    if not price:
        # get prices from the last stock items
        last_stock_item = db(db.stock_item.id_item == item.id).select(
            db.stock_item.price).last()
        price = last_stock_item.price if last_stock_item else item.base_price

    taxes = item_utils.item_taxes(item, 1)
    price /= 1 + taxes

    stock_item = db.stock_item.insert(id_purchase=purchase.id,
                                      id_item=item.id,
                                      purchase_qty=1,
                                      price=price,
                                      taxes=price * taxes,
                                      base_price=item.base_price,
                                      price2=item.price2 or 0,
                                      price3=item.price3 or 0)

    purchase.items_subtotal += price
    purchase.items_total = purchase.items_total or 0
    purchase.items_total += price + price * taxes
    purchase.update_record()

    return stock_item
Esempio n. 3
0
def add_bag_item(bag, item, quantity=None, sale_price=None):
    """ """

    db = current.db

    sale_price = sale_price if sale_price else item.base_price

    bag_item = db((db.bag_item.id_item == item.id)
                  & (db.bag_item.id_bag == bag.id)).select().first()

    # when quantity is not specified, avoid stock checking (the API user knows what he is doing)
    if not quantity:
        stock_qty = item_utils.item_stock_qty(item,
                                              bag.id_store,
                                              id_bag=bag.id)
        if item.has_inventory:
            stock_qty = DQ(stock_qty)

        base_qty = base_qty = 1 if stock_qty >= 1 or ALLOW_OUT_OF_STOCK else stock_qty % 1  # modulo to consider fractionary items
        # if there is no stock notify the user
        if base_qty <= 0:
            raise CP_OutOfStockError()
        quantity = base_qty

    # create item taxes string, the string contains the tax name and its percentage, see db.py > bag_item table for more info
    if not bag_item:
        item_taxes_str = ''
        for tax in item.taxes:
            item_taxes_str += '%s:%s' % (tax.name, tax.percentage)
            if tax != item.taxes[-1]:
                item_taxes_str += ','
        discounts = item_utils.item_discounts(item)
        sale_price = item_utils.discount_data(discounts, sale_price)[0]
        discount = item.base_price - sale_price
        id_bag_item = db.bag_item.insert(id_bag=bag.id,
                                         id_item=item.id,
                                         quantity=quantity,
                                         sale_price=sale_price,
                                         discount=discount,
                                         product_name=item.name,
                                         item_taxes=item_taxes_str,
                                         sale_taxes=item_utils.item_taxes(
                                             item, sale_price))
        bag_item = db.bag_item(id_bag_item)
    else:
        bag_item.quantity += base_qty
        bag_item.update_record()

    return bag_item
def add_bag_item(bag, item, quantity=None, sale_price=None):
    """ """

    db = current.db

    sale_price = sale_price if sale_price else item.base_price

    bag_item = db(
          (db.bag_item.id_item == item.id)
        & (db.bag_item.id_bag == bag.id)
    ).select().first()

    # when quantity is not specified, avoid stock checking (the API user knows what he is doing)
    if not quantity:
        stock_qty = item_utils.item_stock_qty(item, bag.id_store, id_bag=bag.id)
        if item.has_inventory:
            stock_qty = DQ(stock_qty)

        base_qty = base_qty = 1 if stock_qty >= 1 or ALLOW_OUT_OF_STOCK else stock_qty % 1 # modulo to consider fractionary items
        # if there is no stock notify the user
        if base_qty <= 0:
            raise CP_OutOfStockError()
        quantity = base_qty

    # create item taxes string, the string contains the tax name and its percentage, see db.py > bag_item table for more info
    if not bag_item:
        item_taxes_str = ''
        for tax in item.taxes:
            item_taxes_str += '%s:%s' % (tax.name, tax.percentage)
            if tax != item.taxes[-1]:
                item_taxes_str += ','
        discounts = item_utils.item_discounts(item)
        sale_price = item_utils.discount_data(discounts, sale_price)[0]
        discount = item.base_price - sale_price
        id_bag_item = db.bag_item.insert(
            id_bag=bag.id, id_item=item.id, quantity=quantity,
            sale_price=sale_price, discount=discount,
            product_name=item.name, item_taxes=item_taxes_str,
            sale_taxes=item_utils.item_taxes(item, sale_price),
            reward_points=item.reward_points or 0
        )
        bag_item = db.bag_item(id_bag_item)
    else:
        bag_item.quantity += base_qty
        bag_item.update_record()

    return bag_item
Esempio n. 5
0
def item_card(item):
    """ """
    session = current.session
    auth = current.auth
    db = current.db
    T = current.T

    available = "Not available"
    available_class = "label label-danger"

    stock_qty = item_stock_qty(item, session.store)
    if stock_qty > 0:
        available_class = "label label-success"
        available = "Available"

    item_options = DIV()

    bg_style = ""
    images = db((db.item_image.id_item == db.item.id)
                & (db.item.id == item.id)
                & (db.item.is_active == True)).select(db.item_image.ALL)
    if images:
        bg_style = "background-image: url(%s);" % URL(
            'static', 'uploads/' + images.first().sm)
    else:
        bg_style = "background-image: url(%s);" % URL('static',
                                                      'images/no_image.svg')

    brand_link = H4(
        A(item.id_brand.name,
          _href=URL('item', 'browse', vars=dict(
              brand=item.id_brand.id)))) if item.id_brand else H4(
                  T('No brand'))

    item_price = (item.base_price or 0) + item_taxes(item, item.base_price)
    fix_item_price(item, item.base_price)
    item_price = item.discounted_price

    item_price_html = DIV()
    if item.discount_percentage > 0:
        item_price_html.append(
            DIV(
                T('before'),
                SPAN('$ ',
                     SPAN(item.new_price, _class="old-price"),
                     _class="right")))
        item_price_html.append(
            DIV(
                T('discount'),
                SPAN(SPAN(item.discount_percentage),
                     '%',
                     _class="right text-danger")))
    item_price_html.append(
        DIV(SPAN(T(available), _class=available_class + ' item-available'),
            H4('$ ', DQ(item_price, True), _class="item-price"),
            _class="item-card-bottom"))

    # concatenate all the item traits, this string will be appended to the item name
    traits_str = ''
    traits_ids = ''
    item_url = URL('item', 'get_item', args=item.id)
    item_name = item.name
    if item.traits:
        for trait in item.traits:
            traits_ids += str(trait.id)
            traits_str += trait.trait_option + ' '
            if trait != item.traits[-1]:
                traits_ids += ','
        item_url = URL('item',
                       'get_item',
                       vars=dict(name=item.name, traits=traits_ids))
        item_name = item.name + ' ' + traits_str
    elif item.description:
        item_name += ' - ' + item.description[:10]
        if len(item.description) > 10:
            item_name += '...'

    main_content = DIV(H4(A(item_name, _href=item_url)),
                       brand_link,
                       _class="item_data")

    # item options
    item_options = DIV(BUTTON(ICON('shopping_basket'),
                              _type="button",
                              _class="btn btn-default",
                              _onclick="add_bag_item(%s)" % item.id),
                       _class="btn-group item-options")
    if auth.has_membership('Employee'):
        main_content.append(
            P('# ', SPAN(item_barcode(item)), _class="item-barcode"))

        expand_btn = BUTTON(ICON('more_vert'),
                            _type="button",
                            _class="btn btn-default dropdown-toggle",
                            data={'toggle': 'dropdown'})
        item_options.append(expand_btn)
        options_ul = UL(_class="dropdown-menu")
        if auth.has_membership('Items info') or auth.has_membership(
                'Items management') or auth.has_membership('Items prices'):
            options_ul.append(
                LI(A(T('Update'), _href=URL('item', 'update', args=item.id))))
            options_ul.append(
                LI(
                    A(T('Print labels'),
                      _href=URL('item', 'labels', args=item.id))))
            options_ul.append(
                LI(
                    A(T('Add images'),
                      _href=URL('item_image', 'create', args=item.id))))
        if auth.has_membership('Analytics'):
            options_ul.append(
                LI(
                    A(T('Analysis'),
                      _href=URL('analytics', 'item_analysis', args=item.id))))
        item_options.append(options_ul)

    return DIV(A('', _class="panel-heading", _style=bg_style, _href=item_url),
               DIV(main_content,
                   item_options,
                   item_price_html,
                   _class="panel-body"),
               _class="panel panel-default item-card")
def item_card(item):
    """ """
    session = current.session
    auth = current.auth
    db = current.db
    T = current.T

    available = "Not available"
    available_class = "label label-danger"

    stock_qty = item_stock_qty(item, session.store)
    if stock_qty > 0:
        available_class = "label label-success"
        available = "Available"

    item_options = DIV()

    bg_style = ""
    images = db(
        (db.item_image.id_item == db.item.id)
      & (db.item.id == item.id)
      & (db.item.is_active == True)
    ).select(db.item_image.ALL)
    if images:
        bg_style = "background-image: url(%s);" % URL('static','uploads/'+ images.first().sm)
    else:
        bg_style = "background-image: url(%s);" % URL('static', 'images/no_image.svg')

    brand_link = H4(
        A(item.id_brand.name,
          _href=URL('item', 'browse', vars=dict(brand=item.id_brand.id))
        )
    ) if item.id_brand else H4(T('No brand'))

    item_price = (item.base_price or 0) + item_taxes(item, item.base_price)
    fix_item_price(item, item.base_price)
    item_price = item.discounted_price

    item_price_html = DIV()
    if item.discount_percentage > 0:
        item_price_html.append(DIV(T('before'), SPAN('$ ', SPAN(item.new_price, _class="old-price"), _class="right")))
        item_price_html.append(
            DIV(T('discount'), SPAN(SPAN(item.discount_percentage), '%', _class="right text-danger"))
        )
    item_price_html.append(
        DIV(
            SPAN(T(available), _class=available_class + ' item-available'),
            H4('$ ', DQ(item_price, True), _class="item-price"),
            _class="item-card-bottom"
        )
    )


    # concatenate all the item traits, this string will be appended to the item name
    traits_str = ''
    traits_ids = ''
    item_url = URL('item', 'get_item', args=item.id)
    item_name = item.name
    if item.traits:
        for trait in item.traits:
            traits_ids += str(trait.id)
            traits_str += trait.trait_option + ' '
            if trait != item.traits[-1]:
                traits_ids += ','
        item_url = URL('item', 'get_item', vars=dict(name=item.name, traits=traits_ids))
        item_name = item.name + ' ' + traits_str
    elif item.description:
        item_name += ' - ' + item.description[:10]
        if len(item.description) > 10:
            item_name += '...'

    main_content = DIV(
        H4(A(item_name, _href=item_url)),
        brand_link,
        _class="item_data"
    )

    # item options
    item_options = DIV(
        BUTTON(ICON('shopping_basket'), _type="button", _class="btn btn-default", _onclick="add_bag_item(%s)" % item.id)
        , _class="btn-group item-options"
    )
    if auth.has_membership('Employee'):
        main_content.append(
            P('# ', SPAN(item_barcode(item)), _class="item-barcode")
        )

        expand_btn = BUTTON(ICON('more_vert'), _type="button", _class="btn btn-default dropdown-toggle", data={'toggle':'dropdown'})
        item_options.append(expand_btn)
        options_ul = UL(_class="dropdown-menu")
        if auth.has_membership('Items info') or auth.has_membership('Items management') or auth.has_membership('Items prices'):
            options_ul.append(
                LI(A(T('Update'), _href=URL('item', 'update', args=item.id)))
            )
            options_ul.append(
                LI(A(T('Print labels'), _href=URL('item', 'labels', args=item.id)))
            )
            options_ul.append(
                LI(A(T('Add images'), _href=URL('item_image', 'create', args=item.id)))
            )
        if auth.has_membership('Analytics'):
            options_ul.append(
                LI(A(T('Analysis'), _href=URL('analytics', 'item_analysis', args=item.id)))
            )
        item_options.append(options_ul)

    return DIV(
        A('', _class="panel-heading", _style=bg_style, _href=item_url),
        DIV(
            main_content,
            item_options,
            item_price_html,
            _class="panel-body"
        ),
        _class="panel panel-default item-card"
    )