-33"> 33
+
34
+    def __unicode__(self):
35
+        return u'{0.pk}'.format(self)

+ 7 - 0
stock/tests.py

@@ -0,0 +1,7 @@
1
+# -*- coding: utf-8 -*-
2
+from __future__ import unicode_literals
3
+
4
+from django.test import TestCase
5
+
6
+
7
+# Create your tests here.

+ 7 - 0
stock/views.py

@@ -0,0 +1,7 @@
1
+# -*- coding: utf-8 -*-
2
+from __future__ import unicode_literals
3
+
4
+from django.shortcuts import render
5
+
6
+
7
+# Create your views here.

+ 80 - 0
utils/stock_utils.py

@@ -0,0 +1,80 @@
1
+# -*- coding: utf-8 -*-
2
+
3
+import json
4
+
5
+from django.conf import settings
6
+from TimeConvert import TimeConvert as tc
7
+
8
+import jd
9
+from jd.api.rest.EdiInventorySendRequest import EdiInventorySendRequest
10
+from jd.api.rest.VcAplsStockBatchGetProdStockInfoRequest import VcAplsStockBatchGetProdStockInfoRequest
11
+from jd.api.rest.VcItemProductsFindRequest import VcItemProductsFindRequest
12
+from stock.models import StockInfo
13
+
14
+
15
+JOS = settings.JOS['TAMRON']
16
+
17
+
18
+def refresh_stock_info():
19
+    jd.setDefaultAppInfo(JOS['appkey'], JOS['secret'])
20
+
21
+    a = VcItemProductsFindRequest()
22
+    a.brand_id = 16795
23
+    a.category_id = 834
24
+
25
+    try:
26
+        f = a.getResponse(JOS['accessToken'])
27
+        print(json.dumps(f, ensure_ascii=False))
28
+    except Exception, e:
29
+        print(e)
30
+
31
+    products = f['jingdong_vc_item_products_find_responce']['jos_result_dto']['result']
32
+    print products
33
+
34
+    ware_ids = [int(p['ware_id']) for p in products]
35
+    print ware_ids
36
+
37
+    a = VcAplsStockBatchGetProdStockInfoRequest()
38
+    a.vendorCode = JOS['vendorCode']
39
+    a.skuList = list(set(ware_ids) - set(settings.JOS_SKU_EXCLUDE))
40
+
41
+    try:
42
+        f = a.getResponse(JOS['accessToken'])
43
+        print(json.dumps(f, ensure_ascii=False))
44
+    except Exception, e:
45
+        print(e)
46
+
47
+    stocks = f['jingdong_vc_apls_stock_batchGetProdStockInfo_responce']['batchGetProdStockInfoResponse']['stockList']
48
+    for stock in stocks:
49
+        print stock['sku']
50
+        s, _ = StockInfo.objects.get_or_create(vendorProductId=stock['sku'])
51
+        s.vendorProductName = stock['wname']
52
+        s.vendorCode = JOS['vendorCode']
53
+        s.vendorName = JOS['vendorName']
54
+        s.storeId = JOS['storeId']
55
+        s.storeName = JOS['storeName']
56
+        s.save()
57
+
58
+
59
+def update_stock_info(stock):
60
+    jd.setDefaultAppInfo(JOS['appkey'], JOS['secret'])
61
+
62
+    a = EdiInventorySendRequest()
63
+    a.vendorCode = stock.vendorCode
64
+    a.vendorName = stock.vendorName
65
+    a.vendorProductId = stock.vendorProductId
66
+    a.inventoryDate = tc.local_string(tc.to_local_datetime(stock.inventoryDate))
67
+    a.totalQuantity = stock.totalQuantity
68
+    a.estimateDate = tc.local_string(tc.to_local_datetime(stock.estimateDate))
69
+    a.totalEstimateQuantity = stock.totalEstimateQuantity
70
+    a.costPrice = stock.costPrice
71
+    a.storeId = stock.storeId
72
+    a.storeName = stock.storeName
73
+    a.quantity = stock.totalQuantity
74
+    a.estimateQuantity = stock.totalEstimateQuantity
75
+
76
+    try:
77
+        f = a.getResponse(JOS['accessToken'])
78
+        print(json.dumps(f, ensure_ascii=False))
79
+    except Exception, e:
80
+        print(e)

kodo - Gogs: Go Git Service

暂无描述

Brightcells: 8263625d9c new website 10 年之前
..
website 8263625d9c new website 10 年之前