def test_schedule(session): unit1 = add_unit('unit1', 800) unit2 = add_unit('unit2', 700) position1 = add_position('position1') position2 = add_position('position2') position1.units = [unit1, unit2] position2.units = [unit1, unit2] assert unit1.estimate_num == 800 assert unit2.estimate_num == 700 assert position1.estimate_num == unit1.estimate_num + unit2.estimate_num assert position2.estimate_num == unit1.estimate_num + unit2.estimate_num item1 = add_item(position=position1) item2 = add_item(position=position2) _date = date.today() assert position1.schedule_num(_date) == 0 assert position2.schedule_num(_date) == 0 assert unit1.schedule_num(_date) == 0 assert unit2.schedule_num(_date) == 0 assert unit1.retain_num(_date) == 800 assert unit2.retain_num(_date) == 700 assert position1.retain_num(_date) == 1500 assert position2.retain_num(_date) == 1500 AdSchedule.add(item1, 500, _date) AdSchedule.add(item2, 100, _date) user = User.get_by_email('*****@*****.**') AdItem.update_items_with_action([item1], ITEM_STATUS_ACTION_PRE_ORDER, user) AdItem.update_items_with_action([item2], ITEM_STATUS_ACTION_PRE_ORDER, user) assert position1.schedule_num(_date) == 500 assert position2.schedule_num(_date) == 100 assert unit1.schedule_num(_date) == 320 assert unit2.schedule_num(_date) == 280 assert unit1.retain_num(_date) == 480 assert unit2.retain_num(_date) == 420 assert position1.retain_num(_date) == 900 assert position2.retain_num(_date) == 900
def add_schedules(order, data): """新增订单项, 排期项""" items = json.loads(data) for item in items: position = AdPosition.get(item['position']) ad_item = AdItem.add(order=order, sale_type=item['sale_type'], special_sale=item['special_sale'], position=position, creator=g.user, create_time=datetime.now()) ad_item.price = position.price ad_item.description = item['description'] ad_item.item_status = ITEM_STATUS_NEW ad_item.save() for (date_str, num_str) in item['schedule'].items(): _date = datetime.strptime(date_str, DATE_FORMAT).date() num = int(num_str) AdSchedule.add(item=ad_item, num=num, date=_date)
def add_schedule(item=None, num=300): item = item or add_item() today = date.today() start = time.min end = time.max schedule = AdSchedule.add(item=item, num=num, date=today, start=start, end=end) return schedule
def schedule_delete(schedule_id): schedule = AdSchedule.get(schedule_id) if not schedule: abort(404) item = schedule.item schedule.delete() flash(u'删除成功!', 'success') return redirect(url_for("schedule.item_detail", item_id=item.id))
def schedule_update(schedule_id): schedule = AdSchedule.get(schedule_id) if not schedule: abort(404) schedule.date = datetime.strptime(request.form.get('date'), DATE_FORMAT).date() schedule.start = datetime.strptime(request.form.get('start'), TIME_FORMAT).time() schedule.end = datetime.strptime(request.form.get('end'), TIME_FORMAT).time() schedule.num = request.form.get('num') schedule.save() flash(u'投放安排保存成功!', 'success') return redirect(url_for("schedule.item_detail", item_id=schedule.item.id))
def schedule_simple_update(item_id): item = AdItem.get(item_id) if not item: return jsonify({'msg': u"出错啦, 排期不存在"}) data = request.values.get('data') msg = "" status = 0 schedules_info = json.loads(data) flag = False for date_str, num in schedules_info.items(): _date = datetime.strptime(date_str, DATE_FORMAT).date() if not item.position.check_order_num(_date, num): msg = date_str + u"预订量超过最大可预订量" status = 1 if not status: for date_str, num in schedules_info.items(): _date = datetime.strptime(date_str, DATE_FORMAT).date() _schedule = item.schedule_by_date(_date) if _schedule: if num == 0: flag = True _schedule.delete() else: if _schedule.num != num: _schedule.num = num flag = True _schedule.save() elif num != 0: flag = True _schedule = AdSchedule.add(item, num, _date) if flag: if item.schedule_sum: item.change_to_previous_status() msg = u"排期修改成功!当前状态回退至上一状态!" if item.item_status == ITEM_STATUS_NEW: msg = u'排期更改成功!预下单状态不变更!' else: item.item_status = ITEM_STATUS_ARCHIVE item.save() msg = u"当前订单项所有排期总量为0,自动归档!" else: msg = u"当前订单项排期未做修改" return jsonify({'msg': msg, 'status': status})
def test_schedule(session): schedule = add_schedule() schedule2 = AdSchedule.get(schedule.id) assert schedule2 is not None
def get_export_items(_date): """所有该日期需要投放的排期, 广告单元索引""" schedules = AdSchedule.export_schedules(_date) return items_info_by_schedule(schedules)
def order_item(session): item = add_item(get_position(TEST_POSITION)) AdSchedule(item, 600, date.today()) user = User.get_by_email('*****@*****.**') AdItem.update_items_with_action([item], ITEM_STATUS_ACTION_PRE_ORDER, user)