You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

能否定制现金销售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:

1. Create a Graph Extension for ARDocumentRelease

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.

2. Override the ReleaseDoc Method

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);
    }
}
3. Key Notes to Keep in Mind
  • DAC Extension Requirement: Make sure you’ve already created a DAC extension for ARPayment to hold your custom fields (e.g., UsrCustomCashAccount and UsrCustomSubaccount).
  • Field Type Matching: If your custom fields store string identifiers (like account codes) instead of numeric IDs, use PXSelectorAttribute.Select to 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 PXOverride follows 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.

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 08:42:55