采购申请单物料合并下推采购订单(分享帖)
金蝶云社区-戴文剑
戴文剑
7人赞赏了该文章 2224次浏览 未经作者许可,禁止转载编辑于2018年11月16日 09:40:16

收到不少类似以下采购申请单物料合并下推采购订单的提单,现分享一个解决方案。
问题:
在采购申请到采购订单的单据转换分组策略那里,单据体设置的按物料编码,子单据体设置的是物料编码和到货日期。然后采购申请上两个相同的物料,数量是10和20,一个交货日期是10月17号,一个是10月19号,下推生成采购订单后,在交货安排那里出现两行,一行是10月17号,数量30,一行是10月19号,数量30。这样不能保存(30!=30+30),需要人工去修改数量。
客户的需求是需要在明细信息出现一行,数量为30,在交货安排出现两行,但是一个数量是10,一个是20。

解决方案:
1,在采购申请到采购订单的单据转换"表单服务策略"里删除以下三个服务规则:
2.png 

2,同样在"表单服务策略"新增一条服务规则:计算交货计划的数量(基本单位)和剩余数量(基本单位)
3.png 

3,由于在申请单物料和交货日期相同时合并下推订单,会出现交货计划的数量不对的情况,这里需要用插件处理。现提供两种实现方法。
a,C#单据转换插件,注册到采购申请到采购订单的转换规则。
using System;
using System.Linq;
using Kingdee.BOS.Core;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.Core.Metadata.ConvertElement.PlugIn;

namespace XXX.K3.SCM.App.Pur.ServicePlugIn
{
    public class ReqToOrderService : AbstractConvertPlugIn
    {
        public override void AfterConvert(Kingdee.BOS.Core.Metadata.ConvertElement.PlugIn.Args.AfterConvertEventArgs e)
        {
            ExtendedDataEntity[] entrys = e.Result.FindByEntityKey("FPOOrderEntry");
            if (entrys == null)
            {
                return;
            }
            foreach (ExtendedDataEntity entry in entrys)
            {
                decimal qty = Convert.ToDecimal(entry["qty"]);
                decimal baseQty = Convert.ToDecimal(entry["BaseUnitQty"]);
                DynamicObjectCollection deliPlan = entry["POOrderEntryDeliPlan"] as DynamicObjectCollection;
                long deliPlanRowNum = deliPlan != null ? deliPlan.Count() : 0;
                if (deliPlanRowNum == 1)
                {
                    decimal planQty = Convert.ToDecimal(deliPlan[0]["PlanQty"]);
                    if (qty != planQty)
                    {                       //交货明细只有一行且数量不对时,直接用明细数量赋值
                        deliPlan[0]["PlanQty"] = qty;
                        deliPlan[0]["DeliRemainQty"] = qty;

                        deliPlan[0]["BasePlanQty"] = qty;
                        deliPlan[0]["BaseDeliRemainQty"] = qty;

                    }
                }
            }

            base.AfterConvert(e);

        }
    }
}


b,python脚本,在订单的表单插件注册。

import clr
clr.AddReference('System')
clr.AddReference('Kingdee.BOS')
clr.AddReference('Kingdee.BOS.Core')
clr.AddReference('Kingdee.BOS.DataEntity')

from System import *
from Kingdee.BOS import *
from Kingdee.BOS.Core.Metadata.EntityElement  import *
from Kingdee.BOS.Orm.DataEntity  import *
from Kingdee.BOS.Core.DynamicForm.PlugIn import *
from Kingdee.BOS.Core import *

def SetPlanQty():
    entryEntity = this.View.BusinessInfo.GetEntity("FPOOrderEntry");
    entryList = this.View.Model.GetEntityDataObject(entryEntity);
    index = 0;
    while( index < entryList.Count):
        deliPlanRowNum =0;
        qty = Convert.ToDecimal(entryList[index]["qty"]);
        baseQty = Convert.ToDecimal(entryList[index]["BaseUnitQty"]);
        orderEntryPlanList = entryList[index]["POOrderEntryDeliPlan"];
        if orderEntryPlanList != None:
            deliPlanRowNum=orderEntryPlanList.Count;
        if (deliPlanRowNum == 1):
            planQty = Convert.ToDecimal(orderEntryPlanList[0]["PlanQty"]);
            if (qty != planQty):
                #交货明细只有一行且数量不对时,直接用明细数量赋值
                orderEntryPlanList[0]["PlanQty"] = qty;
                orderEntryPlanList[0]["DeliRemainQty"] = qty;
                orderEntryPlanList[0]["BasePlanQty"] = baseQty;
                orderEntryPlanList[0]["BaseDeliRemainQty"] = baseQty;
        index+=1;
        


def AfterBindData(e):
    if (this.View.OpenParameter.Status == OperationStatus.ADDNEW and  (this.View.OpenParameter.CreateFrom == CreateFrom.Draw or this.View.OpenParameter.CreateFrom == CreateFrom.Push)):
        if (Convert.ToString(this.View.Model.GetValue("FSrcBillTypeId", 0))=="PUR_Requisition"):
            #下推或选单且源单是申请单
            SetPlanQty();

赞 7