二开实现单据录入携带序列号主档备注信息原创
金蝶云社区-邱育华
邱育华
5人赞赏了该文章 2,683次浏览 未经作者许可,禁止转载编辑于2022年03月15日 15:11:13

之前一篇文章说到,将入库单上输入序列号、备注,实现单据保存序列号备注写入序列号主档【二开实现单据保存序列号备注写入序列号主档】


这里继续实现另外一部分需求:在出库单据录入序列号时,自动携带主档备注信息到序列号子单据体备注字段。

【客户需求】非库存更新单据如何增加序列号子单据体 


【实现】

大体思路为:表单插件重写DataChanged事件,监听序列号数量字段FSNQTY, 值变化NewValue > OldValue时表示新添加序列号,根据当前序列号和组织物料数据,读取对应的序列号主档信息回填。


二开实现序列号单据备注保存写入序列号主档(Python实现)


1、序列号添加"备注"字段引用属性

image.png


2、表单插件逻辑


using Kingdee.BOS.Core;
using Kingdee.BOS.Core.Bill.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Core.Metadata;
using Kingdee.BOS.Core.Metadata.EntityElement;
using Kingdee.BOS.Core.Metadata.FieldElement;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.ServiceHelper;
using Kingdee.BOS.Util;
using Kingdee.K3.BD.ServiceHelper;
using Kingdee.K3.SCM.Stock.Business.PlugIn;
using Kingdee.K3.Core.SCM.STK;
using System;
using System.Collections.Generic;
using System.Linq;

public override void DataChanged(BOS.Core.DynamicForm.PlugIn.Args.DataChangedEventArgs e)
{
    if (e.Field.Key.ToUpper() == "FSNQTY")
    {
        // 删除行不触发
        if(Convert.ToInt64(e.NewValue) > Convert.ToInt64(e.OldValue))
        {
            DoSerialNoDataChanged(e);
        }
    }
}

internal void DoSerialNoDataChanged(DataChangedEventArgs e)
{
    foreach (Entity entity in this.Model.BusinessInfo.Entrys)
    {
        if (entity is SNSubEntryEntity)
        {
            SNSubEntryEntity snEntity = (SNSubEntryEntity)entity;
            int parRowIndex = this.View.Model.GetEntryCurrentRowIndex(snEntity.ParentEntity.Key);
            DynamicObject entityDataObject = this.View.Model.GetEntityDataObject(snEntity.ParentEntity, parRowIndex);
            if (entityDataObject != null)
            {
                DynamicObjectCollection dataEntrys = snEntity.DynamicProperty.GetValue(entityDataObject) as DynamicObjectCollection;
                Field field = this.View.BusinessInfo.GetField("FMaterialId");
                DynamicObject dyObj = field.DynamicProperty.GetValue<DynamicObject>(entityDataObject);
                long materialId = 0;
                if (dyObj != null)
                {
                    materialId = Convert.ToInt64(dyObj[FormConst.MASTER_ID]);
                }
                field = this.View.BusinessInfo.MainOrgField; // this.View.BusinessInfo.GetField("FStockOrgId");
                dyObj = field.DynamicProperty.GetValue<DynamicObject>((DynamicObject)(entityDataObject.Parent));
                long orgId = 0;
                if (dyObj != null)
                {
                    orgId = Convert.ToInt64(dyObj["Id"]);
                }
                if (materialId <= 0 || orgId <= 0)
                {
                    return;
                }
                
                //初始化基础资料控制类型
                var _baseDataOrgCtl = Common.GetInvBaseDataCtrolType(this.View.Context);
                if (dataEntrys != null && dataEntrys.Count > 0)
                {
                    foreach(DynamicObject item in dataEntrys)
                    {
                        string strSerialNO = item["SerialNo"].ToString();
                        if (item["SerialNote"] != null && !string.IsNullOrEmpty(item["SerialNote"].ToString()))  // 备注信息不为空就不再获取了
                        {
                            continue;
                        }
                        List<SimpleSerialSnap> rets = SerialServiceHelper.GetSerialByNumber(this.View.Context, _baseDataOrgCtl, strSerialNO, orgId, orgId, materialId, false, false).ToList();
                        if(rets.Count > 0)
                        {
                            this.SetBaseFieldValue(this.View.Context, this.View.BillBusinessInfo, "FSerialId", rets.FirstOrDefault().Id, item);
                            this.View.UpdateView(snEntity.Key, e.Row);
                        }
                    } 
                } 
            }
        }
    }
}

public void SetBaseFieldValueByFilter(BOS.Context ctx, BusinessInfo info, string baseKey, long baseId, DynamicObject rowEntity)
{
    OQLFilter ofilter = new OQLFilter();
    OQLFilterHeadEntityItem filteritem = new OQLFilterHeadEntityItem();
    filteritem.FilterString = string.Format(" FSERIALID = {0} ", baseId.ToString());
    ofilter.Add(filteritem);

    List<SelectorItemInfo> serialselector = new List<SelectorItemInfo>();
    serialselector.Add(new SelectorItemInfo("FDescription"));

    DynamicObject serial = BusinessDataServiceHelper.Load(this.Context, "BD_SerialMainFile", serialselector, ofilter).FirstOrDefault();
    if(serial != null)
    {
        rowEntity["SerialNote"] = Convert.ToString(serial["DESCRIPTION"]);
    }
}

public void SetBaseFieldValue(BOS.Context ctx, BusinessInfo info, string baseKey, long baseId, DynamicObject rowEntity)
{
    try
    {
        DynamicObject newValue = null;
        BaseDataField field = info.GetField(baseKey) as BaseDataField;
        if (baseId > 0L)
        {
            newValue = BusinessDataServiceHelper.LoadSingle(ctx, baseId, field.RefFormDynamicObjectType, null);
        }
        field.RefIDDynamicProperty.SetValue(rowEntity, baseId);
        field.DynamicProperty.SetValue(rowEntity, newValue);
        if (newValue != null)
        {
            // 序列号需添加"备注"属性的引用
            rowEntity["SerialNote"] = Convert.ToString(newValue["DESCRIPTION"]);
        }
    }
    catch { }
}


【实现效果】

image.png



图标赞 5
5人点赞
还没有人点赞,快来当第一个点赞的人吧!
图标打赏
0人打赏
还没有人打赏,快来当第一个打赏的人吧!