金蝶云星空实时库存专题

通过向金蝶库存单据注册Python脚本,用于实时监听库存单据审核/反审核,并且将数据发送到轻易云系统集成平台

。通过集成平台将数据分发到对应的目标系统。

向金蝶的库存单据注册脚本

注意修改脚本中的三个变量参数,MAIN_NAME表描述,MAIN_TABLE主表名,ENTRY_TABLE分录表名。关键库存单据表名参考:

库存变动表单 表头 表体
采购入库单 t_STK_InStock T_STK_INSTOCKENTRY
采购退料单 t_PUR_MRB T_PUR_MRBENTRY
销售出库单 T_SAL_OUTSTOCK T_SAL_OUTSTOCKENTRY
销售退货单 T_SAL_RETURNSTOCK T_SAL_RETURNSTOCKENTRY

更多表单名与字段可以自行查阅金蝶BOS平台,不在此赘述。

注意正式运行时将python脚本中的 SHOW_DEBUG 设置为 False 当然这不是必需的

注册金蝶列表插件

ListViewBarItemClick.py

import clr
clr.AddReference("System")
clr.AddReference("System.Web.Extensions")
clr.AddReference("Kingdee.BOS.Core")
clr.AddReference("Kingdee.BOS")
clr.AddReference('Kingdee.BOS.App')
clr.AddReference("Kingdee.BOS.DataEntity")
clr.AddReference("Kingdee.BOS.ServiceHelper")
clr.AddReference("Newtonsoft.Json")
import sys
from System import *
from System.Collections.Generic import *
from System.Web.Script.Serialization import *
from System.Security.Cryptography import *
from System.Text import *
from System.Net import *
from System.IO import *
from System.Threading import *
from System.Collections.Generic import Dictionary
from Newtonsoft.Json import *
from Newtonsoft.Json.Linq import *
from Kingdee.BOS.ServiceHelper import *
from Kingdee.BOS.Core.DynamicForm import *
from Kingdee.BOS.App.Data import *
reload(sys)
sys.setdefaultencoding('utf-8') # 金蝶Cloud列表插件
# 用于监听审核、反审核事件后查询变动物料的库存数据,并将数据发送到DATAHUB
# 在应用到需要监听的不同表单时,注意需要更换 MAIN_NAME,MAIN_TABLE,ENTRY_TABLE 三个变量 # 开启debug调试消息提醒
SHOW_DEBUG = True # DataHub Host 服务器主机
DATAHUB_HOST = 'https://www.qliang.cloud' # StrategyId 集线器ID
STRATEGY_ID = '2509d92a-a91e-30a3-ae4e-33eead036a97' # 当前表名
MAIN_NAME = '外购入库';
# 当前表的主表名
MAIN_TABLE = 't_STK_InStock'
# 当前表的分录表名
ENTRY_TABLE = 'T_STK_INSTOCKENTRY' # 当前表的单据编码字段
BILL_FIELD = 'FBILLNO';
# 物料字段名,通常情况下应该是 FMATERIALID 不需要修改
MATERIAL_FIELD = 'FMATERIALID'
# 仓库字段名,通常情况下应该是 FSTOCKID 不需要修改
STOCK_FIELD = 'FSTOCKID'
# 库位字段名,通常情况下应该是 FSTOCKLOCID 不需要修改
STOCKLOC_FIELD = 'FSTOCKLOCID'
# 批次号字段名,通常情况下应该是 FLOT 不需要修改
LOT_FIELD = 'FLOT'
# 货主字段名,通常情况下应该是 FOWNERID 不需要修改
OWNER_FIELD = 'FOWNERID' class Inventory: def __init__(self,BarItemKey):
keys = this.ListView.SelectedRowsInfo.GetPrimaryKeyValues()
self.BarItemKey = BarItemKey
self.PKS = ','.join(keys) def fetch(self):
return DBServiceHelper.ExecuteDynamicObject(
this.Context, self.__generateSQL()) def collectionToJson(self, collection):
json = '['
for row in collection:
json += '{"FID":"'+row[0].ToString() + '"' \
',"FStockId":"'+row[1].ToString()+'"' \
',"FMaterialId":"'+row[2].ToString()+'"' \
',"FBaseQty":"'+row[3].ToString()+'"' \
',"FBaseAVBQty":"'+row[4].ToString()+'"' \
',"FLot":"'+row[5].ToString()+'"' \
',"FUpdateTime":"'+row[6].ToString()+'"' \
',"FOwnerId":"'+row[7].ToString()+'"' \
',"FKeeperId":"'+row[8].ToString()+'"' \
',"FStockOrgId":"'+row[9].ToString()+'"' \
',"FOwnerTypeId":"'+row[10].ToString()+'"' \
',"FMaterialId_FNumber":"'+row[11].ToString()+'"' \
',"FOwnerId_FNumber":"'+row[12].ToString()+'"' \
',"FKeeperId_FNumber":"'+row[13].ToString()+'"' \
',"FStockOrgId_FNumber":"'+row[14].ToString()+'"' \
',"FProduceDate":"'+row[15].ToString()+'"' \
',"FMtoNo":"'+row[16].ToString()+'"' \
',"FStockStatusId":"'+row[17].ToString()+'"' \
',"FBILLNO":"'+row[18].ToString()+'"' \
',"id":"'+row[0].ToString()+'"' \
',"FormName":"'+MAIN_NAME+'"},'
json = json.rstrip(',') + ']'
return '{"idCheck":false,"content":'+json+',"multiple":true,"id":1}'; def __generateSQL(self):
sqlArray = [
'SELECT DISTINCT',
'INV.FID,',
'INV.FStockId,',
'INV.FMaterialId,',
'INV.FBaseQty,',
'INV.FBaseAVBQty,',
'INV.FLot,',
'INV.FUpdateTime,',
'INV.FOwnerId,',
'INV.FKeeperId,',
'INV.FStockOrgId,',
'INV.FOwnerTypeId,',
'MATE.FNUMBER AS FMaterialId_FNumber,',
'ORG1.FNUMBER AS FOwnerId_FNumber,',
'ORG2.FNUMBER AS FKeeperId_FNumber,',
'ORG3.FNUMBER AS FStockOrgId_FNumber,',
'INV.FProduceDate,',
'INV.FMtoNo,',
'INV.FStockStatusId,',
# 如果现实单据号,则可能导致会重复发送多一些数据.但是这并不影响真实库存.如果非要传入单号,可以开启
# 'MAIN.'+BILL_FIELD,
# 将单号现实为0,避免POST数据中存在重复
"'0' AS FBillNo",
'FROM T_STK_INVENTORY INV',
'LEFT JOIN '+ENTRY_TABLE+' BILL ON',
'INV.FMATERIALID = BILL.'+MATERIAL_FIELD,
'AND INV.FSTOCKID = BILL.'+STOCK_FIELD,
'AND INV.FSTOCKLOCID = BILL.'+STOCKLOC_FIELD,
'AND INV.FLOT = BILL.'+LOT_FIELD,
'AND INV.FOWNERID = BILL.'+OWNER_FIELD,
'LEFT JOIN t_bd_material MATE ON INV.FMATERIALID = MATE.FMATERIALID',
'LEFT JOIN t_ORG_Organizations ORG1 ON INV.FOwnerId = ORG1.FORGID',
'LEFT JOIN t_ORG_Organizations ORG2 ON INV.FKeeperId = ORG2.FORGID',
'LEFT JOIN t_ORG_Organizations ORG3 ON INV.FStockOrgId = ORG3.FORGID',
'LEFT JOIN '+MAIN_TABLE+' MAIN ON BILL.FID = MAIN.FID',
'WHERE BILL.FID IN ('+self.PKS+')',
]
sql = ' '.join(sqlArray)
if self.BarItemKey == 'tbApprove':
sql += " AND MAIN.FDOCUMENTSTATUS = 'C'"
else:
sql += " AND MAIN.FDOCUMENTSTATUS = 'D'"
# this.View.ShowMessage(sql)
return sql def AfterBarItemClick(e):
if e.BarItemKey == 'tbApprove' or e.BarItemKey == 'tbReject':
if len(this.ListView.SelectedRowsInfo.GetPrimaryKeyValues()) > 0:
handle(e.BarItemKey) def handle(BarItemKey):
inv = Inventory(BarItemKey)
url = DATAHUB_HOST + '/api/open/operation/'+STRATEGY_ID
collection = inv.fetch()
if len(collection) == 0:
return;
webRequest = post(url, inv.collectionToJson(collection))
result = JObject.Parse(webRequest)
if SHOW_DEBUG == True:
this.View.ShowMessage(webRequest) def get(url):
webRequest = WebRequest.Create(url)
webRequest.Method = "GET"
webResponse = webRequest.GetResponse()
stream = webResponse.GetResponseStream()
streamReader = StreamReader(stream, Encoding.GetEncoding("utf-8"))
result = streamReader.ReadToEnd()
return result def post(url, postdata):
webRequest = HttpWebRequest.Create(url)
webRequest.Method = "POST"
webRequest.Accept = "application/json, text/plain, */*"
webRequest.ContentType = "application/json;charset=UTF-8"
data = Encoding.ASCII.GetBytes(postdata)
webRequest.ContentLength = data.Length
webRequest.GetRequestStream().Write(data, 0, data.Length)
webRequest.GetRequestStream().Flush()
webRequest.GetRequestStream().Close()
webResponse = webRequest.GetResponse()
streamReader = StreamReader(
webResponse .GetResponseStream(), Encoding.GetEncoding("utf-8"))
result = streamReader.ReadToEnd()
return result

注册金蝶表单插件

DynamicFormDataChanged.py

import clr
clr.AddReference("System")
clr.AddReference("System.Web.Extensions")
clr.AddReference("Kingdee.BOS.Core")
clr.AddReference("Kingdee.BOS")
clr.AddReference('Kingdee.BOS.App')
clr.AddReference("Kingdee.BOS.DataEntity")
clr.AddReference("Kingdee.BOS.ServiceHelper")
clr.AddReference("Newtonsoft.Json")
import sys
from System import *
from System.Collections.Generic import *
from System.Web.Script.Serialization import *
from System.Security.Cryptography import *
from System.Text import *
from System.Net import *
from System.IO import *
from System.Threading import *
from System.Collections.Generic import Dictionary
from Newtonsoft.Json import *
from Newtonsoft.Json.Linq import *
from Kingdee.BOS.ServiceHelper import *
from Kingdee.BOS.Core.DynamicForm import *
from Kingdee.BOS.App.Data import *
reload(sys)
sys.setdefaultencoding('utf-8') # 金蝶Cloud表单插件
# 用于监听数据变动审核、反审核事件后查询变动物料的库存数据,并将数据发送到DATAHUB
# 在应用到需要监听的不同表单时,注意需要更换 MAIN_NAME,MAIN_TABLE,ENTRY_TABLE 三个变量 # 开启debug调试消息提醒
SHOW_DEBUG = True # DataHub Host 服务器主机
DATAHUB_HOST = 'https://www.qliang.cloud' # StrategyId 集线器ID
STRATEGY_ID = '2509d92a-a91e-30a3-ae4e-33eead036a97' # 当前表名
MAIN_NAME = '外购入库';
# 当前表的主表名
MAIN_TABLE = 't_STK_InStock'
# 当前表的分录表名
ENTRY_TABLE = 'T_STK_INSTOCKENTRY'
# 当前表的单据编码字段
BILL_FIELD = 'FBILLNO'; # 物料字段名,通常情况下应该是 FMATERIALID 不需要修改
MATERIAL_FIELD = 'FMATERIALID'
# 仓库字段名,通常情况下应该是 FSTOCKID 不需要修改
STOCK_FIELD = 'FSTOCKID'
# 库位字段名,通常情况下应该是 FSTOCKLOCID 不需要修改
STOCKLOC_FIELD = 'FSTOCKLOCID'
# 批次号字段名,通常情况下应该是 FLOT 不需要修改
LOT_FIELD = 'FLOT'
# 货主字段名,通常情况下应该是 FOWNERID 不需要修改
OWNER_FIELD = 'FOWNERID' class Inventory: def __init__(self):
self.PK = this.View.Model.GetPKValue().ToString() def fetch(self):
return DBServiceHelper.ExecuteDynamicObject(
this.Context, self.__generateSQL()) def collectionToJson(self, collection):
json = '['
for row in collection:
json += '{"FID":"'+row[0].ToString() + '"' \
',"FStockId":"'+row[1].ToString()+'"' \
',"FMaterialId":"'+row[2].ToString()+'"' \
',"FBaseQty":"'+row[3].ToString()+'"' \
',"FBaseAVBQty":"'+row[4].ToString()+'"' \
',"FLot":"'+row[5].ToString()+'"' \
',"FUpdateTime":"'+row[6].ToString()+'"' \
',"FOwnerId":"'+row[7].ToString()+'"' \
',"FKeeperId":"'+row[8].ToString()+'"' \
',"FStockOrgId":"'+row[9].ToString()+'"' \
',"FOwnerTypeId":"'+row[10].ToString()+'"' \
',"FMaterialId_FNumber":"'+row[11].ToString()+'"' \
',"FOwnerId_FNumber":"'+row[12].ToString()+'"' \
',"FKeeperId_FNumber":"'+row[13].ToString()+'"' \
',"FStockOrgId_FNumber":"'+row[14].ToString()+'"' \
',"FProduceDate":"'+row[15].ToString()+'"' \
',"FMtoNo":"'+row[16].ToString()+'"' \
',"FStockStatusId":"'+row[17].ToString()+'"' \
',"FBILLNO":"'+row[18].ToString()+'"' \
',"id":"'+row[0].ToString()+'"' \
',"FormName":"'+MAIN_NAME+'"},'
json = json.rstrip(',') + ']'
return '{"idCheck":false,"content":'+json+',"multiple":true,"id":1}'; def __generateSQL(self):
sqlArray = [
'SELECT DISTINCT',
'INV.FID,',
'INV.FStockId,',
'INV.FMaterialId,',
'INV.FBaseQty,',
'INV.FBaseAVBQty,',
'INV.FLot,',
'INV.FUpdateTime,',
'INV.FOwnerId,',
'INV.FKeeperId,',
'INV.FStockOrgId,',
'INV.FOwnerTypeId,',
'MATE.FNUMBER AS FMaterialId_FNumber,',
'ORG1.FNUMBER AS FOwnerId_FNumber,',
'ORG2.FNUMBER AS FKeeperId_FNumber,',
'ORG3.FNUMBER AS FStockOrgId_FNumber,',
'INV.FProduceDate,',
'INV.FMtoNo,',
'INV.FStockStatusId,',
'MAIN.'+BILL_FIELD,
'FROM T_STK_INVENTORY INV',
'LEFT JOIN '+ENTRY_TABLE+' BILL ON',
'INV.FMATERIALID = BILL.'+MATERIAL_FIELD,
'AND INV.FSTOCKID = BILL.'+STOCK_FIELD,
'AND INV.FSTOCKLOCID = BILL.'+STOCKLOC_FIELD,
'AND INV.FLOT = BILL.'+LOT_FIELD,
'AND INV.FOWNERID = BILL.'+OWNER_FIELD,
'LEFT JOIN t_bd_material MATE ON INV.FMATERIALID = MATE.FMATERIALID',
'LEFT JOIN t_ORG_Organizations ORG1 ON INV.FOwnerId = ORG1.FORGID',
'LEFT JOIN t_ORG_Organizations ORG2 ON INV.FKeeperId = ORG2.FORGID',
'LEFT JOIN t_ORG_Organizations ORG3 ON INV.FStockOrgId = ORG3.FORGID',
'LEFT JOIN '+MAIN_TABLE+' MAIN ON BILL.FID = MAIN.FID',
'WHERE BILL.FID = '+self.PK,
]
return ' '.join(sqlArray) def DataChanged(e):
if e.Key.ToString() == 'FDocumentStatus' and e.OldValue.ToString() == 'B' and e.NewValue.ToString() == 'C':
handle()
elif e.Key.ToString() == 'FDocumentStatus' and e.OldValue.ToString() == 'C' and e.NewValue.ToString() == 'D':
handle() def handle():
inv = Inventory()
url = DATAHUB_HOST + '/api/open/operation/'+STRATEGY_ID
collection = inv.fetch()
if len(collection) == 0:
return;
webRequest = post(url, inv.collectionToJson(collection))
result = JObject.Parse(webRequest)
if SHOW_DEBUG == True:
this.View.ShowMessage(webRequest) def get(url):
webRequest = WebRequest.Create(url)
webRequest.Method = "GET"
webResponse = webRequest.GetResponse()
stream = webResponse.GetResponseStream()
streamReader = StreamReader(stream, Encoding.GetEncoding("utf-8"))
result = streamReader.ReadToEnd()
return result def post(url, postdata):
webRequest = HttpWebRequest.Create(url)
webRequest.Method = "POST"
webRequest.Accept = "application/json, text/plain, */*"
webRequest.ContentType = "application/json;charset=UTF-8"
data = Encoding.ASCII.GetBytes(postdata)
webRequest.ContentLength = data.Length
webRequest.GetRequestStream().Write(data, 0, data.Length)
webRequest.GetRequestStream().Flush()
webRequest.GetRequestStream().Close()
webResponse = webRequest.GetResponse()
streamReader = StreamReader(
webResponse .GetResponseStream(), Encoding.GetEncoding("utf-8"))
result = streamReader.ReadToEnd()
return result

金蝶对接电商ERP库存数据,实现监听库存变化的更多相关文章

  1. 电商ERP如何接入智选物流平台?

    智选物流是综合地址库+时效库+逻辑库(成本.订单属性.仓库)选择出最优快递,通过多家快递网点地址库精准数据,点对点的运输时间,各种行业包裹的所有快递价格逻辑,不同产品类型.支付方式等分析,实现不同仓库 ...

  2. 关于电商ERP的想法

    原文地址: http://www.chinaodoo.net/thread-465-1-1.html 试用了下odoo的淘宝订单处理模块,从整个业务流程上已经打通,如果要求不是很高的话,现有的功能基本 ...

  3. 小特跨境电商ERP桌面版 1.不止包括进销存 还能算毛利

    经过近几年跨境电商ERP的开发,加上对跨境电商行业的业务积累,开发出一套适合中小跨境电商公司使用的ERP软件.欢迎选购.支持目前流行的各大电商平台,如速卖通.敦煌网.亚马逊.Shopee.Wish等. ...

  4. 电商ERP常见功能模块

      电商ERP是适用企业卖家的专业电子商务ERP,支持淘宝.天猫.京东.1688.当当.苏宁.拍拍.唯品会.亚马逊.独立B2C等多网络销售渠道:也包括 异地多仓..货位管理.智能配货等专业的WMS(仓 ...

  5. Java生鲜电商平台-高并发核心技术订单与库存实战

    Java生鲜电商平台-高并发核心技术订单与库存实战 一. 问题 一件商品只有100个库存,现在有1000或者更多的用户来购买,每个用户计划同时购买1个到几个不等商品. 如何保证库存在高并发的场景下是安 ...

  6. R系列:关联分析;某电商平台的数据;做捆绑销售和商品关联推荐

    附注:不要问我为什么写这么快,是16年写的. 一.分析目的 I用户在某电商平台买了A,那么平台接下来应该给用户推荐什么,即用户在买了商品A之后接下来买什么的倾向性最大: II应该把哪些商品在一起做捆绑 ...

  7. Zookeeper 客户端API调用示例(基本使用,增删改查znode数据,监听znode,其它案例,其它网络参考资料)

    9.1 基本使用 org.apache.zookeeper.Zookeeper是客户端入口主类,负责建立与server的会话 它提供以下几类主要方法  : 功能 描述 create 在本地目录树中创建 ...

  8. es6的set和get实现数据双向绑定,监听变量变化。

    直接上代码吧,这个用法真的是效仿了.net的枚举. vue的数据双向绑定就是用这个实现的. 代码: html: <input type="text" id="inp ...

  9. 09.VUE学习之watch监听属性变化实现类百度搜索栏功能ajax异步请求数据,返回字符串

    cmd下安装axios npm install axios 安装好后,会多出node_modules文件夹 思路: 监听data里的word改变时,发送ajax异步请求数据, 把返回的数据赋值给dat ...

  10. linkedin databus介绍——监听数据库变化,有新数据到来时通知其他消费者app,新数据存在内存里,多份快照

    概要结构如下图. 图中显示:Search Index和Read Replicas等系统是Databus的消费者.当主OLTP数据库发生写操作时,连接其上的中继系统会将数据拉到中继中.签入在Search ...

随机推荐

  1. quarkus依赖注入之八:装饰器(Decorator)

    欢迎访问我的GitHub 这里分类和汇总了欣宸的全部原创(含配套源码):https://github.com/zq2599/blog_demos 本篇概览 本篇是<quarkus依赖注入> ...

  2. SpringBoot3之Web编程

    标签:Rest.拦截器.swagger.测试; 一.简介 基于web包的依赖,SpringBoot可以快速启动一个web容器,简化项目的开发: 在web开发中又涉及如下几个功能点: 拦截器:可以让接口 ...

  3. [ABC145E] All-you-can-eat

    2023-02-25 题目 题目传送门 翻译 翻译 难度&重要性(1~10):5 题目来源 AtCoder 题目算法 背包dp 解题思路 设 \(dp_i\) 为最后一道菜在第 \(i\) 时 ...

  4. 【Windows】KMS 激活命令记录

    目录 KMS 服务器激活 Office.Visio 推荐使用 office tool plus 部署并配置 KMS 激活 什么是 KMS? KMS 正版与否的区别 总结 KMS 服务器激活 利用 KM ...

  5. 每日一库:fsnotify简介

    fsnotify是一个用Go编写的文件系统通知库.它提供了一种观察文件系统变化的机制,例如文件的创建.修改.删除.重命名和权限修改.它使用特定平台的事件通知API,例如Linux上的inotify,m ...

  6. Python 潮流周刊#17:Excel 终于支持 Python 了、Meta 重磅开源新项目、Mojo 新得 1 亿美元融资

    你好,我是猫哥.这里每周分享优质的 Python.AI 及通用技术内容,大部分为英文.标题取自其中两则分享,不代表全部内容都是该主题,特此声明. 本周刊由 Python猫 出品,精心筛选国内外的 25 ...

  7. CodeForces 1174D Ehab and the Expected XOR Problem

    题意: 给定两个数\(n\)和\(x\),构造一个序列,设为\(a[l]\)(\(l\)不确定) \(1\).\(1\leq a[i]<2^{n}\) \(2\).序列中没有子序列异或和为\(0 ...

  8. [SDR] SDR 教程实战 —— 利用 GNU Radio + HackRF 手把手深入了解蓝牙协议栈(从电磁波 -> 01数据流 -> 蓝牙数据包)

    目录 0.前言 1.体验 2.代码解析 2.1 目录结构 2.2 main.py 2.3 grc gnu radio 流程图 2.4 如何从 01 数据流中解析出 BLE 广播包 2.4.1 物理层 ...

  9. Github的一个奇技淫巧

    背景 前段时间给 VictoriaLogs 提交了一个 PR: https://github.com/VictoriaMetrics/VictoriaMetrics/pull/4934 本来一切都很顺 ...

  10. Unexpected keys "@@dva", "user" found in preloadedState argument passed to createStore. Expected to find one of the known reducer keys instead: "router", "loading". Unexpected keys will be ignored.

    Please use `require("history").DOMUtils` instead of `require("history/DOMUtils") ...