示例#1
0
def calllogs():
    current_user = g.user
    store_id = get_or_set_store_id()

    from application.forms.calllog import CalllogSearchForm
    search_form = CalllogSearchForm(request.args)
    search_form.sales_filter.choices = get_sales_selection(store_id)

    query = dict()
    if search_form.start_date.data and search_form.start_date.data != '':
        query['start_date'] = search_form.start_date.data
    if search_form.end_date.data and search_form.end_date.data != '':
        query['end_date'] = search_form.end_date.data
    if search_form.sales_filter.data not in ('None', 'all'):
        query['sales_filter'] = search_form.sales_filter.data
    if search_form.keywords.data:
        query['keywords'] = search_form.keywords.data

    sort_params = SortMixin.get_order_query(search_form)
    if sort_params:
        query.update(sort_params)

    query.update(get_page_info(request))

    calllogs = Calllog.find_all_by_query_params_in_store(store_id, **query)
    return render_template('calllogs/calllogs.html', selected_menu=CALL_LOG, form=search_form,
                           calllogs=calllogs, back_endpoint=request.args.get('back_endpoint', None))
示例#2
0
文件: campaign.py 项目: sungitly/isr
def campaigns():
    current_user = g.user
    store_id = get_or_set_store_id()
    from application.forms.campaign import CampaignSearchForm
    form = CampaignSearchForm(request.args)

    type = form.type.data
    keywords = form.keywords.data
    days = None
    active = False
    if type == 'active-campaigns':
        days = 15
        active = True

    query = {
        'days': days,
        'active': active,
        'keywords': keywords,
    }

    sort_params = SortMixin.get_order_query(form)
    if sort_params:
        query.update(sort_params)
    query.update(get_page_info(request))

    campaigns = Campaign.find_all_by_store_in_recent_days_and_keywords(
        store_id, **query)

    return render_template('campaigns/campaigns.html',
                           selected_menu=CAMPAIGN_MGMT,
                           form=form,
                           campaigns=campaigns,
                           back_endpoint=request.args.get(
                               'back_endpoint', None))
示例#3
0
文件: user.py 项目: sungitly/isr
def morning_call():
    current_user = g.user
    store_id = get_or_set_store_id()

    today = datetime.date.today()
    yesterday = today - datetime.timedelta(days=1)
    orders_stats = dict()
    orders_stats['yesterday_orders_count'] = Order.count_orders_by_date_and_store(yesterday, store_id)
    orders_stats['current_month_orders_count'] = Order.count_orders_from_date_and_store(
        datetime.date.today().replace(day=1),
        store_id)
    current_month_ta = TaSetting.find_active_monthly_ta(today.year, today.month, store_id)
    orders_stats['current_month_target'] = current_month_ta.value if current_month_ta else 'N/A'

    sales_stats = User.get_all_sales_by_store_from_cache(long(store_id))
    yesterday_receptions = Reception.find_all_by_date_in_store(yesterday, store_id)
    today_appointments = Appointment.find_all_by_date_in_store(datetime.date.today(), store_id)

    rx_stats = dict()
    rx_stats['yesterday_incomplete_count'] = len(
        [x for x in yesterday_receptions if x._last_status_changer == 'system'])

    total_counts, sales_counts = calc_reception_counts(yesterday_receptions, sales_stats)

    for sale in sales_stats:
        sale.rx_count = sales_counts.get(sale.id, {'total': 0, 'new': 0, 'appt_new': 0, 'appt': 0, 'other': 0})

        populate_appt_count_agg_by_sale_and_type(today_appointments, sale)

    sales_stats.sort(key=lambda sale: sale.rx_count, reverse=True)

    appts_count = generate_appt_count_agg_by_type(today_appointments)
    recent_campaigns = Campaign.find_all_by_store_in_recent_days(store_id, 15)

    current_endpoint = 'user.morning_call'
    now = datetime.datetime.now()
    yesterday_datetime = now - datetime.timedelta(days=1)
    rx_base_url, rx_url_params = get_filter_link('receptions.receptions', yesterday_datetime, yesterday_datetime,
                                                 current_endpoint)
    rx_incomplete_params = rx_url_params.copy()
    rx_incomplete_params['incomplete'] = 'y'

    appt_base_url, appt_url_params = get_filter_link('appointments.appts', now, now, current_endpoint)

    order_base_url, order_url_params = get_filter_link('orders.orders', yesterday_datetime, yesterday_datetime,
                                                       current_endpoint)
    monthly_order_url_params = order_url_params.copy()
    monthly_order_url_params['start_date'] = datetime.date.today().replace(day=1).strftime(DATE_FORMAT)
    monthly_order_url_params['end_date'] = now.strftime(DATE_FORMAT)

    return render_template('user/salesmanager/morningcall.html', selected_menu=USER_MORNING_CALL,
                           orders_stats=orders_stats, sales_stats=sales_stats, appts_count=appts_count,
                           total_rx_count=total_counts, recent_campaigns=recent_campaigns,
                           recent_campaigns_count=len(recent_campaigns), current_month_ta=current_month_ta,
                           rx_base_url=rx_base_url, rx_url_params=rx_url_params, appt_base_url=appt_base_url,
                           appt_url_params=appt_url_params, rx_incomplete_params=rx_incomplete_params,
                           order_base_url=order_base_url, order_url_params=order_url_params,
                           monthly_order_url_params=monthly_order_url_params, rx_stats=rx_stats,
                           back_endpoint=request.args.get('back_endpoint', None))
示例#4
0
def download_inv():
    store_id = get_or_set_store_id()
    from application.docgen.docgen import generate_store_inventories_excel
    filename = generate_store_inventories_excel(
        store_id, Inventory.find_all_by_store_id_wo_pagination(store_id))
    from application.docgen.docgen import OUTPUT_FOLDER
    return send_from_directory(OUTPUT_FOLDER,
                               filename=filename,
                               as_attachment=True)
示例#5
0
def get_inventories():
    from application.models.inventory import Inventory
    from application.utils import CustomizedEncoder

    result = Inventory.find_all_by_store_id_wo_pagination(
        get_or_set_store_id())

    data = json.dumps(result, cls=CustomizedEncoder)

    resp = Response(response=data, status=200, mimetype="application/json")
    return (resp)
示例#6
0
文件: customer.py 项目: sungitly/isr
def customers():
    current_user = g.user
    store_id = get_or_set_store_id()

    from application.forms.customer import CustomerSearchForm
    search_form = CustomerSearchForm(request.args)
    search_form.intent_level_filter.choices = get_intent_level_selection(
        store_id)
    search_form.intent_car_ids_filter.choices = get_intent_car_ids_selection(
        store_id)
    search_form.last_instore_filter.choices = get_last_instore_selection(
        store_id)
    search_form.status_filter.choices = get_status_selection()
    search_form.sales_filter.choices = get_sales_selection(store_id)

    # build query
    query = dict()
    if search_form.intent_level_filter.data not in ('None', 'all'):
        query['intent_level'] = search_form.intent_level_filter.data
    if search_form.intent_car_ids_filter.data not in ('None', 'all'):
        query['intent_car_ids'] = search_form.intent_car_ids_filter.data
    if search_form.last_instore_filter.data not in ('None', 'all'):
        query['last_instore'] = search_form.last_instore_filter.data
    if search_form.status_filter.data not in ('None', 'all'):
        query['status'] = search_form.status_filter.data
    if search_form.keywords.data:
        query['keywords'] = search_form.keywords.data
    if search_form.sales_filter.data not in ('None', 'all'):
        query['sales_id'] = search_form.sales_filter.data

    if not current_user.has_role_in_current_store(USER_ROLE_STORE_MANAGER):
        query.pop('sales_id', None)

    # TODO:
    scope = current_user.getDataScope('customer', store_id)
    if scope:
        scope.pop('store_id', None)
        query.update(scope)

    sort_params = SortMixin.get_order_query(search_form)
    if sort_params:
        query.update(sort_params)

    query.update(get_page_info(request))

    customers_list = Customer.find_all_with_last_appt_by_query_params_in_store(
        store_id, **query)
    return render_template('customers/customers.html',
                           selected_menu=CUSTOMER_MGMT,
                           form=search_form,
                           customers=customers_list,
                           back_endpoint=request.args.get(
                               'back_endpoint', None))
示例#7
0
文件: campaign.py 项目: sungitly/isr
def edit_campaign(campaign_id):
    current_user = g.user
    store_id = get_or_set_store_id()

    campaign = Campaign.find_by_id_and_store(campaign_id, store_id)

    if not campaign:
        abort(404)

    return edit(
        CAMPAIGN_MGMT, campaign=campaign
    )  # render_template('campaigns/edit.html', selected_menu=CAMPAIGN_MGMT)
示例#8
0
文件: campaign.py 项目: sungitly/isr
def edit(selected_menu, campaign=None):
    current_user = g.user
    store_id = get_or_set_store_id()

    from application.forms.campaign import CampaignForm

    form = None
    campaign_cars = []
    if campaign:
        campaign_cars = campaign.related_cars.split(',')
        form = CampaignForm(obj=campaign)
    else:
        form = CampaignForm()

    lookup = Lookup.find_by_name_and_store(store_id, 'intent-car')

    if lookup:
        cars = LookupValue.find_all_by_lookup_id(lookup.id)
        form.related_cars.choices = [(car.code, car.value) for car in cars]

    if form.related_cars.choices is None:
        form.related_cars.choices = []

    if request.method == 'GET':
        form.related_cars.data = campaign_cars

    if request.method == 'POST' and form.validate_on_submit():
        if campaign is None:
            campaign = Campaign()
            campaign.store_id = store_id
        form.populate_obj(campaign)
        campaign.related_cars = u','.join(form.related_cars.data)
        campaign.save_and_flush()
        flash_success(gettext(u'campaign saved'))

        return redirect(url_for('campaigns.campaigns'))
        # form.
        # campaign = form.po
        # if form.validate_on_submit():
        # json_r = uc_login(form.username.data, form.password.data)
        #
        # if json_r and json_r['status'] == 0 and get_user_type(json_r) == 6:
        #     user = save_user_from_uc(json_r)
        #     add_user(user)
        #     return redirect(referer or url_for('user.dashboard'))
        #
        # flash_error(gettext(u'login failed'))

    return render_template('campaigns/edit.html',
                           selected_menu=selected_menu,
                           campaign=campaign,
                           form=form,
                           back_url=back_url(url_for('campaigns.campaigns')))
示例#9
0
def sales_consultant():
    if require_json():
        # stats_fields = ['total_customer_count', 'test_drive_customers_count']
        # stats = get_weekly_store_stats_between_dates(*extract_stats_params(), stats_names=stats_fields)
        stats = get_sales_stats(get_or_set_store_id(), [
            'total_rx_customer_count', 'total_orders_count',
            'total_customer_count', 'formal_customer_count',
            'instore_appt_count', 'closed_instore_appt_count',
            'test_drive_customer_count', 'avg_rx_duration',
            'total_deliver_count'
        ])
        return dump_json(stats)
    return render_template('stats/sc.html',
                           selected_menu=SM_SC,
                           back_endpoint=request.args.get(
                               'back_endpoint', None))
示例#10
0
文件: customer.py 项目: sungitly/isr
def view_details(cid):
    current_user = g.user
    store_id = get_or_set_store_id()

    customer = Customer.find_by_id_and_store(cid, store_id)

    if not customer:
        abort(404)

    orders = Order.find_all_by_customer_sales(customer.id)
    appts = Appointment.find_all_by_customer_sales(customer.id)
    receptions = Reception.find_all_by_customer_sales(customer.id)
    calllogs = Calllog.find_all_by_customer_id(customer.id)

    form = CustomerReassignForm()
    form.saleses_list.choices = get_sales_selection(store_id)

    if current_user.is_receptionist() or (
            current_user.is_sales()
            and current_user.is_role_in_store_id(store_id, 'manager') == False
            and customer.sales_id != current_user.id):
        abort(401)

    if request.method == 'GET':
        form.saleses_list.data = customer.sales_id

    if request.method == 'POST' and (
            form.saleses_list.data not in ('None', customer.sales_id)
            and current_user.is_role_in_store_id(store_id, 'manager')):
        customer.reassign(int(form.saleses_list.data))
        customer.save_and_flush()
        flash_success(u'重新分配成功')
        return redirect(url_for('customers.view_details',
                                cid=cid,
                                back_url=back_url(
                                    url_for('customers.customers'))),
                        code=303)

    return render_template('customers/detail.html',
                           selected_menu=CUSTOMER_MGMT,
                           customer=customer,
                           orders=orders,
                           appts=appts,
                           receptions=receptions,
                           calllogs=calllogs,
                           form=form,
                           back_url=back_url(url_for('customers.customers')))
示例#11
0
文件: order.py 项目: sungitly/isr
def orders():
    store_id = request.args.get('store_id', None)
    if not store_id:
        store_id = get_or_set_store_id()

    from application.forms.order import OrderSearchForm
    search_form = OrderSearchForm(request.args)
    search_form.ordered_car_ids_filter.choices = get_intent_car_ids_selection(
        store_id)
    search_form.sales_filter.choices = get_sales_selection(store_id)
    search_form.status_filter.choices = get_status_selection()

    # build query
    query = dict()
    if search_form.start_date.data and search_form.start_date.data != '':
        query['start_date'] = search_form.start_date.data
    if search_form.end_date.data and search_form.end_date.data != '':
        query['end_date'] = search_form.end_date.data
    if search_form.ordered_car_ids_filter.data not in ('None', 'all'):
        query['ordered_car_ids'] = search_form.ordered_car_ids_filter.data
    if search_form.sales_filter.data not in ('None', 'all'):
        query['sales_id'] = search_form.sales_filter.data
    if search_form.status_filter.data not in ('None', 'all'):
        query['status'] = search_form.status_filter.data
    if search_form.keywords.data:
        query['keywords'] = search_form.keywords.data
    if search_form.history.data:
        query['history'] = search_form.history.data

    sort_params = SortMixin.get_order_query(search_form)
    if sort_params:
        query.update(sort_params)

    query.update(get_page_info(request))

    cancel_form = OrderCancelForm()

    orders_list = Order.find_all_by_query_params_in_store(store_id, **query)
    return render_template('orders/orders.html',
                           selected_menu=ORDERS_MGMT,
                           form=search_form,
                           orders=orders_list,
                           cancel_form=cancel_form,
                           back_endpoint=request.args.get(
                               'back_endpoint', None))
示例#12
0
def import_inv():
    if request.method == 'POST':
        upload_file = request.files['upload_file']
        if not upload_file or not allowed_file(upload_file.filename):
            flash_error(u'导入文件不存在或者不是合法的文件类型')
        else:
            origin_file_name = upload_file.filename
            store_id = get_or_set_store_id()
            gen_file_name = gen_inv_upload_file_path(store_id,
                                                     origin_file_name)
            upload_file.save(gen_file_name)

            import_his = InvImportHistory()
            import_his.origin_file = origin_file_name
            import_his.import_file = os.path.relpath(
                gen_file_name, current_app.config['INV_UPLOAD_FOLDER'])
            db.session.add(import_his)

            Inventory.save_from_excel(gen_file_name, store_id)
            flash_success(u'导入成功')
    return redirect(url_for('inventories.inventories'))
示例#13
0
文件: reception.py 项目: sungitly/isr
def receptions():
    current_user = g.user
    store_id = get_or_set_store_id()

    from application.forms.reception import RxSearchForm
    search_form = RxSearchForm(request.args)
    search_form.type_filter.choices = get_type_selection()
    search_form.sales_filter.choices = get_sales_selection(store_id)
    search_form.status_filter.choices = get_status_selection()

    query = dict()
    if search_form.start_date.data and search_form.start_date.data != '':
        query['start_date'] = search_form.start_date.data
    if search_form.end_date.data and search_form.end_date.data != '':
        query['end_date'] = search_form.end_date.data
    if search_form.type_filter.data and search_form.type_filter.data not in (
            'None', 'all'):
        query['type_filter'] = search_form.type_filter.data
    if search_form.sales_filter.data not in ('None', 'all'):
        query['sales_filter'] = search_form.sales_filter.data
    if search_form.incomplete.data:
        query['incomplete'] = search_form.incomplete.data
    if search_form.status_filter.data not in ('None', 'all'):
        query['status'] = search_form.status_filter.data

    sort_params = SortMixin.get_order_query(search_form)
    if sort_params:
        query.update(sort_params)
    query.update(get_page_info(request))

    receptions = Reception.find_all_by_query_params_in_store(store_id, **query)
    return render_template('receptions/receptions.html',
                           selected_menu=RX_VIEW,
                           form=search_form,
                           receptions=receptions,
                           back_endpoint=request.args.get(
                               'back_endpoint', None),
                           today=datetime.date.today())
示例#14
0
文件: appt.py 项目: sungitly/isr
def appts():
    current_user = g.user
    store_id = get_or_set_store_id()

    from application.forms.appt import ApptSearchForm
    search_form = ApptSearchForm(request.args)
    search_form.type_filter.choices = get_type_selection()
    search_form.status_filter.choices = get_status_selection()
    search_form.sales_filter.choices = get_sales_selection(store_id)

    query = dict()
    if search_form.start_date.data and search_form.start_date.data != '':
        query['start_date'] = search_form.start_date.data
    if search_form.end_date.data and search_form.end_date.data != '':
        query['end_date'] = search_form.end_date.data
    if search_form.type_filter.data and search_form.type_filter.data not in (
            'None', 'all'):
        query['type_filter'] = search_form.type_filter.data
    if search_form.status_filter.data and search_form.status_filter.data not in (
            'None', 'all'):
        query['status'] = search_form.status_filter.data
    if search_form.sales_filter.data and search_form.sales_filter.data not in (
            'None', 'all'):
        query['sales_filter'] = search_form.sales_filter.data

    sort_params = SortMixin.get_order_query(search_form)
    if sort_params:
        query.update(sort_params)

    query.update(get_page_info(request))

    appts = Appointment.find_all_by_query_params_in_store(store_id, **query)
    return render_template('appts/appts.html',
                           selected_menu=APPTS_VIEW,
                           form=search_form,
                           back_endpoint=request.args.get(
                               'back_endpoint', None),
                           appts=appts)
示例#15
0
文件: order.py 项目: sungitly/isr
def cancel_order():
    current_user = g.user
    store_id = get_or_set_store_id()
    form = OrderCancelForm()

    if form.order_id.data is None or int(form.order_id.data) < 1:
        flash_error(u'订单信息错误,请选择需要取消的订单')
    else:
        order = Order.find_by_id_and_store(form.order_id.data, store_id)

        if not order:
            abort(404)

        if order and order.status not in ('delivered', 'cancelled'):
            order.status = 'cancelled'
            order.save_and_flush()
            flash_success(u'订单已取消')
        elif order:
            flash_error(u'订单已交车或已取消')
        else:
            flash_error(u'找不到需要取消的订单')

    return redirect(url_for('orders.orders'))
示例#16
0
    def _get_menu_items(role_titles):
        menu_items = []
        # combine roles menu
        for role in role_titles:
            role_menu_items_list = [
                m for m in _role_to_endpoint_menu if m.role == role
            ]
            if len(role_menu_items_list) == 0:
                continue
            else:
                menu_items = menu_items + [
                    m for m in role_menu_items_list[0].menu
                    if m not in menu_items
                ]

        if len(menu_items) > 0:
            # hack to move setting menu to the end
            if L1_SETTINGS in menu_items:
                menu_items.remove(L1_SETTINGS)
                menu_items.append(L1_SETTINGS)
                # if both L1 and L2 settings exist. Remove L2 settings
                if L2_SETTINGS in menu_items:
                    menu_items.remove(L2_SETTINGS)
            elif L2_SETTINGS in menu_items:
                menu_items.remove(L2_SETTINGS)
                menu_items.append(L2_SETTINGS)

            if L1_RADAR in menu_items:
                from application.session import get_or_set_store_id
                current_store_id = get_or_set_store_id()
                from application.models.setting import StoreSetting
                if not StoreSetting.is_radar_avail(current_store_id):
                    menu_items.remove(L1_RADAR)

            return menu_items
        else:
            return _role_to_endpoint_menu_default.menu
示例#17
0
文件: user.py 项目: sungitly/isr
def evening_call():
    current_user = g.user
    store_id = get_or_set_store_id()

    today = datetime.date.today()
    orders_stats = dict()
    orders_stats['today_orders_count'] = Order.count_orders_by_date_and_store(datetime.date.today(), store_id)
    orders_stats['current_month_orders_count'] = Order.count_orders_from_date_and_store(
        datetime.date.today().replace(day=1),
        store_id)
    current_month_ta = TaSetting.find_active_monthly_ta(today.year, today.month, store_id)
    orders_stats['current_month_target'] = current_month_ta.value if current_month_ta else 'N/A'

    sales_stats = User.get_all_sales_by_store_from_cache(long(store_id))
    today_receptions = Reception.find_all_of_today_in_store(store_id)
    today_appointments = Appointment.find_all_by_date_in_store(datetime.date.today(), store_id)
    tomorrow_appointments = Appointment.find_all_by_date_in_store(datetime.date.today() + datetime.timedelta(days=1),
                                                                  store_id)
    total_counts, sales_counts = calc_reception_counts(today_receptions, sales_stats)

    for sale in sales_stats:
        populate_appt_count_agg_by_sale_and_type(today_appointments, sale, include_closed=True)
        populate_appt_count_agg_by_sale_and_type(tomorrow_appointments, sale, attr_prefix='tomorrow_')
        sale.rx_count = sales_counts.get(sale.id, {'total': 0, 'new': 0, 'appt_new': 0, 'appt': 0, 'other': 0})

    appts_count = generate_appt_count_agg_by_type(today_appointments, include_closed=True)
    tomorrow_appts_count = generate_appt_count_agg_by_type(tomorrow_appointments)

    sales_stats.sort(key=lambda sale: sale.rx_count, reverse=True)

    rx_stats = {'today_incomplete_count': len([x for x in today_receptions if x.status != 'completed'])}

    appt_stats = dict()
    appt_stats['instore'] = len([x for x in today_appointments if x.status != 'cancelled' and x.type == 'instore'])
    appt_stats['open_instore'] = len([x for x in today_appointments if x.status == 'opened' and x.type == 'instore'])
    appt_stats['followup'] = len([x for x in today_appointments if x.type == 'followup'])
    appt_stats['open_followup'] = len([x for x in today_appointments if x.status == 'opened' and x.type == 'followup'])

    now = datetime.datetime.now()
    tomorrow_datetime = now + datetime.timedelta(days=1)
    current_endpoint = 'user.evening_call'

    rx_base_url, rx_url_params = get_filter_link('receptions.receptions', now, now, current_endpoint)
    rx_incomplete_params = rx_url_params.copy()
    rx_incomplete_params['status_filter'] = 'in-store'
    appt_base_url, appt_url_params = get_filter_link('appointments.appts', now, now, current_endpoint)

    tomorrow_appt_base_url, tomorrow_appt_url_params = get_filter_link('appointments.appts', tomorrow_datetime,
                                                                       tomorrow_datetime,
                                                                       current_endpoint)

    recent_campaigns = Campaign.find_all_by_store_in_recent_days(store_id, 15)

    order_base_url, order_url_params = get_filter_link('orders.orders', now, now, current_endpoint)
    monthly_order_url_params = order_url_params.copy()
    monthly_order_url_params['start_date'] = datetime.date.today().replace(day=1).strftime(DATE_FORMAT)
    monthly_order_url_params['end_date'] = now.strftime(DATE_FORMAT)

    return render_template('user/salesmanager/eveningcall.html', selected_menu=USER_EVENING_CALL, rx_stats=rx_stats,
                           orders_stats=orders_stats, today_receptions_count=len(today_receptions),
                           rx_incomplete_params=rx_incomplete_params,
                           sales_stats=sales_stats, appts_count=appts_count, total_rx_count=total_counts,
                           tomorrow_appts_count=tomorrow_appts_count, recent_campaigns=recent_campaigns,
                           recent_campaigns_count=len(recent_campaigns), rx_base_url=rx_base_url,
                           rx_url_params=rx_url_params, order_base_url=order_base_url,
                           tomorrow_appt_base_url=tomorrow_appt_base_url,
                           tomorrow_appt_url_params=tomorrow_appt_url_params,
                           order_url_params=order_url_params, appt_stats=appt_stats, appt_base_url=appt_base_url,
                           appt_url_params=appt_url_params,
                           monthly_order_url_params=monthly_order_url_params,
                           back_endpoint=request.args.get('back_endpoint', None))
示例#18
0
def extract_stats_params():
    return parse(request.args.get('start')), parse(
        request.args.get('end')), get_or_set_store_id()
示例#19
0
def set_target():
    store_id = get_or_set_store_id()
    current_year = datetime.datetime.now().isocalendar()[0]
    monthly_form = TAForm(prefix='monthly')
    monthly_form.type.data = 'monthly'

    weekly_form = TAForm(prefix='weekly')
    weekly_form.type.data = 'weekly'

    if monthly_form.validate_on_submit():
        setting_date = parse(monthly_form.date.data)
        year = setting_date.year
        month = setting_date.month

        existing_ta_settings = TaSetting.find_all_active_monthly_ta(
            year, month, store_id)
        for setting in existing_ta_settings:
            setting.is_deleted = 1

        ta_setting = TaSetting(type='monthly',
                               year=year,
                               month=month,
                               value=monthly_form.ta.data,
                               store_id=store_id)
        ta_setting.save()

        monthly_form.date.data = ''
        monthly_form.ta.data = ''
        return redirect(url_for('settings.set_target'))

    if weekly_form.validate_on_submit():
        setting_date = parse(weekly_form.date.data)
        year = setting_date.year
        week = setting_date.isocalendar()[1]

        existing_ta_settings = TaSetting.find_all_active_weekly_ta(
            year, week, store_id)
        for setting in existing_ta_settings:
            setting.is_deleted = 1

        ta_setting = TaSetting(type='weekly',
                               year=year,
                               week=week,
                               value=weekly_form.ta.data,
                               store_id=store_id)
        ta_setting.save()

        weekly_form.date.data = ''
        weekly_form.ta.data = ''
        return redirect(url_for('settings.set_target'))

    monthly_ta_settings = TaSetting.find_all_active_by_type_and_store(
        'monthly', store_id)
    weekly_ta_settings = TaSetting.find_all_active_by_type_and_store(
        'weekly', store_id)

    return render_template('settings/ta.html',
                           selected_menu=TARGET_SETTINGS,
                           monthly_form=monthly_form,
                           weekly_form=weekly_form,
                           current_year=current_year,
                           monthly_ta_settings=monthly_ta_settings,
                           weekly_ta_settings=weekly_ta_settings,
                           back_endpoint=request.args.get(
                               'back_endpoint', None))
示例#20
0
def inventories():
    inv_status_items = build_inv_status_items(get_or_set_store_id())
    return render_template('inventories/inventories.html',
                           selected_menu=INV_MGMT,
                           inv_status_items=inv_status_items)
示例#21
0
文件: mmgmt.py 项目: sungitly/isr
def stats_summary():
    now = datetime.datetime.now()
    today = datetime.date.today()
    first_day_of_currrent_month = datetime.date.today().replace(day=1)
    store_id = get_or_set_store_id()
    current_endpoint = 'mmgmt.stats_summary'

    orders_stats = dict()
    orders_stats['today_orders_count'] = Order.count_orders_by_date_and_store(
        today, store_id)
    orders_stats[
        'today_delivered_count'] = Order.count_delivered_orders_between_date_and_store(
            store_id, today, today)
    orders_stats[
        'current_month_delivered_count'] = Order.count_delivered_orders_between_date_and_store(
            store_id, first_day_of_currrent_month, today)
    orders_stats['undelivered_count'] = Order.count_all_new_orders_by_store(
        store_id)

    # inv_status = dict()
    # inv_status['total_inv'] = ?

    rx_stats = dict()
    from application.models.reception import Reception
    today_receptions = Reception.find_all_of_today_in_store(store_id)
    rx_stats['rx_new'] = len(
        [rx for rx in today_receptions if rx.rx_type == 'new'])
    rx_stats['rx_appt_new'] = len(
        [rx for rx in today_receptions if rx.rx_type == 'appt_new'])
    rx_stats['rx_appt'] = len(
        [rx for rx in today_receptions if rx.rx_type == 'appt'])
    rx_stats['rx_other'] = len(
        [rx for rx in today_receptions if rx.rx_type == 'other'])

    rx_stats['rx_total'] = len(today_receptions)
    rx_stats['rx_instore'] = len(
        [rx for rx in today_receptions if rx.status != 'completed'])

    rx_base_url, rx_url_params = get_filter_link('receptions.receptions', now,
                                                 now, current_endpoint)
    order_base_url, order_url_params = get_filter_link('orders.orders', now,
                                                       now, current_endpoint)

    monthly_delivered_order_url_params = order_url_params.copy()
    monthly_delivered_order_url_params.update({
        'start_date':
        datetime.date.today().replace(day=1).strftime(DATE_FORMAT)
    })
    monthly_delivered_order_url_params['status_filter'] = 'delivered'
    monthly_delivered_order_url_params['history'] = 'y'

    all_new_order_url_params = order_url_params.copy()
    all_new_order_url_params['start_date'] = ''
    all_new_order_url_params['end_date'] = ''
    all_new_order_url_params['status_filter'] = 'new'

    return render_template(
        'mmgmt/summary.html',
        today_str=format_date_zh(datetime.date.today()),
        orders_stats=orders_stats,
        rx_stats=rx_stats,
        rx_base_url=rx_base_url,
        rx_url_params=rx_url_params,
        order_base_url=order_base_url,
        order_url_params=order_url_params,
        monthly_delivered_order_url_params=monthly_delivered_order_url_params,
        all_new_order_url_params=all_new_order_url_params)
示例#22
0
 def has_role_in_current_store(self, role):
     from application.session import get_or_set_store_id
     return self.is_role_in_store_id(get_or_set_store_id(), role)
示例#23
0
文件: user.py 项目: sungitly/isr
def dashboard():
    current_user = g.user
    now = datetime.datetime.now()
    store_id = get_or_set_store_id()
    orders_stats = dict()
    orders_stats['today_orders_count'] = Order.count_orders_by_date_and_store(datetime.date.today(), store_id)
    orders_with_status = Order.find_orders_status_from_date_and_store(datetime.date.today().replace(day=1), store_id)
    orders_stats['current_month_new_count'] = len(
        [x for x in orders_with_status if x.status == 'new'])
    orders_stats['current_month_delivered_count'] = Order.count_delivered_orders_between_date_and_store(store_id,
                                                                                                        get_first_day_of_month(
                                                                                                            now).date(),
                                                                                                        now.date())

    customer_stats = dict()
    today_receptions = Reception.find_all_of_today_in_store(store_id)
    completed_reception = filter(lambda rx: rx.status == 'completed', today_receptions)
    customer_stats['total'] = len(today_receptions) if today_receptions else 0
    customer_stats['complete'] = len(completed_reception) if completed_reception else 0
    customer_stats['instore'] = customer_stats['total'] - customer_stats['complete']
    customer_stats['new'] = len([x for x in today_receptions if x.rx_type == 'new'])
    customer_stats['appt_new'] = len([x for x in today_receptions if x.rx_type == 'appt_new'])
    customer_stats['appt'] = len([x for x in today_receptions if x.rx_type == 'appt'])
    customer_stats['other'] = len([x for x in today_receptions if x.rx_type == 'other'])

    today_appointments = Appointment.find_all_by_date_in_store(datetime.date.today(), store_id)
    appt_stats = dict()
    appt_stats['instore'] = len([x for x in today_appointments if x.status != 'cancelled' and x.type == 'instore'])
    appt_stats['open_instore'] = len([x for x in today_appointments if x.status == 'opened' and x.type == 'instore'])
    appt_stats['followup'] = len([x for x in today_appointments if x.type == 'followup'])
    appt_stats['open_followup'] = len([x for x in today_appointments if x.status == 'opened' and x.type == 'followup'])

    sales = User.get_all_sales_by_store_from_cache(long(store_id))
    # make sure the status is correct
    SalesStatus.reset_all_sales_status(store_id)
    sales_status = SalesStatus.get_all_sales_status(store_id)

    total_counts, reception_counts = calc_reception_counts(today_receptions, sales)

    for sale in sales:
        sale.status = sales_status.get(str(sale.id), 'free')
        set_status_label_and_style(sale)
        sale.rx_count = reception_counts.get(sale.id, {'total': 0, 'new': 0, 'appt_new': 0, 'appt': 0, 'other': 0})
    # receptions_per_sale = filter(lambda rx: rx.sales_id == sale.id, today_receptions)
    #     sale.rx_count = len(receptions_per_sale) if receptions_per_sale else 0
    #     total_rx_count += sale.rx_count

    sales.sort(key=lambda sale: sale.status)

    today_orders = Order.find_all_created_today_by_store(store_id)
    today_orders_count = len(today_orders) if today_orders else 0

    current_endpoint = 'user.dashboard'
    rx_base_url, rx_url_params = get_filter_link('receptions.receptions', now, now, current_endpoint)
    order_base_url, order_url_params = get_filter_link('orders.orders', now, now, current_endpoint)
    monthly_order_url_params = order_url_params.copy()
    monthly_order_url_params.update({'start_date': datetime.date.today().replace(day=1).strftime(DATE_FORMAT)})
    monthly_delivered_order_url_params = monthly_order_url_params.copy()
    monthly_delivered_order_url_params['status_filter'] = 'delivered'
    monthly_delivered_order_url_params['history'] = 'y'
    appt_base_url, appt_url_params = get_filter_link('appointments.appts', now, now, current_endpoint)
    # tbc_orders = Order.find_all_in_status_by_store(store_id, confirmed=0, status='new')

    return render_template('user/salesmanager/dashboard.html', selected_menu=USER_RT_DATA, orders_stats=orders_stats,
                           appt_stats=appt_stats,
                           customer_stats=customer_stats, sales=sales, today_orders=today_orders,
                           total_count=total_counts, today_orders_count=today_orders_count,
                           sales_receptions=reception_counts, rx_base_url=rx_base_url, rx_url_params=rx_url_params,
                           order_base_url=order_base_url, order_url_params=order_url_params,
                           monthly_order_url_params=monthly_order_url_params,
                           monthly_delivered_order_url_params=monthly_delivered_order_url_params,
                           appt_base_url=appt_base_url,
                           appt_url_params=appt_url_params)