Exemple #1
0
 def pull_order(self, cr, uid, ids, tid, context=None):
     """
     1) 取得交易tid信息
     2) ERP中创建交易对应的SO订单
     3) 如果ERP无此买家、发货地址,自动创建对应的Partner对象及联系人
     4) 如果ERP中无此商品,则报同步异常,不同步此tid
     """
     port = 80
     shop = self.browse(cr,uid,ids[0], context = context)
     setDefaultAppInfo(shop.appkey, shop.appsecret)
     try:
         #req = TradeFullinfoGetRequest(shop.apiurl, port)
         req = TradeGetRequest(shop.apiurl, port)
         req.fields="seller_nick,buyer_nick,created,sid,tid,status,buyer_memo,seller_memo,payment,discount_fee,adjust_fee,post_fee,total_fee,pay_time,end_time,modified,received_payment,price,alipay_id,receiver_name,receiver_state,receiver_city,receiver_district,receiver_address,receiver_zip,receiver_mobile,receiver_phone,orders.price,orders.num,orders.iid,orders.num_iid,orders.sku_id,orders.refund_status,orders.status,orders.oid,orders.total_fee,orders.payment,orders.discount_fee,orders.adjust_fee,orders.sku_properties_name,orders.outer_iid,orders.outer_sku_id"
         
         req.tid = long(tid)
         resp = req.getResponse(shop.sessionkey)
         trade =  resp.get('trade_get_response') and resp.get('trade_get_response').get('trade')
         if not trade: return False
         
         trade['created'] = (datetime.strptime(trade['created'], '%Y-%m-%d %H:%M:%S',) - timedelta(hours=8)).strftime('%Y-%m-%d %H:%M:%S')
         trade['pay_time'] = (datetime.strptime(trade['pay_time'], '%Y-%m-%d %H:%M:%S',) - timedelta(hours=8)).strftime('%Y-%m-%d %H:%M:%S')
         #创建Partner
         partner_id, address_id = self.create_partner_address(cr, uid, shop.code, trade, context = context )
         #创建订单及明细行
         order_id = self.create_order(cr, uid, shop, partner_id, address_id, trade, context = context )
         return order_id
     except Exception,e:
        #写入 同步异常日志
         syncerr = u"店铺【%s】订单【%s】同步错误: %s" % (shop.name, tid, e)
         self.pool.get('ebiz.syncerr').create(cr, uid, {'name':syncerr, 'shop_id': shop.id, 'type': 'order' }, context = context )
         return False
Exemple #2
0
 def _order_signed(self, cr, uid, shop, order):
     #tid 格式为 店铺前缀_电商订单编号,如果是合并订单,则格式为 店铺前缀mg_流水号
     signed = True
     setDefaultAppInfo(shop.appkey, shop.appsecret)
     req = TradeGetRequest(shop.apiurl)
     req.fields="tid, modified, consign_time, status"
     
     i = order.name.find('_')
     if i <= 0:
         signed = False
     tid = order.name[i+1:]
     if order.name[:i].endswith('mg'):  #处理合并订单
         if not order.origin:
             syncerr = u"店铺【%s】订单【%s】买家签收同步错误: 合并订单的源单据中没有原始订单号!" % (shop.name, order.name)
             self.pool.get('ebiz.syncerr').create(cr, uid, {'name':syncerr, 'shop_id': shop.id, 'type': 'invoice' }, context = context )
             signed = False
         tids = order.origin.split(',')
         for t in tids:
             i = t.find('_')
             if i <= 0:
                 signed = False
                 continue
             tid = t[i+1:]
             req.tid = long(tid)
             resp = req.getResponse(shop.sessionkey)
             trade =  resp.get('trade_get_response') and resp.get('trade_get_response').get('trade')
             if not trade or trade['status'] != 'TRADE_FINISHED': 
                 signed = False
                 continue
     else:
         req.tid = long(tid)
         resp = req.getResponse(shop.sessionkey)
         trade =  resp.get('trade_get_response') and resp.get('trade_get_response').get('trade')
         if not trade or trade['status'] != 'TRADE_FINISHED': 
             signed = False
     
     return signed