def response_stock_item(stock_item):
    """ Returns relevant stock_item information """

    serials = stock_item.serial_numbers.replace(',', ',\n') if stock_item.serial_numbers else ''
    item_name = stock_item.id_item.name + item_utils.concat_traits(stock_item.id_item)

    res = {
          "id": stock_item.id
        , "id_item": stock_item.id_item
        , "item_name": item_name
        , "item_barcode": item_barcode(stock_item.id_item)
        , "purchase_qty": str(stock_item.purchase_qty or 0)
        , "price": str(DQ(stock_item.price or 0))
        , "base_price": str(DQ(stock_item.base_price or 0))
        , "price2": str(DQ(stock_item.price2 or 0))
        , "price3": str(DQ(stock_item.price3 or 0))
        , "taxes": str(DQ(stock_item.taxes) or 0)
        , "serial_numbers": serials
        , "earnp_base_price": 0
        , "earnp_price2": 0
        , "earnp_price3": 0
    }

    if stock_item.price:
        price = DQ(stock_item.price) + DQ(stock_item.taxes)
        for target in ['base_price', 'price2', 'price3']:
            earnp = DQ(
                ((stock_item[target] or 0) / price - 1) * 100, True, True
            )
            earnp = max(0, earnp)
            res['earnp_' + target] = earnp

    return res
Exemple #2
0
def response_stock_item(stock_item):
    """ Returns relevant stock_item information """

    serials = stock_item.serial_numbers.replace(
        ',', ',\n') if stock_item.serial_numbers else ''
    item_name = stock_item.id_item.name + item_utils.concat_traits(
        stock_item.id_item)

    res = {
        "id": stock_item.id,
        "id_item": stock_item.id_item,
        "item_name": item_name,
        "item_barcode": item_barcode(stock_item.id_item),
        "purchase_qty": str(stock_item.purchase_qty or 0),
        "price": str(DQ(stock_item.price or 0)),
        "base_price": str(DQ(stock_item.base_price or 0)),
        "price2": str(DQ(stock_item.price2 or 0)),
        "price3": str(DQ(stock_item.price3 or 0)),
        "taxes": str(DQ(stock_item.taxes) or 0),
        "serial_numbers": serials,
        "earnp_base_price": 0,
        "earnp_price2": 0,
        "earnp_price3": 0
    }

    if stock_item.price:
        price = DQ(stock_item.price) + DQ(stock_item.taxes)
        for target in ['base_price', 'price2', 'price3']:
            earnp = DQ(((stock_item[target] or 0) / price - 1) * 100, True,
                       True)
            earnp = max(0, earnp)
            res['earnp_' + target] = earnp

    return res
Exemple #3
0
def set_bag_item(bag_item, discounts=None):
    """ modifies bag item data, in order to display it properly, this method does not modify the database """

    if discounts is None:
        discounts = []

    session = current.session

    item = bag_item.id_item

    bag_item.product_name = item.name + " " + item_utils.concat_traits(item)
    if discounts is None:
        discounts = []

    # stores the price without discounts
    real_price = bag_item.sale_price + (bag_item.discount or 0)
    # discount percentage
    discount_p = 0
    try:
        discount_p = DQ(1.0) - bag_item.sale_price / real_price
    except:
        pass
    item.base_price -= item.base_price * discount_p

    bag_item.total_sale_price = str(
        DQ(bag_item.sale_price + bag_item.sale_taxes, True))
    bag_item.base_price = money_format(DQ(item.base_price,
                                          True)) if item.base_price else 0
    bag_item.price2 = money_format(
        DQ(item.price2 - item.price2 * discount_p, True)) if item.price2 else 0
    bag_item.price3 = money_format(
        DQ(item.price3 - item.price3 * discount_p, True)) if item.price3 else 0
    bag_item.sale_price = money_format(DQ(bag_item.sale_price or 0, True))

    # add taxes without discounts
    real_price += bag_item_taxes(bag_item, real_price)
    bag_item.price_no_discount = real_price

    bag_item.measure_unit = item.id_measure_unit.symbol

    bag_item.barcode = item_utils.item_barcode(item)
    bag_item.stock = item_utils.item_stock_qty(item, session.store)
    bag_item.has_inventory = item.has_inventory
    bag_item.discount_percentage = int(discount_p * D(100.0))
    bag_item.real_price = bag_item.sale_price

    return bag_item
def set_bag_item(bag_item, discounts=None):
    """ modifies bag item data, in order to display it properly, this method does not modify the database """

    if discounts is None:
        discounts = []

    session = current.session

    item = bag_item.id_item

    bag_item.product_name = item.name + " " + item_utils.concat_traits(item)
    if discounts is None:
        discounts = []

    # stores the price without discounts
    real_price = bag_item.sale_price + (bag_item.discount or 0)
    # discount percentage
    discount_p = 0
    try:
        discount_p = DQ(1.0) - bag_item.sale_price / real_price
    except:
        pass
    item.base_price -= item.base_price * discount_p

    bag_item.total_sale_price = str(DQ(bag_item.sale_price + bag_item.sale_taxes, True))
    bag_item.base_price = money_format(DQ(item.base_price, True)) if item.base_price else 0
    bag_item.price2 = money_format(DQ(item.price2 - item.price2 * discount_p, True)) if item.price2 else 0
    bag_item.price3 = money_format(DQ(item.price3 - item.price3 * discount_p, True)) if item.price3 else 0
    bag_item.sale_price = money_format(DQ(bag_item.sale_price or 0, True))


    # add taxes without discounts
    real_price += bag_item_taxes(bag_item, real_price)
    bag_item.price_no_discount = real_price

    bag_item.measure_unit = item.id_measure_unit.symbol

    bag_item.barcode = item_utils.item_barcode(item)
    bag_item.stock = item_utils.item_stock_qty(item, session.store)
    bag_item.has_inventory = item.has_inventory
    bag_item.discount_percentage = int(discount_p * D(100.0))
    bag_item.real_price = bag_item.sale_price

    return bag_item