Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
2487 Lượt xem

I want to add shipping delivery to customer order line

but when I call the method to do that I got this error 
" cannot marshal None unless allow_none is enabled\")\\nTypeError: cannot marshal None unless allow_none is enabled
"

this is my code 
@http.route('/shipping/',  auth="public",csrf=False, website=True, methods=['POST'])    

def add_shipping_to_cart(self,shipping_id, **kw):        

response = ''        

authe = request.httprequest.headers        

common = xmlrpclib.ServerProxy('{}/xmlrpc/2/common'.format(self.url), allow_none=True)        

models = xmlrpclib.ServerProxy('{}/xmlrpc/2/object'.format(self.url), allow_none=True)        

uid = common.authenticate(self.db,self.username, self.password, {})       

 try:           

 token = authe['Authorization'].replace('Bearer ', '')            

valid_token = models.execute_kw(self.db, uid, self.password, 'x_user_token', 'search_read', [[['x_studio_user_token' , '=' , token]]],{'fields':['x_studio_user_name']})        

except Exception as e:            

response = json.dumps({ 'data': 'no data', 'message': 'Unauthorized!'})            return Response(            response, status=401,            headers=[('Content-Type', 'application/json'), ('Content-Length', 100)]        )
               

if valid_token:            

​shipping_id = models.execute_kw(self.db, uid, self.password, 'delivery.carrier', 'search_read', [[['id' , '=' , shipping_id]]],{'fields':['id','name','delivery_type','fixed_price', 'free_over','amount']})            ​user_id =int(valid_token[0]['x_studio_user_name'][0])            

​print('shipping_id >>>>>>' , shipping_id)             

​print('shipping_id >>>>>>' , shipping_id[0]['name'])            

​user_partner = models.execute_kw(self.db, uid, self.password, 'res.users', 'search_read', [[['id' , '=' , user_id]]],{'fields':['partner_id','property_product_pricelist']})           

​ user_product_pricelist_id =user_partner[0]['property_product_pricelist'][0]             user_partner = user_partner[0]['partner_id'][0]                        

​user_quot = models.execute_kw(self.db, uid, self.password, 'sale.order', 'search_read', [['&',['state' ,'=' ,'draft'],['partner_id' , '=' , user_partner]]],{'fields':['id']})            

​if user_quot:                                                

​delivery_wizard = models.execute_kw(self.db, uid, self.password, 'choose.delivery.carrier', 'create', [{  'order_id': int(user_quot[0]['id']), 'carrier_id': int(shipping_id[0]['id']),          }])                

​try:                    

​context = {'allow_none': True}                    

​update = models.execute_kw(self.db, uid, self.password, 'choose.delivery.carrier', 'button_confirm', [[int(delivery_wizard)]], { 'context': context})                    

                except Exception as e:                     

​response=json.dumps({"data":[],"message":str(e)})                    

​return Response(                    response, status=403,                    headers=[('Content-Type', 'application/json'), ('Accept', 'application/json')]                )

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

As I can see in your code you're enabeling none values only when an exception happens.
I suggest you allow none values before and inside the exception or test your responce if it's null return false.
I think that python by default returns none values if there is no response from the server.

Hope this answer helps.
Good Luck.

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 3 24
982
4
thg 4 24
2897
0
thg 2 24
881
1
thg 7 24
1739
2
thg 4 24
1546