E = [
@@ -298,6 +301,7 @@ DJANGO_SHORT_URL_REDIRECT_URL = ''
# Django-We Settings
DJANGO_WE_QUOTE_OR_NOT = True
+DJANGO_WE_MODEL_DISPLAY_OR_NOT = False
# Enable Cookie or not
# DJANGO_WE_BASE_REDIRECT_SET_COOKIE = False
# DJANGO_WE_USERINFO_REDIRECT_SET_COOKIE = True
@@ -305,6 +309,20 @@ DJANGO_WE_QUOTE_OR_NOT = True
DJANGO_WE_COOKIE_MAX_AGE = COOKIE_MAX_AGE
DJANGO_WE_COOKIE_SALT = COOKIE_SALT
+
+JOS = {
+ 'TAMRON': {
+ 'appkey': '',
+ 'secret': '',
+ 'accessToken': '',
+ 'vendorCode': '',
+ 'vendorName': '',
+ 'storeId': '',
+ 'storeName': '',
+ }
+}
+JOS_SKU_EXCLUDE = [1, 2, 3]
+
# 开发调试相关配置
if DEBUG:
try:
@@ -342,6 +360,7 @@ WECHAT_DIRECT_USERINFO_REDIRECT_URI = '{0}/we/direct_userinfo_redirect'.format(D
JDJOS_OAUTH_AUTHORIZE = 'https://oauth.jd.com/oauth/authorize?response_type=code&client_id={client_id}&redirect_uri={redirect_uri}&state={state}'
JDJOS_OAUTH_TOKEN = 'https://oauth.jd.com/oauth/token?grant_type=authorization_code&client_id={client_id}&redirect_uri={redirect_uri}&code={code}&state={state}&client_secret={client_secret}'
+
JDJOS_REDIRECT_URI = '{0}/jos/oauth'.format(DOMAIN)
# Redis 连接
@@ -44,9 +44,13 @@ urlpatterns += [ |
||
| 44 | 44 |
# url(r'^page/', include('page.urls', namespace='page')),
|
| 45 | 45 |
] |
| 46 | 46 |
|
| 47 |
+urlpatterns += [ |
|
| 48 |
+ url(r'^jos/', include('jos.urls', namespace='jos')),
|
|
| 49 |
+] |
|
| 50 |
+ |
|
| 47 | 51 |
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) |
| 48 | 52 |
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) |
| 49 | 53 |
|
| 50 | 54 |
# AdminSite |
| 51 |
-admin.site.site_title = '' |
|
| 52 |
-admin.site.site_header = 'My administration' |
|
| 55 |
+admin.site.site_title = '[腾龙]京东EDI管理系统' |
|
| 56 |
+admin.site.site_header = '[腾龙]京东EDI管理系统' |
@@ -0,0 +1,7 @@ |
||
| 1 |
+# -*- coding: utf-8 -*- |
|
| 2 |
+from __future__ import unicode_literals |
|
| 3 |
+ |
|
| 4 |
+from django.contrib import admin |
|
| 5 |
+ |
|
| 6 |
+ |
|
| 7 |
+# Register your models here. |
@@ -0,0 +1,8 @@ |
||
| 1 |
+# -*- coding: utf-8 -*- |
|
| 2 |
+from __future__ import unicode_literals |
|
| 3 |
+ |
|
| 4 |
+from django.apps import AppConfig |
|
| 5 |
+ |
|
| 6 |
+ |
|
| 7 |
+class JosConfig(AppConfig): |
|
| 8 |
+ name = 'jos' |
@@ -0,0 +1,10 @@ |
||
| 1 |
+# -*- coding: utf-8 -*- |
|
| 2 |
+ |
|
| 3 |
+from __future__ import division |
|
| 4 |
+ |
|
| 5 |
+from django.conf import settings |
|
| 6 |
+from django.shortcuts import redirect |
|
| 7 |
+ |
|
| 8 |
+ |
|
| 9 |
+def redirect_func(request): |
|
| 10 |
+ return redirect('{}/admin'.format(settings.DOMAIN))
|
@@ -0,0 +1,7 @@ |
||
| 1 |
+# -*- coding: utf-8 -*- |
|
| 2 |
+from __future__ import unicode_literals |
|
| 3 |
+ |
|
| 4 |
+from django.db import models |
|
| 5 |
+ |
|
| 6 |
+ |
|
| 7 |
+# Create your models here. |
@@ -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. |
@@ -0,0 +1,10 @@ |
||
| 1 |
+# -*- coding: utf-8 -*- |
|
| 2 |
+ |
|
| 3 |
+from django.conf.urls import url |
|
| 4 |
+ |
|
| 5 |
+from jos import jos_views |
|
| 6 |
+ |
|
| 7 |
+ |
|
| 8 |
+urlpatterns = [ |
|
| 9 |
+ url(r'^$', jos_views.redirect_func, name='redirect_func'), |
|
| 10 |
+] |
@@ -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. |
@@ -6,5 +6,6 @@ |
||
| 6 | 6 |
# -- E128 continuation line under-indented for visual indent |
| 7 | 7 |
# -- E402 module level import not at top of file |
| 8 | 8 |
# -- E501 line too long |
| 9 |
+# -- E731 do not assign a lambda expression, use a def |
|
| 9 | 10 |
|
| 10 |
-pycodestyle --exclude=build,migrations,.tox --ignore=E128,E402,E501 . |
|
| 11 |
+pycodestyle --exclude=build,migrations,.tox --ignore=E128,E402,E501,E731 . |
@@ -1,4 +1,4 @@ |
||
| 1 |
-Django==1.11.16 |
|
| 1 |
+Django==1.11.20 |
|
| 2 | 2 |
django-admin==1.3.2 |
| 3 | 3 |
django-detect==1.0.8 |
| 4 | 4 |
django-file==1.0.3 |
@@ -0,0 +1,21 @@ |
||
| 1 |
+# -*- coding: utf-8 -*- |
|
| 2 |
+ |
|
| 3 |
+from django.contrib import admin |
|
| 4 |
+from django_admin import AdvancedExportExcelModelAdmin, ReadOnlyModelAdmin |
|
| 5 |
+ |
|
| 6 |
+from stock.models import StockInfo |
|
| 7 |
+from utils.stock_utils import update_stock_info |
|
| 8 |
+ |
|
| 9 |
+ |
|
| 10 |
+class StockInfoAdmin(AdvancedExportExcelModelAdmin, admin.ModelAdmin): |
|
| 11 |
+ # list_display = ('stock_id', 'vendorCode', 'vendorName', 'vendorProductId', 'vendorProductName', 'storeId', 'storeName', 'quantity', 'estimateQuantity', 'inventoryDate', 'totalQuantity', 'estimateDate', 'totalEstimateQuantity', 'costPrice', 'status', 'created_at', 'updated_at')
|
|
| 12 |
+ list_display = ('vendorProductId', 'vendorProductName', 'inventoryDate', 'totalQuantity', 'estimateDate', 'totalEstimateQuantity', 'costPrice', 'updated_at')
|
|
| 13 |
+ readonly_fields = ('stock_id', 'vendorCode', 'vendorName', 'vendorProductId', 'vendorProductName', 'storeId', 'storeName', 'quantity', 'estimateQuantity', 'status')
|
|
| 14 |
+ |
|
| 15 |
+ def save_model(self, request, obj, form, change): |
|
| 16 |
+ obj.save() |
|
| 17 |
+ if obj.inventoryDate and obj.estimateDate: |
|
| 18 |
+ update_stock_info(obj) |
|
| 19 |
+ |
|
| 20 |
+ |
|
| 21 |
+admin.site.register(StockInfo, StockInfoAdmin) |
@@ -0,0 +1,8 @@ |
||
| 1 |
+# -*- coding: utf-8 -*- |
|
| 2 |
+from __future__ import unicode_literals |
|
| 3 |
+ |
|
| 4 |
+from django.apps import AppConfig |
|
| 5 |
+ |
|
| 6 |
+ |
|
| 7 |
+class StockConfig(AppConfig): |
|
| 8 |
+ name = 'stock' |
@@ -0,0 +1,43 @@ |
||
| 1 |
+# -*- coding: utf-8 -*- |
|
| 2 |
+# Generated by Django 1.11.20 on 2019-03-03 21:40 |
|
| 3 |
+from __future__ import unicode_literals |
|
| 4 |
+ |
|
| 5 |
+from django.db import migrations, models |
|
| 6 |
+import shortuuidfield.fields |
|
| 7 |
+ |
|
| 8 |
+ |
|
| 9 |
+class Migration(migrations.Migration): |
|
| 10 |
+ |
|
| 11 |
+ initial = True |
|
| 12 |
+ |
|
| 13 |
+ dependencies = [ |
|
| 14 |
+ ] |
|
| 15 |
+ |
|
| 16 |
+ operations = [ |
|
| 17 |
+ migrations.CreateModel( |
|
| 18 |
+ name='StockInfo', |
|
| 19 |
+ fields=[ |
|
| 20 |
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
|
| 21 |
+ ('status', models.BooleanField(db_index=True, default=True, help_text='Status', verbose_name='status')),
|
|
| 22 |
+ ('created_at', models.DateTimeField(auto_now_add=True, help_text='Create Time', verbose_name='created_at')),
|
|
| 23 |
+ ('updated_at', models.DateTimeField(auto_now=True, help_text='Update Time', verbose_name='updated_at')),
|
|
| 24 |
+ ('stock_id', shortuuidfield.fields.ShortUUIDField(blank=True, db_index=True, editable=False, help_text='Stock\u552f\u4e00\u6807\u8bc6', max_length=22, null=True)),
|
|
| 25 |
+ ('vendorCode', models.CharField(blank=True, help_text='\u4f9b\u5e94\u5546\u7b80\u7801', max_length=8, null=True, verbose_name='vendorCode')),
|
|
| 26 |
+ ('vendorName', models.CharField(blank=True, help_text='\u4f9b\u5e94\u5546\u540d\u79f0', max_length=32, null=True, verbose_name='vendorName')),
|
|
| 27 |
+ ('vendorProductId', models.CharField(blank=True, db_index=True, help_text='\u4f9b\u5e94\u5546\u5546\u54c1ID', max_length=32, null=True, verbose_name='vendorProductId')),
|
|
| 28 |
+ ('storeId', models.CharField(blank=True, help_text='\u4f9b\u5e94\u5546\u4ed3\u5e93ID', max_length=8, null=True, verbose_name='storeId')),
|
|
| 29 |
+ ('storeName', models.CharField(blank=True, help_text='\u4f9b\u5e94\u5546\u4ed3\u5e93\u540d\u79f0', max_length=32, null=True, verbose_name='storeName')),
|
|
| 30 |
+ ('quantity', models.IntegerField(default=0, help_text='\u5206\u4ed3\u5e93\u5b58\u6570\u91cf', verbose_name='quantity')),
|
|
| 31 |
+ ('estimateQuantity', models.IntegerField(default=0, help_text='\u9884\u8ba1\u5e93\u5b58\u6570\u91cf', verbose_name='estimateQuantity')),
|
|
| 32 |
+ ('inventoryDate', models.DateTimeField(blank=True, help_text='\u5e93\u5b58\u65e5\u671f', null=True, verbose_name='inventoryDate')),
|
|
| 33 |
+ ('totalQuantity', models.IntegerField(default=0, help_text='\u5e93\u5b58\u603b\u91cf', verbose_name='totalQuantity')),
|
|
| 34 |
+ ('estimateDate', models.DateTimeField(blank=True, help_text='\u9884\u8ba1\u5e93\u5b58\u65e5\u671f', null=True, verbose_name='estimateDate')),
|
|
| 35 |
+ ('totalEstimateQuantity', models.IntegerField(default=0, help_text='\u9884\u8ba1\u5e93\u5b58\u603b\u91cf', verbose_name='totalEstimateQuantity')),
|
|
| 36 |
+ ('costPrice', models.IntegerField(default=0, help_text='\u8fdb\u4ef7', verbose_name='costPrice')),
|
|
| 37 |
+ ], |
|
| 38 |
+ options={
|
|
| 39 |
+ 'verbose_name': 'StockInfo', |
|
| 40 |
+ 'verbose_name_plural': 'StockInfo', |
|
| 41 |
+ }, |
|
| 42 |
+ ), |
|
| 43 |
+ ] |
@@ -0,0 +1,20 @@ |
||
| 1 |
+# -*- coding: utf-8 -*- |
|
| 2 |
+# Generated by Django 1.11.20 on 2019-03-03 21:48 |
|
| 3 |
+from __future__ import unicode_literals |
|
| 4 |
+ |
|
| 5 |
+from django.db import migrations, models |
|
| 6 |
+ |
|
| 7 |
+ |
|
| 8 |
+class Migration(migrations.Migration): |
|
| 9 |
+ |
|
| 10 |
+ dependencies = [ |
|
| 11 |
+ ('stock', '0001_initial'),
|
|
| 12 |
+ ] |
|
| 13 |
+ |
|
| 14 |
+ operations = [ |
|
| 15 |
+ migrations.AddField( |
|
| 16 |
+ model_name='stockinfo', |
|
| 17 |
+ name='vendorProductName', |
|
| 18 |
+ field=models.CharField(blank=True, help_text='\u4f9b\u5e94\u5546\u5546\u54c1\u540d\u79f0', max_length=32, null=True, verbose_name='vendorProductName'), |
|
| 19 |
+ ), |
|
| 20 |
+ ] |
@@ -0,0 +1,20 @@ |
||
| 1 |
+# -*- coding: utf-8 -*- |
|
| 2 |
+# Generated by Django 1.11.20 on 2019-03-03 21:49 |
|
| 3 |
+from __future__ import unicode_literals |
|
| 4 |
+ |
|
| 5 |
+from django.db import migrations, models |
|
| 6 |
+ |
|
| 7 |
+ |
|
| 8 |
+class Migration(migrations.Migration): |
|
| 9 |
+ |
|
| 10 |
+ dependencies = [ |
|
| 11 |
+ ('stock', '0002_stockinfo_vendorproductname'),
|
|
| 12 |
+ ] |
|
| 13 |
+ |
|
| 14 |
+ operations = [ |
|
| 15 |
+ migrations.AlterField( |
|
| 16 |
+ model_name='stockinfo', |
|
| 17 |
+ name='vendorProductName', |
|
| 18 |
+ field=models.CharField(blank=True, help_text='\u4f9b\u5e94\u5546\u5546\u54c1\u540d\u79f0', max_length=255, null=True, verbose_name='vendorProductName'), |
|
| 19 |
+ ), |
|
| 20 |
+ ] |
@@ -0,0 +1,35 @@ |
||
| 1 |
+# -*- coding: utf-8 -*- |
|
| 2 |
+ |
|
| 3 |
+from django.db import models |
|
| 4 |
+from django.utils.translation import ugettext_lazy as _ |
|
| 5 |
+from django_models_ext import BaseModelMixin |
|
| 6 |
+from shortuuidfield import ShortUUIDField |
|
| 7 |
+ |
|
| 8 |
+ |
|
| 9 |
+class StockInfo(BaseModelMixin): |
|
| 10 |
+ stock_id = ShortUUIDField(_(u'stock_id'), max_length=32, blank=True, null=True, help_text=u'Stock唯一标识', db_index=True) |
|
| 11 |
+ |
|
| 12 |
+ vendorCode = models.CharField(_(u'vendorCode'), max_length=8, blank=True, null=True, help_text=u'供应商简码') |
|
| 13 |
+ vendorName = models.CharField(_(u'vendorName'), max_length=32, blank=True, null=True, help_text=u'供应商名称') |
|
| 14 |
+ vendorProductId = models.CharField(_(u'vendorProductId'), max_length=32, blank=True, null=True, help_text=u'供应商商品ID', db_index=True) |
|
| 15 |
+ vendorProductName = models.CharField(_(u'vendorProductName'), max_length=255, blank=True, null=True, help_text=u'供应商商品名称') |
|
| 16 |
+ |
|
| 17 |
+ storeId = models.CharField(_(u'storeId'), max_length=8, blank=True, null=True, help_text=u'供应商仓库ID') |
|
| 18 |
+ storeName = models.CharField(_(u'storeName'), max_length=32, blank=True, null=True, help_text=u'供应商仓库名称') |
|
| 19 |
+ # 分仓库存数量=库存总量,预计库存数量=预计库存总量 |
|
| 20 |
+ quantity = models.IntegerField(_(u'quantity'), default=0, help_text=u'分仓库存数量') |
|
| 21 |
+ estimateQuantity = models.IntegerField(_(u'estimateQuantity'), default=0, help_text=u'预计库存数量') |
|
| 22 |
+ |
|
| 23 |
+ # Tamron 填写 |
|
| 24 |
+ inventoryDate = models.DateTimeField(_(u'inventoryDate'), blank=True, null=True, help_text=_(u'库存日期')) |
|
| 25 |
+ totalQuantity = models.IntegerField(_(u'totalQuantity'), default=0, help_text=u'库存总量') |
|
| 26 |
+ estimateDate = models.DateTimeField(_(u'estimateDate'), blank=True, null=True, help_text=_(u'预计库存日期')) |
|
| 27 |
+ totalEstimateQuantity = models.IntegerField(_(u'totalEstimateQuantity'), default=0, help_text=u'预计库存总量') |
|
| 28 |
+ costPrice = models.IntegerField(_(u'costPrice'), default=0, help_text=u'进价') |
|
| 29 |
+ |
|
| 30 |
+ class Meta: |
|
| 31 |
+ verbose_name = _(u'StockInfo') |
|
| 32 |
+ verbose_name_plural = _(u'StockInfo') |
|
| 33 |
+ |
|
| 34 |
+ def __unicode__(self): |
|
| 35 |
+ return u'{0.pk}'.format(self)
|
@@ -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. |
@@ -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. |
@@ -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) |