def new_agent(): if not (g.user.is_contract() or g.user.is_super_leader()): abort(403) form = NewAgentForm(request.form) if request.method == 'POST' and form.validate(): db_agent_name = Agent.name_exist(form.name.data) if not db_agent_name: agent = Agent.add(form.name.data, Group.get(form.group.data), form.tax_num.data, form.address.data, form.phone_num.data, form.bank.data, form.bank_num.data, form.contact.data, form.contact_phone.data) flash(u'新建代理/直客(%s)成功!' % agent.name, 'success') else: flash(u'新建代理/直客(%s)失败, 名称已经被占用!' % form.name.data, 'danger') return tpl('/client/agent/info.html', form=form, title=u"新建代理公司", status='news') agent.add_comment(g.user, u"新建了代理: %s\n\n税号:%s\n\n地址:%s\n\n电话:%s\n\n开户行:%s\n\n\ 银行账号:%s\n\n内部联系人:%s\n\n内部联系人电话:%s\n\n" % (agent.name, agent.tax_num, agent.address, agent.phone_num, agent.bank, agent.bank_num, agent.contact, agent.contact_phone), msg_channel=13) return redirect(url_for("client.agents")) return tpl('/client/agent/info.html', form=form, status='news', title=u"新建代理/直客")
def __init__(self, *args, **kwargs): super(ClientMediumOrderForm, self).__init__(*args, **kwargs) self.agent.choices = [(m.id, m.name) for m in Agent.all()] self.client.choices = [(c.id, c.name) for c in Client.all()] self.direct_sales.choices = [(m.id, m.name) for m in User.sales()] self.agent_sales.choices = [(m.id, m.name) for m in User.sales()] self.assistant_sales.choices = [(m.id, m.name) for m in User.sales()] operaters = User.gets_by_team_type( TEAM_TYPE_OPERATER) + User.gets_by_team_type( TEAM_TYPE_OPERATER_LEADER) self.operaters.choices = [(m.id, m.name) for m in operaters] self.operaters.hidden = True self.designers.choices = [ (m.id, m.name) for m in User.gets_by_team_type(TEAM_TYPE_DESIGNER) ] self.designers.hidden = True self.planers.choices = [ (m.id, m.name) for m in User.gets_by_team_type(TEAM_TYPE_PLANNER) ] self.planers.hidden = True self.sale_CPM.hidden = True self.medium_CPM.hidden = True self.contract_type.choices = CONTRACT_TYPE_CN.items() self.resource_type.choices = RESOURCE_TYPE_CN.items() self.sale_type.choices = SALE_TYPE_CN.items() self.medium_group.choices = [(m.id, m.name) for m in MediumGroup.all()] self.medium.choices = [(m.id, m.name) for m in Medium.all()]
def agent_rebate(agent_id): agent = Agent.get(agent_id) rebates = AgentRebate.query.filter_by(agent=agent) medium_rebates = AgentMediumRebate.query.filter_by(agent=agent) return tpl('/client/agent/rebate/index.html', agent=agent, rebates=rebates, medium_rebates=medium_rebates)
def agent_medium_rebate_delete(agent_id, rebate_id): rebate = AgentMediumRebate.get(rebate_id) agent = Agent.get(agent_id) agent.add_comment(g.user, u"删除了媒体返点信息: 所属媒体:%s 执行年:%s 返点信息:%s%%" % (rebate.medium.name, rebate.year.year, str(rebate.rebate)), msg_channel=9) rebate.delete() return redirect(url_for('client.agent_rebate', agent_id=agent_id))
def agent_rebate_delete(agent_id, rebate_id): rebate = AgentRebate.get(rebate_id) agent = Agent.get(agent_id) agent.add_comment(g.user, u"删除了返点信息: 执行年:%s 致趣返点信息:%s%% 豆瓣返点信息:%s%%" % (rebate.year.year, str(rebate.inad_rebate), str(rebate.douban_rebate)), msg_channel=9) rebate.delete() return redirect(url_for('client.agent_rebate', agent_id=agent_id))
def index(): if not g.user.is_super_admin(): abort(403) form = FrameworkOrderForm(request.form) if request.method == 'POST' and form.validate(): order = FrameworkOrder.add(group=Group.get(form.group.data), agents=Agent.gets(form.agents.data), description=form.description.data, money=int( round(float(form.money.data or 0))), client_start=form.client_start.data, client_end=form.client_end.data, reminde_date=form.reminde_date.data, direct_sales=User.gets( form.direct_sales.data), agent_sales=User.gets(form.agent_sales.data), contract_type=form.contract_type.data, creator=g.user, contract_status=2, contract=request.values.get('contract'), create_time=datetime.now()) order.add_comment(g.user, u"导入了框架订单") flash(u'导入框架订单成功', 'success') return redirect(order.info_path()) else: form.client_start.data = datetime.now().date() form.client_end.data = datetime.now().date() form.reminde_date.data = datetime.now().date() return tpl('insert_framework_order.html', form=form)
def rebate_agent_douban_by_month(self, year, month): if self.medium_id == 3: try: rebate = Agent.get(94).douban_rebate_by_year(year) except: rebate = 0 elif self.medium_id == 8: try: rebate = Agent.get(105).douban_rebate_by_year(year) except: rebate = 0 else: rebate = 0 ex_money = self.get_executive_report_medium_money_by_month( year, month, 'normal')['medium_money2'] return round(ex_money * rebate / 100, 2)
def index(): if not g.user.is_super_admin(): abort(403) form = ClientOrderForm(request.form) mediums = [(m.id, m.name) for m in Medium.all()] if request.method == 'POST' and form.validate(): if ClientOrder.query.filter_by(contract=request.values.get('contract')).count() > 0: flash(u'合同号已存在', 'danger') return redirect(url_for('util_insert_orders.index')) order = ClientOrder.add(agent=Agent.get(form.agent.data), client=Client.get(form.client.data), campaign=form.campaign.data, money=int("%.0f" % (form.money.data or 0)), client_start=form.client_start.data, client_end=form.client_end.data, reminde_date=form.reminde_date.data, direct_sales=User.gets(form.direct_sales.data), agent_sales=User.gets(form.agent_sales.data), contract_type=form.contract_type.data, resource_type=form.resource_type.data, sale_type=form.sale_type.data, contract=request.values.get('contract', ''), creator=g.user, contract_status=2, create_time=datetime.now()) order.add_comment(g.user, u"导入了客户订单:%s - %s - %s" % ( order.agent.name, order.client.name, order.campaign )) medium_ids = request.values.getlist('medium') medium_moneys = request.values.getlist('medium_money') medium_moneys2 = request.values.getlist('medium_money2') medium_contracts = request.values.getlist('medium_contract') if medium_ids and medium_moneys and len(medium_ids) == len(medium_moneys): for x in range(len(medium_ids)): medium = Medium.get(medium_ids[x]) mo = Order.add(campaign=order.campaign, medium=medium, sale_money=int("%.0f" % (form.money.data or 0)), medium_money=int(medium_moneys[x] or 0), medium_money2=int(medium_moneys2[x] or 0), medium_contract=medium_contracts[x], medium_start=order.client_start, medium_end=order.client_end, creator=g.user) order.medium_orders = order.medium_orders + [mo] order.add_comment(g.user, u"导入了媒体订单: %s %s元" % (medium.name, mo.sale_money)) order.save() flash(u'导入客户订单成功!', 'success') insert_executive_report(order, '') return redirect(order.info_path()) else: form.client_start.data = datetime.now().date() form.client_end.data = datetime.now().date() form.reminde_date.data = datetime.now().date() return tpl('insert_order.html', form=form, mediums=mediums)
def douban_order_json(): if not (g.user.is_super_leader() or g.user.is_aduit() or g.user.is_finance()): abort(403) now_date = datetime.datetime.now() location = int(request.values.get('location', 0)) start_year = str(request.values.get('start_year', now_date.year)) start_month = str(request.values.get('start_month', now_date.month)) end_year = str(request.values.get('end_year', now_date.year - 1)) end_month = str(request.values.get('end_month', now_date.month)) start_date_month = datetime.datetime.strptime( start_year + '-' + start_month, '%Y-%m') end_date_month = datetime.datetime.strptime(end_year + '-' + end_month, '%Y-%m') douban_orders = DoubanOrderExecutiveReport.query.filter( DoubanOrderExecutiveReport.month_day >= start_date_month, DoubanOrderExecutiveReport.month_day <= end_date_month) medium_orders = MediumOrderExecutiveReport.query.filter( MediumOrderExecutiveReport.month_day >= start_date_month, MediumOrderExecutiveReport.month_day <= end_date_month) medium_orders = [_format_order(k) for k in medium_orders if k.status == 1] medium_date = [{ 'agent_name': k['agent'].name, 'medium_id': k['medium_id'], 'money': _get_money_by_location(k, location) } for k in medium_orders if k['medium_id'] in [3, 8]] douban_orders = [ _format_order(k, 'douban') for k in douban_orders if k.status == 1 ] douban_date = [{ 'agent_name': k['agent'].name, 'money': _get_money_by_location(k, location) } for k in douban_orders] agent_params = {} for k in Agent.all(): agent_params[k.name] = 0 for k in douban_date + medium_date: if k['agent_name'] in agent_params: agent_params[k['agent_name']] += k['money'] agent_params = sorted(agent_params.iteritems(), key=lambda x: x[1]) agent_params.reverse() data = [{"name": u"占比", "data": []}] sum_saler_money = sum([v for k, v in agent_params]) for k, v in agent_params: if v > 0: if sum_saler_money == 0: percent = u'0.00%' else: percent = v / sum_saler_money * 100 data[0]['data'].append({'name': k, 'y': v, 'percent': percent}) return jsonify({ 'data': data, 'title': u'直签豆瓣订单(含:优力、无线)代理分析', 'total': float(sum_saler_money) })
def __init__(self, *args, **kwargs): super(FrameworkOrderForm, self).__init__(*args, **kwargs) self.agents.choices = [(a.id, a.name) for a in Agent.all()] self.group.choices = [(g.id, g.name) for g in Group.all()] self.direct_sales.choices = [(m.id, m.name) for m in User.sales()] self.agent_sales.choices = [(m.id, m.name) for m in User.sales()] self.assistant_sales.choices = [(m.id, m.name) for m in User.sales()] self.contract_type.choices = CONTRACT_TYPE_CN.items()
def agents(): agents = Agent.all() agent_rebate = AgentRebate.all() agent_mediun_rebate = AgentMediumRebate.all() agent_rebate_data = {} for k in agent_rebate: if str(k.agent.id) + '_' + str(k.year.year) not in agent_rebate_data: agent_rebate_data[str(k.agent.id) + '_' + str(k.year.year)] = str(k.inad_rebate) + '%' agent_medium_rebate_data = {} for k in agent_mediun_rebate: if str(k.agent.id) + '_' + k.medium_name or '' + '_' + str(k.year.year) not in agent_rebate_data: agent_medium_rebate_data[str(k.agent.id) + '_' + k.medium_name + '_' + str(k.year.year)] = str(k.rebate) + '%' info = request.values.get('info', '') if info: agents = [k for k in agents if info in k.name] agent_data = [] for agent in agents: dict_agent = {} dict_agent['id'] = agent.id dict_agent['name'] = agent.name dict_agent['group_name'] = agent.group.name dict_agent['group_id'] = agent.group.id if str(agent.id) + '_2014' in agent_rebate_data: dict_agent['rebate_2014'] = agent_rebate_data[str(agent.id) + '_2014'] else: dict_agent['rebate_2014'] = u'无' if str(agent.id) + '_2015' in agent_rebate_data: dict_agent['rebate_2015'] = agent_rebate_data[str(agent.id) + '_2015'] else: dict_agent['rebate_2015'] = u'无' if str(agent.id) + '_2016' in agent_rebate_data: dict_agent['rebate_2016'] = agent_rebate_data[str(agent.id) + '_2016'] else: dict_agent['rebate_2016'] = u'无' dict_agent['mediums_rebate'] = [] agent_mediums = set([k.medium_name for k in agent_mediun_rebate if k.agent == agent]) for m in agent_mediums: m_dict = {} m_dict['name'] = m if str(agent.id) + '_' + m + '_2014' in agent_medium_rebate_data: m_dict['rebate_2014'] = agent_medium_rebate_data[str(agent.id) + '_' + m + '_2014'] else: m_dict['rebate_2014'] = u'无' if str(agent.id) + '_' + m + '_2015' in agent_medium_rebate_data: m_dict['rebate_2015'] = agent_medium_rebate_data[str(agent.id) + '_' + m + '_2015'] else: m_dict['rebate_2015'] = u'无' if str(agent.id) + '_' + m + '_2016' in agent_medium_rebate_data: m_dict['rebate_2016'] = agent_medium_rebate_data[str(agent.id) + '_' + m + '_2016'] else: m_dict['rebate_2016'] = u'无' dict_agent['mediums_rebate'].append(m_dict) agent_data.append(dict_agent) if request.values.get('action') == 'excel': return write_client_excel(agents=agent_data) return tpl('/client/agent/index.html', agents=agent_data, info=info)
def __init__(self, *args, **kwargs): super(ClientOrderForm, self).__init__(*args, **kwargs) self.agent.choices = [(m.id, m.name) for m in Agent.all()] self.client.choices = [(c.id, c.name) for c in Client.all()] self.direct_sales.choices = [(m.id, m.name) for m in User.sales()] self.agent_sales.choices = [(m.id, m.name) for m in User.sales()] self.assistant_sales.choices = [(m.id, m.name) for m in User.sales()] self.contract_type.choices = CONTRACT_TYPE_CN.items() self.resource_type.choices = RESOURCE_TYPE_CN.items() self.sale_type.choices = SALE_TYPE_CN.items()
def client_order_excle_data(): now_date = datetime.datetime.now() location = int(request.values.get('location', 0)) start_year = str(request.values.get('start_year', now_date.year)) start_month = str(request.values.get('start_month', now_date.month)) end_year = str(request.values.get('end_year', now_date.year - 1)) end_month = str(request.values.get('end_month', now_date.month)) start_date_month = datetime.datetime.strptime( start_year + '-' + start_month, '%Y-%m') end_date_month = datetime.datetime.strptime(end_year + '-' + end_month, '%Y-%m') medium_orders = MediumOrderExecutiveReport.query.filter( MediumOrderExecutiveReport.month_day >= start_date_month, MediumOrderExecutiveReport.month_day <= end_date_month) medium_orders = [_format_order(k) for k in medium_orders if k.status == 1] medium_date = [{ 'agent_name': k['agent'].name, 'money': _get_money_by_location(k, location) } for k in medium_orders] agent_params = {} for k in Agent.all(): agent_params[k.name] = 0 for k in medium_date: if k['agent_name'] in agent_params: agent_params[k['agent_name']] += k['money'] agent_params = sorted(agent_params.iteritems(), key=lambda x: x[1]) agent_params = [(k, v) for k, v in agent_params if v > 0] agent_params.reverse() headings = ['#', u'代理名称', u'执行额', u'占比'] data = [] data.append([k + 1 for k in range(len(agent_params))]) data.append([k for k, v in agent_params]) data.append([v for k, v in agent_params]) sum_saler_money = sum([v for k, v in agent_params]) if sum_saler_money: data.append( ['%.2f%%' % (v / sum_saler_money * 100) for k, v in agent_params]) else: data.append(['0.00%' for k, v in agent_params]) return { 'data': data, 'title': u'新媒体订单代理分析', 'total': float(sum_saler_money), 'headings': headings }
def agents(): clients = [] for k in Agent.all(): agent_licence_file = k.get_last_client_file(100) if agent_licence_file: licence_file = agent_licence_file.agent_path else: licence_file = '' agent_f_certifcate_file = k.get_last_client_file(101) if agent_f_certifcate_file: f_certifcate_file = agent_f_certifcate_file.agent_path else: f_certifcate_file = '' agent_o_certifcate_file = k.get_last_client_file(102) if agent_o_certifcate_file: o_certifcate_file = agent_o_certifcate_file.agent_path else: o_certifcate_file = '' agent_tax_certifcate_file = k.get_last_client_file(103) if agent_tax_certifcate_file: tax_certifcate_file = agent_tax_certifcate_file.agent_path else: tax_certifcate_file = '' agent_t_info_file = k.get_last_client_file(104) if agent_t_info_file: t_info_file = agent_t_info_file.agent_path else: t_info_file = '' agent_a_licence_file = k.get_last_client_file(105) if agent_a_licence_file: a_licence_file = agent_a_licence_file.agent_path else: a_licence_file = '' dict_agent = {} dict_agent['id'] = k.id dict_agent['name'] = k.name dict_agent['licence_file'] = licence_file dict_agent['f_certifcate_file'] = f_certifcate_file dict_agent['o_certifcate_file'] = o_certifcate_file dict_agent['tax_certifcate_file'] = tax_certifcate_file dict_agent['t_info_file'] = t_info_file dict_agent['a_licence_file'] = a_licence_file dict_agent['files'] = [f.agent_path for f in k.get_agent_attachments()] clients.append(dict_agent) return jsonify({'data': clients})
def index(): print g.user.is_contract() if not (g.user.is_super_admin() or g.user.is_contract()): abort(403) form = DoubanOrderForm(request.form) if request.method == 'POST' and form.validate(): if DoubanOrder.query.filter_by(contract=request.values.get('contract')).count() > 0: flash(u'合同号已存在', 'danger') return redirect(url_for('util_insert_douban_orders.index')) order = DoubanOrder.add(client=Client.get(form.client.data), agent=Agent.get(form.agent.data), campaign=form.campaign.data, money=int(round(float(form.money.data or 0))), medium_CPM=form.medium_CPM.data, sale_CPM=form.sale_CPM.data, client_start=form.client_start.data, client_end=form.client_end.data, reminde_date=form.reminde_date.data, direct_sales=User.gets(form.direct_sales.data), agent_sales=User.gets(form.agent_sales.data), operaters=User.gets(form.operaters.data), designers=User.gets(form.designers.data), planers=User.gets(form.planers.data), contract_type=form.contract_type.data, resource_type=form.resource_type.data, sale_type=form.sale_type.data, creator=g.user, contract=request.values.get('contract'), contract_status=2, create_time=datetime.now()) order.add_comment(g.user, u"导入了直签豆瓣订单:%s - %s - %s" % ( order.agent.name, order.client.name, order.campaign )) insert_executive_report(order, '') flash(u'导入订单成功', 'success') return redirect(order.info_path()) else: form.client_start.data = datetime.now().date() form.client_end.data = datetime.now().date() form.reminde_date.data = datetime.now().date() return tpl('insert_douban_order.html', form=form)
def new_invoice(order_id, redirect_endpoint='saler_client_order_agent_invoice.index'): order = ClientOrder.get(order_id) if not order: abort(404) form = AgentInvoiceForm(request.form) form.client_order.choices = [(order.id, order.client.name)] form.agent.choices = [(order.id, order.client.name) for k in order.agents] form.bool_invoice.choices = AGENT_INVOICE_BOOL_INVOICE_CN.items() # if order.agent_money < order.agents_invoice_sum + float(form.money.data): # flash(u'新建打款发票失败,发票超过代理总金额!', 'danger') # return redirect(url_for(redirect_endpoint, order_id=order_id)) if request.method == 'POST': invoice = AgentInvoice.add(client_order=order, agent=Agent.get(form.agent.data), company=form.company.data, tax_id=form.tax_id.data, address=form.address.data, phone=form.phone.data, bank_id=form.bank_id.data, bank=form.bank.data, detail=form.detail.data, money=form.money.data, pay_money=form.money.data, invoice_type=form.invoice_type.data, invoice_status=AGENT_INVOICE_STATUS_NORMAL, creator=g.user, invoice_num=form.invoice_num.data, add_time=form.add_time.data, bool_invoice=form.bool_invoice.data) invoice.save() flash(u'新建打款发票(%s)成功!' % form.company.data, 'success') order.add_comment( g.user, u"添加打款发票申请信息:%s" % (u'发票内容: %s; 发票金额: %s元; 发票号: %s' % (invoice.detail, str(invoice.money), invoice.invoice_num)), msg_channel=5) else: for k in form.errors: flash(u"新建打款发票失败,%s" % (form.errors[k][0]), 'danger') return redirect(url_for(redirect_endpoint, order_id=order_id))
def index(): print g.user.is_contract() if not (g.user.is_super_admin() or g.user.is_contract()): abort(403) form = DoubanOrderForm(request.form) if request.method == 'POST' and form.validate(): if DoubanOrder.query.filter_by( contract=request.values.get('contract')).count() > 0: flash(u'合同号已存在', 'danger') return redirect(url_for('util_insert_douban_orders.index')) order = DoubanOrder.add(client=Client.get(form.client.data), agent=Agent.get(form.agent.data), campaign=form.campaign.data, money=int(round(float(form.money.data or 0))), medium_CPM=form.medium_CPM.data, sale_CPM=form.sale_CPM.data, client_start=form.client_start.data, client_end=form.client_end.data, reminde_date=form.reminde_date.data, direct_sales=User.gets(form.direct_sales.data), agent_sales=User.gets(form.agent_sales.data), operaters=User.gets(form.operaters.data), designers=User.gets(form.designers.data), planers=User.gets(form.planers.data), contract_type=form.contract_type.data, resource_type=form.resource_type.data, sale_type=form.sale_type.data, creator=g.user, contract=request.values.get('contract'), contract_status=2, create_time=datetime.now()) order.add_comment( g.user, u"导入了直签豆瓣订单:%s - %s - %s" % (order.agent.name, order.client.name, order.campaign)) insert_executive_report(order, '') flash(u'导入订单成功', 'success') return redirect(order.info_path()) else: form.client_start.data = datetime.now().date() form.client_end.data = datetime.now().date() form.reminde_date.data = datetime.now().date() return tpl('insert_douban_order.html', form=form)
def agent_medium_rebate_create(agent_id): agent = Agent.get(agent_id) if request.method == 'POST': rebate = float(request.values.get('rebate', 0)) year = request.values.get( 'year', datetime.datetime.now().strftime('%Y')) now_year = datetime.datetime.strptime(year, '%Y').date() medium_name = request.values.get('medium_name', '') AgentMediumRebate.add(agent=agent, medium=Medium.get(1), medium_name=medium_name, rebate=rebate, year=now_year, creator=g.user, create_time=datetime.datetime.now()) flash(u'添加成功!', 'success') agent.add_comment(g.user, u"新建了媒体返点信息: 所属媒体:%s 执行年:%s 返点信息:%s%%" % (medium_name, year, str(rebate)), msg_channel=9) return redirect(url_for('client.agent_rebate', agent_id=agent_id)) return tpl('/client/agent/rebate/medium/create.html', agent=agent, medium_groups=MediumGroup.all())
def index(): if not (g.user.is_super_leader() or g.user.is_aduit() or g.user.is_finance()): abort(403) now_date = datetime.datetime.now() year = int(request.values.get('year', now_date.year)) orders = [_format_order(k, year) for k in ClientOrder.all()] orders = [k for k in orders if k['client_start'].year == year] # 去掉撤单、申请中的合同 orders = [k for k in orders if k['contract_status'] in [2, 4, 5, 10, 19, 20] and k['status'] == 1 and k['contract']] # 获取所有代理 agents = [{'name': a.name, 'id': a.id, 'group_id': a.group.id} for a in Agent.all()] # 获取代理集团 groups = [{'name': gp.name, 'agents': [p for p in agents if p['group_id'] == gp.id]} for gp in Group.all()] # xxx_count 用于html合并表单 agent_obj = [] total_is_sale_money = 0 total_is_medium_money = 0 for k in groups: if not k['agents']: html_order_count = 0 else: html_order_count = 1 excel_order_count = 0 agent_data = [] for a in k['agents']: order_data = [o for o in orders if o['agent_id'] == a['id']] if order_data: html_order_count += len(order_data) + 1 excel_order_count += len(order_data) total_is_sale_money += sum([o['is_sale_money'] for o in order_data]) total_is_medium_money += sum([o['is_medium_money'] for o in order_data]) agent_data.append({'name': a['name'], 'orders': order_data, 'html_order_count': len(order_data)}) if agent_data: agent_obj.append({'name': k['name'], 'agents': agent_data, 'html_order_count': html_order_count, 'excel_order_count': excel_order_count}) action = request.values.get('action', '') if action == 'excel': return write_agent_total_excel(year=year, agent_obj=agent_obj, total_is_sale_money=total_is_sale_money, total_is_medium_money=total_is_medium_money) return tpl('/data_query/super_leader/agent_total.html', year=year, agent_obj=agent_obj, total_is_sale_money=total_is_sale_money, total_is_medium_money=total_is_medium_money)
def files_upload(f_type, id): if f_type == 'medium_group': obj_data = MediumGroup.get(id) elif f_type == 'agent': obj_data = Agent.get(id) type = int(request.values.get('type', 5)) try: request.files['file'].filename.encode('gb2312') except: flash(u'文件名中包含非正常字符,请使用标准字符', 'danger') if f_type == 'medium_group': return redirect(url_for('client.medium_group_detail', medium_group_id=id)) elif f_type == 'agent': return redirect(url_for('client.agent_detail', agent_id=id)) filename = files_set.save(request.files['file']) obj_data.add_client_attachment(g.user, filename, type) flash(FILE_TYPE_CN[type] + u' 上传成功', 'success') if f_type == 'medium_group': return redirect(url_for('client.medium_group_detail', medium_group_id=id)) elif f_type == 'agent': return redirect(url_for('client.agent_detail', agent_id=id))
def agent_detail(agent_id): if not (g.user.is_contract() or g.user.is_super_leader() or g.user.is_finance()): abort(403) agent = Agent.get(agent_id) if not agent: abort(404) form = NewAgentForm(request.form) if request.method == 'POST' and form.validate(): agent.name = form.name.data agent.group = Group.get(form.group.data) agent.tax_num = form.tax_num.data agent.address = form.address.data agent.phone_num = form.phone_num.data agent.bank = form.bank.data agent.bank_num = form.bank_num.data agent.contact = form.contact.data agent.contact_phone = form.contact_phone.data agent.save() agent.add_comment(g.user, u"修改了代理: %s\n\n税号:%s\n\n地址:%s\n\n电话:%s\n\n开户行:%s\n\n\ 银行账号:%s\n\n内部联系人:%s\n\n内部联系人电话:%s\n\n" % (agent.name, agent.tax_num, agent.address, agent.phone_num, agent.bank, agent.bank_num, agent.contact, agent.contact_phone), msg_channel=13) flash(u'保存成功', 'success') else: form.name.data = agent.name form.group.data = agent.group.id if agent.group else None form.tax_num.data = agent.tax_num form.address.data = agent.address form.phone_num.data = agent.phone_num form.bank.data = agent.bank form.bank_num.data = agent.bank_num form.contact.data = agent.contact or "" form.contact_phone.data = agent.contact_phone or "" return tpl('/client/agent/info.html', form=form, agent=agent, status='update', title=u"代理/直客-" + agent.name, FILE_TYPE_CN=FILE_TYPE_CN)
def agent_rebate_create(agent_id): agent = Agent.get(agent_id) if request.method == 'POST': douban_rebate = float(request.values.get('douban_rebate', 0)) inad_rebate = float(request.values.get('inad_rebate', 0)) year = request.values.get( 'year', datetime.datetime.now().strftime('%Y')) now_year = datetime.datetime.strptime(year, '%Y').date() if AgentRebate.query.filter_by(agent=agent, year=now_year).count() > 0: flash(u'该执行年返点信息已存在!', 'danger') return tpl('/client/agent/rebate/create.html', agent=agent) AgentRebate.add(agent=agent, douban_rebate=douban_rebate, inad_rebate=inad_rebate, year=now_year, creator=g.user, create_time=datetime.datetime.now()) flash(u'添加成功!', 'success') agent.add_comment(g.user, u"新建了返点信息: 执行年:%s 致趣返点信息:%s%% 豆瓣返点信息:%s%%" % (year, str(inad_rebate), str(douban_rebate)), msg_channel=9) return redirect(url_for('client.agent_rebate', agent_id=agent_id)) return tpl('/client/agent/rebate/create.html', agent=agent)
def new_invoice(order_id, redirect_endpoint='saler_client_order_agent_invoice.index'): order = ClientOrder.get(order_id) if not order: abort(404) form = AgentInvoiceForm(request.form) form.client_order.choices = [(order.id, order.client.name)] form.agent.choices = [(order.id, order.client.name) for k in order.agents] form.bool_invoice.choices = AGENT_INVOICE_BOOL_INVOICE_CN.items() # if order.agent_money < order.agents_invoice_sum + float(form.money.data): # flash(u'新建打款发票失败,发票超过代理总金额!', 'danger') # return redirect(url_for(redirect_endpoint, order_id=order_id)) if request.method == 'POST': invoice = AgentInvoice.add(client_order=order, agent=Agent.get(form.agent.data), company=form.company.data, tax_id=form.tax_id.data, address=form.address.data, phone=form.phone.data, bank_id=form.bank_id.data, bank=form.bank.data, detail=form.detail.data, money=form.money.data, pay_money=form.money.data, invoice_type=form.invoice_type.data, invoice_status=AGENT_INVOICE_STATUS_NORMAL, creator=g.user, invoice_num=form.invoice_num.data, add_time=form.add_time.data, bool_invoice=form.bool_invoice.data) invoice.save() flash(u'新建打款发票(%s)成功!' % form.company.data, 'success') order.add_comment(g.user, u"添加打款发票申请信息:%s" % ( u'发票内容: %s; 发票金额: %s元; 发票号: %s' % (invoice.detail, str(invoice.money), invoice.invoice_num)), msg_channel=5) else: for k in form.errors: flash(u"新建打款发票失败,%s" % (form.errors[k][0]), 'danger') return redirect(url_for(redirect_endpoint, order_id=order_id))
def tax_info(agent_id): agent = Agent.get(agent_id) return jsonify(agent.tax_info)
def client_agent_upload(): agent_id = request.values.get('agent') agent = Agent.get(agent_id) return attachment_upload(agent, FILE_TYPE_AGENT)
def agent_delete(agent_id): Agent.get(agent_id).delete() flash(u'删除成功', 'success') return redirect(url_for('client.agents'))
def _into_order(param): group = Group.query.filter_by(name=u'默认集团').first() if not group: group = Group.add(name=u'默认集团') group.save() agent = Agent.query.filter_by(name=param['agent_name']).first() if not agent: agent = Agent.add( name=param['agent_name'], group=group, tax_num='', address='', phone_num='', bank='', bank_num='', ) client = Client.query.filter_by(name=param['client_name']).first() if not client: client = Client.add(name=param['client_name'], industry=1) # client.save() medium = Medium.query.filter_by(name=param['medium_name']).first() if not medium: medium = Medium.add(name=param['medium_name'], abbreviation=param['medium_name'], tax_num='', address='', phone_num='', bank='', bank_num='', owner=Team.query.filter_by(type=8).first()) team_huabei = Team.query.filter_by(name=u'导入渠道销售团队华北').first() if not team_huabei: team_huabei = Team.add( name=u'导入渠道销售团队华北', type=4, location=1, admins=[], ) team_huanan = Team.query.filter_by(name=u'导入渠道销售团队华南').first() if not team_huanan: team_huanan = Team.add( name=u'导入渠道销售团队华南', type=4, location=3, admins=[], ) team_huadong = Team.query.filter_by(name=u'导入渠道销售团队华东').first() if not team_huadong: team_huadong = Team.add( name=u'导入渠道销售团队华东', type=4, location=2, admins=[], ) team_qita = Team.query.filter_by(name=u'导入渠道销售团队其他').first() if not team_qita: team_qita = Team.add( name=u'导入渠道销售团队其他', type=4, location=0, admins=[], ) if not param['agent_sale_name']: agents = [] else: agent_names = param['agent_sale_name'].split(' ') agents = [] if param['location'] == u'华北': team = team_huabei elif param['location'] == u'华东': team = team_huadong elif param['location'] == u'华南': team = team_huanan else: team = team_qita for k in agent_names: name = k.strip() p_name = p.get_pinyin(name, '').lower() email = p_name + '@inad.com' user = User.query.filter_by(email=email).first() if not user: user = User.add(name, email, 'pwd@inad', team, 1) agents.append(user.id) if param['contract_type'].find(u'非标') >= 0: contract_type = 1 else: contract_type = 0 if param['resource_type'].find(u'硬广') >= 0: resource_type = 0 elif param['resource_type'].find(u'互动') >= 0: resource_type = 1 else: resource_type = 4 if param['sale_type'] == u'代理': sale_type = 0 else: sale_type = 1 if ClientOrder.query.filter_by(agent=agent, client=client, campaign=param['campaign'], status=1).first(): return order = ClientOrder.add( agent=agent, client=client, campaign=param['campaign'], money=param['money'], client_start=param['medium_start'], client_end=param['medium_end'], reminde_date=param['reminde_date'], direct_sales=[], agent_sales=User.gets(agents), contract_type=contract_type, resource_type=resource_type, sale_type=sale_type, creator=g.user, create_time=datetime.datetime.now(), ) order.add_comment( g.user, u"新建了客户订单:%s - %s - %s" % (order.agent.name, order.client.name, order.campaign)) mo = Order.add(campaign=order.campaign, medium=medium, sale_money=param['money'], medium_money=param['medium_money'], medium_money2=param['medium_money2'], medium_start=param['medium_start'], medium_end=param['medium_end'], creator=g.user) order.add_comment(g.user, u"新建了媒体订单: %s %s元" % (medium.name, mo.sale_money)) order.medium_orders = [mo] order.save() return
from app import app from libs.db import db db.create_all() from models.user import (User, Team, TEAM_TYPE_SUPER_ADMIN, TEAM_TYPE_MEDIUM, TEAM_TYPE_LEADER, TEAM_TYPE_DIRECT_SELLER) from models.medium import Medium, MediumGroup from models.client import Client, Agent, Group from models.order import Order from config import DEFAULT_PASSWORD admin_team = Team.add(u'管理员', type=TEAM_TYPE_SUPER_ADMIN) medium_team = Team.add(u'媒体', type=TEAM_TYPE_MEDIUM) leader_team = Team.add('ledaer', type=TEAM_TYPE_LEADER) sale_team = Team.add('ledaer', type=TEAM_TYPE_DIRECT_SELLER) user = User.add(name="admin", email="*****@*****.**", password=DEFAULT_PASSWORD, team=admin_team) leader = User.add(name="leader", email="*****@*****.**", password=DEFAULT_PASSWORD, team=leader_team) saler = User.add(name="saler", email="*****@*****.**", password=DEFAULT_PASSWORD, team=sale_team) medium_group = MediumGroup.add(name='测试媒体供应商', tax_num="", address="", phone_num="", bank="", bank_num="", level=100) medium = Medium.add(medium_group, u"测试媒体", owner=medium_team) client = Client.add(u"测试客户", 0) group = Group.add(u'测试代理集团') agent = Agent.add(u"测试代理", group=group)
def test_agent(session): agent = add_agent('testagent') agent2 = Agent.get(agent.id) assert agent2.name == 'testagent'
def add_agent(name): agent = Agent.add(name) return agent
def update(oid): out = Out.get(oid) joiners_form = JoinersForm(request.form) joiners_form.joiners.data = [u.id for u in out.joiners] m_persions = [] if g.user.is_out_saler: m_persions += [{'key': '1' + '-' + str(k.id) + '-' + k.name, 'name': k.name} for k in Client.all()] m_persions += [{'key': '2' + '-' + str(k.id) + '-' + k.name, 'name': k.name} for k in Agent.all()] m_persions += [{'key': '3' + '-' + str(k.id) + '-' + k.name, 'name': k.name} for k in Medium.all()] m_persions.append({'key': 100, 'name': u'其他'}) if request.method == 'POST': if g.user.is_out_saler: creator_type = 1 else: creator_type = 2 start_time = request.values.get('start_time', '') end_time = request.values.get('end_time', '') # m_person有两种类型,一种是其他所以填写,一种是代理+客户+媒体组合而成,例如:1-1,2-1,3-1(具体请查看m_persions) m_persion = request.values.get('m_persion', '') m_persion_type = int(request.values.get('m_persion_type', 1)) reason = request.values.get('reason', '') persions = request.values.get('persions', '') address = request.values.get('address', '') joiners = User.gets(request.values.getlist('joiners')) out.start_time = datetime.datetime.strptime( start_time, '%Y-%m-%d %H:%M') out.end_time = datetime.datetime.strptime(end_time, '%Y-%m-%d %H:%M') out.reason = reason out.joiners = joiners out.persions = persions out.address = address out.m_persion = m_persion out.m_persion_type = m_persion_type out.creator_type = creator_type out.status = int(request.values.get('action', 0)) out.create_time = datetime.datetime.now() out.save() # 先删除外出报表,在从新添加 OutReport.query.filter_by(out_id=oid).delete() for k in list(set(joiners + [out.creator])): OutReport.add( start_time=datetime.datetime.strptime( start_time, '%Y-%m-%d %H:%M'), end_time=datetime.datetime.strptime( end_time, '%Y-%m-%d %H:%M'), reason=reason, out=out, meeting_s='', persions=persions, address=address, m_persion=m_persion, m_persion_type=m_persion_type, creator_type=creator_type, status=int(request.values.get('action', 0)), creator=k, create_time=datetime.datetime.now() ) if int(int(request.values.get('action', 0))) == OUT_STATUS_APPLY: flash(u'已发送申请', 'success') account_out_apply_signal.send( current_app._get_current_object(), out=out, status=1) else: flash(u'添加成功,请及时申请外出报备', 'success') return redirect(url_for('account_out.index')) return tpl('/account/out/update.html', out=out, m_persions=m_persions, joiners_form=joiners_form)
leader_team = Team.add('ledaer', type=TEAM_TYPE_LEADER) sale_team = Team.add('ledaer', type=TEAM_TYPE_DIRECT_SELLER) user = User.add(name="admin", email="*****@*****.**", password=DEFAULT_PASSWORD, team=admin_team) leader = User.add(name="leader", email="*****@*****.**", password=DEFAULT_PASSWORD, team=leader_team) saler = User.add(name="saler", email="*****@*****.**", password=DEFAULT_PASSWORD, team=sale_team) medium_group = MediumGroup.add(name='测试媒体供应商', tax_num="", address="", phone_num="", bank="", bank_num="", level=100) medium = Medium.add(medium_group, u"测试媒体", owner=medium_team) client = Client.add(u"测试客户", 0) group = Group.add(u'测试代理集团') agent = Agent.add(u"测试代理", group=group)