示例#1
0
def add(request, auction_id, template_name):
    cform = CommodityForm()
    request.session["auction_id"] = auction_id
    try:
        auc_obj = AuctionField.objects.get(pk=auction_id)
    except AuctionField.DoesNotExist:
        raise Http404
    auc_varietys = auc_obj.variety_set.all()
    if request.method == "POST":
        mem = memcache.Client(settings.MEMCACHES)
        cform = CommodityForm(request.POST)
        if cform.is_valid():
            c_obj = cform.save(commit=False)
            c_obj.auction = auc_obj
            c_obj.save()
            mem.set("last_form", request.POST)
            cform = CommodityForm()
            html = render_to_string("auctionweb/commodity/modform.html", {
                "cform": cform,
                "auc_varietys": auc_varietys
            },
                                    context_instance=RequestContext(request))
            return ajax_success({"success": True, "html": html})
        else:
            html = render_to_string("auctionweb/commodity/modform.html", {
                "cform": cform,
                "auc_varietys": auc_varietys
            },
                                    context_instance=RequestContext(request))
            return ajax_success({"html": html})
    C = {"cform": cform, "auc_varietys": auc_varietys}
    return render(request, template_name, C)
示例#2
0
def add(request, auction_id, template_name):
    cform = CommodityForm()
    request.session["auction_id"] = auction_id
    try:
        auc_obj = AuctionField.objects.get(pk=auction_id)
    except AuctionField.DoesNotExist:
        raise Http404
    auc_varietys = auc_obj.variety_set.all()
    if request.method == "POST":
        mem = memcache.Client(settings.MEMCACHES)
        cform = CommodityForm(request.POST)
        if cform.is_valid():
            c_obj = cform.save(commit=False)
            c_obj.auction = auc_obj
            c_obj.save()
            mem.set("last_form", request.POST)
            cform = CommodityForm()
            html = render_to_string(
                "auctionweb/commodity/modform.html",
                {"cform": cform, "auc_varietys": auc_varietys}, 
                context_instance=RequestContext(request)
            )
            return ajax_success({"success": True, "html": html})
        else:
            html = render_to_string(
                "auctionweb/commodity/modform.html",
                {"cform": cform, "auc_varietys": auc_varietys}, 
                context_instance=RequestContext(request)
            )
            return ajax_success({"html": html})
    C = {"cform": cform, "auc_varietys": auc_varietys}   
    return render(request, template_name, C)
示例#3
0
def change_rate(request, template_name):
    if request.method=="POST":
        auction_id = request.POST.get("auction")
        auc_event = request.POST.get("auction_event")
        confirm = request.GET.get("confirm", False)
        try:
            auc_obj = AuctionField.objects.get(id=auction_id)
            auc_event_obj = AuctionEvent.objects.get(auction=auc_obj, event=auc_event)
        except AuctionField.DoesNotExist:
            return ajax_error("auction field does not exist")
        except AuctionEvent.DoesNotExist:
            return ajax_error("auction event does not exist")
        all_invoices = auc_event_obj.invoice_set.all().filter(is_pre=0).order_by("invoice_nu")
        if not confirm:
            confirm_invoice_list = [i.toDICT() for i in all_invoices]
            return ajax_success(confirm_invoice_list)
        new_an_rmb_rate = request.POST.get("new_rate")
        try:
            new_an_rmb_rate = float(new_an_rmb_rate)
        except ValueError:
            return ajax_error("rate data format is abnormal")
        for i in all_invoices:
            com_list = i.commodity_set.all()
            post_data = {
                "commission_rate": i.commission_rate, 
                "final_exchange_rate": i.final_exchange_rate,
                "an_rmb_rate": i.an_rmb_rate
            }
            try:
                i.goods_nu, i.dollar_sum, i.cost_sum = invoice_formula(com_list, post_data, False)
                i.save()
            except Exception, e:
                return ajax_error("公式错误:%s"%str(e))
        confirm_invoice_list = [i.toDICT() for i in all_invoices]
        return ajax_success(confirm_invoice_list)
示例#4
0
def vmodify(request, invoice_id):
    '''发票拆分后重新生成invoice'''
    if request.method != "POST":
        raise Http404
    try:
        invoice_obj = Invoice.objects.get(pk=invoice_id)
    except Invoice.DoesNotExist:
        return ajax_error("invoice obj does not exist")
    all_in_lot_nu = [
        com_obj.lot for com_obj in invoice_obj.commodity_set.all()
    ]
    all_post_lot_nu = json.loads(request.POST.get("data", ''))
    all_lot_nu = list(set(all_in_lot_nu) - set(all_post_lot_nu))
    if len(all_lot_nu) == 0:
        invoice_obj.delete()
        return ajax_success()
    form_data = {
        "commodity": ','.join(all_lot_nu),
        "goods_nu": 50,
        "dollar_sum": 300,
        "cost_sum": 200
    }
    [setattr(invoice_obj, key, val) for key, val in form_data.items()]
    commodity_list = Commodity.objects.filter(lot__in=all_lot_nu)
    invoice_com = invoice_obj.save(commit=False)
    invoice_com.commodity_set.add(commodity_list)
    invoice_com.save()
    Commodity.objects.filter(lot__in=all_post_lot_nu).update(is_invoice=0)
    return ajax_success()
示例#5
0
def lot_list_invoice(request, invoice_id):
    """发票拆分功能, 获取关于某个初始发票的所有lot信息"""
    try:
        invoice_obj = Invoice.objects.get(pk=invoice_id)
    except Invoice.DoesNotExist:
        return ajax_success([])
    all_lot = invoice_obj.commodity_set.all()
    json_lot_list = [i.toDICT() for i in all_lot]
    return ajax_success(json_lot_list)
示例#6
0
def lot_list_invoice(request, invoice_id):
    """发票拆分功能, 获取关于某个初始发票的所有lot信息"""
    try:
        invoice_obj = Invoice.objects.get(pk=invoice_id)
    except Invoice.DoesNotExist:
        return ajax_success([])
    all_lot = invoice_obj.commodity_set.all()
    json_lot_list = [i.toDICT() for i in all_lot]
    return ajax_success(json_lot_list)
示例#7
0
def export_ship_excel(request):
    '''导出货运excel列表'''
    if request.method != "POST":
        with open("/tmp/ship_list.xls") as f:
            data = f.read()
        response = HttpResponse(data, content_type='application/vnd.ms-excel')
        response['Content-Disposition'] = 'attachment;filename=ship_list.xls'
        return response
    data = json.loads(request.POST.get("data"))
    wb = xlwt.Workbook(encoding = 'utf-8')
    sheet = wb.add_sheet(u'货运列表清单')
    th = [
        "货运号", "拍卖会", "数量", "原始发票总额", "国外货运公司",
        "地接公司", "清关公司", "主单号", "分单号", "件数", "计费重量", 
        "起飞日期", "落地日期", "货运状态", "清关日期", "清关状态"
    ]
    [sheet.write(0, i, th[i]) for i in range(len(th))]
    ship_obj_list = Shiping.objects.all()
    if data.get("id_lis") and data.get("id_lis")[0] != "all":
        ship_obj_list = ship_obj_list.filter(id__in=data.get("id_lis")).order_by("shiping_nu")
    property = [
        "shiping_nu", "auction_name", "com_num", "invoice_count", "foreign_ship" ,
        "delivery_company", "clearance_company", "master_nu", "branch_nu",
        "ship_num", "charge_weight", "takeoff_time", "arrive_time",
        "ship_status", "clear_time", "clear_status"
    ]
    row = 1
    for ship_obj in ship_obj_list:
        data = ship_obj.toDICT()
        data.update({"ship_status": ship_obj.get_ship_status})
        data.update({"clear_status": ship_obj.get_clear_status})
        [sheet.write(row, i, data[property[i]]) for i in range(len(property))]
        row = row + 1
    wb.save("/tmp/ship_list.xls")
    return ajax_success() 
示例#8
0
def fexcel(request):
    if request.method != "POST":
        with open("/tmp/final_invoice.xls") as f:
            data = f.read()
        response = HttpResponse(data, content_type='application/vnd.ms-excel')
        response[
            'Content-Disposition'] = 'attachment;filename=final_invoice.xls'
        return response
    data = json.loads(request.POST.get("data"))
    wb = xlwt.Workbook(encoding='utf-8')
    sheet = wb.add_sheet(u'最终发票清单')
    th = ["发票号", "客户号", "品种", "生皮总额", "美金总额", "修改次数", "修改时间"]
    [sheet.write(0, i, th[i]) for i in range(len(th))]
    row = 1
    all_final_invoice = Invoice.objects.filter(
        id__in=data.get("id_lis")).order_by("invoice_nu")
    property = [
        "invoice_nu", "customer_id", "goods_type", "goods_nu", "cost_sum",
        "modify_times", "modify_date"
    ]
    json_list = [i.toDICT() for i in all_final_invoice]
    for lis in json_list:
        [sheet.write(row, i, lis[property[i]]) for i in range(len(property))]
        row = row + 1
    wb.save("/tmp/final_invoice.xls")
    return ajax_success()
示例#9
0
def cus_trans(request, cus_id):
    '''客户向公司字账户转账'''
    com_ac_id = request.POST.get("company")
    balance = request.POST.get("balance")
    if not com_ac_id or not balance:
        return ajax_error("公司账户与充值金额不能为空")
    else:
        try:
            balance = int(balance)
        except:
            return ajax_error("请填写正确类型的充值金额")
    try:
        com_ac_obj = Account.objects.get(pk=com_ac_id)
        cus_obj = Account.objects.get(pk=cus_id)
    except:
        return ajax_error("账户不存在")
    com_ac_obj.balance = balance + com_ac_obj.balance
    cus_obj.balance = cus_obj.balance + balance
    com_ac_obj.save()
    cus_obj.save()
    trans_log = TransferRecord(
        fro=cus_obj, to=com_ac_obj, 
        money=balance, date=datetime.datetime.now()
    )
    trans_log.save()
    return ajax_success()
示例#10
0
def account_export(request):
    if request.method != "POST":
        with open("/tmp/account.xls") as f:
            data = f.read()
        response = HttpResponse(data, content_type='application/vnd.ms-excel')
        response['Content-Disposition'] = 'attachment;filename=account.xls'
        return response
    data = json.loads(request.POST.get("data"))
    wb = xlwt.Workbook(encoding = 'utf-8')
    sheet = wb.add_sheet(u'账户清单')
    th = ["账户名称", "账户类型", "账户余额"]
    [sheet.write(0, i, th[i]) for i in range(len(th))]
    row = 1
    style = data.get("style")
    if style == "AMERICAN" or style == "LOCAL":
        accounts = AuctionAccount.objects.all()
    else:
        accounts = Account.objects.filter(style=style)
    for ac in accounts.filter(id__in=data.get("account_id_lis")):
        sheet.write(row, 0, ac.name)
        sheet.write(row, 1, ac.style)
        sheet.write(row, 2, ac.balance)
        row = row + 1
    wb.save("/tmp/account.xls")
    return ajax_success()
示例#11
0
def to_pay_shiping(request):
    '''货运分类付费'''
    # 类别
    com_pro = request.GET.get("company")
    com_id = request.GET.get("idl")
    credit_note = request.POST.get("credit_note")
    payment = request.POST.get("payment")
    if not payment:
        return ajax_error("payment不能为空!!!")
    if not com_pro or not com_id:
        return ajax_error("异常请求")
    if com_pro == "ship":
        try:
            ship_obj = ForeignShip.objects.get(id=com_id)
        except ForeignShip.DoesNotExist:
            return ajax_error("异常请求")
        ship_obj.account.balance = ship_obj.account.balance - \
            int(credit_note) if credit_note else 0 - int(payment)
        ship_obj.account.save()
        PaymentOrder(
            account=ship_obj.account, 
            credit_note=credit_note if credit_note else '',
            payment=payment
        ).save()
    return ajax_success({"blance": ship_obj.account.balance})
示例#12
0
def delete(request):
    if request.method != "POST":
        raise Http404
    lot_nu_list = [str(lot) for lot in json.loads(request.POST.get("data", ''))]
    del_list = Commodity.objects.filter(lot__in=lot_nu_list)
    del_list.delete()
    return ajax_success()
示例#13
0
def export_ship_excel(request):
    '''导出货运excel列表'''
    if request.method != "POST":
        with open("/tmp/ship_list.xls") as f:
            data = f.read()
        response = HttpResponse(data, content_type='application/vnd.ms-excel')
        response['Content-Disposition'] = 'attachment;filename=ship_list.xls'
        return response
    data = json.loads(request.POST.get("data"))
    wb = xlwt.Workbook(encoding='utf-8')
    sheet = wb.add_sheet(u'货运列表清单')
    th = [
        "货运号", "拍卖会", "数量", "原始发票总额", "国外货运公司", "地接公司", "清关公司", "主单号", "分单号",
        "件数", "计费重量", "起飞日期", "落地日期", "货运状态", "清关日期", "清关状态"
    ]
    [sheet.write(0, i, th[i]) for i in range(len(th))]
    ship_obj_list = Shiping.objects.all()
    if data.get("id_lis") and data.get("id_lis")[0] != "all":
        ship_obj_list = ship_obj_list.filter(
            id__in=data.get("id_lis")).order_by("shiping_nu")
    property = [
        "shiping_nu", "auction_name", "com_num", "invoice_count",
        "foreign_ship", "delivery_company", "clearance_company", "master_nu",
        "branch_nu", "ship_num", "charge_weight", "takeoff_time",
        "arrive_time", "ship_status", "clear_time", "clear_status"
    ]
    row = 1
    for ship_obj in ship_obj_list:
        data = ship_obj.toDICT()
        data.update({"ship_status": ship_obj.get_ship_status})
        data.update({"clear_status": ship_obj.get_clear_status})
        [sheet.write(row, i, data[property[i]]) for i in range(len(property))]
        row = row + 1
    wb.save("/tmp/ship_list.xls")
    return ajax_success()
示例#14
0
def copy_last_form(request, template_name):
    """复制上一个lotform"""
    auction_id = request.session.get("auction_id")
    try:
        auc_obj = AuctionField.objects.get(pk=auction_id)
        varietys = auc_obj.variety_set.all()
    except AuctionField.DoesNotExist:
        raise Http404
    mem = memcache.Client(settings.MEMCACHES)
    last_form_data = mem.get(mckeys.COPY_LAST_FORM)
    customers = Customer.objects.all()
    if last_form_data:
        copy_form_data = last_form_data.copy()
        cform = CommodityForm(copy_form_data)
    else:
        cform = CommodityForm()
    html = render_to_string(
        template_name,
        {
            "cform": cform, 
            "copy": True,
            "auc_varietys": varietys,
            "customers": customers,
            "auction": auc_obj
        },
        context_instance=RequestContext(request)
    )
    return ajax_success(html=html)
示例#15
0
def auc_trans(request, auc_id):
    '''拍卖账户向美元账户或本地账户转账'''
    balance = request.POST.get("balance")
    rate = request.POST.get("rate")
    if not balance or not rate:
        return ajax_error("存在为空的项")
    else:
        try:
            balance = int(balance)
            rate = float(rate)
        except ValueError:
            return ajax_error("请填写正确类型的转账金额")
    try:
        auc_account_obj = AuctionAccount.objects.get(pk=auc_id)
        to_account = AuctionAccount.objects.\
            filter(name=auc_account_obj.name).exclude(style=auc_account_obj.style)
    except:
        return ajax_error("账户不存在")
    if to_account:
        to_account = to_account[0]
    else:
        return ajax_error("账户不存在")
    auc_account_obj.balance = auc_account_obj.balance - balance
    to_account.balance = to_account.balance + balance * rate
    auc_account_obj.save()
    to_account.save()
    return ajax_success()
示例#16
0
def voadd(request, template_name):
    '''接收post请求,生成初始发票'''
    if request.method == "POST":
        post_data = json.loads(request.POST.get("data", ''))
        all_lot_nu = post_data.get("all_lot_nu")
        new_rate = post_data.get("new_rate")
        com_rate = post_data.get("com_rate")
        comm_list = Commodity.objects.filter(lot__in=all_lot_nu)
        invoice_nu = Invoice.get_last_nu()
        form_data = {
            "customer_id": post_data.get("customer_id"),
            "begin_exchange_rate": new_rate,
            "invoice_nu": invoice_nu,
            "goods_nu": 100,
            "dollar_sum": 3000,
            "cost_sum": 2000,
            "commission_rate": com_rate
        }
        iform = InvoiceForm(form_data)
        if iform.is_valid():
            invoice_com = iform.save(commit=False)
            invoice_com.save()
            invoice_com.commodity_set = comm_list
            comm_list.update(is_invoice=1)
            mem = memcache.Client(settings.MEMCACHES)
            mem.set_multi({
                "begin_rate": new_rate,
                "commpression_rate": com_rate
            })
            return ajax_success()
    return ajax_error("检查数据格式")
示例#17
0
def get_invoice_table(request, invoice_id, template_name):
    try:
        invoice_obj = Invoice.objects.get(id=invoice_id)
    except Invoice.DoesNotExist:
        return ajax_error("invoice_obj is not exist")
    html = render_to_string(template_name,
                            {"invoice_obj": invoice_obj.toDICT()},
                            context_instance=RequestContext(request))
    return ajax_success(html)
示例#18
0
def delete(request):
    if request.method != "POST":
        raise Http404
    lot_nu_list = [
        str(lot) for lot in json.loads(request.POST.get("data", ''))
    ]
    del_list = Commodity.objects.filter(lot__in=lot_nu_list)
    del_list.delete()
    return ajax_success()
示例#19
0
def ship_data(request):
    '''获取ship的datatables信息'''
    ship_obj_list = Shiping.objects.all()
    back_data = []
    for ship_obj in ship_obj_list:
        data = ship_obj.toDICT()
        data.update({"status": ship_obj.get_ship_status})
        back_data.append(data)
    return ajax_success(back_data)
示例#20
0
def vmodify_info(request, invoice_id, template_name):
    '''初始发票修改功能'''
    try:
        invoice_obj = Invoice.objects.get(pk=invoice_id)
    except Invoice.DoesNotExist:
        return ajax_error("invoice obj does not exist")
    form = FinalInvoiceForm(instance=invoice_obj)
    html = render_to_string(template_name, {"form": form},
                            context_instance=RequestContext(request))
    return ajax_success(html=html)
示例#21
0
def get_select(request):
    if request.method == "POST":
        auction = json.loads(request.POST.get("data")).get("auction")
        try:
            auction_obj = AuctionField.objects.get(name=auction)
        except AuctionField.DoesNotExist:
            return ajax_error("auction obj does not exist")
        variety = [v.name for v in auction_obj.variety_set.all()]
        return ajax_success({"id_variety": variety})
    auction_name_list = [auc.name for auc in AuctionField.objects.all()]
    choice_data = {
        "id_auction": auction_name_list,
        "id_size": ['1-20', '20-40', '50-60'],
        "id_level": ["特等品", "一级品", "二级品"],
        "id_color": ["red", "white", "yellow", "golden"],
        "id_definition": ["模糊", "清晰", "微模糊", "微清晰"],
        "id_sex": ["female", "male"]
    }
    return ajax_success(choice_data)
示例#22
0
def get_invoice_table(request, invoice_id, template_name):
    try:
        invoice_obj = Invoice.objects.get(id=invoice_id)
    except Invoice.DoesNotExist:
        return ajax_error("invoice_obj is not exist")
    html = render_to_string(
        template_name,
        {"invoice_obj": invoice_obj.toDICT()},
        context_instance=RequestContext(request))
    return ajax_success(html)
示例#23
0
def get_select(request):
    if request.method == "POST":
        auction = json.loads(request.POST.get("data")).get("auction")
        try:
            auction_obj = AuctionField.objects.get(name=auction)
        except AuctionField.DoesNotExist:
            return ajax_error("auction obj does not exist")
        variety = [v.name for v in auction_obj.variety_set.all()]
        return ajax_success({"id_variety": variety})
    auction_name_list = [auc.name for auc in AuctionField.objects.all()]
    choice_data = {
        "id_auction": auction_name_list,
        "id_size": ['1-20', '20-40', '50-60'],
        "id_level": ["特等品", "一级品", "二级品"],
        "id_color": ["red", "white", "yellow", "golden"],
        "id_definition": ["模糊", "清晰", "微模糊", "微清晰"],
        "id_sex": ["female", "male"]
    }
    return ajax_success(choice_data)
示例#24
0
def add(request, auction_id, template_name):
    cform = CommodityForm()
    request.session["auction_id"] = auction_id
    try:
        auc_obj = AuctionField.objects.get(pk=auction_id)
    except AuctionField.DoesNotExist:
        raise Http404
    auc_varietys = auc_obj.variety_set.all()
    customers = Customer.objects.all()
    if request.method == "POST":
        mem = memcache.Client(settings.MEMCACHES)
        cform = CommodityForm(request.POST)
        if cform.is_valid():
            c_obj = cform.save()
            #c_obj.auction = auc_obj
            #c_obj.save()
            #根据拍卖日期创建公司子账户及更新客户账户欠款
            try:
                date_split = request.POST.get("auction_event").split("-")
                son_count = '-'.join([date_split[0], date_split[1], auc_obj.name])
                account, create = Account.objects.get_or_create(name=son_count, style="COM", defaults={"balance": 0})
                cus_obj = customers.get(name=c_obj.customer_id)
                cus_obj.account.balance = cus_obj.account.balance - c_obj.final_price*c_obj.number
                cus_obj.account.save()
            except Exception, e:
                print str(e)
            tt = mem.set(mckeys.COPY_LAST_FORM, request.POST)
            print tt, mckeys.COPY_LAST_FORM, request.POST
            cform = CommodityForm()
            html = render_to_string(
                "auctionweb/commodity/modform.html",
                {"cform": cform, "auc_varietys": auc_varietys, "customers":customers, "auction": auc_obj}, 
                context_instance=RequestContext(request)
            )
            return ajax_success({"success": True, "html": html})
        else:
            html = render_to_string(
                "auctionweb/commodity/modform.html",
                {"cform": cform, "auc_varietys": auc_varietys, "customers":customers, "auction": auc_obj}, 
                context_instance=RequestContext(request)
            )
            return ajax_success({"html": html})
示例#25
0
def classify_data(request):
    '''分类显示货运数据'''
    back_data = {}
    ship_obj = Shiping.objects.all()
    for ship in ship_obj:
        data = ship.toDICT()
        if data.get("foreign_ship") in back_data:
            back_data[data.get("foreign_ship")].append(data)
        else:
            back_data[data.get("foreign_ship")] = [data]
    return ajax_success(back_data)
示例#26
0
def get_select(request):
    if request.method == "POST":
        auction = json.loads(request.POST.get("data")).get("auction")
        try:
            auction_obj = AuctionField.objects.get(name=auction)
        except AuctionField.DoesNotExist:
            return ajax_error("auction obj does not exist")
        variety = [v.name for v in auction_obj.variety_set.all()]
        return ajax_success({"id_variety": variety})
    auction_name_list = [auc.name for auc in AuctionField.objects.all()]
    all_obj_def = lambda x: x.objects.all()
    choice_data = {
        "id_auction": auction_name_list,
        "id_size": [i.size for i in all_obj_def(LotSize)],
        "id_level": [i.level for i in all_obj_def(LotLevel)],
        "id_color": [i.color for i in all_obj_def(LotColor)],
        "id_definition": [i.definition for i in all_obj_def(LotClear)],
        "id_sex": ["Female", "Male"]
    }
    return ajax_success(choice_data)
示例#27
0
def get_commission_data(request):
    '''获取佣金模块的数据
    '''
    all_final_invoice = Invoice.objects.filter(is_pre=0).order_by("invoice_nu")
    comiss_obj = Commission.objects.all()[0]
    comiss_data = []
    for invoice in all_final_invoice:
        flag, data = invoice.commission_fee(comiss_obj)
        if not flag:
            continue
        comiss_data.append(data)
    return ajax_success(comiss_data)
示例#28
0
def get_commission_data(request):
    '''获取佣金模块的数据
    '''
    all_final_invoice = Invoice.objects.filter(is_pre=0).order_by("invoice_nu")
    comiss_obj = Commission.objects.all()[0]
    comiss_data = []
    for invoice in all_final_invoice:
        flag, data = invoice.commission_fee(comiss_obj)
        if not flag:
            continue
        comiss_data.append(data)
    return ajax_success(comiss_data)
示例#29
0
def add_peel_time(request, com_id):
    '''添加发票的削皮场流程时间参数'''
    if request.method != "POST":
        raise Http404
    try:
        com_obj = Commodity.objects.get(pk=com_id)
    except Commodity.DoesNotExist:
        return ajax_error("commodity obj does not exist")
    data = request.POST.copy()
    data.pop('csrfmiddlewaretoken')
    [setattr(invoice_obj, key, val) for key, val in data.items() if val]
    com_obj.save()
    return ajax_success()
示例#30
0
def vmodify_info(request, invoice_id, template_name):
    '''初始发票修改功能'''
    try:
        invoice_obj = Invoice.objects.get(pk=invoice_id)
    except Invoice.DoesNotExist:
        return ajax_error("invoice obj does not exist")
    lots = invoice_obj.commodity_set.all()
    if lots:
        auction = lots[0].auction
    form = FinalInvoiceForm(instance=invoice_obj)
    html = render_to_string(template_name, {"form": form},
                            context_instance=RequestContext(request))
    return ajax_success({"html": html, "is_dollar": True})
示例#31
0
def create_ship(request):
    '''生成货运信息'''
    invoice_id_list = json.loads(request.POST.get("invoice_id_list"))
    ship_invoice_obj = Invoice.objects.filter(id__in=invoice_id_list)
    goods_sum = ship_invoice_obj.aggregate(goods_nu_sum=Sum("goods_nu"),cost_sum=Sum("cost_sum"))
    ship_obj = Shiping.objects.create(
        shiping_nu=Shiping.get_last_nu(),
        com_num=goods_sum.get("goods_nu_sum"),
        invoice_count=goods_sum.get("cost_sum"),
    )
    ship_invoice_obj.update(is_ship=1, ship=ship_obj)
    ship_obj.save()
    return ajax_success()
示例#32
0
def add_peel_time(request, com_id):
    '''添加发票的削皮场流程时间参数'''
    if request.method != "POST":                                   
        raise Http404
    try:
        com_obj = Commodity.objects.get(pk=com_id)
    except Commodity.DoesNotExist:
        return ajax_error("commodity obj does not exist")
    data = request.POST.copy()
    data.pop('csrfmiddlewaretoken')
    [setattr(com_obj, key, val) for key, val in data.items() if val]
    com_obj.save()
    return ajax_success()
示例#33
0
def change_rate(request, template_name):
    if request.method == "POST":
        auction_id = request.POST.get("auction")
        auc_event = request.POST.get("auction_event")
        confirm = request.GET.get("confirm", False)
        try:
            auc_obj = AuctionField.objects.get(id=auction_id)
            auc_event_obj = AuctionEvent.objects.get(auction=auc_obj,
                                                     event=auc_event)
        except AuctionField.DoesNotExist:
            return ajax_error("auction field does not exist")
        except AuctionEvent.DoesNotExist:
            return ajax_error("auction event does not exist")
        all_invoices = auc_event_obj.invoice_set.all().filter(
            is_pre=0).order_by("invoice_nu")
        if not confirm:
            confirm_invoice_list = [i.toDICT() for i in all_invoices]
            return ajax_success(confirm_invoice_list)
        new_an_rmb_rate = request.POST.get("new_rate")
        try:
            new_an_rmb_rate = float(new_an_rmb_rate)
        except ValueError:
            return ajax_error("rate data format is abnormal")
        for i in all_invoices:
            com_list = i.commodity_set.all()
            post_data = {
                "commission_rate": i.commission_rate,
                "final_exchange_rate": i.final_exchange_rate,
                "an_rmb_rate": i.an_rmb_rate
            }
            try:
                i.goods_nu, i.dollar_sum, i.cost_sum = invoice_formula(
                    com_list, post_data, False)
                i.save()
            except Exception, e:
                return ajax_error("公式错误:%s" % str(e))
        confirm_invoice_list = [i.toDICT() for i in all_invoices]
        return ajax_success(confirm_invoice_list)
示例#34
0
def add_ship_info(request, ship_nu):
    '''接收ship的post信息,并保存'''
    try:
        ship_obj = Shiping.objects.get(pk=ship_nu)
    except Shiping.DoesNotExist:
        raise Http404
    foreign_ship = ForeignShip.objects.get(name=request.POST.get("foreign_ship"))
    data = {}
    for key, val in request.POST.items():
        data[key] = val
    data["foreign_ship"] = foreign_ship
    [setattr(ship_obj, key, val) for key, val in data.items()]
    ship_obj.save()
    return ajax_success()
示例#35
0
def add_ship_fee(request, ship_nu):
    '''添加货运付费详情'''
    try:
        ship_obj = Shiping.objects.get(pk=ship_nu)
    except Shiping.DoesNotExist:
        raise Http404
    invoice_nu = request.POST.get("invoice_nu") # 货运单发票号
    total_fee = request.POST.get("total_fee") # 运费总金额
    delivery_fee = request.POST.get("delivery_fee") # 地接费
    proxy_fee = request.POST.get("proxy_fee") # 代理费
    ship_obj.invoice_nu = invoice_nu
    ship_obj.total_fee = total_fee
    ship_obj.delivery_fee = delivery_fee
    ship_obj.proxy_fee = proxy_fee
    ship_obj.save()
    return ajax_success()
示例#36
0
def vmodify_info(request, invoice_id, template_name):
    '''初始发票修改功能'''
    try:
        invoice_obj = Invoice.objects.get(pk=invoice_id)
    except Invoice.DoesNotExist:
        return ajax_error("invoice obj does not exist")
    lots = invoice_obj.commodity_set.all()
    if lots:
        auction = lots[0].auction
    form = FinalInvoiceForm(instance=invoice_obj)
    html = render_to_string(
        template_name,
        {"form": form},
        context_instance=RequestContext(request)
    )
    return ajax_success({"html": html, "is_dollar": True})
示例#37
0
def create_final_invoice(request):
    '''生成最终发票'''
    print request.POST
    invoice_list = json.loads(request.POST.get("data", ''))
    error = False
    for idl in invoice_list:
        try:
            invoice_obj = Invoice.objects.get(pk=idl)
        except Invoice.DoesNotExist:
            error = True
        else:
            invoice_obj.is_pre = 0
            invoice_obj.save()
    if not error:
        return ajax_success()
    else:
        return ajax_error("存在未成功生成最终发票的数据")
示例#38
0
def cus_charge(request, cus_id):
    '''客户账户充值'''
    balance = request.POST.get("balance")
    if not balance:
        return ajax_error("充值金额不能为空")
    else:
        try:
            balance = int(balance)
        except:
            return ajax_error("请填写正确类型的充值金额")
    try:
        cus_obj = Account.objects.get(pk=cus_id)
    except:
        return ajax_error("账户不存在")
    cus_obj.balance = balance + cus_obj.balance
    cus_obj.save()
    return ajax_success()
示例#39
0
def add_peel_field(request, invoice_id):
    '''添加削皮场和削皮指示'''
    if request.method != "POST":
        raise Http404
    peel_field = request.POST.get("peel_field")
    peel_inform = request.POST.get("peel_inform")
    lot_id_lis = json.loads(request.POST.get("lot_id_arr"))
    try:
        peel_field_obj = PeelField.objects.get(pk=peel_field)
        peel_inform_obj = PeelInform.objects.get(pk=peel_inform)
    except:
        return ajax_error("object does not exist")
    com_list = Commodity.objects.filter(id__in=lot_id_lis)
    for com in com_list:
        com.peel_field = peel_field_obj
        com.peel_inform = peel_inform_obj
        com.save()
    return ajax_success()
示例#40
0
def add_ship_com(request):
    '''添加发票的货运相关公司'''
    if request.method != "POST":
        raise Http404
    clearance_com = request.POST.get("clearance_company")  # 清关公司
    delivery_com = request.POST.get("delivery_company")  # 地接公司
    harbour = request.POST.get("harbour")  # 港口
    not_net_weight = request.POST.get("not_net_weight")  # 毛重
    invoice_id_list = json.loads(request.POST.get("invoice_id_list"))
    update_dict = {
        "clearance_company": Clearance.objects.get(name=clearance_com),
        "delivery_company": Delivery.objects.get(name=delivery_com),
        "harbour": Harbour.objects.get(name=harbour),
    }
    if not_net_weight:
        update_dict['not_net_weight'] = not_net_weight
    Invoice.objects.filter(id__in=invoice_id_list).update(**update_dict)
    return ajax_success()
示例#41
0
def add_ship_com(request):
    '''添加发票的货运相关公司'''
    if request.method != "POST":
        raise Http404
    clearance_com = request.POST.get("clearance_company") # 清关公司
    delivery_com = request.POST.get("delivery_company") # 地接公司
    harbour = request.POST.get("harbour") # 港口
    not_net_weight = request.POST.get("not_net_weight") # 毛重
    invoice_id_list =  json.loads(request.POST.get("invoice_id_list"))
    update_dict = {
        "clearance_company": Clearance.objects.get(name=clearance_com),
        "delivery_company": Delivery.objects.get(name=delivery_com),
        "harbour": Harbour.objects.get(name=harbour),
    }
    if not_net_weight:
        update_dict['not_net_weight'] = not_net_weight
    Invoice.objects.filter(id__in=invoice_id_list).update(**update_dict)
    return ajax_success()
示例#42
0
def vlist(request, template_name):
    '''显示初始发票列表,和修改发票信息'''
    if request.method == "POST":
        invoice_id = request.POST.get("invoice_id")
        try:
            invoice_obj = Invoice.objects.get(pk=invoice_id)
        except Invoice.DoesNotExist:
            return ajax_error("invoice id not exist")
        form = FinalInvoiceForm(request.POST, instance=invoice_obj)
        if form.is_valid():
            invoice_obj.modify_date = datetime.datetime.now()
            invoice_obj.modify_times = 1 + (invoice_obj.modify_times if invoice_obj.modify_times else 0)
            invoice_obj.save()
            form.save()
            return ajax_success()
        else:
            return ajax_error(form.errors)
    return render(request, template_name)
示例#43
0
def begin_invoice_add(request, template_name):
    '''接收post请求,生成初始发票'''
    if request.method == "POST":
        post_data = json.loads(request.POST.get("data", ''))
        all_lot_nu = post_data.get("all_lot_nu")
        comm_list = Commodity.objects.filter(lot__in=all_lot_nu)
        invoice_nu = Invoice.get_last_nu()
        form_data = {
            "customer_id": post_data.get("customer_id"),
            "invoice_nu": invoice_nu,
            "an_rmb_rate": post_data.get("an_rmb_rate"),
            "commission_rate": post_data.get("commission_rate")
        }
        if post_data.get("begin_exchange_rate"):
            form_data["begin_exchange_rate"] = post_data.get(
                "begin_exchange_rate")
        iform = InvoiceForm(form_data)
        if iform.is_valid():
            invoice_com = iform.save(commit=False)
            try:
                goods_nu, dollar_sum, cost_sum = invoice_formula(
                    comm_list, post_data, True)
            except Exception, e:
                return ajax_error("公式错误:%s" % str(e))
            invoice_com.goods_nu = goods_nu
            invoice_com.dollar_sum = dollar_sum
            invoice_com.cost_sum = cost_sum
            if comm_list:
                auc_event, flag = AuctionEvent.objects.get_or_create(
                    auction=comm_list[0].auction,
                    event=comm_list[0].auction_event)
                invoice_com.auction_event = auc_event
            invoice_com.save()
            invoice_com.commodity_set.add(*comm_list)
            comm_list.update(is_invoice=1)
            mem = memcache.Client(settings.MEMCACHES)
            mem.set_multi({
                "begin_rate": post_data.get("begin_exchange_rate"),
                "commpression_rate": post_data.get("commission_rate"),
                "an_rmb_rate": post_data.get("an_rmb_rate")
            })
            return ajax_success()
        else:
            print iform.errors
示例#44
0
def ship_invoice(request, ship_nu):
    '''获取货运发票详情'''
    try:
        ship_obj = Shiping.objects.get(pk=ship_nu)
    except Shiping.DoesNotExist:
        raise Http404
    invoice_obj = ship_obj.invoice_set.all()
    print invoice_obj
    back_data = []
    for invo in invoice_obj:
        data = {}
        com_obj = invo.get_commodity_info().get("commodity")
        data["auction"] = com_obj.auction.name
        data["customer_id"] = com_obj.customer_id
        data["invoice_nu"] = invo.invoice_nu
        data["goods_num"] = invo.goods_nu
        data["invoice_count"] = invo.cost_sum
        back_data.append(data)
    return ajax_success(back_data)
示例#45
0
def unshipped_data(request):
    '''unshipped 数据信息获取渲染datatables'''
    all_invoice_obj = Invoice.objects.filter(is_pre=0, is_ship=0)
    back_data = []
    for v in all_invoice_obj:
        data = {}
        commodity_info = v.get_commodity_info()
        com_obj = commodity_info.get("commodity")
        try:
            peel_name = com_obj.peel_field.name
        except AttributeError:
            data["peel_name"] = ''
        else:
            data["peel_name"] = peel_name
        data["auction"] = com_obj.auction.name
        data["customer_no"] = com_obj.customer_id
        data.update(v.toDICT())
        back_data.append(data)
    return ajax_success(back_data)
示例#46
0
def auc_transothers(request, auc_id):
    '''拍卖行向其他账户转账'''
    balance = request.POST.get("balance")
    if not com_id or not balance:
        return ajax_error("存在为空的项")
    else:
        try:
            balance = int(balance)
        except ValueError:
            return ajax_error("请填写正确类型的转账金额")
    try:
        auc_account_obj = AuctionAccount.objects.get(pk=auc_id)
    except:
        return ajax_error("账户不存在")
    if auc_account_obj.style != "LOCAL":
        return ajax_error("拍卖行本地账户可以转账到其他账户")
    auc_account_obj.balance = auc_account_obj.balance - balance
    auc_account_obj.save()
    return ajax_success()
示例#47
0
def account_data(request):
    style = request.GET.get("style")
    accounts = Account.objects.all()
    if not style or style == "customer":
        account = accounts.filter(style="CUS")
    elif style == "company":
        account = accounts.filter(style="COM")
    elif style == "auction":
        account = AuctionAccount.objects.all()
    else:
        account = accounts.filter(style="OTHER")
    res = []
    for ac in account:
        data = {
            "name": ac.name, "balance": ac.balance, 
            "style": ac.style, "id": ac.id
        }
        res.append(data)
    return ajax_success({"account": res})
示例#48
0
def vlist(request, template_name):
    '''显示初始发票列表,和修改发票信息'''
    if request.method == "POST":
        invoice_id = request.POST.get("invoice_id")
        try:
            invoice_obj = Invoice.objects.get(pk=invoice_id)
        except Invoice.DoesNotExist:
            return ajax_error("invoice id not exist")
        form = FinalInvoiceForm(request.POST, instance=invoice_obj)
        if form.is_valid():
            invoice_obj.modify_date = datetime.datetime.now()
            invoice_obj.modify_times = 1 + (invoice_obj.modify_times
                                            if invoice_obj.modify_times else 0)
            invoice_obj.save()
            form.save()
            return ajax_success()
        else:
            return ajax_error(form.errors)
    return render(request, template_name)