Esempio 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)
Esempio n. 2
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)
Esempio n. 3
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)