【问题标题】:Force tax recalculation when TaxZoneID is updated inside event handler在事件处理程序内更新 TaxZoneID 时强制重新计算税款
【发布时间】:2020-05-07 14:29:55
【问题描述】:

我有一个用于发票的图表覆盖

public class ARInvoiceEntry_Extension : PXGraphExtension<ARInvoiceEntry>

在其中一个事件处理程序中,我正在更新TaxZoneID,它工作正常。但是,税收不会更新或重新计算。我试过here提到的方法

cache.SetValueExt<SOOrder.taxZoneID>(order, branchLoc.VTaxZoneID);

但这对我不起作用。我已经在_FieldUpdating_FieldUpdated 甚至ARInvoice_RowPersisting(PXCache cache, PXRowPersistingEventArgs e, PXRowPersisting InvokeBaseHandler) 事件中尝试过。关于为什么它不起作用的任何想法? TaxZone 和税率已经在数据库中(我们没有使用 Avatax)。

--- 编辑 1 ---

这是更新 TaxZoneID 的代码

namespace PX.Objects.AR
{
    public class ARInvoiceEntry_Extension : PXGraphExtension<ARInvoiceEntry>
    {
        #region Event Handlers
        protected void ARShippingAddress_PostalCode_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e, PXFieldUpdated del)
        {
            // PXTrace.WriteInformation("ARShippingAddress_PostalCode_FieldUpdated");
            ARShippingAddress row = e.Row as ARShippingAddress;

            if (row != null) {
                if (DoChangeTaxZone(row)) {
                    var invoice = Base.Document.Current;

                    if (invoice != null) {
                        invoice.TaxZoneID = GetTaxZoneId(row);

                        sender.SetValueExt<ARInvoice.taxZoneID>(invoice, invoice.TaxZoneID);
                    }
                }
            }

            if (del != null)
            {
                del(sender, e);
            }
        }
        #endregion

        private bool DoChangeTaxZone(ARShippingAddress row)
        {
            // logic ...

            return true;
        }

        private string GetTaxZoneId(ARShippingAddress row)
        {
            // logic ...

            return "TAX-ZONE-ID";
        }
    }
}


【问题讨论】:

  • 请将您更新 TaxZoneID 的代码添加到问题中
  • 您使用的是ARInvoiceEntry PXGraph 而不是SOOrderEntry,很可能税务引擎正在对ARInvoiceTaxZoneID 而不是SOOrder 的作出反应。在ARInvoiceTaxZoneID 上尝试SetValueExt
  • @SamvelPetrosov - 我添加了更新发生的代码。正如您在添加的代码中看到的那样,我确实尝试在ARInvoice.taxZoneID 上调用SetValueExt,但由于某种原因这似乎不起作用。也许我使用了错误的事件传播顺序?
  • 这样做并不简单,我正在四处询问我以前见过的示例。有人应该尽快发布答案。

标签: acumatica


【解决方案1】:

当您使用典型方法以编程方式与税务记录进行交互时,总税额将无法正确刷新。默认情况下,Tax DAC 属性不会重新计算总计以提高性能。

要强制刷新税收属性,您需要更改税收计算模式。

税收计算模式NoCalc 不会重新计算总计。这是默认模式。

需要将税金计算模式设置为ManualCalc 才能刷新更新的税金。

更新税额字段的代码示例,您可以对其进行调整以更新税区。

ARInvoiceEntry invoiceMaint = PXGraph.CreateInstance<ARInvoiceEntry>(); 
TX.TaxAttribute.SetTaxCalc<ARTran.taxCategoryID>(invoiceMaint.Transaction.Cache, null, TX.TaxCalc.ManualCalc); 
invoiceMaint.CurrentDocument.Current = invoiceMaint.Document.Search<ARInvoice.refNbr>("AR005452", ARDocType.Invoice).FirstOrDefault(); 
invoiceMaint.Taxes.Select();
invoiceMaint.Taxes.Current = invoiceMaint.Taxes.Search<ARTaxTran.taxID>("CAGST").FirstOrDefault(); 
invoiceMaint.Taxes.Cache.SetValueExt<ARTaxTran.curyTaxAmt>(invoiceMaint.Taxes.Current, 3); 
invoiceMaint.Taxes.Update(invoiceMaint.Taxes.Current);
invoiceMaint.SelectTimeStamp(); 
invoiceMaint.Save.Press(); 

【讨论】:

    猜你喜欢
    • 2012-12-20
    • 2019-01-21
    • 2012-03-01
    • 2012-08-19
    • 2015-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多