单据转换.二开案例.列表整单下推默认按照列表选中行顺序整单排序

栏目:云星空知识作者:金蝶来源:金蝶云社区发布:2024-09-16浏览:1

单据转换.二开案例.列表整单下推默认按照列表选中行顺序整单排序

【逻辑】系统默认逻辑:整单转换不会排序 在没有强制排序时,最终是什么顺序最终依赖数据库的返回 【场景】列表整单下推默认按照列表选中行顺序整单排序 【案例】采购申请单下推采购订单 (0)数据准备 ![image.webp](/download/010083c7343151e94314b1dd4a84ac862fd7.webp) 默认下推效果,设置了按照物料编码升序 ![image.webp](/download/010009f7df08b91a4b3686ae8db29c24d6b8.webp) (1)插件排序,整单转换时按照选中行单据顺序 + 分录序号排序 ![image.webp](/download/01007ab818a09689408b869df7e3b4fa01b5.webp) ```csharp using Kingdee.BOS.Core.List; using Kingdee.BOS.Core.Metadata.ConvertElement.PlugIn; using Kingdee.BOS.Core.Metadata.ConvertElement.PlugIn.Args; using Kingdee.BOS.Util; using System; using System.Collections.Generic; using System.Linq; namespace DynamicFormPlugIn.BillConvert { [Kingdee.BOS.Util.HotUpdate] public class ConvertServicePlugIn_SortSourceBill : AbstractConvertPlugIn { /* * 当单据转换是整单转换时,按照列表选中行 + 实体序号排序 */ public override void OnGetSourceData(GetSourceDataEventArgs e) { if (e.SourceData == null || e.SourceData.Count <= 1) return; string srcEntryKey; Option.TryGetVariableValue("SourceEntryKey", out srcEntryKey); if (string.IsNullOrEmpty(srcEntryKey)) return; ListSelectedRow[] selectRows; Option.TryGetVariableValue("SelectedRows", out selectRows); if (selectRows == null || selectRows.Length <= 1) return; if (IsGetByEntry(srcEntryKey, selectRows)) { //分录下推 return; } //整单下推 //按照单据编号和序号排序 string pkFieldName = e.SourceBusinessInfo.GetForm().PkFieldName; var entity = e.SourceBusinessInfo.GetEntity(srcEntryKey) as Kingdee.BOS.Core.Metadata.EntityElement.Entity; if (entity == null) return; string entityFieldName = string.Concat(entity.Key, "_", entity.EntryPkFieldName); if (string.IsNullOrWhiteSpace(entity.SeqFieldKey)) { entityFieldName = string.Concat(entity.Key, "_", entity.SeqFieldKey); } //取选中行的主键和序号 Dictionary<string, string> pkIdx = new Dictionary<string, string>(); for (int i = 0; i < selectRows.Length; ++i) { string pk = selectRows[i].PrimaryKeyValue; if (pkIdx.ContainsKey(pk)) continue; pkIdx[pk] = i.ToString("000000"); } e.SourceData.Sort(x => { return string.Format("{0}_{1}", pkIdx.ContainsKey(x[pkFieldName].ToString()) ? pkIdx[x[pkFieldName].ToString()] : "999999", ObjectUtils.Object2Int(x[entityFieldName]).ToString("000000")); }); } private bool IsGetByEntry(string srcEntryKey, ListSelectedRow[] selectRows) { var firstRow = selectRows.First(); if (string.IsNullOrEmpty(firstRow.EntryPrimaryKeyValue)) return false; if (!srcEntryKey.Equals(firstRow.EntryEntityKey, StringComparison.OrdinalIgnoreCase)) return false; bool SelectByBillId = false; Option.TryGetVariableValue("SelectByBillId", out SelectByBillId); if (SelectByBillId) return false; return true; } } } ``` ```python #引入clr运行库 import clr #添加对cloud插件开发的常用组件的引用 clr.AddReference("mscorlib") clr.AddReference("Kingdee.BOS") clr.AddReference("Kingdee.BOS.ServiceHelper") clr.AddReference("Kingdee.BOS.Core") #导入cloud基础库中的常用实体对象(分命名空间导入,不会递归导入) from System import * from System.Collections.Generic import * from Kingdee.BOS.Util import * from Kingdee.BOS.ServiceHelper import FormMetaDataCache def OnGetSourceData(e): if e.SourceData == None or e.SourceData.Count <=1: return; optionDic = this.Option.GetVariables(); srcEntryKey = optionDic["SourceEntryKey"] if optionDic.ContainsKey("SourceEntryKey") else None; if srcEntryKey == None or srcEntryKey=="": return; selectRows = optionDic["SelectedRows"] if optionDic.ContainsKey("SelectedRows") else None; if selectRows == None or len(selectRows) <=1: return; selectByBillId = optionDic["SelectByBillId"] if optionDic.ContainsKey("SelectByBillId") else False; if not selectByBillId: return; pkFieldName = e.SourceBusinessInfo.GetForm().PkFieldName; entity = e.SourceBusinessInfo.GetEntity(srcEntryKey); if entity == None: return; entityFieldName = entity.Key + "_" + entity.EntryPkFieldName; if entity.SeqFieldKey == None or entity.SeqFieldKey == "": entityFieldName = entity.Key + "_" + entity.SeqFieldKey; pkIdx = {}; for idx in range(len(selectRows)): pk = selectRows[idx].PrimaryKeyValue; if pkIdx.has_key(pk): continue; pkIdx[pk] = str(idx).zfill(6); e.SourceData.Sort[str](lambda x: getKey(x, pkIdx, pkFieldName, entityFieldName)); ##raise Exception('error'+ str(1).zfill(6)); def getKey(rowObj, pkIdx, pkFieldName, entityFieldName): key = ""; pk = str(rowObj[pkFieldName]); if pkIdx.has_key(pk): key +=pkIdx[pk]; else: key +="999999"; subKey = str(rowObj[entityFieldName]).zfill(6); key +="_" + subKey; return key; ``` 【效果】按照选中行单据顺序,单据内按照序号排序 ![image.webp](/download/0100f6f5cfad456c47ffb6c07f50fb3fe6b6.webp)

已看

单据转换.二开案例.列表整单下推默认按照列表选中行顺序整单排序

【逻辑】系统默认逻辑:整单转换不会排序在没有强制排序时,最终是什么顺序最终依赖数据库的返回【场景】列表整单下推默认按照列表选中行顺...
点击下载文档
确认删除?
回到顶部
客服QQ
  • 客服QQ点击这里给我发消息