def main(): with dbapi.session: for x in dbapi.search(ProdItem): prod_id = get_real_prod_id(x.prod_id) itemgroup = dbapi.getone(ProdItemGroup, prod_id=prod_id) if itemgroup: dbapi.update(x, {'itemgroupid': itemgroup.uid}) else: print prod_id
def main(): with dbapi.session: to_be_deleted = [] for ig in dbapi.search(ProdItemGroup, **{'base_price_usd-gte': 31}): items = list(dbapi.search(ProdItem, itemgroupid=ig.uid)) prices = list(get_prices(dbapi, items)) if not prices: print 'delete item', ig.name if int(raw_input('delete?')): to_be_deleted.append(ig) continue price = min(prices) print ig.name, price print 'updated', dbapi.update(ig, {'base_price_usd': price}) print 'delete for sure', to_be_deleted if int(raw_input('delete')): map(dbapi.delete, to_be_deleted)
def get_price_list(): almacen_id = request.query.get('almacen_id') prefix = request.query.get('prefix') if not prefix: prefix = '' if almacen_id is None: abort(400, 'input almacen_id') prods = dbapi.search(**{'nombre-prefix': prefix, 'almacen_id': almacen_id}) temp = jinja_env.get_template('buscar_precios.html') return temp.render(prods=prods)
def show_items(): all_itemgroups = dbapi.search(ProdItemGroup) items = dbapi.search(ProdItem) pricelist = dbapi.search(PriceList) by_id = defaultdict(Prod) def get_id(x): if x[-1] == '+': return x[:-1].upper() return x.upper() for x in all_itemgroups: by_id[get_id(x.prod_id)].prod = x for x in items: by_id[get_id(x.prod_id)].items.append(x) for x in pricelist: by_id[get_id(x.prod_id)].pricelist.append(x) temp = jinja_env.get_template('items.html') return temp.render(all=by_id)
def main(): with dbapi.session as session: all_prod = dbapi.search(PriceList) by_signature = defaultdict(list) for x in all_prod: sig = x.prod_id if x.prod_id[-1] == '+': sig = x.prod_id[:-1] by_signature[sig].append(x) for x, y in by_signature.items(): res = backfill_item(y) print x, res session.commit()
def main(): now = datetime.datetime.now() now = now - datetime.timedelta(days=1) with dbapi.session: for x in dbapi.search(ProdCount): itemgroup = dbapi.getone(ProdItemGroup, prod_id=x.prod_id) if itemgroup: t = InventoryMovement( from_inv_id=-1, to_inv_id=x.bodega_id, prod_id=x.prod_id, itemgroup_id=itemgroup.uid, timestamp=now, type=InvMovementType.INITIAL, quantity=x.cant, reference_id=None, ) transactionapi.save(t) else: print x.bodega_id, x.prod_id, x.cant
def main(): result = {} prods = {} with dbapi.session: for prod in dbapi.search(ProdItemGroup): prods[prod.uid] = prod for guid in prods: data = requests.get("http://192.168.0.23/app/api/itemgroup/{}/transaction".format(guid), params=params) if data.status_code == 200: transactions = map(InventoryMovement.deserialize, json.loads(data.text)["results"]) in_ = 0 out_ = 0 for t in transactions: if int(t.from_inv_id) == 1: out_ += t.quantity if int(t.to_inv_id) == 1: in_ += t.quantity result[guid] = (in_, out_) writer = csv.writer(sys.stdout, delimiter=",", quotechar='"') for x in sorted(result.items(), key=lambda x: x[1][1]): p = prods[x[0]] writer.writerow([x[0], p.prod_id, p.name, x[1][0], x[1][1]])
def getallitems(): return dbapi.search(PriceList, almacen_id=2)
def get_prices(dbapi, items): prices = [] for i in items: prices.extend(dbapi.search(PriceList, prod_id=i.prod_id)) return map(lambda x: Decimal(x.precio2 or x.precio1) / x.multiplicador / 100, prices)