Skip to Content
Menu
This question has been flagged
1 Reply
1852 Views

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')]                )

Avatar
Discard
Best Answer

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.

Avatar
Discard
Related Posts Replies Views Activity
1
Mar 24
566
4
Apr 24
1946
0
Feb 24
523
1
Jul 24
1193
2
Apr 24
947