Esempio n. 1
0
def update_invoice(
        invoice_id,
        redirect_endpoint='searchAd_saler_client_order_agent_invoice.index'):
    invoice = searchAdAgentInvoice.get(invoice_id)
    if not invoice:
        abort(404)
    form = AgentInvoiceForm(request.form)
    form.client_order.choices = [(invoice.client_order.id,
                                  invoice.client_order.name)]
    form.agent.choices = [(invoice.agent.id, invoice.agent.name)]
    form.bool_invoice.bool_invoice = AGENT_INVOICE_BOOL_INVOICE_CN.items()
    # order = invoice.client_order
    # 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':
        if not form.invoice_num.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.pay_money = form.money.data,
            invoice.invoice_type = form.invoice_type.data,
            invoice.invoice_num = form.invoice_num.data,
            invoice.creator = g.user
            invoice.create_time = datetime.date.today()
            invoice.add_time = form.add_time.data
            invoice.bool_invoice = form.bool_invoice.data
            invoice.save()
            flash(u'修改打款发票(%s)成功!' % form.company.data, 'success')
            invoice.client_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=invoice.client_order.id))
Esempio n. 2
0
def index(order_id):
    order = ClientOrder.get(order_id)
    if not order:
        abort(404)
    invoices = AgentInvoice.query.filter_by(client_order=order)
    reminder_emails = [(u.name, u.email) for u in User.all_active()]
    new_invoice_form = AgentInvoiceForm()
    new_invoice_form.client_order.choices = [(order.id, order.client.name)]
    new_invoice_form.agent.choices = [(k.id, k.name) for k in order.agents]
    new_invoice_form.add_time.data = datetime.date.today()
    return tpl('/saler/client_order/agent/index.html',
               order=order,
               reminder_emails=reminder_emails,
               new_invoice_form=new_invoice_form,
               invoices=invoices,
               AGENT_INVOICE_STATUS_CN=AGENT_INVOICE_STATUS_CN,
               INVOICE_TYPE_CN=INVOICE_TYPE_CN)
Esempio n. 3
0
def info(order_id):
    if not g.user.is_finance():
        abort(404)
    order = ClientOrder.get(order_id)
    if not order:
        abort(404)
    invoices = AgentInvoice.query.filter_by(client_order=order)
    reminder_emails = [(u.id, u.name) for u in User.all_active()]
    new_invoice_form = AgentInvoiceForm()
    new_invoice_form.client_order.choices = [(order.id, order.name)]
    new_invoice_form.agent.choices = [(k.id, k.name) for k in order.agents]
    new_invoice_form.add_time.data = datetime.date.today()
    return tpl('/finance/client_order/agent_pay/info.html',
               order=order,
               invoices=invoices,
               new_invoice_form=new_invoice_form,
               reminder_emails=reminder_emails,
               INVOICE_TYPE_CN=INVOICE_TYPE_CN)
Esempio n. 4
0
def new_invoice(
        order_id,
        redirect_endpoint='searchAd_saler_client_order_agent_invoice.index'):
    order = searchAdClientOrder.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 = searchAdAgentInvoice.add(
            client_order=order,
            agent=searchAdAgent.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))
Esempio n. 5
0
def get_invoice_form(invoice):
    invoice_form = AgentInvoiceForm()
    invoice_form.client_order.choices = [(invoice.client_order.id,
                                          invoice.client_order.client.name)]

    invoice_form.agent.choices = [(invoice.agent.id, invoice.agent.name)]
    invoice_form.company.data = invoice.company
    invoice_form.bank.data = invoice.bank
    invoice_form.bank_id.data = invoice.bank_id
    invoice_form.address.data = invoice.address
    invoice_form.phone.data = invoice.phone
    invoice_form.tax_id.data = invoice.tax_id
    invoice_form.money.data = invoice.money
    invoice_form.detail.data = invoice.detail
    invoice_form.invoice_type.data = invoice.invoice_type
    invoice_form.invoice_num.data = invoice.invoice_num
    if invoice.add_time:
        invoice_form.add_time.data = invoice.add_time.strftime('%Y-%m-%d')
    else:
        invoice_form.add_time.data = ''
    invoice_form.bool_invoice.data = str(invoice.bool_invoice)
    return invoice_form