代码之家  ›  专栏  ›  技术社区  ›  Jerry Welliver

以代码形式发布发票和库存问题

  •  0
  • Jerry Welliver  · 技术社区  · 6 年前

    我有一个在v6.1中工作的例行程序来发布发票并过帐到库存。我想它也在2017R2工作,但我不确定。在2018R1中似乎根本不起作用。发票已释放,但库存问题未释放。这些自动操作都设置为自动释放问题,并且在手动处理时可以正常工作。只有我的代码不会释放问题。我不知道为什么。有什么想法吗?

    我已经根据您的建议将代码更新到最新版本,但库存问题仍未发布。

    foreach (EDASNShipment asnShipment in PXSelect<EDASNShipment,
        Where<EDASNShipment.aSNNbr, Equal<Required<EDASN.aSNNbr>>>>.Select(this, asn.ASNNbr))
    {
        soShipmentGraph.Clear();
        SOShipment soShipment = soShipmentGraph.Document.Search<SOShipment.shipmentNbr>(asnShipment.ShipmentNbr);
        var soShipmentExt = PXCache<SOShipment>.GetExtension<SOShipmentExt>(soShipment);
    
        SOOrderShipment soOrderShipment = PXSelect<SOOrderShipment,
            Where<SOOrderShipment.shipmentNbr, Equal<Required<SOOrderShipment.shipmentNbr>>>>.Select(this, asnShipment.ShipmentNbr);
    
        ARInvoice arInvoice = PXSelect<ARInvoice, Where<ARInvoice.refNbr, Equal<Required<ARInvoice.refNbr>>,
            And<ARInvoice.docType, Equal<Required<ARInvoice.docType>>>>>.Select(this, soOrderShipment.InvoiceNbr, "INV");
        if (soShipment.Status != "C")
        {
            if (autoReleaseInvoices)
            {
                if (arInvoice != null)
                {
                    /*
                    soInvoiceGraph.Clear();
                    soInvoiceGraph.Document.Current = arInvoice;
                    soInvoiceGraph.release.Press();
                    var a = new PXAdapter(soShipmentGraph.Document)
                    {
                        Searches = new object[] { soShipment.ShipmentNbr }
                    };
                    //Note: Post Invoice to IN is Action 3 
                    a.Arguments.Add("actionID", 3);
                    a.MassProcess = false;                       //Don't pop up invoice screen
                    a.MaximumRows = 1;
                    PXLongOperation.StartOperation(this, () =>
                    {
                        foreach (SOShipment shipment in soShipmentGraph.action.Press(a))
                        {
                            shipment.ShipmentNbr = shipment.ShipmentNbr;
                        }
                    });
                    */
    
                    //Release Invoice
                    PXLongOperation.StartOperation(this, delegate ()
                    {
                        soInvoiceGraph.Clear();
                        soInvoiceGraph.Document.Current = arInvoice;
                        soInvoiceGraph.release.Press();
    
                        //Update IN on Shipment
                        soShipmentGraph.Clear();
                        soShipmentGraph.Document.Current = 
                                soShipmentGraph.Document.Search<SOShipment.shipmentNbr>(asnShipment.ShipmentNbr);
                        soShipmentGraph.UpdateIN.Press();
                    });
                }
                else
                {
                    statusText += String.Format("Acumatica Invoice could not be located: {0}  ", soOrderShipment.InvoiceNbr);
                    errorOccurred = true;
                    bolAtLeastOneError = true;
                }
            }
        }
        soShipmentGraph.Clear();
        soShipment = soShipmentGraph.Document.Search<SOShipment.shipmentNbr>(asnShipment.ShipmentNbr);
        soShipmentExt = PXCache<SOShipment>.GetExtension<SOShipmentExt>(soShipment);
        soShipmentExt.UsrEDIStatus = "S";       //Sent
        soShipmentGraph.Document.Update(soShipment);
        soShipmentGraph.Persist();
    }
    
    2 回复  |  直到 6 年前
        1
  •  0
  •   DChhapgar    6 年前

    你可以参考下面的代码并修改你的代码

    using System.Collections;
    using PX.Data;
    using PX.Objects.AR;
    using PX.Objects.SO;
    
    namespace PXDemoPkg
    {
        public class SOShipmentEntryPXExt : PXGraphExtension<SOShipmentEntry>
        {
            public PXAction<SOShipment> DummyCustomAction;
            [PXButton()]
            [PXUIField(DisplayName = "Dummy Custom Action",
                       MapEnableRights = PXCacheRights.Select,
                       MapViewRights = PXCacheRights.Select)]
            protected virtual IEnumerable dummyCustomAction(PXAdapter adapter)
            {
                SOShipment shipment = Base.Document.Current;
    
                SOOrderShipment soOrderShipment = PXSelect<SOOrderShipment,
                                                        Where<SOOrderShipment.shipmentNbr, Equal<Required<SOOrderShipment.shipmentNbr>>>>.
                                                        Select(Base, shipment.ShipmentNbr);
    
                ARInvoice arInvoice = PXSelect<ARInvoice, Where<ARInvoice.refNbr, Equal<Required<ARInvoice.refNbr>>,
                                                            And<ARInvoice.docType, Equal<Required<ARInvoice.docType>>>>>.
                                                            Select(Base, soOrderShipment.InvoiceNbr, "INV");
    
                PXLongOperation.StartOperation(Base, delegate ()
                {
                    SOInvoiceEntry soInvoiceGraph = PXGraph.CreateInstance<SOInvoiceEntry>();
                    SOShipmentEntry soShipmentGraph = PXGraph.CreateInstance<SOShipmentEntry>();
    
                    //Release Sales Invoice
                    soInvoiceGraph.Clear();
                    soInvoiceGraph.Document.Current = soInvoiceGraph.Document.Search<ARInvoice.docType, ARInvoice.refNbr>(arInvoice.DocType, arInvoice.RefNbr);
                    soInvoiceGraph.release.Press();
    
                    //Update IN on Shipment
                    soShipmentGraph.Clear();
                    soShipmentGraph.Document.Current = soShipmentGraph.Document.Search<SOShipment.shipmentNbr>(shipment.ShipmentNbr);
                    soShipmentGraph.UpdateIN.Press();
    
                });
                return adapter.Get();
            }
        }
    }
    
        2
  •  0
  •   Jerry Welliver    6 年前

    在浏览了大量代码库之后,我发现了一些用于发布问题的代码。我把它适应了我的情况,并提出了下面的解决方案。我会把它贴出来,以防有人遇到类似的情况。

    if (arInvoice != null)
    {
        //Release Invoice
        PXLongOperation.StartOperation(this, delegate ()
        {
            soInvoiceGraph.Clear();
            soInvoiceGraph.Document.Current = arInvoice;
            soInvoiceGraph.release.Press();
    
            //Lookup issue, add to list, and call release
            INRegister issue = PXSelect<INRegister,
                Where<INRegister.sOShipmentNbr, Equal<Required<INRegister.sOShipmentNbr>>,
                And<INRegister.docType, Equal<Required<INRegister.docType>>>>>
                .Select(this, asnShipment.ShipmentNbr, INDocType.Issue);
            //Check setup flag and issue status
            if (sosetup.Current.AutoReleaseIN == true &&
                issue.Hold == false &&
                issue.Released == false)
            {
                List<INRegister> issues = new List<INRegister>();
                issues.Add(issue);
                INDocumentRelease.ReleaseDoc(issues, false);
            }
        });
    }