Esempio n. 1
0
def add_peel_field(request, invoice_id):
    '''添加削皮场和削皮指示'''
    if request.method != "POST":
        raise Http404
    post_data = request.POST
    lot_id_lis = json.loads(request.POST.get("lot_id_arr"))
    sizes = LotSize.objects.all()
    varietys = Variety.objects.all()
    try:
        peel_field_obj = PeelField.objects.get(pk=post_data.get("peel_field"))
    except:
        return ajax_error("peelfield object does not exist")
    com_list = Commodity.objects.filter(id__in=lot_id_lis)
    for com in com_list:
        try:
            variety_obj = varietys.get(name=com.types, auction=com.auction)
            size_obj = sizes.get(size=com.size)
            args = {
                "sex": com.sex[0], "variety": variety_obj, 
                "name": post_data.get("peel_inform"),
                "peel_field": peel_field_obj, "size": size_obj
            }
            peel_inform_obj = PeelInform.objects.get(**args)
        except Exception, e:
            return ajax_error("%s"%str(e))
        com.peel_field = peel_field_obj
        com.peel_inform = peel_inform_obj
        com.peel_mo_num = com.peel_mo_num + 1
        com.peel_mo_time = datetime.datetime.now()
        com.peel_comment = post_data.get("peel_comment")
        com.peel_time_flag = post_data.get("peel_time_flag")
        com.peel_level = post_data.get("peel_level")
        com.save()
Esempio n. 2
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()
Esempio n. 3
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})
Esempio n. 4
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)
Esempio n. 5
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()
Esempio n. 6
0
def add_peel_field(request, invoice_id):
    '''添加削皮场和削皮指示'''
    if request.method != "POST":
        raise Http404
    post_data = request.POST
    lot_id_lis = json.loads(request.POST.get("lot_id_arr"))
    sizes = LotSize.objects.all()
    varietys = Variety.objects.all()
    try:
        peel_field_obj = PeelField.objects.get(pk=post_data.get("peel_field"))
    except:
        return ajax_error("peelfield object does not exist")
    com_list = Commodity.objects.filter(id__in=lot_id_lis)
    for com in com_list:
        try:
            variety_obj = varietys.get(name=com.types, auction=com.auction)
            size_obj = sizes.get(size=com.size)
            args = {
                "sex": com.sex[0],
                "variety": variety_obj,
                "name": post_data.get("peel_inform"),
                "peel_field": peel_field_obj,
                "size": size_obj
            }
            peel_inform_obj = PeelInform.objects.get(**args)
        except Exception, e:
            return ajax_error("%s" % str(e))
        com.peel_field = peel_field_obj
        com.peel_inform = peel_inform_obj
        com.peel_mo_num = com.peel_mo_num + 1
        com.peel_mo_time = datetime.datetime.now()
        com.peel_comment = post_data.get("peel_comment")
        com.peel_time_flag = post_data.get("peel_time_flag")
        com.peel_level = post_data.get("peel_level")
        com.save()
Esempio n. 7
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("检查数据格式")
Esempio n. 8
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()
Esempio n. 9
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()
Esempio n. 10
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)
Esempio n. 11
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)
Esempio n. 12
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))
    del_com_list = Commodity.objects.filter(lot__in=all_post_lot_nu)
    com_list = Commodity.objects.filter(lot__in=all_lot_nu)
    args = invoice_obj.toDICT()
    try:
        goods_nu, dollar_sum, cost_sum = invoice_formula(com_list, args, True)
    except Exception, e:
        return ajax_error("公式错误:%s"%str(e))
Esempio n. 13
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)
Esempio n. 14
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()
Esempio n. 15
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)
Esempio n. 16
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)
Esempio n. 17
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))
    del_com_list = Commodity.objects.filter(lot__in=all_post_lot_nu)
    com_list = Commodity.objects.filter(lot__in=all_lot_nu)
    args = invoice_obj.toDICT()
    try:
        goods_nu, dollar_sum, cost_sum = invoice_formula(com_list, args, True)
    except Exception, e:
        return ajax_error("公式错误:%s" % str(e))
Esempio n. 18
0
def com_transothers(request, com_id):
    '''公司子账户向其他账户转账'''
    other_id = request.POST.get("other")
    balance = request.POST.get("balance")
    if not other_id or not balance:
        return ajax_error("存在为空的项")
    else:
        try:
            balance = int(balance)
        except ValueError:
            return ajax_error("请填写正确类型的转账金额")
    try:
        other_account_obj = Account.objects.get(pk=other_id)
        com_ac_obj = Account.objects.get(pk=com_id)
    except:
        return ajax_error("账户不存在")
    com_ac_obj.balance = com_ac_obj.balance - balance 
    other_account_obj.balance = other_account_obj.balance + balance
    com_ac_obj.save()
    other_account_obj.save()
    return ajax_success()
Esempio n. 19
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})
Esempio n. 20
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()
Esempio n. 21
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()
Esempio n. 22
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)
Esempio n. 23
0
def com_trans(request, com_id):
    '''公司子账户向拍卖行美元账户转账'''
    auc_id = request.POST.get("auction")
    balance = request.POST.get("balance")
    rate = request.POST.get("rate")
    if not auc_id or 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)
        com_ac_obj = Account.objects.get(pk=com_id)
    except:
        return ajax_error("账户不存在")
    com_ac_obj.balance = com_ac_obj.balance - balance
    auc_account_obj.balance = auc_account_obj.balance + balance*rate
    com_ac_obj.save()
    auc_account_obj.save()
    return ajax_success()
Esempio n. 24
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})
Esempio n. 25
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("存在未成功生成最终发票的数据")
Esempio n. 26
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()
Esempio n. 27
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
Esempio n. 28
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)
Esempio n. 29
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)
Esempio n. 30
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)
Esempio n. 31
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
Esempio n. 32
0
def create_final_invoice(request):
    '''生成最终发票'''
    invoice_list = json.loads(request.POST.get("data", ''))
    error = False
    for idl in invoice_list:
        try:
           invoice_obj = Invoice.objects.get(pk=idl)
           com_list = invoice_obj.commodity_set.all()
        except Invoice.DoesNotExist:
            error = True
        else:
            print invoice_obj.toDICT()
            try:
                goods_nu, dollar_sum, cost_sum = invoice_formula(com_list, invoice_obj.toDICT(), False)
            except Exception, e:
                return ajax_error("公式错误:%s"%str(e))
            invoice_obj.is_pre = 0
            invoice_obj.goods_nu = goods_nu
            invoice_obj.dollar_sum = dollar_sum
            invoice_obj.cost_sum = cost_sum
            invoice_obj.save()
Esempio n. 33
0
def create_final_invoice(request):
    '''生成最终发票'''
    invoice_list = json.loads(request.POST.get("data", ''))
    error = False
    for idl in invoice_list:
        try:
            invoice_obj = Invoice.objects.get(pk=idl)
            com_list = invoice_obj.commodity_set.all()
        except Invoice.DoesNotExist:
            error = True
        else:
            print invoice_obj.toDICT()
            try:
                goods_nu, dollar_sum, cost_sum = invoice_formula(
                    com_list, invoice_obj.toDICT(), False)
            except Exception, e:
                return ajax_error("公式错误:%s" % str(e))
            invoice_obj.is_pre = 0
            invoice_obj.goods_nu = goods_nu
            invoice_obj.dollar_sum = dollar_sum
            invoice_obj.cost_sum = cost_sum
            invoice_obj.save()
Esempio n. 34
0
        else:
            print invoice_obj.toDICT()
            try:
                goods_nu, dollar_sum, cost_sum = invoice_formula(
                    com_list, invoice_obj.toDICT(), False)
            except Exception, e:
                return ajax_error("公式错误:%s" % str(e))
            invoice_obj.is_pre = 0
            invoice_obj.goods_nu = goods_nu
            invoice_obj.dollar_sum = dollar_sum
            invoice_obj.cost_sum = cost_sum
            invoice_obj.save()
    if not error:
        return ajax_success()
    else:
        return ajax_error("存在未成功生成最终发票的数据")


def fvlist(request, template_name):
    '''显示最终发票列表'''
    year = request.GET.get("year")
    a_event = AuctionEvent.objects.all()
    auction_year = set([i.get_year() for i in a_event])
    if not auction_year:
        return Http404
    if not year:
        year = sorted(auction_year, reverse=True)[0]
    all_auc_events = AuctionEvent.objects.filter(event__icontains=year)
    result = {}
    for ev in all_auc_events:
        au_name = ev.auction.name
Esempio n. 35
0
            error = True
        else:
            print invoice_obj.toDICT()
            try:
                goods_nu, dollar_sum, cost_sum = invoice_formula(com_list, invoice_obj.toDICT(), False)
            except Exception, e:
                return ajax_error("公式错误:%s"%str(e))
            invoice_obj.is_pre = 0
            invoice_obj.goods_nu = goods_nu
            invoice_obj.dollar_sum = dollar_sum
            invoice_obj.cost_sum = cost_sum
            invoice_obj.save()
    if not error:
        return ajax_success()
    else:
        return ajax_error("存在未成功生成最终发票的数据")

def fvlist(request, template_name):
    '''显示最终发票列表'''
    year = request.GET.get("year")
    a_event = AuctionEvent.objects.all()
    auction_year = set([i.get_year() for i in a_event])
    if not auction_year:
        return Http404
    if not year:
        year = sorted(auction_year, reverse=True)[0]
    all_auc_events = AuctionEvent.objects.filter(event__icontains=year)        
    result = {}
    for ev in all_auc_events:
        au_name = ev.auction.name
        if au_name in result: