def get(): user = pay_util.request_user(request) params = request.GET barcode = params.get('barcode') search_type = params.get('type') if search_type == 'like': new_items = models.NewItem.objects.filter( operator=user, status=0, barcode__contains=barcode) elif search_type == 'equal': item = models.NewItem.objects.get(operator=user, status=0, barcode=barcode) temp = model_to_dict(item) if not temp['name']: temp['name'] = '' if not temp['unit']: temp['unit'] = '' if not temp['price']: temp['price'] = '' if not temp['brand']: temp['brand'] = '' if not temp['taste']: temp['taste'] = '' return {'data': temp} results = [] for new_item in new_items: results.append(model_to_dict(new_item)) return {'data': results}
def get(): params = request.GET barcode = params.get('barcode') user = pay_util.request_user(request) cashier = user.cashier item = models.Item.objects.get(barcode=barcode, store=cashier.store) return {'data': model_to_dict(item)}
def get(): user = pay_util.request_user(request) store = user.cashier.store cart = models.StoreCart.objects.get(store=store) cart_items = cart.get_cart_items() amount = 0 result, amount = pay_util.bundling(cart_items, store) return {'items': result, 'amount': amount}
def post(): params = QueryDict(request.body) name = params.get('name') cid = int(params.get('cid')) user = pay_util.request_user(request) user.name = name user.company_id = cid user.is_active = True user.save()
def get(): user = pay_util.request_user(request) new_items = models.NewItem.objects.filter(operator=user, status=0, name=None) results = [] for new_item in new_items: results.append(model_to_dict(new_item)) return {'data': results}
def post(): user = pay_util.request_user(request) store = user.cashier.store temps = models.InventoryTemp.objects.filter(item__store_id=store.id, status=1) for temp in temps: item = temp.item item.inventory = temp.num item.save() temp.status = 0 temp.save()
def get(): user = pay_util.request_user(request) items = models.NewItem.objects.filter( operator=user).order_by('-add_time') results = [] status_map = {0: u'待审核', 1: u'已通过', 2: u'已被拒'} for item in items: temp = model_to_dict(item) temp['status'] = status_map[temp['status']] if not temp['name']: temp['name'] = u'信息不全' results.append(temp) return {'data': results}
def post(): barcode = params.get('barcode') user = pay_util.request_user(request) store_id = user.cashier.store_id store = models.Store.objects.get(pk=store_id) item = models.Item.objects.get(barcode=barcode, store=store) cart = models.StoreCart.objects.get_or_create(store=store)[0] cart.save() cart_item = models.StoreCartItem.objects.create(item=item, num=1, cart=cart) cart_item.save() return {'data': model_to_dict(item)}
def get(): params = request.GET user = pay_util.request_user(request) barcode = params.get('barcode') store_id = int(params.get('store_id')) store_name = params.get('store_name') lat = float(params.get('lat')) lng = float(params.get('lng')) location = str(lng) + ',' + str(lat) gd_address, adcode = recommendorder_utils.location_to_addrr(location) if store_id == -1: store = StandardStore.objects.create(source=1, name=store_name, lat=lat, lng=lng, address=gd_address) store.save() store_id = store.id data_engine = sqlalchemy.create_engine(settings.STD_DB_URL) results = pandas.read_sql_query(sqlalchemy.text(""" SELECT id, name FROM standard_item WHERE barcodes @> array[:barcode]; """), data_engine, params={'barcode': barcode}) if results.empty: item_count = models.NewItem.objects.filter(barcode=barcode).count() if item_count == 0: new_item = models.NewItem.objects.create(operator=user, store_id=store_id, barcode=barcode) new_item.save() return {'code': 0, 'data': store_id} else: return {'code': 1, 'data': store_id} else: item_dict = {} for item in results.itertuples(): item_dict['id'] = item[1] item_dict['name'] = item[2] log = models.ScanedItemLog.objects.create( standard_item_id=item_dict['id'], store_id=store_id, operator=user) log.save() return {'code': 1, 'data': store_id} item_dict = {}
def post(): params = QueryDict(request.body) item_id = int(params.get('id')) num = int(params.get('num')) user = pay_util.request_user(request) cashier = user.cashier stock_taking = models.StockTaking.objects.get_or_create( store=cashier.store, status=1)[0] stock_taking.save() sub_stock_taking = models.SubStockTaking.objects.create( operator=cashier, stock_taking=stock_taking, item_id=item_id, num=num) sub_stock_taking.save()
def get(): params = request.GET user = pay_util.request_user(request) barcode = params.get('barcode') store = user.cashier.store item = models.Item.objects.get(store=store, barcode=barcode) result = model_to_dict(item) result['temp_inventory'] = 0 if hasattr(item, 'inventorytemp') and item.inventorytemp.status == 1: result['temp_inventory'] = item.inventorytemp.num else: temp_inventory = models.InventoryTemp.objects.create(item=item, num=0, status=1) temp_inventory.save() return {'data': result}
def get(): user = pay_util.request_user(request) companies = models.Company.objects.all() results = [] name_map = {} user_msg = model_to_dict(user) if user.company: user_msg['company'] = user.company.name for company in companies: temp = model_to_dict(company) name_map[temp['name']] = temp['id'] results.append(temp['name']) results.append(u'其他') return { 'data': { 'companies': results, 'name_map': name_map, 'user': user_msg } }
def post(): user = pay_util.request_user(request) params = QueryDict(request.body) nid = int(params.get('nid')) name = params.get('name') brand = params.get('brand') unit = params.get('unit') taste = params.get('taste') price = float(params.get('price')) best_before_date = int(params.get('best_before_date')) pack = params.get('pack') models.NewItem.objects.filter(operator=user, id=nid).update( name=name, unit=unit, price=price, taste=taste, brand=brand, best_before_date=best_before_date, pack=pack, update_time=timezone.now()) new_item = models.NewItem.objects.get(operator_id=user.id, id=nid)
def get(): user = pay_util.request_user(request) result = pay_util.get_order_data(user, True, True) user_rankings = pay_util.get_order_user_data() return {'data': dict(result, **user_rankings)}
def get(): user = pay_util.request_user(request) result = pay_util.get_order_data(user, True, True) return {'data': result}