تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
1 الرد
2480 أدوات العرض

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

الصورة الرمزية
إهمال
أفضل إجابة

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.

الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
1
مارس 24
975
4
أبريل 24
2873
0
فبراير 24
879
1
يوليو 24
1725
2
أبريل 24
1543