def outsource_pay_num(outsource_id): if not g.user.is_finance(): abort(404) 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 outsource.invoice: pay_num = outsource.num else: pay_num = outsource.num * float(1 - INVOICE_RATE) pay_num = request.values.get('pay_num', pay_num) outsource.pay_num = pay_num outsource.save() flash(u'保存成功!', 'success') if type == 'douban': outsource.douban_order.add_comment(g.user, u"更新了外包:\n\r%s 打款金额%s" % ( outsource.name, str(outsource.pay_num)), msg_channel=2) else: outsource.client_order.add_comment(g.user, u"更新了外包:\n\r%s 打款金额%s" % ( outsource.name, str(outsource.pay_num)), msg_channel=2) if type == 'douban': return redirect(url_for("finance_outsource_pay.douban_info", order_id=outsource.douban_order.id)) else: return redirect(url_for("finance_outsource_pay.info", order_id=outsource.client_order.id))
def outsource_back(outsource_id): if not g.user.is_finance(): abort(404) type = request.values.get('type', '') if type == 'douban': outsource = DoubanOutSource.get(outsource_id) else: outsource = OutSource.get(outsource_id) outsource.status = OUTSOURCE_STATUS_APPLY_MONEY outsource.create_time = datetime.date.today() outsource.save() flash(u'外包款项撤回,名称:%s打款金额%s' % (outsource.name, str(outsource.pay_num)), 'success') if type == 'douban': outsource.douban_order.add_comment( g.user, u'外包款项撤回,名称%s打款金额%s' % (outsource.name, str(outsource.pay_num)), msg_channel=2) else: outsource.client_order.add_comment( g.user, u'外包款项撤回,名称%s打款金额%s' % (outsource.name, str(outsource.pay_num)), msg_channel=2) if type == 'douban': order = outsource.douban_order else: order = outsource.medium_order.client_order if type == 'douban': to_users = outsource.douban_order.direct_sales + outsource.douban_order.agent_sales + \ [outsource.douban_order.creator, g.user] + \ User.operater_leaders() + outsource.douban_order.operater_users else: to_users = outsource.client_order.direct_sales + outsource.client_order.agent_sales + \ [outsource.client_order.creator, g.user] + \ User.operater_leaders() + outsource.client_order.operater_users to_emails = list(set([x.email for x in to_users])) 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": u'', "order": order, "title": title, "to_users": ','.join([k.name for k in order.agent_sales] + [k.name for k in order.operater_users]), "outsources": [outsource]} outsource_apply_signal.send( current_app._get_current_object(), context=apply_context) if type == 'douban': return redirect(url_for("finance_outsource_pay.douban_info", order_id=outsource.douban_order.id)) else: return redirect(url_for("finance_outsource_pay.info", order_id=outsource.client_order.id))
def update_personal_pay_num(): type = request.values.get('type', '') outsource_id = request.values.get('outsource_id') pay_num = request.values.get('update_pay_num', 0) if type == 'douban': outsource = DoubanOutSource.get(outsource_id) else: outsource = OutSource.get(outsource_id) outsource.pay_num = pay_num outsource.save() flash(u'修改实际付款金额:%s 成功' % (str(pay_num)), 'success') if type == 'douban': return redirect(url_for("outsource.merget_douban_target_personal_info")) else: return redirect(url_for("outsource.merget_client_target_personal_info"))
def outsource_delete(outsource_id): type = request.values.get('type', '') if type == 'douban': outsource = DoubanOutSource.get(outsource_id) order = outsource.douban_order else: outsource = OutSource.get(outsource_id) order = outsource.medium_order 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) url = outsource.info_path() outsource.delete() _insert_executive_report(order, rtype='reload') return redirect(url)
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())
def outsource_pass(outsource_id): if not g.user.is_finance(): abort(404) type = request.values.get('type', '') if type == 'douban': outsource = DoubanOutSource.get(outsource_id) else: outsource = OutSource.get(outsource_id) if not outsource: abort(404) outsources_ids = request.values.getlist('outsources') if type == 'douban': outsources = DoubanOutSource.gets(outsources_ids) else: outsources = OutSource.gets(outsources_ids) if not outsources: abort(403) emails = request.values.getlist('email') msg = request.values.get('msg', '') action = int(request.values.get('action', 0)) if type == 'douban': to_users = outsource.douban_order.direct_sales + outsource.douban_order.agent_sales + \ [outsource.douban_order.creator, g.user] + User.operater_leaders() else: to_users = outsource.client_order.direct_sales + outsource.client_order.agent_sales + \ [outsource.client_order.creator, g.user] + User.operater_leaders() to_emails = list(set(emails + [x.email for x in to_users])) if action != 10: outsource_status = OUTSOURCE_STATUS_PAIED action_msg = u'外包款已打' for outsource in outsources: outsource.status = outsource_status outsource.create_time = datetime.date.today() outsource.save() flash(u'外包款已打,名称:%s打款金额%s' % (outsource.name, str(outsource.pay_num)), 'success') if type == 'douban': outsource.douban_order.add_comment( g.user, u'外包款已打,名称%s打款金额%s' % (outsource.name, str(outsource.pay_num)), msg_channel=2) else: outsource.client_order.add_comment( g.user, u'外包款已打,名称%s打款金额%s' % (outsource.name, str(outsource.pay_num)), msg_channel=2) else: action_msg = u'消息提醒' if type == 'douban': order = outsource.douban_order else: order = outsource.medium_order.client_order title = u'【费用报备】%s-%s-%s' % (order.contract or u'无合同号', order.jiafang_name, action_msg) apply_context = {"sender": g.user, "to": to_emails, "action_msg": action_msg, "msg": msg, "order": order, "title": title, "to_users": ','.join([k.name for k in order.agent_sales] + [k.name for k in order.operater_users]), "outsources": outsources} outsource_apply_signal.send( current_app._get_current_object(), apply_context=apply_context) if type == 'douban': return redirect(url_for("finance_outsource_pay.douban_info", order_id=outsource.douban_order.id)) else: return redirect(url_for("finance_outsource_pay.info", order_id=outsource.client_order.id))