日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

django-oscar的物流状态pending修改以及分析源码解决报错:The new status 'xxx' is not valid for this order

發(fā)布時(shí)間:2023/12/31 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 django-oscar的物流状态pending修改以及分析源码解决报错:The new status 'xxx' is not valid for this order 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

先說物流狀態(tài)的修改:

django-oscar自帶的物流狀態(tài)是四個(gè):

OSCAR_INITIAL_ORDER_STATUS = 'Pending'
OSCAR_INITIAL_LINE_STATUS = 'Pending'
OSCAR_ORDER_STATUS_PIPELINE = {
??? 'Pending': ('Being processed', 'Cancelled',),
??? 'Being processed': ('Processed', 'Cancelled',),
??? 'Cancelled': (),
}

?

我們改為:

OSCAR_INITIAL_ORDER_STATUS = "已經(jīng)拍下,等待支付"
OSCAR_INITIAL_LINE_STATUS = "Pending"
#這個(gè)是供貨商的狀態(tài),不需要理會(huì)

OSCAR_ORDER_STATUS_PIPELINE = {
??? "已經(jīng)拍下,等待支付":("買家已經(jīng)支付,等待賣家發(fā)貨","取消訂單"),
??? "買家已經(jīng)支付,等待賣家發(fā)貨":("賣家已經(jīng)發(fā)貨","取消訂單"),#這里需要引入物流詳情
??? "賣家已經(jīng)發(fā)貨": ("物流派件中,等待買家取件", "Cancelled"),
??? "物流派件中,等待買家取件": ("訂單交易成功", "Cancelled"),
??? "訂單交易成功":(),
??? "訂單取消":(),
}

?

好了,有些同學(xué)想要定制修改上面的訂單狀態(tài),但是一不小心在使用的時(shí)候就出現(xiàn)了:

The new status 'xxx' is not valid for this order

先從settings.py中開始檢查:

①查看標(biāo)點(diǎn)是不是都是統(tǒng)一的圓角或者半角

②引號(hào)請(qǐng)統(tǒng)一,別一會(huì)兒?jiǎn)我?hào)一會(huì)兒雙引號(hào).

③不能跨key-value修改訂單狀態(tài),上面我們看到,總共6個(gè)key-value對(duì),

你可以在dashboard中對(duì)某個(gè)訂單從"已經(jīng)拍下,等待支付"改成"買家已經(jīng)支付,等待賣家發(fā)貨",

但是你不能在dashboard中對(duì)某個(gè)訂單從"已經(jīng)拍下,等待支付"直接改成"物流派件中"

#------------------------------------

如果上面檢查過后還是報(bào)這個(gè)錯(cuò),

那么我們來查看源碼:

上面的③受源碼/home/appleyuchi/.virtualenvs/python3.7/lib/python3.7/site-packages/oscar/apps/dashboard/views.py

中函數(shù)決定

def change_order_status(self, request, order):# This method is pretty similar to what# OrderDetailView.change_order_status does. Ripe for refactoring.new_status = request.POST['new_status'].strip()if not new_status:messages.error(request, _("The new status '%s' is not valid")% new_status)elif new_status not in order.available_statuses():print("new_status=",new_status)print("order.available_statuses=",order.available_statuses())messages.error(request, _("The new status '%s' is not valid for"" this order") % new_status)else:handler = EventHandler(request.user)old_status = order.statustry:handler.handle_order_status_change(order, new_status)except PaymentError as e:messages.error(request, _("Unable to change order status due"" to payment error: %s") % e)else:msg = _("Order status changed from '%(old_status)s' to"" '%(new_status)s'") % {'old_status': old_status,'new_status': new_status}messages.info(request, msg)order.notes.create(user=request.user, message=msg, note_type=OrderNote.SYSTEM)

當(dāng)訂單狀態(tài)選擇不對(duì)或者"兩個(gè)訂單狀態(tài)不相鄰"(注意看key-value對(duì))就會(huì)報(bào)錯(cuò).

上面的函數(shù)調(diào)用了:

/home/appleyuchi/.virtualenvs/python3.7/lib/python3.7/site-packages/oscar/apps/order/abstract_models.py

def available_statuses(self):"""Return all possible statuses that this order can move to"""print("函數(shù)內(nèi)self.pipeline=",self.pipeline)print("返回的是:",self.pipeline.get(self.status, ()))print("self_status=",self.status)return self.pipeline.get(self.status, ())

而這個(gè)abstract_models.py會(huì)去讀取OSCAR_ORDER_STATUS_PIPELINE變量.

上述就是關(guān)于這個(gè)問題的排查思路

?

然后問題來了,我們會(huì)發(fā)現(xiàn)在用戶的歷史訂單中,

物流狀態(tài)不顯示,怎么辦呢?

首先確保:

templates/oscar/customer/order/order_detail.html

中有下面的代碼:

{% if order.status %}<h2>{% trans 'Status' %}</h2>{{order.status}}<hr>{% endif %}

?

?

?

總結(jié)

以上是生活随笔為你收集整理的django-oscar的物流状态pending修改以及分析源码解决报错:The new status 'xxx' is not valid for this order的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。