保存时自动生成批号——python脚本
原理参考:【[单据保存时如何自动生成批号](https://vip.kingdee.com/article/329936268761261824?productLineId=1)】
### python实现(以采购订单为例)
> 由于是直接在保存操作插件中调用的自动获取,支持导入时自动获取
```python
import clr
clr.AddReference('Kingdee.BOS')
clr.AddReference('Kingdee.BOS.Core')
clr.AddReference('Kingdee.BOS.App')
clr.AddReference('Kingdee.K3.SCM.Contracts')
clr.AddReference('Kingdee.K3.Core')
clr.AddReference('Kingdee.BOS.DataEntity')
from Kingdee.BOS import *
from Kingdee.BOS.Core import *
from Kingdee.BOS.Core.DynamicForm.PlugIn import *
from Kingdee.BOS.Core.Metadata.FieldElement import *
from Kingdee.BOS.Core.Base import *
from Kingdee.K3.SCM.Contracts import *
from Kingdee.K3.Core.SCM.STK import *
from Kingdee.BOS.Orm.DataEntity import *
def OnPreparePropertys(e):
e.FieldKeys.Add("FLot")
def BeforeDoSaveExecute(e):
lotField = this.BusinessInfo.GetField("FLot")
if lotField == None or lotField.OrgFieldKey == "" or lotField.ControlFieldKey == "" or lotField.InputModel != lotField.Enum_InputModel.TextAndSelect:
return
exEntitySet = ExtendedDataEntitySet()
exEntitySet.Parse(e.DataEntities, this.BusinessInfo)
entitys = exEntitySet.FindByEntityKey(lotField.EntityKey)
lotService = ServiceFactory.GetLotService(this.Context)
codeRet = lotService.GenerateLotMasterByCodeRule(this.Context,this.BusinessInfo,lotField,entitys)
lotLists = codeRet.CodeResults
if lotLists == None or lotLists.Count == 0:
return
index = 0
for entity in entitys:
lotPair = None
for lotlist in lotLists:
if lotlist.Key == index:
lotPair = lotlist
break
if lotPair != None and lotPair.Value != None and lotPair.Value.Length > 0:
lot = lotPair.Value[0]
if lot != None:
if lot["Id"] > 0:
entity.DataEntity["FLot"] = lot
entity.DataEntity["FLot_Text"] = lot["Number"]
else:
entity.DataEntity["FLot"] = None
entity.DataEntity["FLot_Text"] = None
index = index + 1
```
**其他更多文章入口:**[https://vip.kingdee.com/link/s/lbRPP](https://vip.kingdee.com/link/s/lbRPP)
保存时自动生成批号——python脚本
原理参考:【[单据保存时如何自动生成批号](https://vip.kingdee.com/article/329936268761261824?productLineId=1)】### python实现(以采...
点击下载文档
本文2024-09-23 02:34:23发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-153311.html
您需要登录后才可以发表评论, 登录登录 或者 注册
最新文档
热门文章