自动计算和添加Landedcost

时间:2017-08-17 18:42:27

标签: acumatica

我需要在PO收据屏幕(PO302000)中添加LandedCost,基于固定百分比(我可以将其作为PO首选项中的自定义字段包含在内)。它应该在PO收据发布时自动添加。哪个事件应该是触发和添加LandedCost的最佳方法?

当用户取消选中OnHold复选框时是吗?
或者,用户点击发布按钮?如果是,那么我可以延长发布行动吗?

1 个答案:

答案 0 :(得分:1)

释放POReceipts的方法是静态的,我们无法覆盖它。 但是,我们可以覆盖调用此静态方法的位置。它在两个地方被调用: 1)在POReceiptEntry(图形)和 2)的释放动作上设置进程委托的POReleaseReceipt(图形)的构造函数。

1)在POReceiptEntry上,您可以扩展此图表以首先执行自定义代码,然后调用基本版本方法。

public class POReceiptEntry_Extension:PXGraphExtension<POReceiptEntry>
  {
        public PXSetup<POSetup> posetup;

        #region Event Handlers
        public PXAction<POReceipt> release;
        [PXUIField(DisplayName = Messages.Release, MapEnableRights = PXCacheRights.Update, MapViewRights = PXCacheRights.Update)]
        [PXProcessButton]
        public virtual void Release()
        {
            //retrieve value from Custom field added on PO Preferences screen
            //POSetup setup = posetup.Current;
            //POSetupExt setupExt = setup.GetExtension<POSetupExt>();

            LandedCostTran landedCost = Base.landedCostTrans.Insert();
            landedCost.LandedCostCodeID = "YOURLANDEDCOSTCODE";
            landedCost.InvoiceNbr = "YOURINVOICENUMBER";
            landedCost.CuryLCAmount = 2;  //Formula here using setupExt.UsrFieldPercentange
            Base.landedCostTrans.Update(landedCost);

            Base.release.Press();
        }
    #endregion
  }

2)在POReleaseReceipt图上,由于在此图的构造函数上设置了进程委托,您可以扩展此图并覆盖 Initialize()方法来设置自定义进程委托。 您的自定义流程代理将拥有您的自定义代码,然后调用基本方法。

using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Text;
using PX.Common;
using PX.Data;
using PX.Objects.CS;
using PX.Objects.IN;
using PX.Objects.AP;
using PX.Objects.PO;
using PX.Objects.GL;
using PX.Objects.CM;
using PX.Objects;

namespace PX.Objects.PO
{

  public class POReleaseReceipt_Extension:PXGraphExtension<POReleaseReceipt>
  {
        public override void Initialize()
        {
            //Gets Process Delegate
            var processDelegate = (PXProcessingBase<POReceipt>.ProcessListDelegate)Base.Orders.GetProcessDelegate();

            //Change the process delegate that was created by the framework by your custom one.
            Base.Orders.SetProcessDelegate(delegate (List<POReceipt> orders) { POReceiptsProc(orders, processDelegate); });

        }

        public static void POReceiptsProc(List<POReceipt> orders, PXProcessingBase<POReceipt>.ProcessListDelegate processDelegate)
        {
            //Execute your custom code here
            //create POReceiptEntry graph, Loop through the orders,  Access your Custom field, Add LandedCost
            PXTrace.WriteInformation("Start Process execution");

            POReceiptEntry graph = PXGraph.CreateInstance<POReceiptEntry>();

            ........

            //Call the base action
            if (processDelegate != null)
                processDelegate(orders);
        }
    }
}