取消销售订单

时间:2018-10-10 19:31:44

标签: acumatica

如何通过代码取消特定的销售订单?也许我可以调用ProcessOrders图,遍历选择订单并执行Cancel Order方法。不幸的是,我看不到这种方法。下拉操作由自动化菜单驱动。我在标准销售订单输入图中找不到取消订单操作。那么实现目标的最佳方法是什么?

通过代码,我可以手动设置已取消的标志和状态。这似乎可行,但是我不确定是否建议这样做。好像我正在跳过某些内容,自动化菜单应该是这样。

1 个答案:

答案 0 :(得分:0)

我正在复制此Acumatica博客文章中的答案,因为它确实满足了您的需求,请从代码Running Automation Step from Code

中调用“取消订单”自动化步骤

要调用自动化步骤,您必须:

  • 定义一个新的自定义PXView,它将返回我们想要的记录 处理
  • 创建一个适配器,该适配器将为按钮处理程序提供数据。适配器 将从自定义PXview获取数据。
  • 创建一个单独的图实例,以处理操作。

代码:

public class SOOrderEntry_Extension:PXGraphExtension<SOOrderEntry>
{
    //Lets define additional button than will call automation button.    
    public PXAction<SOOrder> ButtonExample;       
    [PXButton()]
    [PXUIField(DisplayName = "Button Example")]
    public virtual IEnumerable buttonExample(PXAdapter adapter)
    {
        SOOrder order = Base.Document.Current;

        //creating a graph that will process Internal command
        SOOrderEntry graph = PXGraph.CreateInstance<SOOrderEntry>();

        graph.Document.Current = graph.Document.Search<SOOrder.orderNbr>(order.OrderNbr, order.OrderType);

        //Searching for correct button from that is defined in Automatin steps.
        //All sub  menues are adden under action button, so we can get them and iterate.
        foreach (var action in (graph.action.GetState(null) as PXButtonState).Menus)
        {
            if (action.Command == "Cancel Order")
            {
                //Constructing dummy view that will always return only one record.
                adapter = new PXAdapter(new DummyView(graph, graph.Document.View.BqlSelect, new List<object> { order }));

                //defining a button command
                adapter.Menu = action.Command;

                //running button
                return graph.action.Press(adapter);
            }
        }

        return adapter.Get();
    }

    //Defining a dummy view that is inherited from PXView
    internal class DummyView : PXView
    {
        //Storing list of records
        List<object> _Records;

        internal DummyView(PXGraph graph, BqlCommand command, List<object> records)
            : base(graph, true, command)
        {
            _Records = records;
        }

        //Everytime when system calls select for the view, retun saved records.
        public override List<object> Select(object[] currents, object[] parameters, object[] searches, string[] sortcolumns, bool[] descendings, PXFilterRow[] filters, ref int startRow, int maximumRows, ref int totalRows)
        {
            return _Records;
        }
    }
}

我认为最好是调用“自动化步骤”,而不是手动设置“已取消” 字段,因为如果用户更改了“自动化步骤”,则可以通过调用它来进行更改。

请注意,在可能的情况下,当需要手动处理数据时,应始终使用现有的Graph,因为这会触发验证。

如果您要使用SOOrderEntry而不是调用自动化步骤来手动更改已取消字段,则仍将应用SOOrderEntry中的以下验证:

protected virtual void SOOrder_Cancelled_FieldVerifying(PXCache sender, PXFieldVerifyingEventArgs e)
{
    SOOrder row = (SOOrder) e.Row;
    PXResultset<CCProcTran> trans = PXSelect<CCProcTran, Where<CCProcTran.origRefNbr, Equal<Current<SOOrder.orderNbr>>,
                    And<CCProcTran.origDocType, Equal<Current<SOOrder.orderType>>,
                    And<CCProcTran.refNbr, IsNull,
                    And<CCProcTran.docType, IsNull>>>>>
                    .Select(this);
    CCProcTranHelper.UpdateCCPaymentState(row, trans);
    if (row != null && (row.IsCCAuthorized == true || row.IsCCCaptured == true))
    {
        bool authIsValid = true;
        if (row.IsCCAuthorized == true)
        {
            if (row.CCAuthTranNbr != null)
            {
                CCProcTran authTran = PXSelect<CCProcTran, Where<CCProcTran.tranNbr, Equal<Required<CCProcTran.tranNbr>>>>.Select(this, row.CCAuthTranNbr);
                if (String.IsNullOrEmpty(authTran.DocType) == false && String.IsNullOrEmpty(authTran.RefNbr) == false)
                {
                    authIsValid = false;
                }
            }
            else
            {
                CCProcTran authTran = this.ccAuthTrans.Select(); //Double-checking for valid auth tran
                if (authTran == null)
                    authIsValid = false;
            }

            if (authIsValid && row.CCAuthExpirationDate.HasValue)
            {
                authIsValid = row.CCAuthExpirationDate.Value > PXTimeZoneInfo.Now;
            }
        }
        if (authIsValid)
        {
            sender.RaiseExceptionHandling<SOOrder.cCPaymentStateDescr>(row, row.CCPaymentStateDescr, new PXSetPropertyException(Messages.CannotCancelCCProcessed, PXErrorLevel.Error));
        }
    }
}