二开实现单据录入携带序列号主档备注信息(Python实现)原创
30人赞赏了该文章
1,490次浏览
编辑于2022年03月15日 09:33:30
业务需求和C#的插件实现,参考文章:【二开实现单据录入携带序列号主档备注信息】,重写一个Python版本的实现,供参考。
clr.AddReference("System.Core") clr.AddReference("Kingdee.BOS") clr.AddReference("Kingdee.BOS.Core") clr.AddReference("Kingdee.BOS.DataEntity") clr.AddReference('Kingdee.BOS.ServiceHelper') clr.AddReference('Kingdee.BOS.Contracts') clr.AddReference("Kingdee.K3.SCM.Stock.Business.PlugIn") clr.AddReference("Kingdee.K3.Core") clr.AddReference("Kingdee.K3.BD.ServiceHelper") from System import * from Kingdee.BOS.Log import Logger from Kingdee.BOS import * from Kingdee.BOS.Core import * from System import StringComparison from System.Collections.Generic import List from Kingdee.BOS.ServiceHelper import * from Kingdee.BOS.Core.Metadata.EntityElement import * from Kingdee.BOS.Core.DynamicForm.PlugIn.Args import * from Kingdee.K3.SCM.Stock.Business.PlugIn import * from Kingdee.BOS.Orm.DataEntity import * from Kingdee.K3.Core.SCM.STK import * from Kingdee.K3.BD.ServiceHelper import * from Kingdee.BOS.Core.Metadata.FieldElement import * from Kingdee.BOS.Core.Metadata import * def DataChanged(e): if e.Field.Key.Equals("FSNQTY", StringComparison.OrdinalIgnoreCase): if Convert.ToInt64(e.NewValue) > Convert.ToInt64(e.OldValue): DoSerialNoDataChanged(e) def DoSerialNoDataChanged(e): for entity in this.Model.BusinessInfo.Entrys: if type(entity) is SNSubEntryEntity: parRowIndex = this.View.Model.GetEntryCurrentRowIndex(entity.ParentEntity.Key) entityDataObject = this.View.Model.GetEntityDataObject(entity.ParentEntity, parRowIndex) if entityDataObject != None: dataEntrys = entity.DynamicProperty.GetValue(entityDataObject) field = this.View.BusinessInfo.GetField("FMaterialId") dyObj = field.DynamicProperty.GetValue[DynamicObject](entityDataObject) materialId = 0 if dyObj != None: materialId = Convert.ToInt64(dyObj["msterID"]) field = this.View.BusinessInfo.MainOrgField dyObj = field.DynamicProperty.GetValue[DynamicObject](entityDataObject.Parent) orgId = 0 if dyObj != None: orgId = Convert.ToInt64(dyObj["Id"]) if materialId <= 0 or orgId <= 0: return _baseDataOrgCtl = Common.GetInvBaseDataCtrolType(this.View.Context) if dataEntrys != None and dataEntrys.Count > 0: for item in dataEntrys: strSerialNO = Convert.ToString(item["SerialNo"]) if item["SerialNote"] != None and item["SerialNote"].ToString() != "": continue rets = SerialServiceHelper.GetSerialByNumber(this.View.Context, _baseDataOrgCtl, strSerialNO, orgId, orgId, materialId, False, False) if len(rets) > 0: #SetBaseFieldValue(this.View.Context, this.View.BillBusinessInfo, "FSerialId", rets[0].Id, item) SetBaseFieldValueByFilter(this.View.Context, rets[0].Id, item) this.View.UpdateView(entity.Key, e.Row) # 直接查询序列号主档,比较通用,不用修改BOS添加字段引用,但是返回序列号数量多触发查询,对性能有影响 def SetBaseFieldValueByFilter(ctx, baseId, rowEntity): ofilter = OQLFilter() filteritem = OQLFilterHeadEntityItem() filteritem.FilterString = '''FSERIALID = {0} '''.format(str(baseId)) ofilter.Add(filteritem); serialselector = List[SelectorItemInfo](); selectorItemInfo = SelectorItemInfo("FDescription") serialselector.Add(selectorItemInfo); serials = BusinessDataServiceHelper.Load(ctx, "BD_SerialMainFile", serialselector, ofilter) if len(serials) > 0: rowEntity["SerialNote"] = Convert.ToString(serials[0]["DESCRIPTION"]); this.View.UpdateView("FSerialNote") # 加载基础资料的方式,需要序列号子单据体添加"备注"字段的引用 def SetBaseFieldValue(ctx, businessinfo, baseKey, baseId, rowEntity): newValue = None field = businessinfo.GetField(baseKey) if baseId > 0: newValue = BusinessDataServiceHelper.LoadSingle(ctx, baseId, field.RefFormDynamicObjectType, None) field.RefIDDynamicProperty.SetValue(rowEntity, baseId) field.DynamicProperty.SetValue(rowEntity, newValue) if newValue != None: rowEntity["SerialNote"] = Convert.ToString(newValue["DESCRIPTION"]) this.View.UpdateView("FSerialNote")
SerialBillEdit.rar(1.57KB)
赞 30
30人点赞
还没有人点赞,快来当第一个点赞的人吧!
打赏
0人打赏
还没有人打赏,快来当第一个打赏的人吧!
推荐阅读