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 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(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_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 = 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 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 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 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 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 test_agent(session): agent = add_agent('testagent') agent2 = Agent.get(agent.id) assert agent2.name == 'testagent'
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'))