def new_douban_outsource(): form = DoubanOutsourceForm(request.form) order = DoubanOrder.get(form.douban_order.data) try: int(form.num.data) except: flash(u'保存失败,金额必须为数字!', 'danger') return redirect(url_for("outsource.douban_outsources", order_id=order.id)) status = 0 if g.user.is_super_leader(): status = 2 outsource = DoubanOutSource.add(target=OutSourceTarget.get(form.target.data), douban_order=order, num=form.num.data, type=form.type.data, subtype=form.subtype.data, remark=form.remark.data, invoice=False, status=status, pay_num=form.num.data) flash(u'新建外包成功!', 'success') outsource.douban_order.add_comment(g.user, u"""新建外包:\n\r %s""" % outsource.name, msg_channel=2) if g.user.is_super_leader(): _insert_executive_report(order, rtype='reload') return redirect(outsource.info_path())
def target_detail(target_id): target = OutSourceTarget.get(target_id) if not target: abort(404) form = OutSourceTargetForm(request.form) if request.method == 'POST' and form.validate(): if OutSourceTarget.query.filter_by(name=form.name.data).first() and target.name != form.name.data: flash(u'修改失败,已存在该收款方!', 'danger') return redirect(url_for("outsource.target_detail", target_id=target_id)) target.name = form.name.data target.bank = form.bank.data target.card = form.card.data target.alipay = form.alipay.data target.contract = form.contract.data target.remark = form.remark.data target.type = form.type.data target.otype = form.otype.data target.save() flash(u'保存成功', 'success') else: form.name.data = target.name form.bank.data = target.bank form.card.data = target.card form.alipay.data = target.alipay form.contract.data = target.contract form.remark.data = target.remark form.type.data = target.type form.otype.data = target.otype or 1 return tpl('target.html', form=form, title=u"收款方-" + target.name)
def info(target_id): if not g.user.is_finance(): abort(404) if int(target_id) == 0: target = None apply_money_merger_outsources = list( MergerPersonalOutSource.query.filter_by(status=2)) paid_merger_outsources = list( MergerPersonalOutSource.query.filter_by(status=0)) else: target = OutSourceTarget.get(target_id) apply_money_merger_outsources = target.merger_client_order_outsources_by_status( 2) paid_merger_outsources = target.merger_client_order_outsources_by_status( 0) reminder_emails = [(u.name, u.email) for u in User.all_active()] return tpl('/finance/outsource/pay/info.html', target=target, reminder_emails=reminder_emails, apply_money_merger_outsources=apply_money_merger_outsources, paid_merger_outsources=paid_merger_outsources)
def merget_douban_target_info(target_id): target = OutSourceTarget.get(target_id) if request.method == 'POST': form = MergerOutSourceForm(request.form) outsource_ids = request.values.getlist('outsources') outsources = DoubanOutSource.gets(outsource_ids) emails = request.values.getlist('email') msg = request.values.get('msg', '') action = int(request.values.get('action', 1)) merger_outsources = [] if action == 1: for o in outsources: o.status = OUTSOURCE_STATUS_APPLY_MONEY o.create_time = datetime.date.today() o.save() merger_outsource = MergerDoubanOutSource.add(target=target, outsources=outsources, invoice=form.invoice.data, pay_num=form.pay_num.data, num=form.num.data, remark=form.remark.data, status=1) merger_outsource.save() merger_outsources.append(merger_outsource) elif action == 2: for o in outsources: o.status = OUTSOURCE_STATUS_APPLY_MONEY o.create_time = datetime.date.today() o.save() merger_outsource = MergerDoubanOutSource.add(target=target, outsources=[o], invoice=False, pay_num=o.pay_num, num=o.pay_num, remark=o.remark, status=1) merger_outsource.save() merger_outsources.append(merger_outsource) flash(u'合并付款申请成功', 'success') title = u'【费用报备】%s' % (u'合并付款申请审批') for k in merger_outsources: apply_context = {"sender": g.user, "to": emails, "msg": msg, "title": title, "action": 1, "merger_outsource": k} merger_outsource_apply_signal.send( current_app._get_current_object(), apply_context=apply_context) return redirect(url_for("outsource.merget_douban_target_info", target_id=target_id)) apply_outsources = DoubanOutSource.get_outsources_by_target(target_id, 2) paid_outsources = list(MergerDoubanOutSource.get_outsources_by_status(0, target_id)) apply_merger_outsources = MergerDoubanOutSource.get_outsources_by_status( MERGER_OUTSOURCE_STATUS_APPLY, target_id=target_id) # 在流程中的合并付款中的外包项不用出现再正在付款中 m_outsources = [] for k in apply_merger_outsources: m_outsources += k.outsources apply_money_outsources = [k for k in DoubanOutSource.get_outsources_by_target(target_id, 3) if k not in m_outsources] reminder_emails = [(u.name, u.email) for u in User.all_active()] form = MergerOutSourceForm(request.form) return tpl('merger_douban_target_info.html', target=target, reminder_emails=reminder_emails, OUTSOURCE_STATUS_APPLY_MONEY=OUTSOURCE_STATUS_APPLY_MONEY, OUTSOURCE_STATUS_PAIED=OUTSOURCE_STATUS_PAIED, OUTSOURCE_STATUS_PASS=OUTSOURCE_STATUS_PASS, form=form, INVOICE_RATE=INVOICE_RATE, apply_merger_outsources=apply_merger_outsources, apply_money_outsources=apply_money_outsources, paid_outsources=paid_outsources, apply_outsources=apply_outsources)
def outsource_status(order_id): type = request.values.get('type', '') if type == 'douban': order = DoubanOrder.get(order_id) else: order = ClientOrder.get(order_id) if not order: abort(404) outsource_ids = request.values.getlist('outsources') action = int(request.values.get('action', 0)) # emails = request.values.getlist('email') msg = request.values.get('msg', '') to_users = order.direct_sales + order.agent_sales + \ [order.creator, g.user] + order.operater_users try: outsource_apply_user = User.outsource_leaders_email( (order.agent_sales + order.direct_sales)[0]) except: outsource_apply_user = [] outsources_ids = set(outsource_ids) | set( [str(k.id) for k in order.apply_outsources()]) if type == 'douban': total_outsources = DoubanOutSource.gets(outsources_ids) outsources = DoubanOutSource.gets(outsource_ids) else: total_outsources = OutSource.gets(outsources_ids) outsources = OutSource.gets(outsource_ids) if not outsources: abort(403) if order.money: outsource_percent = sum( [k.pay_num for k in total_outsources]) / float(order.money) else: outsource_percent = sum([k.pay_num for k in total_outsources]) / 1 if action == 0: if outsource_percent >= 0.02: next_status = OUTSOURCE_STATUS_EXCEED action_msg = u'外包费用超过2%,申请审批' else: next_status = OUTSOURCE_STATUS_APPLY_LEADER action_msg = u'外包费用申请审批' # to_users_name = ','.join( # [k.name for k in outsource_apply_user] + [k.name for k in order.operater_users]) elif action == 1: next_status = OUTSOURCE_STATUS_PASS action_msg = u'外包费用审批通过' # to_users_name = ','.join( # [k.name for k in order.agent_sales] + [k.name for k in order.operater_users]) elif action == 2: next_status = OUTSOURCE_STATUS_NEW action_msg = u'外包费用拒绝通过' # to_users_name = ','.join( # [k.name for k in order.agent_sales] + [k.name for k in order.operater_users]) elif action == 3: next_status = OUTSOURCE_STATUS_APPLY_MONEY action_msg = u'外包费用申请打款' # to_users_name = ','.join([k.name for k in User.operater_leaders()]) elif action == 100: # to_users_name = ','.join([k.name for k in outsource_apply_user] + [k.name for k in order.operater_users]) outsources_json = json.loads( request.values.get('outsource_json', '[]')) outsources = [] # 先修改外包金额 for k in outsources_json: if type == 'douban': outsource = DoubanOutSource.get(k['id']) else: outsource = OutSource.get(k['id']) outsource.num = float(k['num']) outsource.target = OutSourceTarget.get(k['target']) outsource.type = k['type'] outsource.subtype = k['subtype'] outsource.remark = k['remark'] outsource.pay_num = float(k['num']) # outsource.status = next_status outsource.save() outsources.append(outsource) # 根据修改后的金额,计算是否超过占比 outsource_percent = float(order.outsources_percent) / 100 if outsource_percent >= 0.02: action_msg = u'外包费用超过2%,修改并申请审批' next_status = OUTSOURCE_STATUS_EXCEED else: action_msg = u'外包费用修改并重新申请审批' next_status = OUTSOURCE_STATUS_APPLY_LEADER for k in outsources_json: if type == 'douban': outsource = DoubanOutSource.get(k['id']) else: outsource = OutSource.get(k['id']) outsource.status = next_status outsource.save() else: action_msg = u'外包费用消息提醒' if action < 4: for outsource in outsources: outsource.status = next_status outsource.save() if action == 1: _insert_executive_report(order, rtype='reload') order.add_comment(g.user, u"%s:\n\r%s\n\r%s" % ( action_msg, "\n\r".join([o.name for o in outsources]), msg), msg_channel=2) # to_emails = list(set(emails + [x.email for x in to_users] + [k.email for k in outsource_apply_user])) apply_context = {"to_users": to_users + outsource_apply_user, "outsource_apply_user": outsource_apply_user, "action_msg": action_msg, "info": msg, "order": order, "action": action, "outsource_percent": outsource_percent, "outsources": outsources} outsource_apply_signal.send( current_app._get_current_object(), context=apply_context) if type == 'douban': return redirect(url_for("outsource.douban_outsources", order_id=order.id)) else: return redirect(url_for("outsource.client_outsources", order_id=order.id))
def outsource(outsource_id): type = request.values.get('type', '') if type == 'douban': outsource = DoubanOutSource.get(outsource_id) else: outsource = OutSource.get(outsource_id) if not outsource: abort(404) if type == 'douban': form = DoubanOutsourceForm(request.form) else: form = OutsourceForm(request.form) outsource.target = OutSourceTarget.get(form.target.data) if type == 'douban': outsource.douban_order = DoubanOrder.get(form.douban_order.data) else: outsource.medium_order = Order.get(form.medium_order.data) try: int(form.num.data) except: flash(u'保存失败,金额必须为数字!', 'danger') return redirect(outsource.info_path()) outsource.num = form.num.data outsource.type = form.type.data outsource.subtype = form.subtype.data outsource.remark = form.remark.data outsource.invoice = True outsource.pay_num = form.num.data outsource.save() flash(u'保存成功!', 'success') if type == "douban": outsource.douban_order.add_comment(g.user, u"更新了外包:\n\r%s" % outsource.name, msg_channel=2) else: outsource.client_order.add_comment(g.user, u"更新了外包:\n\r%s" % outsource.name, msg_channel=2) if type == 'douban': order = outsource.douban_order else: order = outsource.medium_order.client_order if outsource.status not in [0, 4]: to_users = order.direct_sales + order.agent_sales + \ [order.creator, g.user] + order.operater_users try: outsource_apply_user = User.outsource_leaders_email( order.agent_sales[0]) except: outsource_apply_user = [] if outsource.status in [1, 2, 5]: to_users_name = ','.join( [k.name for k in order.operater_users] + [k.name for k in order.agent_sales]) elif outsource.status == 3: to_users += User.finances() to_users_name = ','.join( [k.name for k in User.finances()] + [k.name for k in order.operater_users]) to_emails = list( set([x.email for x in to_users] + [k.email for k in outsource_apply_user])) title = u'【费用报备】%s-%s-%s' % (order.contract or u'无合同号', order.jiafang_name, u'修改外包信息') apply_context = {"sender": g.user, "to": to_emails, "action_msg": u'修改外包信息', "msg": '', "order": order, "title": title, "to_users": to_users_name, "outsources": [outsource]} outsource_apply_signal.send( current_app._get_current_object(), context=apply_context) return redirect(outsource.info_path())