def apply_invoice(invoice_id): invoice = ClientMediumInvoice.get(invoice_id) if not invoice: abort(404) invoices_ids = request.values.getlist('invoices') invoices = ClientMediumInvoice.gets(invoices_ids) if not invoices: abort(403) emails = request.values.getlist('email') msg = request.values.get('msg', '') action = int(request.values.get('action', 0)) to_users = invoice.client_medium_order.direct_sales + invoice.client_medium_order.agent_sales + \ [invoice.client_medium_order.creator, g.user] + \ invoice.client_medium_order.leaders send_type = "saler" if action == 2: invoice_status = INVOICE_STATUS_APPLY action_msg = u'客户发票开具申请' elif action == 3: to_users = User.finances() invoice_status = INVOICE_STATUS_APPLYPASS action_msg = u'同意客户发票开具申请' send_type = "finance" elif action == 4: invoice_status = INVOICE_STATUS_FAIL action_msg = u'客户发票开具申请未通过' if action != 10: for invoice in invoices: invoice.invoice_status = invoice_status invoice.create_time = datetime.date.today() invoice.save() flash(u'[%s 发票开具申请,发票金额%s] %s ' % (invoice.company, invoice.money, action_msg), 'success') invoice.client_medium_order.add_comment(g.user, u"%s,%s" % ( action_msg, u'发票内容: %s; 发票金额: %s元' % (invoice.detail, str(invoice.money))), msg_channel=1) else: action_msg = u'消息提醒' context = {"to_users": to_users, "action_msg": action_msg, "info": msg, "order": invoice.client_medium_order, "send_type": send_type, "action": action, "invoices": invoices, "to_other": emails } invoice_apply_signal.send( current_app._get_current_object(), context=context) return redirect(url_for("saler_client_medium_order_invoice.index", order_id=invoice.client_medium_order.id))
def pass_invoice(invoice_id): if not g.user.is_finance(): abort(404) invoice = ClientMediumInvoice.get(invoice_id) if not invoice: abort(404) invoices_ids = request.values.getlist('invoices') invoices = ClientMediumInvoice.gets(invoices_ids) if not invoices: abort(403) emails = request.values.getlist('email') msg = request.values.get('msg', '') action = int(request.values.get('action', 0)) to_users = invoice.client_medium_order.direct_sales + invoice.client_medium_order.agent_sales + \ [invoice.client_medium_order.creator, g.user] + \ invoice.client_medium_order.leaders if action != 10: invoice_status = INVOICE_STATUS_PASS action_msg = u'客户发票已开' for invoice in invoices: invoice.invoice_status = invoice_status invoice.create_time = datetime.date.today() invoice.save() flash( u'[%s 发票已开,发票金额%s] %s ' % (invoice.company, invoice.money, action_msg), 'success') invoice.client_medium_order.add_comment( g.user, u"%s,%s" % (action_msg, u'发票内容: %s; 发票金额: %s元' % (invoice.detail, str(invoice.money))), msg_channel=1) else: action_msg = u'消息提醒' context = { "to_users": to_users, "to_other": emails, "action_msg": action_msg, "action": 0, "info": msg, "order": invoice.client_medium_order, "send_type": 'end', "invoices": invoices } invoice_apply_signal.send(current_app._get_current_object(), context=context) return redirect( url_for("finance_client_medium_order_invoice.info", order_id=invoice.client_medium_order.id))
def index(): if not g.user.is_finance(): abort(404) search_info = request.args.get('searchinfo', '') location_id = int(request.args.get('selected_location', '-1')) year = int(request.values.get('year', datetime.datetime.now().year)) orders = set([ invoice.client_medium_order for invoice in ClientMediumInvoice.get_invoices_status(INVOICE_STATUS_APPLYPASS)]) if location_id >= 0: orders = [o for o in orders if location_id in o.locations] orders = [k for k in orders if k.client_start.year == year or k.client_end.year == year] if search_info != '': orders = [ o for o in orders if search_info.lower() in o.search_invoice_info.lower()] select_locations = TEAM_LOCATION_CN.items() select_locations.insert(0, (-1, u'全部区域')) select_statuses = CONTRACT_STATUS_CN.items() select_statuses.insert(0, (-1, u'全部合同状态')) for k in orders: k.apply_count = len(k.get_invoice_by_status(3)) return tpl('/finance/client_medium_order/invoice/index.html', orders=orders, locations=select_locations, location_id=location_id, statuses=select_statuses, now_date=datetime.date.today(), search_info=search_info, year=year, params='?&searchinfo=%s&selected_location=%s&year=%s' % (search_info, location_id, str(year)))
def update_invoice(invoice_id): invoice = ClientMediumInvoice.get(invoice_id) if not invoice: abort(404) if request.method == 'POST': company = request.values.get('edit_company', '') tax_id = request.values.get('edit_tax_id', '') detail = request.values.get('edit_detail', '') money = request.values.get('edit_money', 0) invoice_num = request.values.get('edit_invoice_num', '') invoice_type = request.values.get('invoice_type', 0) create_time = request.values.get( 'edit_create_time', datetime.datetime.now().strftime('%Y-%m-%d')) if not tax_id: flash(u"修改发票失败,公司名称不能为空", 'danger') elif not detail: flash(u"修改发票失败,发票内容不能为空", 'danger') elif not money: flash(u"修改发票失败,发票金额不能为空", 'danger') elif not invoice_num: flash(u"修改发票失败,发票号不能为空", 'danger') else: invoice.company = company invoice.tax_id = tax_id invoice.detail = detail invoice.invoice_num = invoice_num invoice.money = money invoice.invoice_type = invoice_type invoice.create_time = create_time invoice.save() flash(u'修改发票(%s)成功!' % company, 'success') invoice.client_medium_order.add_comment(g.user, u"修改发票信息,%s" % ( u'发票内容: %s; 发票号: %s; 发票金额: %s元' % (invoice.detail, invoice_num, str(invoice.money))), msg_channel=1) return redirect(url_for("finance_client_medium_order_invoice.info", order_id=invoice.client_medium_order.id))
def new_invoice(order_id): order = ClientMediumOrder.get(order_id) if not order: abort(404) form = ClientMediumInvoiceForm(request.form) form.client_medium_order.choices = [(order.id, order.medium.name)] if request.method == 'POST' and form.validate(): if int(form.money.data) > (int(order.money) - int(order.invoice_apply_sum) - int(order.invoice_pass_sum)): flash(u"新建发票失败,您申请的发票超过了合同总额", 'danger') return redirect(url_for("finance_client_medium_order_invoice.info", order_id=order_id)) invoice = ClientMediumInvoice.add(client_medium_order=order, 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, invoice_type=form.invoice_type.data, creator=g.user, invoice_status=0, invoice_num=request.values.get( 'new_invoice_num', ''), back_time=form.back_time.data, create_time=request.values.get('create_time', datetime.datetime.now().strftime('%Y-%m-%d'))) invoice.save() flash(u'开发票(%s)成功!' % form.company.data, 'success') order.add_comment(g.user, u"已开发票信息:%s" % ( u'发票内容: %s; 发票金额: %s元' % (invoice.detail, str(invoice.money))), msg_channel=1) else: for k in form.errors: flash(u"新建发票失败,%s" % (form.errors[k][0]), 'danger') return redirect(url_for("finance_client_medium_order_invoice.info", order_id=order.id))
def delete_invoice(invoice_id): if not g.user.is_finance(): abort(404) invoice = ClientMediumInvoice.get(invoice_id) order_id = invoice.client_medium_order.id invoice.client_medium_order.add_comment(g.user, u"删除发票信息:%s" % ( u'发票内容: %s; 发票金额: %s元' % (invoice.detail, str(invoice.money))), msg_channel=1) invoice.delete() flash(u"删除成功", 'danger') return redirect(url_for("finance_client_medium_order_invoice.info", order_id=order_id))
def index_pass(): if not g.user.is_finance(): abort(404) orders = list(ClientMediumOrder.all()) search_info = request.args.get('searchinfo', '') location_id = int(request.args.get('selected_location', '-1')) year = int(request.values.get('year', datetime.datetime.now().year)) page = int(request.args.get('p', 1)) if location_id >= 0: orders = [o for o in orders if location_id in o.locations] orders = [ k for k in orders if k.client_start.year == year or k.client_end.year == year ] if search_info != '': orders = [ o for o in orders if search_info.lower() in o.search_invoice_info.lower() ] select_locations = TEAM_LOCATION_CN.items() select_locations.insert(0, (-1, u'全部区域')) select_statuses = CONTRACT_STATUS_CN.items() select_statuses.insert(0, (-1, u'全部合同状态')) paginator = Paginator(orders, ORDER_PAGE_NUM) try: orders = paginator.page(page) except: orders = paginator.page(paginator.num_pages) type = request.args.get('type', '') if type == 'excel': orders = set([ invoice.client_medium_order for invoice in ClientMediumInvoice.get_invoices_status(INVOICE_STATUS_PASS) ]) xls = write_excel(list(orders)) response = get_download_response( xls, ("%s-%s.xls" % (u"申请过的发票信息", datetime.datetime.now().strftime('%Y%m%d%H%M%S')) ).encode('utf-8')) return response return tpl('/finance/client_medium_order/invoice/index_pass.html', orders=orders, locations=select_locations, location_id=location_id, statuses=select_statuses, now_date=datetime.date.today(), search_info=search_info, page=page, year=year, params='&searchinfo=%s&selected_location=%s&year=%s' % (search_info, location_id, str(year)))
def invoice_num(invoice_id): if not g.user.is_finance(): abort(404) invoice = ClientMediumInvoice.get(invoice_id) if not invoice: abort(404) invoice_num = request.values.get('invoice_num', '') invoice.invoice_num = invoice_num invoice.save() flash(u'保存成功!', 'success') invoice.client_medium_order.add_comment( g.user, u"%s" % (u'更新了发票号: %s;' % (invoice.invoice_num)), msg_channel=1) return redirect(url_for("finance_client_medium_order_invoice.info", order_id=invoice.client_medium_order.id))
def delete_invoice(invoice_id): if not g.user.is_finance(): abort(404) invoice = ClientMediumInvoice.get(invoice_id) order_id = invoice.client_medium_order.id invoice.client_medium_order.add_comment( g.user, u"删除发票信息:%s" % (u'发票内容: %s; 发票金额: %s元' % (invoice.detail, str(invoice.money))), msg_channel=1) invoice.delete() flash(u"删除成功", 'danger') return redirect( url_for("finance_client_medium_order_invoice.info", order_id=order_id))
def invoice_num(invoice_id): if not g.user.is_finance(): abort(404) invoice = ClientMediumInvoice.get(invoice_id) if not invoice: abort(404) invoice_num = request.values.get('invoice_num', '') invoice.invoice_num = invoice_num invoice.save() flash(u'保存成功!', 'success') invoice.client_medium_order.add_comment(g.user, u"%s" % (u'更新了发票号: %s;' % (invoice.invoice_num)), msg_channel=1) return redirect( url_for("finance_client_medium_order_invoice.info", order_id=invoice.client_medium_order.id))
def new_invoice(order_id): order = ClientMediumOrder.get(order_id) if not order: abort(404) form = ClientMediumInvoiceForm(request.form) form.client_medium_order.choices = [(order.id, order.medium.name)] if request.method == 'POST' and form.validate(): if int(form.money.data) > (int(order.money) - int( order.invoice_apply_sum) - int(order.invoice_pass_sum)): flash(u"新建发票失败,您申请的发票超过了合同总额", 'danger') return redirect( url_for("finance_client_medium_order_invoice.info", order_id=order_id)) invoice = ClientMediumInvoice.add( client_medium_order=order, 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, invoice_type=form.invoice_type.data, creator=g.user, invoice_status=0, invoice_num=request.values.get('new_invoice_num', ''), back_time=form.back_time.data, create_time=request.values.get( 'create_time', datetime.datetime.now().strftime('%Y-%m-%d'))) invoice.save() flash(u'开发票(%s)成功!' % form.company.data, 'success') order.add_comment(g.user, u"已开发票信息:%s" % (u'发票内容: %s; 发票金额: %s元' % (invoice.detail, str(invoice.money))), msg_channel=1) else: for k in form.errors: flash(u"新建发票失败,%s" % (form.errors[k][0]), 'danger') return redirect( url_for("finance_client_medium_order_invoice.info", order_id=order.id))
def update_invoice(invoice_id): invoice = ClientMediumInvoice.get(invoice_id) if not invoice: abort(404) if request.method == 'POST': company = request.values.get('edit_company', '') tax_id = request.values.get('edit_tax_id', '') detail = request.values.get('edit_detail', '') money = request.values.get('edit_money', 0) invoice_num = request.values.get('edit_invoice_num', '') invoice_type = request.values.get('invoice_type', 0) create_time = request.values.get( 'edit_create_time', datetime.datetime.now().strftime('%Y-%m-%d')) if not tax_id: flash(u"修改发票失败,公司名称不能为空", 'danger') elif not detail: flash(u"修改发票失败,发票内容不能为空", 'danger') elif not money: flash(u"修改发票失败,发票金额不能为空", 'danger') elif not invoice_num: flash(u"修改发票失败,发票号不能为空", 'danger') else: invoice.company = company invoice.tax_id = tax_id invoice.detail = detail invoice.invoice_num = invoice_num invoice.money = money invoice.invoice_type = invoice_type invoice.create_time = create_time invoice.save() flash(u'修改发票(%s)成功!' % company, 'success') invoice.client_medium_order.add_comment( g.user, u"修改发票信息,%s" % (u'发票内容: %s; 发票号: %s; 发票金额: %s元' % (invoice.detail, invoice_num, str(invoice.money))), msg_channel=1) return redirect( url_for("finance_client_medium_order_invoice.info", order_id=invoice.client_medium_order.id))
def index(): if not g.user.is_finance(): abort(404) search_info = request.args.get('searchinfo', '') location_id = int(request.args.get('selected_location', '-1')) year = int(request.values.get('year', datetime.datetime.now().year)) orders = set([ invoice.client_medium_order for invoice in ClientMediumInvoice.get_invoices_status(INVOICE_STATUS_APPLYPASS) ]) if location_id >= 0: orders = [o for o in orders if location_id in o.locations] orders = [ k for k in orders if k.client_start.year == year or k.client_end.year == year ] if search_info != '': orders = [ o for o in orders if search_info.lower() in o.search_invoice_info.lower() ] select_locations = TEAM_LOCATION_CN.items() select_locations.insert(0, (-1, u'全部区域')) select_statuses = CONTRACT_STATUS_CN.items() select_statuses.insert(0, (-1, u'全部合同状态')) for k in orders: k.apply_count = len(k.get_invoice_by_status(3)) return tpl('/finance/client_medium_order/invoice/index.html', orders=orders, locations=select_locations, location_id=location_id, statuses=select_statuses, now_date=datetime.date.today(), search_info=search_info, year=year, params='?&searchinfo=%s&selected_location=%s&year=%s' % (search_info, location_id, str(year)))
def index_pass(): if not g.user.is_finance(): abort(404) orders = list(ClientMediumOrder.all()) search_info = request.args.get('searchinfo', '') location_id = int(request.args.get('selected_location', '-1')) year = int(request.values.get('year', datetime.datetime.now().year)) page = int(request.args.get('p', 1)) if location_id >= 0: orders = [o for o in orders if location_id in o.locations] orders = [k for k in orders if k.client_start.year == year or k.client_end.year == year] if search_info != '': orders = [ o for o in orders if search_info.lower() in o.search_invoice_info.lower()] select_locations = TEAM_LOCATION_CN.items() select_locations.insert(0, (-1, u'全部区域')) select_statuses = CONTRACT_STATUS_CN.items() select_statuses.insert(0, (-1, u'全部合同状态')) paginator = Paginator(orders, ORDER_PAGE_NUM) try: orders = paginator.page(page) except: orders = paginator.page(paginator.num_pages) type = request.args.get('type', '') if type == 'excel': orders = set([invoice.client_medium_order for invoice in ClientMediumInvoice.get_invoices_status( INVOICE_STATUS_PASS)]) xls = write_excel(list(orders)) response = get_download_response( xls, ("%s-%s.xls" % (u"申请过的发票信息", datetime.datetime.now().strftime('%Y%m%d%H%M%S'))).encode('utf-8')) return response return tpl('/finance/client_medium_order/invoice/index_pass.html', orders=orders, locations=select_locations, location_id=location_id, statuses=select_statuses, now_date=datetime.date.today(), search_info=search_info, page=page, year=year, params='&searchinfo=%s&selected_location=%s&year=%s' % (search_info, location_id, str(year)))
def update_invoice(invoice_id): invoice = ClientMediumInvoice.get(invoice_id) if not invoice: abort(404) form = ClientMediumInvoiceForm(request.form) form.client_medium_order.choices = [ (invoice.client_medium_order.id, invoice.client_medium_order.medium.name)] if request.method == 'POST' and form.validate(): back_time = request.values.get('back_time', datetime.date.today()) if not form.tax_id.data: flash(u"修改发票失败,公司名称不能为空", 'danger') elif not form.detail.data: flash(u"修改发票失败,发票内容不能为空", 'danger') elif not form.money.data: flash(u"修改发票失败,发票金额不能为空", 'danger') else: invoice.company = form.company.data, invoice.tax_id = form.tax_id.data, invoice.address = form.address.data, invoice.phone = form.phone.data, invoice.bank_id = form.bank_id.data, invoice.bank = form.bank.data, invoice.detail = form.detail.data, invoice.money = form.money.data, invoice.invoice_type = form.invoice_type.data, invoice.creator = g.user invoice.create_time = datetime.date.today() invoice.back_time = back_time invoice.save() flash(u'修改发票(%s)成功!' % form.company.data, 'success') invoice.client_medium_order.add_comment(g.user, u"修改发票信息,%s" % ( u'发票内容: %s; 发票金额: %s元' % (invoice.detail, str(invoice.money))), msg_channel=1) else: for k in form.errors: flash(u"修改发票失败,%s" % (form.errors[k][0]), 'danger') return redirect(url_for("saler_client_medium_order_invoice.index", order_id=invoice.client_medium_order.id))