能否定制现金销售Release操作及ARDocumentRelease.ReleaseDoc()函数?
Absolutely, customizing the ARDocumentRelease.ReleaseDoc() method to populate Cash Account and Subaccount from your custom fields is totally feasible in Acumatica! Here’s a step-by-step approach to make this happen:
Instead of modifying out-of-the-box code (which is never recommended), you’ll extend the ARDocumentRelease graph using a graph extension. This keeps your changes isolated and avoids upgrade conflicts down the line.
Use the [PXOverride] attribute to intercept the original ReleaseDoc method. Before running the base release logic, fetch your custom field values from the cash sale record (typically an ARPayment entry for cash sales) and assign them to the CashAccountID and SubID fields.
Here’s a code example to illustrate this:
using PX.Data; using PX.Objects.AR; public class ARDocumentRelease_Extension : PXGraphExtension<ARDocumentRelease> { // Define a delegate matching the original method signature public delegate void ReleaseDocDelegate(ARRegister doc, ARPayment paydoc, bool isPrepayment); [PXOverride] public void ReleaseDoc(ARRegister doc, ARPayment paydoc, bool isPrepayment, ReleaseDocDelegate baseMethod) { // Target only cash sale documents (adjust condition if needed for your setup) if (paydoc != null && paydoc.DocType == ARDocType.CashSale) { // Fetch custom fields from the ARPayment's DAC extension ARPaymentExt paydocExt = paydoc.GetExtension<ARPaymentExt>(); // Assign custom Cash Account if the field has a value if (paydocExt.UsrCustomCashAccount != null) { // If your custom field stores a string code instead of numeric ID, use PXSelector to resolve: // paydoc.CashAccountID = PXSelectorAttribute.Select<ARPayment.cashAccountID>(Base.Document.Cache, paydocExt.UsrCustomCashAccount) as int?; paydoc.CashAccountID = paydocExt.UsrCustomCashAccount; } // Assign custom Subaccount if the field has a value if (paydocExt.UsrCustomSubaccount != null) { // Resolve from string code if needed: // paydoc.SubID = PXSelectorAttribute.Select<ARPayment.subID>(Base.Document.Cache, paydocExt.UsrCustomSubaccount) as int?; paydoc.SubID = paydocExt.UsrCustomSubaccount; } // Update the cache to ensure changes persist before release Base.Document.Update(paydoc); } // Run the original release logic baseMethod(doc, paydoc, isPrepayment); } }
- DAC Extension Requirement: Make sure you’ve already created a DAC extension for
ARPaymentto hold your custom fields (e.g.,UsrCustomCashAccountandUsrCustomSubaccount). - Field Type Matching: If your custom fields store string identifiers (like account codes) instead of numeric IDs, use
PXSelectorAttribute.Selectto resolve the corresponding system IDs. - Testing: Thoroughly test with cash sale documents to confirm the Cash Account and Subaccount populate correctly before the document is released.
- Upgrade Safety: Using graph extensions and
PXOverridefollows Acumatica’s best practices, so your changes will stay compatible with future platform versions.
Alternative Approach: If you’d rather not override the entire ReleaseDoc method, you could use a RowSelected or FieldUpdated event on the ARPayment DAC to set these fields when the release process starts. However, overriding ReleaseDoc is more direct since it’s the exact method triggered by the Release button.
内容的提问来源于stack exchange,提问作者EricP.

