Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Facing problem with storing "ListOrderItems" API response from amazon. Can any one help me please?

By
samba
on 9/1/14, 12:21 AM 587 views

my code:

**********************************************************************************************************

results = connection_obj.call(id,'ListOrderItems',resultval['AmazonOrderId'])
                    if results:
                        last_dictionary = results[-1]
                        while last_dictionary.get('NextToken',False):
                            next_token = last_dictionary.get('NextToken',False)
                            del results[-1]
                            results = results + results
                            results = connection_obj.call(id,'ListOrderItemsByNextToken',next_token)
                            if last_dictionary.get('NextToken',False) == False:
                                break

*************************************************************************************************************

I am printing results after this but its pirnting [{}] empty list of dictionaries. You can reffer total function below. I am getting connection id, shop id and orders perfectly. The response of "ListOrderItems" showing on the terminal. But i unable to get that response in results list. Please help me.

Total function:

*************************************************************************************************************

def createOrder(self, cr, uid, id, shop_id, resultvals, context={}):
        _logger = logging.getLogger(__name__)
        saleorderid = False
        saleorder_obj = self.pool.get('sale.order')
        for resultval in resultvals:
            if resultval != {} and resultval.has_key('AmazonOrderId') :
                partner_obj = self.pool.get('res.partner')
                saleorderid = saleorder_obj.search(cr,uid,[('amazon_order_id','=',resultval.get('AmazonOrderId',False))])
                if not saleorderid:
                    partner_id = 857   #partner_obj.search(cr, uid, [('name','=',resultval['Name'])]) or [0]
                    #partner_id_update = self.updatePartner(cr,uid,id,shop_id,resultval,partner_id[0])
                    #partneraddress_id = self.updatePartnerAddress(cr,uid,id,resultval,partner_id_update)
                    partner_order_id = partner_obj.address_get(cr,uid,[partner_id], ['contact' or 'default'])
                    partner_invoice_id = partner_obj.address_get(cr,uid,[partner_id], ['invoice' or 'default'])
                    partner_shipping_id = partner_obj.address_get(cr,uid,[partner_id], ['delivery' or 'default'])
                    pricelist_id = partner_obj.browse(cr,uid,partner_id)['property_product_pricelist'].id
                    shop_obj = self.pool.get('sale.shop').browse(cr,uid,shop_id)
                    ordervals = {
                        'name' : 'Amazon_' + resultval.get('AmazonOrderId',False),
                        'picking_policy' : shop_obj.amazon_picking_policy,
                        'order_policy' : shop_obj.amazon_order_policy,
                        #'partner_order_id' : partner_order_id['contact' or 'default'],
                        'partner_invoice_id' : partner_invoice_id['invoice' or 'default'],
                        'date_order' : resultval.get('PurchaseDate',False),
                        'shop_id' : shop_id,
                        'partner_id' : partner_id,
                        'partner_shipping_id' : partner_shipping_id['delivery'],
                        'state' : 'draft',
                        'invoice_quantity' : shop_obj.amazon_invoice_quantity,
                        'pricelist_id' : pricelist_id,
                        'ext_payment_method' : 'ccsave',
                        'amazon_order_id': resultval.get('AmazonOrderId',False),
                    }
                    product_obj = self.pool.get('product.product')
                    results = connection_obj.call(id,'ListOrderItems',resultval['AmazonOrderId'])
                    if results:
                        last_dictionary = results[-1]
                        while last_dictionary.get('NextToken',False):
                            next_token = last_dictionary.get('NextToken',False)
                            del results[-1]
                            results = results + results
                            results = connection_obj.call(id,'ListOrderItemsByNextToken',next_token)
                            if last_dictionary.get('NextToken',False) == False:
                                break
                    if results:
                        _logger.exception('.................................results2...................................................  %s', results)
                        saleorderid = saleorder_obj.create(cr,uid,ordervals)
                        for each_result in results:
                            _logger.exception('.................................each_result...................................................  %s', each_result)
                            amazon_sku = each_result.get('SellerSKU',False)
                            _logger.exception('.................................amazon sku...................................................  %s', results)
                            product_search = product_obj.search(cr,uid,[('amazon_sku','=',amazon_sku)])
                            if not product_search:
                                product_id = self.createProduct(cr,uid,id,shop_id,each_result,context)
                            else:
                                product_id =product_search[0]
                            product_amount = product_obj.browse(cr,uid,product_id).list_price
                            tax_id = []
                            if each_result.get('ItemTax',False) > 0.0:
                                amount = float(each_result.get('ItemTax',False)) / 100
                                acctax_id = self.pool.get('account.tax').search(cr,uid,[('type_tax_use', '=', 'sale'), ('amount', '=', amount)])
                                if not acctax_id:
                                    acctax_id = self.createAccountTax(cr,uid,id,each_result.get('ItemTax',False), context)
                                    tax_id = [(6, 0, [acctax_id])]
                                else:
                                    tax_id = [(6, 0, acctax_id)]
                            orderlinevals = {
                            'order_id' : saleorderid,
                            'product_uom_qty' : each_result.get('QuantityOrdered',False),
                            'product_uom' : product_obj.browse(cr,uid,product_id).product_tmpl_id.uom_id.id,
                            'name' : product_obj.browse(cr,uid,product_id).product_tmpl_id.name,
                            'price_unit' : product_amount,
                            'delay' : product_obj.browse(cr,uid,product_id).product_tmpl_id.sale_delay,
                            'invoiced' : False,
                            'state' : 'confirmed',
                            'product_id' : product_id,
                            'tax_id' : tax_id
                                }
                            sale_order_line_obj = self.pool.get('sale.order.line')
                            saleorderlineid = sale_order_line_obj.create(cr,uid,orderlinevals)
                            if saleorderlineid:
                                prod_shipping_id = product_obj.search(cr,uid,[('default_code','=','SHIP AMAZON')])
                                if not prod_shipping_id:
                                    prod_shipping_id = self.createAmazonShippingProduct(cr,uid,id,context)
                                else:
                                    prod_shipping_id = prod_shipping_id[0]
                                if each_result.get('ShippingPrice',False):
                                    shiporderlinevals = {
                                        'order_id' : saleorderid,
                                        'product_uom_qty' : 1,
                                        'product_uom' : product_obj.browse(cr,uid,prod_shipping_id).product_tmpl_id.uom_id.id,
                                        'name' : product_obj.browse(cr,uid,prod_shipping_id).product_tmpl_id.name,
                                        'price_unit' : each_result.get('ShippingPrice',False),
                                        'delay' : product_obj.browse(cr,uid,prod_shipping_id).product_tmpl_id.sale_delay,
                                        'invoiced' : False,
                                        'state' : 'confirmed',
                                        'product_id' : prod_shipping_id,
                                    }
                                    shiplineid = sale_order_line_obj.create(cr,uid,shiporderlinevals)
                        company_id = self.pool.get('res.users').browse(cr,uid,uid).company_id.id
                        defaults = {'company_id':company_id}
                        #paid = True
                        #amazon_oe_status = self.amazon_oe_status(cr, uid, saleorderid, paid, context, defaults)
            else:
                print"No data is available"
        return True

*************************************************************************************************************

0
samba
On 9/11/14, 2:45 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 9/1/14, 12:21 AM
Seen: 587 times
Last updated: 3/16/15, 8:10 AM