def create_product(self,cr,uid,message_id,product_obj,merchant_string,instance_obj,quantity): price_string = """<Message> <MessageID>%(message_id)s</MessageID> <Price> <SKU>%(sku)s</SKU> <StandardPrice currency="USD">%(price)s</StandardPrice> </Price> </Message>""" price_string = price_string % { 'message_id':message_id, 'sku': product_obj.amazon_sku, 'price':product_obj.list_price, } price_str = """<MessageType>Price</MessageType>""" price_data = self.xml_format(price_str,merchant_string,price_string) price_submission_id = connection_obj.call(instance_obj, 'POST_PRODUCT_PRICING_DATA',price_data) print"price_submission_id",price_submission_id time.sleep(40) # if price_submission_id.get('FeedSubmissionId',False): # time.sleep(80) # submission_price_results = connection_obj.call(instance_obj, 'GetFeedSubmissionResult',price_submission_id.get('FeedSubmissionId',False)) inventory_string = """<Message><MessageID>%(message_id)s</MessageID><Inventory><SKU>%(sku)s</SKU><Quantity>%(qty)s</Quantity></Inventory></Message>""" inventory_string = inventory_string % { 'message_id':message_id, 'sku': product_obj.amazon_sku, 'qty':quantity[0]} inventory_str = """<MessageType>Inventory</MessageType>""" inventory_data = self.xml_format(inventory_str,merchant_string,inventory_string) inventory_submission_id = connection_obj.call(instance_obj, 'POST_INVENTORY_AVAILABILITY_DATA',inventory_data) time.sleep(40) print"inventory_submission_id",inventory_submission_id cr.execute("UPDATE product_product SET amazon_prod_status='active',amazon_updated_price='%s' where id=%d"%(product_obj.list_price,product_obj.id,)) cr.commit() return True
def import_orders_amazon(self, cr, uid, ids, context=None): instance_obj = self.browse(cr, uid, ids[0]).amazon_instance_id last_import_time = self.browse(cr, uid, ids[0]).last_amazon_order_import_date if not last_import_time: today = datetime.now() DD = timedelta(days=30) earlier = today - DD earlier_str = earlier.strftime("%Y-%m-%dT%H:%M:%S") createdAfter = earlier_str + 'Z' print "createdAfter", createdAfter createdBefore = '' else: db_import_time = time.strptime(last_import_time, "%Y-%m-%d %H:%M:%S") db_import_time = time.strftime("%Y-%m-%dT%H:%M:%S", db_import_time) createdAfter = time.strftime( "%Y-%m-%dT%H:%M:%S", time.gmtime( time.mktime( time.strptime(db_import_time, "%Y-%m-%dT%H:%M:%S")))) createdAfter = str(createdAfter) + 'Z' print "createdAfter", createdAfter make_time = datetime.utcnow() - timedelta(seconds=120) make_time_str = make_time.strftime("%Y-%m-%dT%H:%M:%S") createdBefore = make_time_str + 'Z' print "createdBefore", createdBefore # try: time.sleep(10) results = connection_obj.call(instance_obj, 'ListOrders', createdAfter, createdBefore) time.sleep(30) if results: last_dictionary = results[-1] while last_dictionary.get('NextToken', False): next_token = last_dictionary.get('NextToken', False) del results[-1] time.sleep(25) results = connection_obj.call(instance_obj, 'ListOrdersByNextToken', next_token) results = results + results last_dictionary = results[-1] if last_dictionary.get('NextToken', False) == False: break if results: orderid = self.pool.get('amazon.instance').createOrder( cr, uid, instance_obj, ids[0], results, context) cr.execute( "UPDATE sale_shop SET last_amazon_order_import_date='%s' where id=%d" % (time.strftime('%Y-%m-%d %H:%M:%S'), ids[0])) else: self.log(cr, uid, ids[0], "No More Orders to Import") return True
def update_amazon_orders(self,cr,uid,ids,context=None): message_information = '' item_string = '' message_id = 1 saleorder_obj = self.pool.get('sale.order') saleorder_ids = [] last_amazon_update_order_export_date = self.browse(cr,uid,ids[0]).last_amazon_update_order_export_date if not last_amazon_update_order_export_date: saleorder_ids = saleorder_obj.search(cr,uid,[('state','=','done'),('shop_id','=',ids[0]),('amazon_order_id','!=',False)]) else: saleorder_ids = saleorder_obj.search(cr,uid,[('write_date','>',last_amazon_update_order_export_date),('state','=','done'),('shop_id','=',ids[0]),('amazon_order_id','!=',False)]) if saleorder_ids: for saleorder_id in saleorder_ids: picking_ids = saleorder_obj.browse(cr,uid,saleorder_id).picking_ids if picking_ids: order_id = saleorder_obj.browse(cr,uid,saleorder_id).amazon_order_id #for getting order_id tracking_id = picking_ids[0].carrier_tracking_ref # for getting tracking_id carrier_id = picking_ids[0].carier_id if carrier_id: carrier_code_split = carrier_id.name.split(' ') carrier_code_split_first = carrier_code_split[0]#for getting shipping method product_info = saleorder_obj.browse(cr,uid,saleorder_id).order_line for each_line in product_info: product_qty = each_line.product_uom_qty product_id = each_line.product_id product_qty_split = str(product_qty).split(".") product_qty_first = product_qty_split[0] product_order_item_id = product_id.product_order_item_id item_string = '''<Item><AmazonOrderItemCode>%s</AmazonOrderItemCode> <Quantity>%s</Quantity></Item>'''%(product_order_item_id,product_qty_first) fulfillment_date = time.strftime('%Y-%m-%dT%H:%M:%S') fulfillment_date_concat = str(fulfillment_date) + '-00:00' message_information += """<Message><MessageID>%s</MessageID><OperationType>Update</OperationType><OrderFulfillment><AmazonOrderID>%s</AmazonOrderID><FulfillmentDate>%s</FulfillmentDate><FulfillmentData><CarrierName>%s</CarrierName><ShippingMethod>%s</ShippingMethod><ShipperTrackingNumber>%s</ShipperTrackingNumber></FulfillmentData>"""+item_string.encode("utf-8")+"""</OrderFulfillment></Message>""" % (message_id,order_id,fulfillment_date_concat,carrier_code_split_first,carrier_code,tracking_id) message_id = message_id + 1 data = """<?xml version="1.0" encoding="utf-8"?><AmazonEnvelope xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="amzn-envelope.xsd"><Header><DocumentVersion>1.01</DocumentVersion><MerchantIdentifier>M_SELLERON_82825133</MerchantIdentifier></Header><MessageType>OrderFulfillment</MessageType>""" + message_information.encode("utf-8") + """</AmazonEnvelope>""" if data: results = connection_obj.call(instance_obj, 'POST_ORDER_FULFILLMENT_DATA',data) print"results",results if results.get('FeedSubmissionId',False): time.sleep(70) submission_results = connection_obj.call(instance_obj, 'GetFeedSubmissionResult',results.get('FeedSubmissionId',False)) if submission_results.get('MessagesWithError',False) == '0': self.log(cr, uid,1, "Status Updated Successfully") else: if submission_results.get('ResultDescription',False): error_message = submission_results.get('ResultDescription',False) error_message = str(error_message).replace("'"," ") self.log(cr, uid,1, error_message) # self.write(cr,uid,ids[0],{'last_ebay_update_order_export_date':time.strftime('%Y-%m-%d %H:%M:%S')}) cr.execute("UPDATE sale_shop SET last_ebay_update_order_export_date='%s' where id=%d"%(time.strftime('%Y-%m-%d %H:%M:%S'),ids[0])) return True
def amazon_product_lookup(self, cr, uid, ids, context=None): """ Function to search product on amazon based on ListMatchingProduct Operation """ amazon_instance_id = self.browse(cr, uid, ids[0]).amazon_instance_id if not amazon_instance_id: raise osv.except_osv( 'Warning !', 'Please select Amazon Instance and try again.') amazon_instance_obj = self.pool.get('amazon.instance').browse( cr, uid, int(amazon_instance_id)) product_query = self.browse(cr, uid, ids[0]).prod_query if not product_query: raise osv.except_osv( 'Warning !', 'Please enter Product Search Query and try again') product_query = product_query.strip().replace(' ', '%') prod_query_contextid = self.browse(cr, uid, ids[0]).prod_query_contextid productData = False try: productData = connection_obj.call(amazon_instance_obj, 'ListMatchingProducts', product_query, prod_query_contextid) print 'productData===--==-', productData except Exception, e: raise osv.except_osv(_('Error !'), e)
def export_stock_levels_amazon(self,cr,uid,ids,context=None): product_obj = self.pool.get('product.product') stock_move_obj = self.pool.get('stock.move') instance_obj = self.browse(cr,uid,ids[0]).amazon_instance_id product_ids = product_obj.search(cr,uid,[('amazon_export','=','True'),('amazon_prod_status','=','active')]) last_amazon_inventory_export_date = self.browse(cr,uid,ids[0]).last_amazon_inventory_export_date if last_amazon_inventory_export_date: recent_move_ids = stock_move_obj.search(cr, uid, [('date', '>', last_amazon_inventory_export_date), ('product_id', 'in', product_ids), ('state', '!=', 'draft'), ('state', '!=', 'cancel')]) else: recent_move_ids = stock_move_obj.search(cr, uid, [('product_id', 'in', product_ids)]) product_ids = [move.product_id.id for move in stock_move_obj.browse(cr, uid, recent_move_ids) if move.product_id.state != 'obsolete'] product_ids = [x for x in set(product_ids)] merchant_string = '' if instance_obj: merchant_string ="<MerchantIdentifier>%s</MerchantIdentifier>"%(instance_obj.aws_merchant_id) warehouse_id = self.browse(cr,uid,ids[0]).warehouse_id.id if warehouse_id: location_id = self.pool.get('stock.warehouse').browse(cr,uid,warehouse_id).lot_input_id.id message_information = '' message_id = 1 for each_product in product_ids: product_sku = product_obj.browse(cr,uid,each_product).amazon_sku product_id_location = self._my_value(cr, uid,location_id,each_product,context={}) product_split = str(product_id_location).split('.') value = product_split[0] message_information += """<Message><MessageID>%s</MessageID><OperationType>Update</OperationType><Inventory><SKU>%s</SKU><Quantity>%s</Quantity></Inventory></Message>""" % (message_id,product_sku,value) message_id = message_id + 1 if message_information: data = """<?xml version="1.0" encoding="utf-8"?><AmazonEnvelope xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="amzn-envelope.xsd"><Header><DocumentVersion>1.01</DocumentVersion>"""+ merchant_string.encode("utf-8") +"""</Header><MessageType>Inventory</MessageType>""" + message_information.encode("utf-8") + """</AmazonEnvelope>""" if data: results = connection_obj.call(instance_obj, 'POST_INVENTORY_AVAILABILITY_DATA',data) print"results",results if results.get('FeedSubmissionId',False): time.sleep(70) submission_results = connection_obj.call(instance_obj, 'GetFeedSubmissionResult',results.get('FeedSubmissionId',False)) if submission_results.get('MessagesWithError',False) == '0': self.log(cr, uid,1, "Inventory Updated Successfully") else: if submission_results.get('ResultDescription',False): error_message = submission_results.get('ResultDescription',False) error_message = str(error_message).replace("'"," ") self.log(cr, uid,1, error_message) self.write(cr,uid,ids[0],{'last_amazon_inventory_export_date':time.strftime('%Y-%m-%d %H:%M:%S')}) return True
def import_orders_amazon(self,cr,uid,ids,context=None): instance_obj = self.browse(cr,uid,ids[0]).amazon_instance_id last_import_time = self.browse(cr,uid,ids[0]).last_amazon_order_import_date if not last_import_time: today = datetime.now() DD = timedelta(days=30) earlier = today - DD earlier_str = earlier.strftime("%Y-%m-%dT%H:%M:%S") createdAfter = earlier_str+'Z' print"createdAfter",createdAfter createdBefore ='' else: db_import_time = time.strptime(last_import_time, "%Y-%m-%d %H:%M:%S") db_import_time = time.strftime("%Y-%m-%dT%H:%M:%S",db_import_time) createdAfter = time.strftime("%Y-%m-%dT%H:%M:%S",time.gmtime(time.mktime(time.strptime(db_import_time,"%Y-%m-%dT%H:%M:%S")))) createdAfter = str(createdAfter)+'Z' print"createdAfter",createdAfter make_time = datetime.utcnow() - timedelta(seconds=120) make_time_str = make_time.strftime("%Y-%m-%dT%H:%M:%S") createdBefore = make_time_str+'Z' print"createdBefore",createdBefore # try: time.sleep(10) results = connection_obj.call(instance_obj, 'ListOrders',createdAfter,createdBefore) time.sleep(30) if results: last_dictionary = results[-1] while last_dictionary.get('NextToken',False): next_token = last_dictionary.get('NextToken',False) del results[-1] time.sleep(25) results = connection_obj.call(instance_obj, 'ListOrdersByNextToken',next_token) results = results + results last_dictionary = results[-1] if last_dictionary.get('NextToken',False) == False: break if results: orderid = self.pool.get('amazon.instance').createOrder(cr,uid,instance_obj,ids[0],results,context) cr.execute("UPDATE sale_shop SET last_amazon_order_import_date='%s' where id=%d"%(time.strftime('%Y-%m-%d %H:%M:%S'),ids[0])) else: self.log(cr,uid,ids[0],"No More Orders to Import") return True
def export_images_amazon(self,cr,uid,ids,context={}): product_image_obj = self.pool.get('product.images') instance_obj = self.browse(cr,uid,ids[0]).amazon_instance_id product_obj = self.pool.get("product.product") product_ids = product_obj.search(cr,uid,[('amazon_export','=','True'),('amazon_prod_status','=','active')]) last_amazon_image_export_date = self.browse(cr,uid,ids[0]).last_amazon_image_export_date if last_amazon_image_export_date: recent_image_ids = product_image_obj.search(cr, uid, [('write_date', '>', last_amazon_image_export_date), ('product_id', 'in', product_ids)]) else: recent_image_ids = product_image_obj.search(cr, uid, [('product_id', 'in', product_ids)]) merchant_string = '' if instance_obj: merchant_string ="<MerchantIdentifier>%s</MerchantIdentifier>"%(instance_obj.aws_merchant_id) message_information = '' message_id = 1 for each_image_id in recent_image_ids: product_id = product_image_obj.browse(cr,uid,each_image_id).product_id product_sku = product_id.amazon_sku image_url = product_image_obj.browse(cr,uid,each_image_id).amazon_url_location message_information += """<Message><MessageID>%s</MessageID><OperationType>Update</OperationType><ProductImage><SKU>%s</SKU><ImageType>Main</ImageType><ImageLocation>%s</ImageLocation></ProductImage></Message>""" % (message_id,product_sku,image_url) message_id = message_id + 1 if message_information: data = """<?xml version="1.0" encoding="utf-8"?><AmazonEnvelope xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="amzn-envelope.xsd"><Header><DocumentVersion>1.01</DocumentVersion>"""+ merchant_string.encode("utf-8") +"""</Header><MessageType>ProductImage</MessageType>""" + message_information.encode("utf-8") + """</AmazonEnvelope>""" if data: results = connection_obj.call(instance_obj, 'POST_PRODUCT_IMAGE_DATA',data) print"results",results if results.get('FeedSubmissionId',False): time.sleep(80) submission_results = connection_obj.call(instance_obj, 'GetFeedSubmissionResult',results.get('FeedSubmissionId',False)) if submission_results.get('MessagesWithError',False) == '0': self.log(cr,uid,1,'Images Updated Successfully') else: if submission_results.get('ResultDescription',False): error_message = submission_results.get('ResultDescription',False) error_message = str(error_message).replace("'"," ") self.log(cr, uid,log_id, product_long_message) cr.execute("UPDATE sale_shop SET last_amazon_image_export_date='%s' where id=%d"%(time.strftime('%Y-%m-%d %H:%M:%S'),ids[0])) return True
def amazon_product_lookup(self, cr, uid, ids, context=None): """ Function to search product on amazon based on ListMatchingProduct Operation """ amazon_instance_id = self.browse(cr,uid,ids[0]).amazon_instance_id if not amazon_instance_id: raise osv.except_osv('Warning !','Please select Amazon Instance and try again.') amazon_instance_obj = self.pool.get('amazon.instance').browse(cr,uid,int(amazon_instance_id)) product_query = self.browse(cr,uid,ids[0]).prod_query if not product_query: raise osv.except_osv('Warning !','Please enter Product Search Query and try again') product_query = product_query.strip().replace(' ','%') prod_query_contextid = self.browse(cr,uid,ids[0]).prod_query_contextid productData = False try: productData = connection_obj.call(amazon_instance_obj, 'ListMatchingProducts',product_query,prod_query_contextid) print'productData===--==-',productData except Exception, e: raise osv.except_osv(_('Error !'),e)
def import_cat(self,cr,uid,ids,context={}): instance = self.browse(cr,uid,ids)[0] call = connection_obj.call(instance, 'POST_PRODUCT_DATA','data') # parser = etree.XMLParser(remove_blank_text=True) # data = etree.parse(open("/home/poonam/AMAZON/Lighting.xsd"),parser) # root = data.getroot().findall('schema/element') # # print"root",root # fdf # for each_iter in root.iter("*"): # print"each_iter",each_iter # tag = each_iter.tag # print"tag",tag # if tag.split('}')[-1] =='element': # print"this is the element tag" # attribute = each_iter.attrib # print"attribute",attribute # if attribute.get('ref'): # find_value = data.find('LightsAndFixtures') # print"find_value",find_value return True
def export_catalog_amazon(self,cr,uid,ids,context={}): instance_obj = self.browse(cr,uid,ids[0]).amazon_instance_id merchant_string = '' standard_product_string = '' category_info = '' final_condition_string = '' condition_string = '' desc = '' log_id = 0 warehouse_id = self.browse(cr,uid,ids[0]).warehouse_id.id location_id = self.pool.get('stock.warehouse').browse(cr,uid,warehouse_id).lot_stock_id.id release_date = datetime.utcnow() release_date = release_date.strftime("%Y-%m-%dT%H:%M:%S") date_string = """<LaunchDate>%s</LaunchDate> <ReleaseDate>%s</ReleaseDate>"""%(release_date,release_date) if instance_obj: merchant_string ="<MerchantIdentifier>%s</MerchantIdentifier>"%(instance_obj.aws_merchant_id) amazon_exportable_product_ids = self.browse(cr,uid,ids[0]).amazon_exportable_product_ids message_information = '' message_id = 1 for each_product in amazon_exportable_product_ids: product_nm = each_product.name_template product_sku = each_product.amazon_sku function_call = self._my_value(cr, uid,location_id,each_product.id,context={}) quantity = str(function_call).split('.') condition = each_product.amzn_condtn condition_note = each_product.condition_note if condition: condition_string += """<ConditionType>%s</ConditionType>"""%(condition) if condition and condition_note: condition_string += """<ConditionNote>%s</ConditionNote>"""%(condition_note) final_condition_string = "<Condition>"+ condition_string.encode('utf-8') + "</Condition>" title = each_product.name_template sale_description = each_product.description_sale if sale_description: desc = "<Description>%s</Description>"%(sale_description) # product_category = each_product.amazon_category amz_type = each_product.amz_type amz_type_value = each_product.amz_type_value product_asin = each_product.amazon_asin if amz_type and amz_type_value: standard_product_string = """ <StandardProductID> <Type>%s</Type> <Value>%s</Value> </StandardProductID> """%(amz_type,amz_type_value) if not standard_product_string: category_info = """<ProductData> <CE> <ProductType> <ConsumerElectronics> <VariationData></VariationData> <Color>Color</Color> <DigitalMediaFormat>4_mm_tape</DigitalMediaFormat> </KindleAccessories> </ProductType> </CE> </ProductData>""" standard_product_string = """ <StandardProductID> <Type>ASIN</Type> <Value>%s</Value> </StandardProductID> """%(product_asin) message_information = """<Message> <MessageID>%(message_id)s</MessageID> <Product> <SKU>%(sku)s</SKU> """ +standard_product_string.encode('utf-8')+""" """+ date_string.encode('utf-8') + """ """+ final_condition_string.encode('utf-8') +""" <DescriptionData> <Title>%(title)s</Title> """ + desc.encode("utf-8") + """ </DescriptionData> </Product> </Message>""" message_information = message_information % { 'sku': product_sku, 'condition': condition, 'title': title, 'message_id':message_id} product_str = """<MessageType>Product</MessageType>""" product_data = self.xml_format(product_str,merchant_string,message_information) print"data",product_data if product_data: product_submission_id = connection_obj.call(instance_obj, 'POST_PRODUCT_DATA',product_data) if product_submission_id.get('FeedSubmissionId',False): time.sleep(80) submission_results = connection_obj.call(instance_obj, 'GetFeedSubmissionResult',product_submission_id.get('FeedSubmissionId',False)) if submission_results.get('MessagesWithError',False) == '0': amazon_status = each_product.amazon_prod_status if amazon_status == 'active': if each_product.list_price != each_product.amazon_updated_price: print"price UnMatches" self.update_product(cr,uid,message_id,each_product,merchant_string,instance_obj) product_long_message = ('%s: Updated Successfully on Amazon') % (product_nm) self.log(cr, uid,log_id, product_long_message) log_id += 1 else: self.create_product(cr,uid,message_id,each_product,merchant_string,instance_obj,quantity) product_long_message = ('%s: Created Successfully on Amazon') % (product_nm) self.log(cr, uid,log_id, product_long_message) log_id += 1 #code for Updating Price### # price_string = """<Message> # <MessageID>%(message_id)s</MessageID> # <Price> # <SKU>%(sku)s</SKU> # <StandardPrice currency="USD">%(price)s</StandardPrice> # </Price> # </Message>""" # price_string = price_string % { # 'message_id':message_id, # 'sku': product_sku, # 'price':list_price, # } # price_str = """<MessageType>Price</MessageType>""" # price_data = self.xml_format(price_str,merchant_string,price_string) # price_submission_id = connection_obj.call(instance_obj, 'POST_PRODUCT_PRICING_DATA',price_data) # print"price_submission_id",price_submission_id ## if price_submission_id.get('FeedSubmissionId',False): ## time.sleep(80) ## submission_price_results = connection_obj.call(instance_obj, 'GetFeedSubmissionResult',price_submission_id.get('FeedSubmissionId',False)) # # inventory_string = """<Message><MessageID>%(message_id)s</MessageID><Inventory><SKU>%(sku)s</SKU><Quantity>%(qty)s</Quantity></Inventory></Message>""" # inventory_string = inventory_string % { # 'message_id':message_id, # 'sku': product_sku, # 'qty':quantity[0]} # inventory_str = """<MessageType>Inventory</MessageType>""" # inventory_data = self.xml_format(inventory_str,merchant_string,inventory_string) # inventory_submission_id = connection_obj.call(instance_obj, 'POST_INVENTORY_AVAILABILITY_DATA',inventory_data) # print"inventory_submission_id",inventory_submission_id # cr.execute("UPDATE product_product SET prod_status='active' where id=%d"%(each_product.id,)) # cr.commit() # if inventory_submission_id.get('FeedSubmissionId',False): # time.sleep(80) # submission_inventory_results = connection_obj.call(instance_obj, 'GetFeedSubmissionResult',inventory_submission_id.get('FeedSubmissionId',False)) else: if submission_results.get('ResultDescription',False): error_message = submission_results.get('ResultDescription',False) error_message = str(error_message).replace("'"," ") cr.execute("UPDATE product_product SET submit_feed_result='%s' where id=%d"%(error_message,each_product.id,)) cr.commit() product_long_message = ('Error : %s:') % (product_nm)+ ' ' + error_message self.log(cr, uid,log_id, product_long_message) log_id += 1 cr.execute("UPDATE sale_shop SET last_amazon_catalog_export_date='%s' where id=%d"%(time.strftime('%Y-%m-%d %H:%M:%S'),ids[0])) return True
def createOrder(self, cr, uid, id, shop_id, resultvals, context={}): saleorderid = False saleorder_obj = self.pool.get('sale.order') for resultval in resultvals: if resultval != {} and resultval.has_key('Name') : 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 = 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_update], ['contact' or 'default']) partner_invoice_id = partner_obj.address_get(cr,uid,[partner_id_update], ['invoice' or 'default']) partner_shipping_id = partner_obj.address_get(cr,uid,[partner_id_update], ['delivery' or 'default']) pricelist_id = partner_obj.browse(cr,uid,partner_id_update)['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_update, '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: saleorderid = saleorder_obj.create(cr,uid,ordervals) for each_result in results: amazon_sku = each_result.get('SellerSKU',False) 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