Skip to main content
Question

Unable to Release GL


Forum|alt.badge.img

Hi Everyone,

In the SO Invoice screen, I have overridden the Release action, and when the GL document is created, I would like to delete the GL Tran line created by Acumatica and would like to insert another 3 new lines. 

It has the right amounts but still getting error like saying Document out of balance.  Can anyone help me with this?

Assume my invoice total is 1000.

  public class SOInvoiceEntry_Extension : PXGraphExtension<PX.Objects.SO.SOInvoiceEntry>
  {
      #region Event Handlers


      public delegate IEnumerable ReleaseDelegate(PXAdapter adapter);
      [PXOverride]
      public IEnumerable Release(PXAdapter adapter, ReleaseDelegate baseMethod)
      {
          //var res = baseMethod(adapter);
          PXGraph.InstanceCreated.AddHandler<JournalEntry>((graph) =>
          {
              graph.RowInserted.AddHandler<Batch>((cache, e) =>
              {
                  Batch row = e.Row as Batch;
                  if (row != null)
                  {
                      graph.BatchModule.Current = row;


                      GLTran gl_AAA = new GLTran
                      {
                          AccountID = 10025, // New Account
                          TranDesc = "AAA",
                          SubID = 467,
                          ProjectID = Base.Document.Current.ProjectID,
                          Qty = 1,
                          RefNbr = Base.Document.Current.RefNbr,
                          CuryDebitAmt = 500, // 50% of original
                          DebitAmt = 500,

                          TranType = ARDocType.Invoice,
                          Released = true
                      };
                      graph.GLTranModuleBatNbr.Cache.Insert(gl_AAA);

                      GLTran gl_BBB = new GLTran
                      {
                          AccountID = 10026,
                          TranDesc = "BBB",
                          SubID = 467,
                          ProjectID = Base.Document.Current.ProjectID,
                          Qty = 1,
                          RefNbr = Base.Document.Current.RefNbr,
                          CuryDebitAmt = 200, // 20% of original
                          DebitAmt = 200,

                          TranType = ARDocType.Invoice,
                          Released = true
                      };
                      graph.GLTranModuleBatNbr.Cache.Insert(gl_BBB);

                      GLTran gl_CCC = new GLTran
                      {
                          AccountID = 10027,
                          TranDesc = "CCC",
                          SubID = 467,
                          ProjectID = Base.Document.Current.ProjectID,
                          RefNbr = Base.Document.Current.RefNbr,
                          Qty = 1,
                          CuryDebitAmt = 300,
                          DebitAmt = 300,

                          TranType = ARDocType.Invoice,
                          Released = true
                      };
                      graph.GLTranModuleBatNbr.Cache.Insert(gl_CCC); 
                  }
              });


              graph.RowInserted.AddHandler<GLTran>((cache, e) =>
              {
                  GLTran row = e.Row as GLTran;
                  if (row != null) 
                  {
                      if (row.AccountID == 1154)
                      {
                          graph.GLTranModuleBatNbr.Cache.Delete(row);
                      }

                  }
              });



          });

          return baseMethod(adapter);
      }

      #endregion
  }

  

13 replies

Nilkanth Dipak
Semi-Pro I
Forum|alt.badge.img+10

Hi ​@nsmith51,


The issue I see in your code is that you are first trying to insert the data and then deleting the old lines. I believe you need to remove the old lines first.

Try something like below.

public class SOInvoiceEntry_Extension : PXGraphExtension<PX.Objects.SO.SOInvoiceEntry>
{
    #region Event Handlers

    public delegate IEnumerable ReleaseDelegate(PXAdapter adapter);
    [PXOverride]
    public IEnumerable Release(PXAdapter adapter, ReleaseDelegate baseMethod)
    {
        PXGraph.InstanceCreated.AddHandler<JournalEntry>((graph) =>
        {
            graph.RowInserted.AddHandler<Batch>((cache, e) =>
            {
                Batch row = e.Row as Batch;
                if (row != null)
                {
                    graph.BatchModule.Current = row;

                    // Delete the original GLTran line created by Acumatica
                    foreach (GLTran glTran in graph.GLTranModuleBatNbr.Select())
                    {
                        if (glTran.AccountID == 1154) // Original AccountID
                        {
                            graph.GLTranModuleBatNbr.Cache.Delete(glTran);
                        }
                    }

                    // Insert new GLTran lines
                    GLTran gl_AAA = new GLTran
                    {
                        AccountID = 10025, // New Account
                        TranDesc = "AAA",
                        SubID = 467,
                        ProjectID = Base.Document.Current.ProjectID,
                        Qty = 1,
                        RefNbr = Base.Document.Current.RefNbr,
                        CuryDebitAmt = 500, // 50% of original
                        DebitAmt = 500,
                        TranType = ARDocType.Invoice,
                        Released = true
                    };
                    graph.GLTranModuleBatNbr.Cache.Insert(gl_AAA);

                    GLTran gl_BBB = new GLTran
                    {
                        AccountID = 10026,
                        TranDesc = "BBB",
                        SubID = 467,
                        ProjectID = Base.Document.Current.ProjectID,
                        Qty = 1,
                        RefNbr = Base.Document.Current.RefNbr,
                        CuryDebitAmt = 200, // 20% of original
                        DebitAmt = 200,
                        TranType = ARDocType.Invoice,
                        Released = true
                    };
                    graph.GLTranModuleBatNbr.Cache.Insert(gl_BBB);

                    GLTran gl_CCC = new GLTran
                    {
                        AccountID = 10027,
                        TranDesc = "CCC",
                        SubID = 467,
                        ProjectID = Base.Document.Current.ProjectID,
                        RefNbr = Base.Document.Current.RefNbr,
                        Qty = 1,
                        CuryDebitAmt = 300,
                        DebitAmt = 300,
                        TranType = ARDocType.Invoice,
                        Released = true
                    };
                    graph.GLTranModuleBatNbr.Cache.Insert(gl_CCC);
                }
            });


        });

        return baseMethod(adapter);
    }

    #endregion
}

Hope, it helps!


davidnavasardyan
Jr Varsity I
Forum|alt.badge.img+2

Hi ​@nsmith51 ,

I think you're running into the 'Document Out of Balance' issue because you're removing a system-generated GL transaction and adding new ones. Acumatica requires debits and credits to be balanced in the GL batch, so if you delete a line, you'll need to make sure the new entries keep everything in balance.

This should help resolve your out-of-balance error :

public class SOInvoiceEntry_Extension : PXGraphExtension<PX.Objects.SO.SOInvoiceEntry>
{
    public delegate IEnumerable ReleaseDelegate(PXAdapter adapter);
    [PXOverride]
    public IEnumerable Release(PXAdapter adapter, ReleaseDelegate baseMethod)
    {
        PXGraph.InstanceCreated.AddHandler<JournalEntry>((graph) =>
        {
            graph.RowInserted.AddHandler<Batch>((cache, e) =>
            {
                Batch row = e.Row as Batch;
                if (row != null)
                {
                    graph.BatchModule.Current = row;

                    foreach (GLTran oldTran in graph.GLTranModuleBatNbr.Cache.Cached)
                    {
                        if (oldTran.AccountID == 1154) 
                        {
                            graph.GLTranModuleBatNbr.Cache.Delete(oldTran);
                        }
                    }

                    decimal totalDebit = 0m;
                    decimal totalCredit = 1000m; // Assuming original amount was credited

                    GLTran gl_AAA = new GLTran
                    {
                        AccountID = 10025,
                        TranDesc = "AAA",
                        SubID = 467,
                        ProjectID = Base.Document.Current.ProjectID,
                        Qty = 1,
                        RefNbr = Base.Document.Current.RefNbr,
                        CuryDebitAmt = 500,
                        DebitAmt = 500,
                        TranType = ARDocType.Invoice,
                        Released = true
                    };
                    totalDebit += 500;
                    graph.GLTranModuleBatNbr.Cache.Insert(gl_AAA);

                    GLTran gl_BBB = new GLTran
                    {
                        AccountID = 10026,
                        TranDesc = "BBB",
                        SubID = 467,
                        ProjectID = Base.Document.Current.ProjectID,
                        Qty = 1,
                        RefNbr = Base.Document.Current.RefNbr,
                        CuryDebitAmt = 200,
                        DebitAmt = 200,
                        TranType = ARDocType.Invoice,
                        Released = true
                    };
                    totalDebit += 200;
                    graph.GLTranModuleBatNbr.Cache.Insert(gl_BBB);

                    GLTran gl_CCC = new GLTran
                    {
                        AccountID = 10027,
                        TranDesc = "CCC",
                        SubID = 467,
                        ProjectID = Base.Document.Current.ProjectID,
                        RefNbr = Base.Document.Current.RefNbr,
                        Qty = 1,
                        CuryDebitAmt = 300,
                        DebitAmt = 300,
                        TranType = ARDocType.Invoice,
                        Released = true
                    };
                    totalDebit += 300;
                    graph.GLTranModuleBatNbr.Cache.Insert(gl_CCC);

                    // Ensure batch total is balanced
                    graph.BatchModule.Current.ControlTotal = totalDebit - totalCredit;
                    graph.BatchModule.Update(graph.BatchModule.Current);
                }
            });
        });

        return baseMethod(adapter);
    }
}

 

 


Forum|alt.badge.img
  • Author
  • Jr Varsity III
  • 55 replies
  • March 12, 2025

@davidnavasardyan ​@Nilkanth Dipak  Thanks for the responses.

I tried above options but still getting the same error. Have you tested the above code and is it working for you?

 

 


Forum|alt.badge.img
  • Author
  • Jr Varsity III
  • 55 replies
  • March 12, 2025

@Dmitrii Naumov  ​@Vignesh Ponnusamy ​@Samuel Olivier Lavigueur 

It seems I need to do a small tweak here,  Can you please review and provide your inputs. 


Dmitrii Naumov
Acumatica Moderator
Forum|alt.badge.img+7
  • Acumatica Moderator
  • 633 replies
  • March 12, 2025

@nsmith51 what is the business requirement here? 

It seems to be extremely dangerous to override the release logic like that. 

The release is an extremely complex process that depends on multiple different settings and handles multiple edge cases, e.g. with rounding and other things. 

 

I’d not recommend overriding this part at all.

 

Also in your code you only populate Debit amount, but the batch needs to be balanced (debit amount = credit amount)


Forum|alt.badge.img
  • Author
  • Jr Varsity III
  • 55 replies
  • March 12, 2025

@Dmitrii Naumov 

By default, Acumatica generates Debit and Credit lines upon invoice release.

In this scenario:

  • The account related to 1154 is a debit account, and I would like to replace the single debit line with three separate debit lines as per my requirement.
  • This adjustment does not alter the core process but simply replaces the system-generated debit line with different accounts.
  • Acumatica will still generate the Credit Line, and I will insert three debit lines in place of the system-generated debit entry.

 


Forum|alt.badge.img
  • Author
  • Jr Varsity III
  • 55 replies
  • March 12, 2025

@Dmitrii Naumov  GL is generating properly but on the screen getting the below error.  Please find the screenshots for reference.

 

 

 

 


Dmitrii Naumov
Acumatica Moderator
Forum|alt.badge.img+7
  • Acumatica Moderator
  • 633 replies
  • March 12, 2025

@nsmith51 I think you should override a different method.

 

ARReleaseProcess.InsertInvoiceTransaction method is exactly the place you are looking for. 

There you do have the GLTran that is about to be inserted, you can instead insert your GLTrans. 

 

That should be more reliable and easier to implement.


Forum|alt.badge.img
  • Author
  • Jr Varsity III
  • 55 replies
  • March 12, 2025

@Dmitrii Naumov Can you please help me with the sample code?


Dmitrii Naumov
Acumatica Moderator
Forum|alt.badge.img+7
  • Acumatica Moderator
  • 633 replies
  • March 12, 2025

@nsmith51 something like that should do:

public class ARReleaseProcessExtension : PXGraphExtension<ARReleaseProcess>
{
	public static bool IsActive()
	{
		return true;
	}

	[PXOverride]
	public virtual GLTran InsertInvoiceTransaction(
		JournalEntry je,
		GLTran tran,
		ARReleaseProcess.GLTranInsertionContext context,
		Func<JournalEntry, GLTran, ARReleaseProcess.GLTranInsertionContext, GLTran> baseMethod)
	{
		if (something)
		{
			GLTran tran1 = (GLTran)je.GLTranModuleBatNbr.Cache.CreateCopy(tran);
			tran1.CuryDebitAmt = tran.CuryDebitAmt * 0.5m;
			tran1.DebitAmt = tran.DebitAmt * 0.5m;
			je.GLTranModuleBatNbr.Insert(tran1);

			GLTran tran2 = (GLTran)je.GLTranModuleBatNbr.Cache.CreateCopy(tran);
			tran2.CuryDebitAmt = tran.CuryDebitAmt * 0.3m;
			tran2.DebitAmt = tran.DebitAmt * 0.3m;
			je.GLTranModuleBatNbr.Insert(tran2);

			GLTran tran3 = (GLTran)je.GLTranModuleBatNbr.Cache.CreateCopy(tran);
			tran3.CuryDebitAmt = tran.CuryDebitAmt * 0.2m;
			tran3.DebitAmt = tran.DebitAmt * 0.2m;
			je.GLTranModuleBatNbr.Insert(tran3);

			return tran1;
		}
		else
		{
			return baseMethod(je, tran, context);
		}
	}
}

 


Forum|alt.badge.img
  • Author
  • Jr Varsity III
  • 55 replies
  • March 12, 2025

@Dmitrii Naumov  Sorry, I’m getting below error with the above code.

 

 


Forum|alt.badge.img
  • Author
  • Jr Varsity III
  • 55 replies
  • March 12, 2025

@Dmitrii Naumov  I tried this way but still getting the error.

 

  public delegate GLTran InsertInvoiceTransactionDelegate(JournalEntry je,
      GLTran tran,
      GLTranInsertionContext context);
  [PXOverride]
  public virtual GLTran InsertInvoiceTransaction(
      JournalEntry je,
      GLTran tran,
      GLTranInsertionContext context,
      InsertInvoiceTransactionDelegate baseMethod)
  {

      return baseMethod(je, tran, context);

   }

 


Dmitrii Naumov
Acumatica Moderator
Forum|alt.badge.img+7
  • Acumatica Moderator
  • 633 replies
  • March 12, 2025

@nsmith51 GLTranInsertionContext must be ARReleaseProcess.GLTranInsertionContext

 

I’ve updated the example above


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings