Ejemplo n.º 1
0
def create_full_item_from_dict(dbapi, content):
    """
        input format:
        {
            "prod" : {prod_id, name, desc, base_unit}< - information on item group
            "items": [multiplier, unit
                "prices": {
                   "display_name":
                   "price1":
                   "price2":
                   "cant":
                }, ...
                ]<- information on items requires multiplier be distinct
        }
        must be called within dbcontext
    """
    itemgroup = ProdItemGroup()
    itemgroup.merge_from(content["prod"])

    itemgroupid = dbapi.create(itemgroup)

    items = {}
    allstores = {x.almacen_id: x for x in dbapi.search(Store)}

    for item in content["items"]:
        prices = item["prices"]
        del item["prices"]
        i = ProdItem()
        i.merge_from(item)
        i.itemgroupid = itemgroupid
        if i.multiplier == 1:
            i.prod_id = itemgroup.prod_id
        elif i.multiplier > 1:
            i.prod_id = itemgroup.prod_id + "+"
        elif i.multiplier < 1:
            i.prod_id = itemgroup.prod_id + "-"

        item_id = dbapi.create(i)
        items[i.unit] = i

        # create prices
        for alm_id, p in prices.items():
            price = PriceList()
            price.nombre = p["display_name"]
            price.precio1 = int(float(p["price1"]) * 100)
            price.precio2 = int(float(p["price2"]) * 100)
            price.cant_mayorista = p["cant"]
            price.prod_id = i.prod_id
            price.unidad = i.unit
            price.almacen_id = int(alm_id)
            price.multiplicador = i.multiplier
            dbapi.create(price)
Ejemplo n.º 2
0
 def save_item_with_price():
     # TODO: VALIDATION
     item_with_price = json.loads(request.body.read())
     item = ProdItem.deserialize(item_with_price)
     prod_id = item_with_price['prod_id']
     if int(item_with_price['multiplier']) > 1:
         prod_id += '+'
     item.prod_id = prod_id
     uid = dbapi.create(item)
     for aid, x in item_with_price['price'].items():
         p = PriceList()
         p.almacen_id = aid
         p.prod_id = prod_id
         p.precio1 = int(Decimal(x['price1']) * 100)
         p.precio2 = int(Decimal(x['price2']) * 100)
         p.nombre = x['display_name']
         p.cant_mayorista = x['cant']
         p.unidad = item.unit
         p.multiplicador = item.multiplier
         dbapi.create(p)
     dbapi.db_session.commit()
     return {'status': 'success', 'uid': uid}
Ejemplo n.º 3
0
 def save_item_with_price():
     # TODO: VALIDATION
     item_with_price = json.loads(request.body.read())
     item = ProdItem.deserialize(item_with_price)
     prod_id = item_with_price['prod_id']
     if int(item_with_price['multiplier']) > 1:
         prod_id += '+'
     item.prod_id = prod_id
     uid = dbapi.create(item)
     for aid, x in item_with_price['price'].items():
         p = PriceList()
         p.almacen_id = aid
         p.prod_id = prod_id
         p.precio1 = int(Decimal(x['price1']) * 100)
         p.precio2 = int(Decimal(x['price2']) * 100)
         p.nombre = x['display_name']
         p.cant_mayorista = x['cant']
         p.unidad = item.unit
         p.multiplicador = item.multiplier
         dbapi.create(p)
     dbapi.db_session.commit()
     return {'status': 'success', 'uid': uid}
Ejemplo n.º 4
0
 def save_item_with_price():
     # TODO: VALIDATION
     item_with_price = json.loads(request.body.read())
     item = ProdItem.deserialize(item_with_price)
     prod_id = item_with_price["prod_id"]
     if int(item_with_price["multiplier"]) > 1:
         prod_id += "+"
     item.prod_id = prod_id
     uid = dbapi.create(item)
     for aid, x in item_with_price["price"].items():
         p = PriceList()
         p.almacen_id = aid
         p.prod_id = prod_id
         p.precio1 = int(Decimal(x["price1"]) * 100)
         p.precio2 = int(Decimal(x["price2"]) * 100)
         p.nombre = x["display_name"]
         p.cant_mayorista = x["cant"]
         p.unidad = item.unit
         p.multiplicador = item.multiplier
         dbapi.create(p)
     dbapi.db_session.commit()
     return {"status": "success", "uid": uid}
Ejemplo n.º 5
0
def create_full_item_from_dict(dbapi, content):
    """
        input format:
        {
            "prod" : {prod_id, name, desc, base_unit}< - information on item group
            "items": [multiplier, unit
                "prices": {
                   "display_name":
                   "price1":
                   "price2":
                   "cant":
                }, ...
                ]<- information on items requires multiplier be distinct
        }
        must be called within dbcontext
    """
    itemgroup = ProdItemGroup()
    itemgroup.merge_from(content['prod'])

    itemgroupid = dbapi.create(itemgroup)

    prod = Product()
    prod.nombre = itemgroup.name
    prod.codigo = itemgroup.prod_id
    dbapi.create(prod)

    items = {}
    inventories = {}
    allstores = {x.almacen_id: x for x in dbapi.search(Store)}

    conts = {}
    for bod in dbapi.search(Bodega):
        if bod.id == -1:
            continue
        contenido = ProdCount()
        contenido.bodega_id = bod.id
        contenido.prod_id = itemgroup.prod_id
        contenido.cant = 0
        contenido.precio = 0
        contenido.precio2 = 0
        cid = dbapi.create(contenido)
        conts[bod.id] = cid

    for item in content['items']:
        prices = item['prices']
        del item['prices']
        i = ProdItem()
        i.merge_from(item)
        i.itemgroupid = itemgroupid
        if i.multiplier == 1:
            i.prod_id = itemgroup.prod_id
        elif i.multiplier > 1:
            i.prod_id = itemgroup.prod_id + '+'
        elif i.multiplier < 1:
            i.prod_id = itemgroup.prod_id + '-'

        item_id = dbapi.create(i)
        items[i.unit] = i

        # create bodega
        invs = {}
        for bod in dbapi.search(Bodega):
            if bod.id == -1:
                continue
            inv = Inventory()
            inv.item_id = item_id
            inv.bodega_id = bod.id
            inv.cant = 0
            inv_id = dbapi.create(inv)
            invs[bod.id] = inv

        # create prices
        for alm_id, p in prices.items():
            price = PriceList()
            price.nombre = p['display_name']
            price.precio1 = int(float(p['price1']) * 100)
            price.precio2 = int(float(p['price2']) * 100)
            price.cant_mayorista = p['cant']
            price.prod_id = i.prod_id
            price.unidad = i.unit
            price.almacen_id = int(alm_id)
            bodid = allstores[price.almacen_id].bodega_id
            price.upi = conts[bodid]
            price.multiplicador = i.multiplier
            dbapi.create(price)
Ejemplo n.º 6
0
def create_full_item_from_dict(dbapi, content):
    """
        input format:
        {
            "prod" : {prod_id, name, desc, base_unit}< - information on item group
            "items": [multiplier, unit
                "prices": {
                   "display_name":
                   "price1":
                   "price2":
                   "cant":
                }, ...
                ]<- information on items requires multiplier be distinct
        }
        must be called within dbcontext
    """
    itemgroup = ProdItemGroup()
    itemgroup.merge_from(content['prod'])

    itemgroupid = dbapi.create(itemgroup)

    prod = Product()
    prod.nombre = itemgroup.name
    prod.codigo = itemgroup.prod_id
    dbapi.create(prod)

    items = {}
    inventories = {}
    allstores = {x.almacen_id: x for x in dbapi.search(Store)}

    conts = {}
    for bod in dbapi.search(Bodega):
        if bod.id == -1:
            continue
        contenido = ProdCount()
        contenido.bodega_id = bod.id
        contenido.prod_id = itemgroup.prod_id
        contenido.cant = 0
        contenido.precio = 0
        contenido.precio2 = 0
        cid = dbapi.create(contenido)
        conts[bod.id] = cid

    for item in content['items']:
        prices = item['prices']
        del item['prices']
        i = ProdItem()
        i.merge_from(item)
        i.itemgroupid = itemgroupid
        if i.multiplier == 1:
            i.prod_id = itemgroup.prod_id
        elif i.multiplier > 1:
            i.prod_id = itemgroup.prod_id + '+'
        elif i.multiplier < 1:
            i.prod_id = itemgroup.prod_id + '-'

        item_id = dbapi.create(i)
        items[i.unit] = i

        # create bodega
        invs = {}
        for bod in dbapi.search(Bodega):
            if bod.id == -1:
                continue
            inv = Inventory()
            inv.item_id = item_id
            inv.bodega_id = bod.id
            inv.cant = 0
            inv_id = dbapi.create(inv)
            invs[bod.id] = inv

        # create prices
        for alm_id, p in prices.items():
            price = PriceList()
            price.nombre = p['display_name']
            price.precio1 = int(float(p['price1']) * 100)
            price.precio2 = int(float(p['price2']) * 100)
            price.cant_mayorista = p['cant']
            price.prod_id = i.prod_id
            price.unidad = i.unit
            price.almacen_id = int(alm_id)
            bodid = allstores[price.almacen_id].bodega_id
            price.upi = conts[bodid]
            price.multiplicador = i.multiplier
            dbapi.create(price)