def update_product_supplierinfo(*args,**options): coll = mongodb_client.get_coll("DHUI_Product") partner_coll = mongodb_client.get_coll("DHUI_Partner") print "update product supplierinfo ...\n" partner_list = partner_coll.find() partner_dict = {} for partner in partner_list: partner_type = partner["type"] partner_dict[partner_type] = {} dic = {} dic["dhui_user_id"] = partner["dhui_user_id"] dic["partner_id"] = partner["partner_id"] partner_dict[partner_type] = dic good_list = coll.find() log_result = [] for good in good_list: sku = good["sku"] good_id = utils.objectid_str(good["_id"]) query_params = dict( sku=sku, categ_id=settings.PRODUCT_CATEGRAY_ID, ) xmlrpcclient = xmlrpc_client.get_xmlrpcclient("ProductTemplate") if utils.has_obj(xmlrpcclient, query_params): result = xmlrpcclient.search(query_params) product_template_id = result[0] else: print "continue\n" continue # partner dhui user id if good["goods_type"] in ["seckill", "normal"]: dhui_user_id = partner_dict[good["goods_type"]]["partner_id"] elif good_id in free_trade_goods: dhui_user_id = partner_dict["other"]["partner_id"] else: dhui_user_id = partner_dict["normal"]["partner_id"] product_supplierinfo_obj = dict( # 东汇商城供应商 name = dhui_user_id, min_qty=1, product_tmpl_id=product_template_id, ) query_params = dict( product_tmpl_id=product_template_id, ) xmlrpcclient = xmlrpc_client.get_xmlrpcclient("ProductSupplierInfo") if utils.has_obj(xmlrpcclient, query_params): #continue result = xmlrpcclient.search(query_params) xmlrpcclient.update(result[0], product_supplierinfo_obj) else: log_result.append(product_supplierinfo_obj) utils.load_obj(xmlrpcclient, product_supplierinfo_obj) return log_result
def update_product_supplierinfo(*args, **options): coll = mongodb_client.get_coll("DHUI_Product") partner_coll = mongodb_client.get_coll("DHUI_Partner") print "update product supplierinfo ...\n" partner_list = partner_coll.find() partner_dict = {} for partner in partner_list: partner_type = partner["type"] partner_dict[partner_type] = {} dic = {} dic["dhui_user_id"] = partner["dhui_user_id"] dic["partner_id"] = partner["partner_id"] partner_dict[partner_type] = dic good_list = coll.find() log_result = [] for good in good_list: sku = good["sku"] good_id = utils.objectid_str(good["_id"]) query_params = dict( sku=sku, categ_id=settings.PRODUCT_CATEGRAY_ID, ) xmlrpcclient = xmlrpc_client.get_xmlrpcclient("ProductTemplate") if utils.has_obj(xmlrpcclient, query_params): result = xmlrpcclient.search(query_params) product_template_id = result[0] else: print "continue\n" continue # partner dhui user id if good["goods_type"] in ["seckill", "normal"]: dhui_user_id = partner_dict[good["goods_type"]]["partner_id"] elif good_id in free_trade_goods: dhui_user_id = partner_dict["other"]["partner_id"] else: dhui_user_id = partner_dict["normal"]["partner_id"] product_supplierinfo_obj = dict( # 东汇商城供应商 name=dhui_user_id, min_qty=1, product_tmpl_id=product_template_id, ) query_params = dict(product_tmpl_id=product_template_id, ) xmlrpcclient = xmlrpc_client.get_xmlrpcclient("ProductSupplierInfo") if utils.has_obj(xmlrpcclient, query_params): #continue result = xmlrpcclient.search(query_params) xmlrpcclient.update(result[0], product_supplierinfo_obj) else: log_result.append(product_supplierinfo_obj) utils.load_obj(xmlrpcclient, product_supplierinfo_obj) return log_result
def update_stock_warehouse_orderpoint(*args,**options): coll = mongodb_client.get_coll("DHUI_Product") print "update stock warehouse order point ...\n" good_list = coll.find() log_result = [] for good in good_list: sku = good["sku"] query_params = dict( sku=sku, categ_id=settings.PRODUCT_CATEGRAY_ID, ) xmlrpcclient = xmlrpc_client.get_xmlrpcclient("ProductTemplate") if utils.has_obj(xmlrpcclient, query_params): result = xmlrpcclient.search(query_params) product_template_id = result[0] else: continue query_params = dict( product_tmpl_id=product_template_id, ) xmlrpcclient = xmlrpc_client.get_xmlrpcclient("Product") if utils.has_obj(xmlrpcclient, query_params): result = xmlrpcclient.search(query_params) product_id = result[0] else: continue stock_warehouse_orderpoint_obj = dict( location_id=12, product_min_qty=1, product_id=product_id, product_max_qty=0, ) query_params = stock_warehouse_orderpoint_obj xmlrpcclient = xmlrpc_client.get_xmlrpcclient("StockWarehouseOrderpoint") if utils.has_obj(xmlrpcclient, query_params): continue result = xmlrpcclient.search(query_params) xmlrpcclient.update(result[0], stock_warehouse_orderpoint_obj) else: log_result.append(stock_warehouse_orderpoint_obj) utils.load_obj(xmlrpcclient, stock_warehouse_orderpoint_obj) return log_result
def get_product_template_by_id(*args, **kwargs): product_id = kwargs["product_id"] query_params = dict(id=product_id, ) xmlrpcclient = xmlrpc_client.get_xmlrpcclient("Product") if utils.has_obj(xmlrpcclient, query_params): [product_obj] = utils.read_obj(xmlrpcclient, query_params) product_tmpl_id = tuple(product_obj["product_tmpl_id"])[0] else: return None query_params = dict(id=product_tmpl_id, ) xmlrpcclient = xmlrpc_client.get_xmlrpcclient("ProductTemplate") if utils.has_obj(xmlrpcclient, query_params): product_template_obj = utils.read_obj(xmlrpcclient, query_params) else: return None return product_template_obj[0]
def update_stock_warehouse_orderpoint(*args, **options): coll = mongodb_client.get_coll("DHUI_Product") print "update stock warehouse order point ...\n" good_list = coll.find() log_result = [] for good in good_list: sku = good["sku"] query_params = dict( sku=sku, categ_id=settings.PRODUCT_CATEGRAY_ID, ) xmlrpcclient = xmlrpc_client.get_xmlrpcclient("ProductTemplate") if utils.has_obj(xmlrpcclient, query_params): result = xmlrpcclient.search(query_params) product_template_id = result[0] else: continue query_params = dict(product_tmpl_id=product_template_id, ) xmlrpcclient = xmlrpc_client.get_xmlrpcclient("Product") if utils.has_obj(xmlrpcclient, query_params): result = xmlrpcclient.search(query_params) product_id = result[0] else: continue stock_warehouse_orderpoint_obj = dict( location_id=12, product_min_qty=1, product_id=product_id, product_max_qty=0, ) query_params = stock_warehouse_orderpoint_obj xmlrpcclient = xmlrpc_client.get_xmlrpcclient( "StockWarehouseOrderpoint") if utils.has_obj(xmlrpcclient, query_params): continue result = xmlrpcclient.search(query_params) xmlrpcclient.update(result[0], stock_warehouse_orderpoint_obj) else: log_result.append(stock_warehouse_orderpoint_obj) utils.load_obj(xmlrpcclient, stock_warehouse_orderpoint_obj) return log_result
def get_purchase_order_line_list(order_id): query_params = dict(order_id=order_id, ) xmlrpcclient = xmlrpc_client.get_xmlrpcclient("PurchaseOrderLine") if utils.has_obj(xmlrpcclient, query_params): purhase_order_line_list = utils.read_obj(xmlrpcclient, query_params) return purhase_order_line_list else: return []
def get_purchase_order_line_list(order_id): query_params = dict( order_id = order_id, ) xmlrpcclient = xmlrpc_client.get_xmlrpcclient("PurchaseOrderLine") if utils.has_obj(xmlrpcclient,query_params): purhase_order_line_list = utils.read_obj(xmlrpcclient,query_params) return purhase_order_line_list else : return []
def get_product_template_by_id(*args,**kwargs): product_id = kwargs["product_id"] query_params = dict( id = product_id, ) xmlrpcclient = xmlrpc_client.get_xmlrpcclient("Product") if utils.has_obj(xmlrpcclient,query_params): [product_obj] = utils.read_obj(xmlrpcclient,query_params) product_tmpl_id = tuple(product_obj["product_tmpl_id"])[0] else : return None query_params = dict( id = product_tmpl_id, ) xmlrpcclient = xmlrpc_client.get_xmlrpcclient("ProductTemplate") if utils.has_obj(xmlrpcclient,query_params): product_template_obj = utils.read_obj(xmlrpcclient,query_params) else : return None return product_template_obj[0]
def get_product_template(*args, **kwargs): sku = kwargs["sku"] query_params = dict( sku=sku, categ_id=settings.PRODUCT_CATEGRAY_ID, ) xmlrpcclient = xmlrpc_client.get_xmlrpcclient("ProductTemplate") if utils.has_obj(xmlrpcclient, query_params): result = utils.read_obj(xmlrpcclient, query_params) else: good = None return result[0]
def get_product_template(*args,**kwargs): sku = kwargs["sku"] query_params = dict( sku = sku, categ_id=settings.PRODUCT_CATEGRAY_ID, ) xmlrpcclient = xmlrpc_client.get_xmlrpcclient("ProductTemplate") if utils.has_obj(xmlrpcclient, query_params): result = utils.read_obj(xmlrpcclient,query_params) else: good = None return result[0]
def get_task_list(*args,**options): user_id = options.get("user_id",None) if user_id == None : return [] xmlrpcclient = xmlrpc_client.get_xmlrpcclient("ResUsers") query_params = dict( user_id = user_id, ) if utils.has_obj(xmlrpcclient,query_params): [uid] = xmlrpcclient.search(query_params) else: return [] xmlrpcclient = xmlrpc_client.get_xmlrpcclient("DhuiTask") task_id_list = [] query_params = dict( create_uid = uid, ) create_id_task_list = xmlrpcclient.search(query_params) query_params = dict( user_id = uid, ) part_id_task_list = xmlrpcclient.search(query_params) query_params = dict( reviewer_id = uid, ) review_id_task_list = xmlrpcclient.search(query_params) task_id_list.extend(create_id_task_list) task_id_list.extend(part_id_task_list) task_id_list.extend(review_id_task_list) task_id_list = list(set(task_id_list)) query_params = dict( id_list = task_id_list, field_list = ["id","create_date","date_end","create_uid","user_id", "data_start","progress","project_id","description", "active","name","date_deadline","reviewer_id", "total_hours","remaining_hours","group_type"] ) task_list = utils.read_obj(xmlrpcclient,query_params) return task_list
def import_user_data(*args,**options): customer_coll = mongodb_client.get_coll("DHUI_User") address_coll = mongodb_client.get_coll("DHUI_Address") user_list = customer_coll.find({}) for user in user_list : user_id = utils.objectid_str(user["_id"]) address = address_coll.find_one({"user_id":user_id}) if address == None : address_id = "" else : address_id = utils.objectid_str(address["_id"]) if user.has_key("wx_info"): wx_info = user["wx_info"] dhui_user_obj = dict( user_id=user_id, address_id=address_id, nickname= wx_info.get("nickname",""), province = wx_info.get("province",""), language = wx_info.get("language",""), openid = wx_info.get("openid",""), unionid = wx_info.get("unionid",""), sex = wx_info.get("sex",0), country = wx_info.get("country",""), privilege = json.dumps(wx_info.get("privilege",[])), headimgurl= wx_info.get("headimgurl",""), city = wx_info.get("city",""), ) else : dhui_user_obj = dict( user_id=user_id, address_id=address_id, ) query_params = dict( user_id= user_id, ) xmlrpcclient = xmlrpc_client.get_xmlrpcclient("ResUsers") if utils.has_obj(xmlrpcclient, query_params): continue result = xmlrpcclient.search(query_params) xmlrpcclient.update(result[0], dhui_user_obj) else: utils.load_obj(xmlrpcclient, dhui_user_obj) print dhui_user_obj
def import_address_data(*args,**kwargs): address_coll = mongodb_client.get_coll("DHUI_Address") address_list = address_coll.find({}).skip(1548) log_result = [] for address in address_list : if address.has_key("user_id"): user_id = address["user_id"] else : continue #查询用户id try : xmlrpcclient = xmlrpc_client.get_xmlrpcclient("DhuiUser") query_params = dict( user_id = user_id, ) result = xmlrpcclient.search(query_params) user_id = result[0] except Exception ,e : continue xmlrpcclient = xmlrpc_client.get_xmlrpcclient("DhuiAddress") query_params = dict( _id=utils.objectid_str(address["_id"]), ) dhui_address_obj = dict() address["_id"] = utils.objectid_str(address["_id"]) dhui_address_obj.update(address) if utils.has_obj(xmlrpcclient, query_params): continue dhui_address_obj['mod_time'] = str(datetime.datetime.now()).split(".")[0] dhui_address_obj['user_id'] = user_id result = xmlrpcclient.search(query_params) xmlrpcclient.update(result[0], dhui_address_obj) else: dhui_address_obj['add_time'] = str(datetime.datetime.now()).split(".")[0] dhui_address_obj['mod_time'] = str(datetime.datetime.now()).split(".")[0] dhui_address_obj['user_id'] = user_id utils.load_obj(xmlrpcclient, dhui_address_obj) log_result.append(dhui_address_obj) print dhui_address_obj
def import_user_data(*args, **options): customer_coll = mongodb_client.get_coll("DHUI_User") address_coll = mongodb_client.get_coll("DHUI_Address") user_list = customer_coll.find({}) for user in user_list: user_id = utils.objectid_str(user["_id"]) address = address_coll.find_one({"user_id": user_id}) if address == None: address_id = "" else: address_id = utils.objectid_str(address["_id"]) if user.has_key("wx_info"): wx_info = user["wx_info"] dhui_user_obj = dict( user_id=user_id, address_id=address_id, nickname=wx_info.get("nickname", ""), province=wx_info.get("province", ""), language=wx_info.get("language", ""), openid=wx_info.get("openid", ""), unionid=wx_info.get("unionid", ""), sex=wx_info.get("sex", 0), country=wx_info.get("country", ""), privilege=json.dumps(wx_info.get("privilege", [])), headimgurl=wx_info.get("headimgurl", ""), city=wx_info.get("city", ""), ) else: dhui_user_obj = dict( user_id=user_id, address_id=address_id, ) query_params = dict(user_id=user_id, ) xmlrpcclient = xmlrpc_client.get_xmlrpcclient("ResUsers") if utils.has_obj(xmlrpcclient, query_params): continue result = xmlrpcclient.search(query_params) xmlrpcclient.update(result[0], dhui_user_obj) else: utils.load_obj(xmlrpcclient, dhui_user_obj) print dhui_user_obj
def get_task_list(*args, **options): user_id = options.get("user_id", None) if user_id == None: return [] xmlrpcclient = xmlrpc_client.get_xmlrpcclient("ResUsers") query_params = dict(user_id=user_id, ) if utils.has_obj(xmlrpcclient, query_params): [uid] = xmlrpcclient.search(query_params) else: return [] xmlrpcclient = xmlrpc_client.get_xmlrpcclient("DhuiTask") task_id_list = [] query_params = dict(create_uid=uid, ) create_id_task_list = xmlrpcclient.search(query_params) query_params = dict(user_id=uid, ) part_id_task_list = xmlrpcclient.search(query_params) query_params = dict(reviewer_id=uid, ) review_id_task_list = xmlrpcclient.search(query_params) task_id_list.extend(create_id_task_list) task_id_list.extend(part_id_task_list) task_id_list.extend(review_id_task_list) task_id_list = list(set(task_id_list)) query_params = dict(id_list=task_id_list, field_list=[ "id", "create_date", "date_end", "create_uid", "user_id", "data_start", "progress", "project_id", "description", "active", "name", "date_deadline", "reviewer_id", "total_hours", "remaining_hours", "group_type" ]) task_list = utils.read_obj(xmlrpcclient, query_params) return task_list
def import_dhuitask_user(*args,**options): customer_coll = mongodb_client.get_coll("DHUI_User") address_coll = mongodb_client.get_coll("DHUI_Address") user_list = customer_coll.find({}) for user in user_list: user_id = utils.objectid_str(user["_id"]) address = address_coll.find_one({"user_id": user_id}) if address == None: address_id = "" else: address_id = utils.objectid_str(address["_id"]) if user.has_key("wx_info"): wx_info = user["wx_info"] dhui_user_obj = dict( user_id=user_id, nickname=wx_info.get("nickname", ""), province=wx_info.get("province", ""), language=wx_info.get("language", ""), openid=wx_info.get("openid", ""), unionid=wx_info.get("unionid", ""), sex=wx_info.get("sex", 0), country=wx_info.get("country", ""), privilege=json.dumps(wx_info.get("privilege", [])), headimgurl=wx_info.get("headimgurl", ""), city=wx_info.get("city", ""), # res.users company_id=1, login=str(datetime.datetime.now()).replace("-", "").replace(" ", "").replace(":", "").replace(".", ""), name=wx_info.get("nickname", u""), email=str(datetime.datetime.now()).replace("-", "").replace(" ", "").replace(":", "").replace(".", "") \ + "@dhui.com", password_crypt="$pbkdf2-sha512$6400$5FzLOcdYaw2htFYq\ 5byXkg$g63/4Py02yxe8MQ1az7FfMI4yLm8Y.mMLpkWlkggZkmMhx3\ Wrh2sUjwDcGRdXpAXeRksK17eQpPhwpwXIoQhtg", ) else: dhui_user_obj = dict( user_id=user_id, address_id=address_id, # res.users company_id=1, login= str(datetime.datetime.now()).replace("-","").replace(" ","").replace(":","").replace(".",""), name=wx_info.get("nickname", u""), email= str(datetime.datetime.now()).replace("-","").replace(" ","").replace(":","").replace(".","")\ + "@dhui.com", password_crypt = "$pbkdf2-sha512$6400$5FzLOcdYaw2htFYq\ 5byXkg$g63/4Py02yxe8MQ1az7FfMI4yLm8Y.mMLpkWlkggZkmMhx3\ Wrh2sUjwDcGRdXpAXeRksK17eQpPhwpwXIoQhtg", ) query_params = dict( user_id=user_id, ) xmlrpcclient = xmlrpc_client.get_xmlrpcclient("ResUsers") if utils.has_obj(xmlrpcclient, query_params): continue result = xmlrpcclient.search(query_params) xmlrpcclient.update(result[0], dhui_user_obj) else: utils.load_obj(xmlrpcclient, dhui_user_obj) print dhui_user_obj
def init_partner_info(*args, **kwargs): """ 创建并更新供应商,更新商品和供应商关系 :param args: :param kwargs: :return: """ coll = mongodb_client.get_coll("DHUI_Partner") print print "start update dhui partner...\n" for partner in partner_list: name = partner["contact_name"] dhui_user_id = partner["dhui_user_id"] type = partner["type"] street = partner["address"] city = partner["city"] display_name = partner["display_name"] # 邮政编码 zip = partner["zip"] country_id = 49 email = partner["email"] phone = partner["phone"] supplier = True res_partner_obj = dict( name=name, street=street, city=city, display_name=display_name, zip=zip, country_id=country_id, email=email, phone=phone, supplier=supplier, ) query_params = dict( name=name, supplier=supplier, ) xmlrpcclient = xmlrpc_client.get_xmlrpcclient("ResPartner") if utils.has_obj(xmlrpcclient, query_params): result = xmlrpcclient.search(query_params) xmlrpcclient.update(result[0], res_partner_obj) partner_id = result[0] else: partner_id = utils.load_obj(xmlrpcclient, res_partner_obj) dhui_partner = coll.find_one({"name": name}) if dhui_partner: dhui_partner["partner_id"] = partner_id coll.save(dhui_partner) else: dhui_partner = {} dhui_partner["name"] = name dhui_partner["dhui_user_id"] = dhui_user_id dhui_partner["partner_id"] = partner_id dhui_partner["type"] = type coll.insert_one(dhui_partner) return partner_list
def import_shipping_data(*args, **kwargs): shipping_coll = mongodb_client.get_coll("DHUI_Shipping") start_time, end_time = utils.get_time_range(delta=0) shipping_list = shipping_coll.find( {"add_time": { "$gte": start_time, "$lte": end_time, }}) for shipping in shipping_list: _id = utils.objectid_str(shipping['_id']) company = shipping['company'] number = shipping['number'] add_time = shipping['add_time'] address = shipping['address'] orders = shipping['orders'] track = shipping['track'] query_params = dict(_id=_id, ) shipping_obj = dict( _id=_id, company=company, number=number, add_time=add_time, ) xmlrpcclient = xmlrpc_client.get_xmlrpcclient("DhuiShipping") if utils.has_obj(xmlrpcclient, query_params): result = xmlrpcclient.search(query_params) xmlrpcclient.update(result[0], shipping_obj) shipping_id = result[0] else: shipping_id = utils.load_obj(xmlrpcclient, shipping_obj) contact_name = address["contact_name"] contact_mobile = address["contact_mobile"] detailed_address = address["detailed_address"] query_params = dict( contact_name=contact_name, contact_mobile=contact_mobile, ) shipping_address_obj = dict() shipping_address_obj.update(address) xmlrpcclient = xmlrpc_client.get_xmlrpcclient("DhuiShippingAddress") if utils.has_obj(xmlrpcclient, query_params): result = xmlrpcclient.search(query_params) xmlrpcclient.update(result[0], shipping_address_obj) else: utils.load_obj(xmlrpcclient, shipping_address_obj) #sale_order order_id_list = [] xmlrpcclient = xmlrpc_client.get_xmlrpcclient("SaleOrder") for order in orders: order_id = order["_id"] query_params = dict(_id=order_id, ) try: result = xmlrpcclient.search(query_params) if len(result): order_id_list.append(result[0]) else: continue except Exception, e: continue obj_list = [] for order_id in order_id_list: obj_list.append( dict(id=order_id, alter_params=dict(shipping_id=shipping_id, ))) utils.update_obj_list(xmlrpcclient, obj_list) # kuaidi status = track.get("status", "") last_result = track.get("lastResult", {}) message = track.get("message", "") billstatus = track.get("billstatus", "") auto_check = track.get("autoCheck", False) com_old = track.get("comOld", "") query_params = dict(shipping_id=shipping_id, ) shipping_kuaidi_obj = dict( status=status, message=message, billstatus=billstatus, auto_check=auto_check, com_old=com_old, shipping_id=shipping_id, ) xmlrpcclient = xmlrpc_client.get_xmlrpcclient("DhuiShippingKuaidi") if utils.has_obj(xmlrpcclient, query_params): result = xmlrpcclient.search(query_params) xmlrpcclient.update(result[0], shipping_kuaidi_obj) kuaidi_id = result[0] else: kuaidi_id = utils.load_obj(xmlrpcclient, shipping_kuaidi_obj) status = last_result.get("status", "") state = last_result.get("state", "") ischeck = last_result.get("ischeck", False) message = last_result.get("message", "") com = last_result.get("com", "") nu = last_result.get("nu", "") condition = last_result.get("condition", "") data = last_result.get("data", []) query_params = dict(kuaidi_id=kuaidi_id, ) shipping_last_result_obj = dict( status=status, state=state, ischeck=ischeck, message=message, com=com, nu=nu, condition=condition, kuaidi_id=kuaidi_id, ) xmlrpcclient = xmlrpc_client.get_xmlrpcclient( "DhuiShippingKuaidiLastresult") if utils.has_obj(xmlrpcclient, query_params): result = xmlrpcclient.search(query_params) xmlrpcclient.update(result[0], shipping_last_result_obj) lastresult_id = result[0] else: lastresult_id = utils.load_obj(xmlrpcclient, shipping_last_result_obj) for last_result_line in data: ftime = last_result_line['ftime'] context = last_result_line['context'] time = last_result_line['time'] query_params = dict( lastresult_id=lastresult_id, ftime=ftime, context=context, time=time, ) last_result_line_obj = dict( ftime=ftime, context=context, time=time, lastresult_id=lastresult_id, ) xmlrpcclient = xmlrpc_client.get_xmlrpcclient( "DhuiShippingKuaidiLastresultLine") if utils.has_obj(xmlrpcclient, query_params): result = xmlrpcclient.search(query_params) xmlrpcclient.update(result[0], last_result_line_obj) else: utils.load_obj(xmlrpcclient, last_result_line_obj)
def import_good_invoice(*args, **options): start_time, end_time = utils.get_report_time(delta=options.get("delta", 0)) coll = mongodb_client.get_coll("DHUI_PartnerGoodDeliverDetail") query_params = {"create_time": {"$gte": start_time, "$lte": end_time}} partner_order_deliver_detail_list = coll.find(query_params) log_result = [] for partner_order_deliver_detail in partner_order_deliver_detail_list: _id = utils.objectid_str(partner_order_deliver_detail["_id"]) create_time = partner_order_deliver_detail["create_time"] sale_order_count = partner_order_deliver_detail["sale_order_count"] partner_id = partner_order_deliver_detail["partner_id"] deliver_status = partner_order_deliver_detail["deliver_status"] invoice_detail_info = partner_order_deliver_detail["detail_info"] invoice_xmlrpcclient = xmlrpc_client.get_xmlrpcclient("DhuiInvoice") purchase_xmlrpcclient = xmlrpc_client.get_xmlrpcclient("DhuiPurchase") purchase_user_line_xmlrpcclient = xmlrpc_client.get_xmlrpcclient( "DhuiPurchaseUserLine") user_xmlrpcclient = xmlrpc_client.get_xmlrpcclient("DhuiUser") product_template_xmlrpcclient = xmlrpc_client.get_xmlrpcclient( "ProductTemplate") if settings.DHUI_PARTNER_DICT.has_key(partner_id): odoo_partner_id = settings.DHUI_PARTNER_DICT[partner_id][1] else: return query_params = dict(_id=_id) dhui_invoice_obj = dict( _id=_id, create_time=create_time, sale_order_count=sale_order_count, partner_id=odoo_partner_id, deliver_status=deliver_status, ) try: if utils.has_obj(invoice_xmlrpcclient, query_params): result = invoice_xmlrpcclient.search(query_params) invoice_id = result[0] invoice_xmlrpcclient.update(result[0], dhui_invoice_obj) else: invoice_id = utils.load_obj(invoice_xmlrpcclient, dhui_invoice_obj) except Exception, e: return for purchase_obj in invoice_detail_info: sku = purchase_obj["sku"] total_count = purchase_obj["total_count"] partner_id = purchase_obj["partner_id"] name = purchase_obj["name"] purchase_user_info = purchase_obj["user_info"] query_params = dict( sku=sku, name=name, partner_id=odoo_partner_id, invoice_id=invoice_id, ) dhui_purchase_obj = dict( sku=sku, name=name, partner_id=odoo_partner_id, invoice_id=invoice_id, total_count=total_count, ) try: if utils.has_obj(purchase_xmlrpcclient, query_params): result = purchase_xmlrpcclient.search(query_params) purchase_id = result[0] purchase_xmlrpcclient.update(result[0], dhui_purchase_obj) else: purchase_id = utils.load_obj(purchase_xmlrpcclient, dhui_purchase_obj) except Exception, e: continue for user_info in purchase_user_info: count = user_info["count"] product_id = user_info["product_id"] user_id = user_info["user_id"] try: query_params = dict(user_id=user_id) if utils.has_obj(user_xmlrpcclient, query_params): result = user_xmlrpcclient.search(query_params) else: continue odoo_user_id = result[0] except Exception, e: continue query_params = dict( user_id=odoo_user_id, product_id=product_id, purchase_id=purchase_id, ) dhui_purchase_user_info_obj = dict( user_id=odoo_user_id, product_id=product_id, purchase_id=purchase_id, count=count, ) try: if utils.has_obj(purchase_user_line_xmlrpcclient, query_params): result = purchase_user_line_xmlrpcclient.search( query_params) purchase_user_line_xmlrpcclient.update( result[0], dhui_purchase_user_info_obj) else: utils.load_obj(purchase_user_line_xmlrpcclient, dhui_purchase_user_info_obj) except Exception, e: print e continue
def import_sale_order_line(*args, **options): coll = mongodb_client.get_coll("DHUI_SaleOrder") start_time, end_time = utils.get_report_time(delta=options.get("delta", 0)) order_list = coll.find({ "pay_time": { "$gte": start_time, "$lte": end_time }, "order_status": 1, "order_goods.goods_type": { "$nin": ["goldbean", "profit", "indiana_count"] } }) order_log_result = [] for order in order_list: order_log_result.append(order) order_id = str(order["_id"]) query_params = dict( _id=order_id, user_id=settings.DHUI_MANAGER_USER_ID, ) xmlrpcclient = xmlrpc_client.get_xmlrpcclient("SaleOrder") if utils.has_obj(xmlrpcclient, query_params): # continue result = xmlrpcclient.search(query_params) sale_order_id = result[0] else: continue good_list = order["order_goods"] for good in good_list: sku = good["sku"] query_params = dict( sku=sku, categ_id=settings.PRODUCT_CATEGRAY_ID, ) xmlrpcclient = xmlrpc_client.get_xmlrpcclient("ProductTemplate") if utils.has_obj(xmlrpcclient, query_params): result = xmlrpcclient.search(query_params) product_template_id = result[0] else: print "sku=%s:this good is not exist!" % good["sku"] continue query_params = dict(product_tmpl_id=product_template_id, ) xmlrpcclient = xmlrpc_client.get_xmlrpcclient("Product") if utils.has_obj(xmlrpcclient, query_params): result = xmlrpcclient.search(query_params) product_id = result[0] else: continue sale_order_line_obj = dict( product_id=product_id, order_id=sale_order_id, ) query_params = sale_order_line_obj xmlrpcclient = xmlrpc_client.get_xmlrpcclient("SaleOrderLine") if utils.has_obj(xmlrpcclient, query_params): print "Has insert good : (sku)%s" % good["sku"] print "\n" continue else: utils.load_obj(xmlrpcclient, sale_order_line_obj) return order_log_result
def import_product_template_data(*args, **options): coll = mongodb_client.get_coll("DHUI_Product") partner_coll = mongodb_client.get_coll("DHUI_Partner") print "" print "update dhui product...\n" partner_list = partner_coll.find() partner_dict = {} for partner in partner_list: partner_type = partner["type"] partner_dict[partner_type] = {} dic = {} dic["dhui_user_id"] = partner["dhui_user_id"] dic["partner_id"] = partner["partner_id"] partner_dict[partner_type] = dic good_list = coll.find() log_result = [] for good in good_list: sku = good["sku"] goods_name = good["goods_name"] box_name = good["box_name"] goods_brief = good["goods_brief"] shop_price = good["shop_price"] goods_name = box_name + goods_brief good_id = utils.objectid_str(good["_id"]) # partner dhui user id if good["goods_type"] in ["seckill", "normal"]: dhui_user_id = partner_dict[good["goods_type"]]["dhui_user_id"] partner_id = partner_dict[good["goods_type"]]["partner_id"] elif good_id in free_trade_goods: dhui_user_id = partner_dict["other"]["dhui_user_id"] partner_id = partner_dict["other"]["partner_id"] else: dhui_user_id = partner_dict["normal"]["dhui_user_id"] partner_id = partner_dict["normal"]["partner_id"] product_template_obj = dict( create_uid=5, sku=sku, name=goods_name, type="product", list_price=shop_price, categ_id=settings.PRODUCT_CATEGRAY_ID, dhui_user_id=dhui_user_id, partner_id=partner_id, weight_net=0.0, weight=0.0, ) query_params = dict( sku=sku, categ_id=settings.PRODUCT_CATEGRAY_ID, ) xmlrpcclient = xmlrpc_client.get_xmlrpcclient("ProductTemplate") if utils.has_obj(xmlrpcclient, query_params): #continue result = xmlrpcclient.search(query_params) xmlrpcclient.update(result[0], product_template_obj) else: log_result.append(good) utils.load_obj(xmlrpcclient, product_template_obj) # update good cost result = xmlrpcclient.search(query_params) res_id = 'product.template,' + str(result[0]) cost = good["cost"] query_params = dict( res_id=res_id, name='standard_price', type='float', ) ir_property_obj = dict( value_float=cost, name="standard_price", type='float', company_id=settings.COMPANY_ID, res_id=res_id, fields_id=2041, ) xmlrpcclient = xmlrpc_client.get_xmlrpcclient("IrProperty") if utils.has_obj(xmlrpcclient, query_params): result = xmlrpcclient.search(query_params) xmlrpcclient.update(result[0], ir_property_obj) else: utils.load_obj(xmlrpcclient, ir_property_obj) return log_result
def init_partner_info(*args,**kwargs): """ 创建并更新供应商,更新商品和供应商关系 :param args: :param kwargs: :return: """ coll = mongodb_client.get_coll("DHUI_Partner") print print "start update dhui partner...\n" for partner in partner_list : name = partner["contact_name"] dhui_user_id = partner["dhui_user_id"] type = partner["type"] street = partner["address"] city = partner["city"] display_name = partner["display_name"] # 邮政编码 zip = partner["zip"] country_id = 49 email = partner["email"] phone = partner["phone"] supplier = True res_partner_obj = dict( name = name, street = street, city = city, display_name = display_name, zip = zip, country_id = country_id, email = email, phone = phone, supplier = supplier, ) query_params = dict( name = name, supplier = supplier, ) xmlrpcclient = xmlrpc_client.get_xmlrpcclient("ResPartner") if utils.has_obj(xmlrpcclient, query_params): result = xmlrpcclient.search(query_params) xmlrpcclient.update(result[0], res_partner_obj) partner_id = result[0] else: partner_id = utils.load_obj(xmlrpcclient, res_partner_obj) dhui_partner = coll.find_one({"name":name}) if dhui_partner: dhui_partner["partner_id"] = partner_id coll.save(dhui_partner) else: dhui_partner = {} dhui_partner["name"] = name dhui_partner["dhui_user_id"] = dhui_user_id dhui_partner["partner_id"] = partner_id dhui_partner["type"] = type coll.insert_one(dhui_partner) return partner_list
def import_sale_order_line(*args,**options): coll = mongodb_client.get_coll("DHUI_SaleOrder") start_time, end_time = utils.get_report_time(delta=options.get("delta",0)) order_list = coll.find({ "pay_time": {"$gte": start_time, "$lte": end_time}, "order_status": 1, "order_goods.goods_type": {"$nin": ["goldbean", "profit", "indiana_count"]}}) order_log_result = [] for order in order_list: order_log_result.append(order) order_id = str(order["_id"]) query_params = dict( _id=order_id, user_id=settings.DHUI_MANAGER_USER_ID, ) xmlrpcclient = xmlrpc_client.get_xmlrpcclient("SaleOrder") if utils.has_obj(xmlrpcclient, query_params): # continue result = xmlrpcclient.search(query_params) sale_order_id = result[0] else: continue good_list = order["order_goods"] for good in good_list: sku = good["sku"] query_params = dict( sku=sku, categ_id=settings.PRODUCT_CATEGRAY_ID, ) xmlrpcclient = xmlrpc_client.get_xmlrpcclient("ProductTemplate") if utils.has_obj(xmlrpcclient, query_params): result = xmlrpcclient.search(query_params) product_template_id = result[0] else: print "sku=%s:this good is not exist!" % good["sku"] continue query_params = dict( product_tmpl_id=product_template_id, ) xmlrpcclient = xmlrpc_client.get_xmlrpcclient("Product") if utils.has_obj(xmlrpcclient, query_params): result = xmlrpcclient.search(query_params) product_id = result[0] else: continue sale_order_line_obj = dict( product_id=product_id, order_id=sale_order_id, ) query_params = sale_order_line_obj xmlrpcclient = xmlrpc_client.get_xmlrpcclient("SaleOrderLine") if utils.has_obj(xmlrpcclient, query_params): print "Has insert good : (sku)%s" % good["sku"] print "\n" continue else: utils.load_obj(xmlrpcclient, sale_order_line_obj) return order_log_result
def import_sale_order_data(*args, **options): coll = mongodb_client.get_coll("DHUI_SaleOrder") start_time, end_time = utils.get_report_time(delta=options.get("delta",0)) order_list = coll.find({ # "pay_time":{"$gte":start_time, "$lte":end_time}, "order_status":1, "order_goods.goods_type":{"$nin":["goldbean","profit","indiana_count"]}}) order_log_result = [] for order in order_list: order_log_result.append(order) try : xmlrpcclient = xmlrpc_client.get_xmlrpcclient("DhuiUser") user_id = order["user_id"] query_params = dict( user_id = user_id, ) result = xmlrpcclient.search(query_params) dhui_user_id = result[0] except Exception,e : pass # 普通客户 partner_id = settings.COMMON_CUSTOMER_ID amount_total = order["goods_amount"] add_time = order["add_time"] # state = "draft" # 报价单 state = "manual" # 销售订单 _id = utils.objectid_str(order["_id"]) address_id = order["address_id"] goldbean = order["goldbean"] pay_time = order["pay_time"] promotion_id = order["promotion_id"] contact_name = order["contact_name"] receive_wx_notify = order["receive_wx_notify"] pay_type = str(order["pay_type"]) customer_user_id = order["user_id"] goods_amount = order["goods_amount"] order_status = str(order["order_status"]) pay_status = str(order["pay_status"]) money_paid = order["money_paid"] order_id = order["order_id"] origin_code = order["origin_code"] discount = order["discount"] shipping_status = str(order["shipping_status"]) order_invoice = str(order["order_invoice"]) add_time = str(order["add_time"]) delivery_time = order["delivery_time"] remark = order["remark"] mobile = order["mobile"] order_goods = order["order_goods"] edit_times = order["edit_times"] shipping_fee = order["shipping_fee"] sale_order_obj = dict( partner_id=partner_id, partner_invoice_id=partner_id, partner_shipping_id=partner_id, amount_total=amount_total, state=state, date_order = add_time, # 东汇进销存管理员 user_id=settings.DHUI_MANAGER_USER_ID, dhui_user_id = dhui_user_id, order_customer_id = user_id, order_address_id = order["address_id"], order_purchase_time = order["pay_time"], #东汇订单信息 _id= _id, address_id = address_id, goldbean = goldbean, pay_time = pay_time , promotion_id = promotion_id, contact_name = contact_name, receive_wx_notify = receive_wx_notify, pay_type = pay_type, customer_user_id = customer_user_id, goods_amount = goods_amount, order_status = order_status, pay_status = pay_status, money_paid = money_paid, order_id = order_id, origin_code = origin_code, discount = discount, shipping_status = shipping_status, order_invoice = order_invoice, add_time = add_time, delivery_time = delivery_time, remark = remark, mobile = mobile, order_goods = order_goods, edit_times = edit_times, shipping_fee = shipping_fee, ) #订单发货地址 order_address = order["order_address"] if order["address_id"] : address = { 'contact_name':order_address.get("contact_name",""), 'contact_mobile':order_address.get("contact_mobile",""), 'area':order_address.get("area",""), 'city':order_address.get("city",""), 'district':order_address.get("district",""), 'remark':order_address.get("remark",""), 'detailed_address':order_address.get("detailed_address",""), 'lng':order_address.get("lng",""), 'lat':order_address.get("lat",""), 'add_time':order_address.get("add_time",""), 'mod_time':order_address.get("mod_time",""), 'is_default_flag':order_address.get("is_default_flag",""), 'order_id':order_id, } query_params = dict( order_id= order_id, ) sale_order_address_obj = address xmlrpcclient = xmlrpc_client.get_xmlrpcclient("SaleOrderAddress") if utils.has_obj(xmlrpcclient,query_params): result = xmlrpcclient.search(query_params) order_address_id = result[0] else : order_address_id = utils.load_obj(xmlrpcclient,sale_order_address_obj) sale_order_obj["odoo_address_id"] = order_address_id else : pass query_params = dict( order_id=order_id, ) xmlrpcclient = xmlrpc_client.get_xmlrpcclient("SaleOrder") if utils.has_obj(xmlrpcclient, query_params): # continue result = xmlrpcclient.search(query_params) xmlrpcclient.update(result[0], sale_order_obj) sale_order_id = result[0] else: sale_order_id = utils.load_obj(xmlrpcclient, sale_order_obj)
def import_good_invoice(*args,**options): start_time, end_time = utils.get_report_time(delta=options.get("delta",0)) coll = mongodb_client.get_coll("DHUI_PartnerGoodDeliverDetail") query_params = { "create_time" : {"$gte":start_time,"$lte":end_time} } partner_order_deliver_detail_list = coll.find(query_params) log_result = [] for partner_order_deliver_detail in partner_order_deliver_detail_list : _id = utils.objectid_str(partner_order_deliver_detail["_id"]) create_time = partner_order_deliver_detail["create_time"] sale_order_count = partner_order_deliver_detail["sale_order_count"] partner_id = partner_order_deliver_detail["partner_id"] deliver_status = partner_order_deliver_detail["deliver_status"] invoice_detail_info = partner_order_deliver_detail["detail_info"] invoice_xmlrpcclient = xmlrpc_client.get_xmlrpcclient("DhuiInvoice") purchase_xmlrpcclient = xmlrpc_client.get_xmlrpcclient("DhuiPurchase") purchase_user_line_xmlrpcclient = xmlrpc_client.get_xmlrpcclient("DhuiPurchaseUserLine") user_xmlrpcclient = xmlrpc_client.get_xmlrpcclient("DhuiUser") product_template_xmlrpcclient = xmlrpc_client.get_xmlrpcclient("ProductTemplate") if settings.DHUI_PARTNER_DICT.has_key(partner_id): odoo_partner_id = settings.DHUI_PARTNER_DICT[partner_id][1] else : return query_params = dict( _id = _id ) dhui_invoice_obj = dict( _id = _id, create_time = create_time, sale_order_count = sale_order_count, partner_id = odoo_partner_id, deliver_status = deliver_status, ) try : if utils.has_obj(invoice_xmlrpcclient, query_params): result = invoice_xmlrpcclient.search(query_params) invoice_id = result[0] invoice_xmlrpcclient.update(result[0], dhui_invoice_obj) else: invoice_id = utils.load_obj(invoice_xmlrpcclient, dhui_invoice_obj) except Exception ,e: return for purchase_obj in invoice_detail_info: sku = purchase_obj["sku"] total_count = purchase_obj["total_count"] partner_id = purchase_obj["partner_id"] name = purchase_obj["name"] purchase_user_info = purchase_obj["user_info"] query_params = dict( sku = sku, name = name, partner_id = odoo_partner_id, invoice_id = invoice_id, ) dhui_purchase_obj = dict( sku=sku, name=name, partner_id= odoo_partner_id, invoice_id= invoice_id, total_count = total_count, ) try : if utils.has_obj(purchase_xmlrpcclient, query_params): result = purchase_xmlrpcclient.search(query_params) purchase_id = result[0] purchase_xmlrpcclient.update(result[0], dhui_purchase_obj) else: purchase_id = utils.load_obj(purchase_xmlrpcclient, dhui_purchase_obj) except Exception,e : continue for user_info in purchase_user_info : count = user_info["count"] product_id = user_info["product_id"] user_id = user_info["user_id"] try: query_params = dict( user_id=user_id ) if utils.has_obj(user_xmlrpcclient, query_params): result = user_xmlrpcclient.search(query_params) else: continue odoo_user_id = result[0] except Exception, e: continue query_params = dict( user_id = odoo_user_id, product_id = product_id, purchase_id = purchase_id, ) dhui_purchase_user_info_obj = dict( user_id=odoo_user_id, product_id=product_id, purchase_id=purchase_id, count = count, ) try : if utils.has_obj(purchase_user_line_xmlrpcclient,query_params): result = purchase_user_line_xmlrpcclient.search(query_params) purchase_user_line_xmlrpcclient.update(result[0],dhui_purchase_user_info_obj) else: utils.load_obj(purchase_user_line_xmlrpcclient, dhui_purchase_user_info_obj) except Exception ,e : print e continue
def import_sale_order_data(*args, **options): coll = mongodb_client.get_coll("DHUI_SaleOrder") start_time, end_time = utils.get_report_time(delta=options.get("delta", 0)) order_list = coll.find({ # "pay_time":{"$gte":start_time, "$lte":end_time}, "order_status": 1, "order_goods.goods_type": { "$nin": ["goldbean", "profit", "indiana_count"] } }) order_log_result = [] for order in order_list: order_log_result.append(order) try: xmlrpcclient = xmlrpc_client.get_xmlrpcclient("DhuiUser") user_id = order["user_id"] query_params = dict(user_id=user_id, ) result = xmlrpcclient.search(query_params) dhui_user_id = result[0] except Exception, e: pass # 普通客户 partner_id = settings.COMMON_CUSTOMER_ID amount_total = order["goods_amount"] add_time = order["add_time"] # state = "draft" # 报价单 state = "manual" # 销售订单 _id = utils.objectid_str(order["_id"]) address_id = order["address_id"] goldbean = order["goldbean"] pay_time = order["pay_time"] promotion_id = order["promotion_id"] contact_name = order["contact_name"] receive_wx_notify = order["receive_wx_notify"] pay_type = str(order["pay_type"]) customer_user_id = order["user_id"] goods_amount = order["goods_amount"] order_status = str(order["order_status"]) pay_status = str(order["pay_status"]) money_paid = order["money_paid"] order_id = order["order_id"] origin_code = order["origin_code"] discount = order["discount"] shipping_status = str(order["shipping_status"]) order_invoice = str(order["order_invoice"]) add_time = str(order["add_time"]) delivery_time = order["delivery_time"] remark = order["remark"] mobile = order["mobile"] order_goods = order["order_goods"] edit_times = order["edit_times"] shipping_fee = order["shipping_fee"] sale_order_obj = dict( partner_id=partner_id, partner_invoice_id=partner_id, partner_shipping_id=partner_id, amount_total=amount_total, state=state, date_order=add_time, # 东汇进销存管理员 user_id=settings.DHUI_MANAGER_USER_ID, dhui_user_id=dhui_user_id, order_customer_id=user_id, order_address_id=order["address_id"], order_purchase_time=order["pay_time"], #东汇订单信息 _id=_id, address_id=address_id, goldbean=goldbean, pay_time=pay_time, promotion_id=promotion_id, contact_name=contact_name, receive_wx_notify=receive_wx_notify, pay_type=pay_type, customer_user_id=customer_user_id, goods_amount=goods_amount, order_status=order_status, pay_status=pay_status, money_paid=money_paid, order_id=order_id, origin_code=origin_code, discount=discount, shipping_status=shipping_status, order_invoice=order_invoice, add_time=add_time, delivery_time=delivery_time, remark=remark, mobile=mobile, order_goods=order_goods, edit_times=edit_times, shipping_fee=shipping_fee, ) #订单发货地址 order_address = order["order_address"] if order["address_id"]: address = { 'contact_name': order_address.get("contact_name", ""), 'contact_mobile': order_address.get("contact_mobile", ""), 'area': order_address.get("area", ""), 'city': order_address.get("city", ""), 'district': order_address.get("district", ""), 'remark': order_address.get("remark", ""), 'detailed_address': order_address.get("detailed_address", ""), 'lng': order_address.get("lng", ""), 'lat': order_address.get("lat", ""), 'add_time': order_address.get("add_time", ""), 'mod_time': order_address.get("mod_time", ""), 'is_default_flag': order_address.get("is_default_flag", ""), 'order_id': order_id, } query_params = dict(order_id=order_id, ) sale_order_address_obj = address xmlrpcclient = xmlrpc_client.get_xmlrpcclient("SaleOrderAddress") if utils.has_obj(xmlrpcclient, query_params): result = xmlrpcclient.search(query_params) order_address_id = result[0] else: order_address_id = utils.load_obj(xmlrpcclient, sale_order_address_obj) sale_order_obj["odoo_address_id"] = order_address_id else: pass query_params = dict(order_id=order_id, ) xmlrpcclient = xmlrpc_client.get_xmlrpcclient("SaleOrder") if utils.has_obj(xmlrpcclient, query_params): # continue result = xmlrpcclient.search(query_params) xmlrpcclient.update(result[0], sale_order_obj) sale_order_id = result[0] else: sale_order_id = utils.load_obj(xmlrpcclient, sale_order_obj)
def import_dhuitask_user(*args, **options): customer_coll = mongodb_client.get_coll("DHUI_User") address_coll = mongodb_client.get_coll("DHUI_Address") user_list = customer_coll.find({}) for user in user_list: user_id = utils.objectid_str(user["_id"]) address = address_coll.find_one({"user_id": user_id}) if address == None: address_id = "" else: address_id = utils.objectid_str(address["_id"]) if user.has_key("wx_info"): wx_info = user["wx_info"] dhui_user_obj = dict( user_id=user_id, nickname=wx_info.get("nickname", ""), province=wx_info.get("province", ""), language=wx_info.get("language", ""), openid=wx_info.get("openid", ""), unionid=wx_info.get("unionid", ""), sex=wx_info.get("sex", 0), country=wx_info.get("country", ""), privilege=json.dumps(wx_info.get("privilege", [])), headimgurl=wx_info.get("headimgurl", ""), city=wx_info.get("city", ""), # res.users company_id=1, login=str(datetime.datetime.now()).replace("-", "").replace(" ", "").replace(":", "").replace(".", ""), name=wx_info.get("nickname", u""), email=str(datetime.datetime.now()).replace("-", "").replace(" ", "").replace(":", "").replace(".", "") \ + "@dhui.com", password_crypt="$pbkdf2-sha512$6400$5FzLOcdYaw2htFYq\ 5byXkg$g63/4Py02yxe8MQ1az7FfMI4yLm8Y.mMLpkWlkggZkmMhx3\ Wrh2sUjwDcGRdXpAXeRksK17eQpPhwpwXIoQhtg" , ) else: dhui_user_obj = dict( user_id=user_id, address_id=address_id, # res.users company_id=1, login= str(datetime.datetime.now()).replace("-","").replace(" ","").replace(":","").replace(".",""), name=wx_info.get("nickname", u""), email= str(datetime.datetime.now()).replace("-","").replace(" ","").replace(":","").replace(".","")\ + "@dhui.com", password_crypt = "$pbkdf2-sha512$6400$5FzLOcdYaw2htFYq\ 5byXkg$g63/4Py02yxe8MQ1az7FfMI4yLm8Y.mMLpkWlkggZkmMhx3\ Wrh2sUjwDcGRdXpAXeRksK17eQpPhwpwXIoQhtg" , ) query_params = dict(user_id=user_id, ) xmlrpcclient = xmlrpc_client.get_xmlrpcclient("ResUsers") if utils.has_obj(xmlrpcclient, query_params): continue result = xmlrpcclient.search(query_params) xmlrpcclient.update(result[0], dhui_user_obj) else: utils.load_obj(xmlrpcclient, dhui_user_obj) print dhui_user_obj
def import_product_template_data(*args, **options): coll = mongodb_client.get_coll("DHUI_Product") partner_coll = mongodb_client.get_coll("DHUI_Partner") print "" print "update dhui product...\n" partner_list = partner_coll.find() partner_dict = {} for partner in partner_list : partner_type = partner["type"] partner_dict[partner_type] = {} dic = {} dic["dhui_user_id"] = partner["dhui_user_id"] dic["partner_id"] = partner["partner_id"] partner_dict[partner_type] = dic good_list = coll.find() log_result = [] for good in good_list: sku = good["sku"] goods_name = good["goods_name"] box_name = good["box_name"] goods_brief = good["goods_brief"] shop_price = good["shop_price"] goods_name = box_name + goods_brief good_id = utils.objectid_str(good["_id"]) # partner dhui user id if good["goods_type"] in ["seckill","normal"]: dhui_user_id = partner_dict[good["goods_type"]]["dhui_user_id"] partner_id = partner_dict[good["goods_type"]]["partner_id"] elif good_id in free_trade_goods : dhui_user_id = partner_dict["other"]["dhui_user_id"] partner_id = partner_dict["other"]["partner_id"] else: dhui_user_id = partner_dict["normal"]["dhui_user_id"] partner_id = partner_dict["normal"]["partner_id"] product_template_obj = dict( create_uid = 5, sku=sku, name=goods_name, type="product", list_price=shop_price, categ_id=settings.PRODUCT_CATEGRAY_ID, dhui_user_id = dhui_user_id, partner_id = partner_id, weight_net = 0.0, weight = 0.0, ) query_params = dict( sku=sku, categ_id=settings.PRODUCT_CATEGRAY_ID, ) xmlrpcclient = xmlrpc_client.get_xmlrpcclient("ProductTemplate") if utils.has_obj(xmlrpcclient, query_params): #continue result = xmlrpcclient.search(query_params) xmlrpcclient.update(result[0], product_template_obj) else: log_result.append(good) utils.load_obj(xmlrpcclient, product_template_obj) # update good cost result = xmlrpcclient.search(query_params) res_id = 'product.template,' + str(result[0]) cost = good["cost"] query_params = dict( res_id=res_id, name='standard_price', type='float', ) ir_property_obj = dict( value_float=cost, name="standard_price", type='float', company_id=settings.COMPANY_ID, res_id=res_id, fields_id=2041, ) xmlrpcclient = xmlrpc_client.get_xmlrpcclient("IrProperty") if utils.has_obj(xmlrpcclient, query_params): result = xmlrpcclient.search(query_params) xmlrpcclient.update(result[0], ir_property_obj) else: utils.load_obj(xmlrpcclient, ir_property_obj) return log_result
def import_shipping_data(*args,**kwargs): shipping_coll = mongodb_client.get_coll("DHUI_Shipping") start_time, end_time = utils.get_time_range(delta=0) shipping_list = shipping_coll.find({ "add_time":{ "$gte":start_time, "$lte":end_time, } }) for shipping in shipping_list: _id = utils.objectid_str(shipping['_id']) company = shipping['company'] number = shipping['number'] add_time = shipping['add_time'] address = shipping['address'] orders = shipping['orders'] track = shipping['track'] query_params = dict( _id = _id , ) shipping_obj = dict( _id=_id, company=company, number=number, add_time=add_time, ) xmlrpcclient = xmlrpc_client.get_xmlrpcclient("DhuiShipping") if utils.has_obj(xmlrpcclient,query_params): result = xmlrpcclient.search(query_params) xmlrpcclient.update(result[0],shipping_obj) shipping_id = result[0] else : shipping_id = utils.load_obj(xmlrpcclient,shipping_obj) contact_name = address["contact_name"] contact_mobile = address["contact_mobile"] detailed_address = address["detailed_address"] query_params = dict( contact_name = contact_name, contact_mobile = contact_mobile, ) shipping_address_obj = dict() shipping_address_obj.update(address) xmlrpcclient = xmlrpc_client.get_xmlrpcclient("DhuiShippingAddress") if utils.has_obj(xmlrpcclient, query_params): result = xmlrpcclient.search(query_params) xmlrpcclient.update(result[0], shipping_address_obj) else: utils.load_obj(xmlrpcclient, shipping_address_obj) #sale_order order_id_list = [] xmlrpcclient = xmlrpc_client.get_xmlrpcclient("SaleOrder") for order in orders : order_id = order["_id"] query_params = dict( _id=order_id, ) try : result = xmlrpcclient.search(query_params) if len(result): order_id_list.append(result[0]) else: continue except Exception ,e : continue obj_list = [] for order_id in order_id_list: obj_list.append(dict( id=order_id, alter_params=dict( shipping_id=shipping_id, ) )) utils.update_obj_list(xmlrpcclient,obj_list) # kuaidi status = track.get("status","") last_result = track.get("lastResult",{}) message = track.get("message","") billstatus = track.get("billstatus","") auto_check = track.get("autoCheck",False) com_old = track.get("comOld","") query_params = dict( shipping_id = shipping_id, ) shipping_kuaidi_obj = dict( status = status, message = message, billstatus = billstatus, auto_check = auto_check, com_old = com_old, shipping_id = shipping_id, ) xmlrpcclient = xmlrpc_client.get_xmlrpcclient("DhuiShippingKuaidi") if utils.has_obj(xmlrpcclient,query_params): result = xmlrpcclient.search(query_params) xmlrpcclient.update(result[0],shipping_kuaidi_obj) kuaidi_id = result[0] else : kuaidi_id = utils.load_obj(xmlrpcclient,shipping_kuaidi_obj) status = last_result.get("status","") state = last_result.get("state","") ischeck = last_result.get("ischeck",False) message = last_result.get("message","") com = last_result.get("com","") nu = last_result.get("nu","") condition = last_result.get("condition","") data = last_result.get("data",[]) query_params = dict( kuaidi_id = kuaidi_id, ) shipping_last_result_obj = dict( status = status, state = state, ischeck = ischeck, message = message, com = com, nu = nu, condition = condition, kuaidi_id = kuaidi_id, ) xmlrpcclient = xmlrpc_client.get_xmlrpcclient("DhuiShippingKuaidiLastresult") if utils.has_obj(xmlrpcclient,query_params): result = xmlrpcclient.search(query_params) xmlrpcclient.update(result[0],shipping_last_result_obj) lastresult_id = result[0] else: lastresult_id = utils.load_obj(xmlrpcclient,shipping_last_result_obj) for last_result_line in data : ftime = last_result_line['ftime'] context = last_result_line['context'] time = last_result_line['time'] query_params = dict( lastresult_id = lastresult_id, ftime=ftime, context=context, time=time, ) last_result_line_obj = dict( ftime = ftime, context = context, time = time, lastresult_id = lastresult_id, ) xmlrpcclient = xmlrpc_client.get_xmlrpcclient("DhuiShippingKuaidiLastresultLine") if utils.has_obj(xmlrpcclient,query_params): result = xmlrpcclient.search(query_params) xmlrpcclient.update(result[0],last_result_line_obj) else : utils.load_obj(xmlrpcclient,last_result_line_obj)