django-oscar的物流状态pending修改以及分析源码解决报错:The new status 'xxx' is not valid for this order
先說物流狀態(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)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: OpenAI 开 300 万 + 年薪招
- 下一篇: django的页面报错中出现xxxx.h