发布过程完成后,如何在ARCashSale中保存自定义字段?

时间:2018-06-21 15:45:36

标签: acumatica

当我发布现金销售文档时,一切都成功验证并且创建了GL批处理之后,我执行了代码,该代码创建了第二个GL批处理来处理与现金销售有关的其他交易。创建该批次后,我也想将第二个GL批次的Ref Nbr也保存在Cash Sales文档中。尝试保存时,出现错误:

enter image description here

这是我的代码,覆盖了正常的发布过程:

public delegate IEnumerable ReleaseDelegate(PXAdapter adapter);
[PXOverride]
public IEnumerable Release(PXAdapter adapter, ReleaseDelegate baseMethod)
{
    ARCashSale cashSale = Base.Document.Current;

    PXGraph.InstanceCreated.AddHandler<JournalEntry>(delegate (JournalEntry oldJournalEntry)
    {
        oldJournalEntry.RowPersisted.AddHandler<Batch>(delegate (PXCache sender, PXRowPersistedEventArgs e)
        {
            Batch oldBatch = oldJournalEntry.BatchModule.Current;

            if (oldBatch != null && isCreated == false && e.Operation == PXDBOperation.Insert && e.TranStatus == PXTranStatus.Completed)
            {
                isCreated = true;
                if (CFBSAdjustments.Select().Count > 0)
                {

                    JournalEntry newJournalEntry = PXGraph.CreateInstance<JournalEntry>();

                    Batch newBatch = new Batch();

                    newBatch = newJournalEntry.BatchModule.Insert(newBatch);

                    Customer customer = PXSelect<Customer, Where<Customer.bAccountID, Equal<Required<Customer.bAccountID>>>>.Select(Base, cashSale.CustomerID);
                    newBatch.Description = "Fund Entry for Cash Sales Reference " + cashSale.RefNbr;
                    newBatch.FinPeriodID = oldBatch.FinPeriodID;
                    newBatch.LedgerID = oldBatch.LedgerID;
                    newBatch.DateEntered = oldBatch.DateEntered;

                    decimal? debit = 0;
                    decimal? credit = 0;
                    foreach (CFBSCashSalesAdjustment row in CFBSAdjustments.Select())
                    {
                        GLTran tran = newJournalEntry.GLTranModuleBatNbr.Insert();

                        tran.SummPost = true;
                        tran.BranchID = cashSale.BranchID;
                        tran.TranType = GLTran.tranClass.Normal;
                        tran.TranClass = GL.Messages.RoundingDiff;
                        tran.LedgerID = newBatch.LedgerID;
                        tran.FinPeriodID = newBatch.FinPeriodID;
                        tran.TranDate = newBatch.DateEntered;
                        tran.CuryInfoID = Base.currencyinfo.Current.CuryInfoID;

                        tran.AccountID = row.Account;
                        tran.SubID = row.Subaccount;
                        tran.DebitAmt = row.DebitAmt;
                        tran.CuryDebitAmt = row.DebitAmt;
                        debit += row.DebitAmt;
                        tran.CreditAmt = row.CreditAmt;
                        tran.CuryCreditAmt = row.CreditAmt;
                        credit += row.CreditAmt;
                        tran.RefNbr = row.CashSalesRefNbr;
                        tran.TranDesc = customer.AcctCD + " - " + customer.AcctName;
                        newJournalEntry.GLTranModuleBatNbr.Update(tran);
                    }

                    newBatch = newJournalEntry.BatchModule.Update(newBatch);

                    if (GLSetup.Current.GetExtension<GLSetupExt>().UsrAutoRelease == true)
                    {
                        newJournalEntry.BatchModule.Current.Hold = false;
                        newJournalEntry.release.Press();
                    }

                    newJournalEntry.Save.Press();
                    if (isCreated)
                        isCreated = false;

                    cashSale.GetExtension<ARRegisterExt>().UsrFundBatch = newJournalEntry.BatchModule.Current.BatchNbr;
                    //Base.Document.Current.GetExtension<ARRegisterExt>().UsrFundBatch = newJournalEntry.BatchModule.Current.BatchNbr;
                    //Base.dummy_CATran.View.RequestRefresh();
                    Base.Document.Update(cashSale);
                    //TODO - Figure out why the fund batch isn't saving to the Cash Sale
                    Base.Actions.PressSave();
                    //Base.dummy_CATran.Cache.ClearQueryCache();
                    //Base.Persist(typeof(ARCashSale), PXDBOperation.Update);
                }
            }
        });

    });
    return baseMethod(adapter);
}

我遗忘了所有尝试保存引用nbr的方法。我曾经尝试为BatchNbr字段添加一个字段更新的处理程序,并以这种方式强制使用新的数字,但是它不起作用。

编辑:我还注意到,我无法在批处理DAC上成功设置扩展字段。例如,我在行newBatch.GetExtension<BatchExt>().ExtRefNbr = cashSale.RefNbr;中也设置了该文档中的ref nbr,但是任何时候我运行'NewJournal.Press.Save()'都会将扩展字段的设置值更改为null。如果有人知道如何设置扩展字段,我也许可以使用它来替代一条可能满足我需要的路径。

0 个答案:

没有答案