acumatica - 在发布后的发票和备忘录上,我们启用了页眉和页脚的自定义字段,但在修改余额时更新错误值
问题描述
如果状态已关闭且余额 = 0,我需要启用一些自定义字段,包括页眉和页脚,然后如果我们修改持久委托上的任何页脚字段值,设置修改后字段的值并更新事务缓存(下面的示例代码)然后余额 0 正在更新发票总计字段的值。
public class KWARInvoiceEntryExt : PXGraphExtension<ARInvoiceEntry>
{
[PXOverride]
public void Persist(Action del)
{
if ((Base.Document.Cache.GetStatus(Base.Document.Current) == PXEntryStatus.Inserted || Base.Document.Cache.GetStatus(Base.Document.Current) == PXEntryStatus.Updated))
{
foreach (ARTran items in Base.Transactions.Select())
{
if (Base.Document.Current.DocType == ARDocType.Invoice)
{
if (Base.Document.Current.Released == true)
{
Base.Transactions.Cache.SetValue<ARTran.curyTranAmt>(items, items.CuryTranAmt);
}
}
Base.Transactions.Update(items);
}
}
del();
}
}
解决方案
这发生在 ARInvoiceEntry.ARTran_RowUpdated 事件中。通常在 Acumatica 中,您无法更新已发布的交易,因此那里没有其他条件,并且一旦您尝试更新任何值并保存交易 - 余额的计算方式与平衡文档的计算方式相同。
protected virtual void ARTran_RowUpdated(PXCache sender, PXRowUpdatedEventArgs e)
{
ARTran row = (ARTran)e.Row;
ARTran oldRow = (ARTran)e.OldRow;
if (row != null)
{
if ((!sender.ObjectsEqual<ARTran.branchID>(e.Row, e.OldRow) || !sender.ObjectsEqual<ARTran.inventoryID>(e.Row, e.OldRow) ||
!sender.ObjectsEqual<ARTran.baseQty>(e.Row, e.OldRow) || !sender.ObjectsEqual<ARTran.curyUnitPrice>(e.Row, e.OldRow) || !sender.ObjectsEqual<ARTran.curyTranAmt>(e.Row, e.OldRow) ||
!sender.ObjectsEqual<ARTran.curyExtPrice>(e.Row, e.OldRow) || !sender.ObjectsEqual<ARTran.curyDiscAmt>(e.Row, e.OldRow) ||
!sender.ObjectsEqual<ARTran.discPct>(e.Row, e.OldRow) || !sender.ObjectsEqual<ARTran.manualDisc>(e.Row, e.OldRow) ||
!sender.ObjectsEqual<ARTran.discountID>(e.Row, e.OldRow)) && row.LineType != SOLineType.Discount)
RecalculateDiscounts(sender, row);
if (row.ManualDisc != true)
{
var discountCode = (ARDiscount)PXSelectorAttribute.Select<SOLine.discountID>(sender, row);
row.DiscPctDR = (discountCode != null && discountCode.IsAppliedToDR == true) ? row.DiscPct : 0.0m;
}
if ((e.ExternalCall || sender.Graph.IsImport)
&& sender.ObjectsEqual<ARTran.inventoryID>(e.Row, e.OldRow) && sender.ObjectsEqual<ARTran.uOM>(e.Row, e.OldRow)
&& sender.ObjectsEqual<ARTran.qty>(e.Row, e.OldRow) && sender.ObjectsEqual<ARTran.branchID>(e.Row, e.OldRow)
&& sender.ObjectsEqual<ARTran.siteID>(e.Row, e.OldRow) && sender.ObjectsEqual<ARTran.manualPrice>(e.Row, e.OldRow)
&& (!sender.ObjectsEqual<ARTran.curyUnitPrice>(e.Row, e.OldRow) || !sender.ObjectsEqual<ARTran.curyExtPrice>(e.Row, e.OldRow))
&& row.ManualPrice == oldRow.ManualPrice)
row.ManualPrice = true;
if (row.ManualPrice != true)
{
row.CuryUnitPriceDR = row.CuryUnitPrice;
}
// BALANCE WILL BE CALCULATED HERE!!!
//
TaxAttribute.Calculate<ARTran.taxCategoryID>(sender, e);
//Validate that Sales Account <> Deferral Account:
if (!sender.ObjectsEqual<ARTran.accountID, ARTran.deferredCode>(e.Row, e.OldRow))
{
if (!string.IsNullOrEmpty(row.DeferredCode))
{
DRDeferredCode defCode = PXSelect<DRDeferredCode, Where<DRDeferredCode.deferredCodeID, Equal<Required<DRDeferredCode.deferredCodeID>>>>.Select(this, row.DeferredCode);
if (defCode != null)
{
if (defCode.AccountID == row.AccountID)
{
sender.RaiseExceptionHandling<ARTran.accountID>(e.Row, row.AccountID,
new PXSetPropertyException(Messages.AccountIsSameAsDeferred, PXErrorLevel.Warning));
}
}
}
}
}
}
因此,您只需覆盖 ARInvoiceEntry.ARTran_RowUpdated 事件并禁用已发布文档的计算。像这样的东西:
[Serializable]
public class ARInvoiceEntry_Extension : PXGraphExtension<ARInvoiceEntry>
{
public delegate void EventDelegate(PXCache sender, PXRowUpdatedEventArgs e);
[PXOverride]
public void ARTran_RowUpdated(PXCache sender, PXRowUpdatedEventArgs e, EventDelegate baseMethod)
{
if (Base.Document.Current.Released != true)
{
baseMethod.Invoke(sender, e);
}
}
}
推荐阅读
- azure - 如何从 Terraform 配置 Azure 托管磁盘的备份?
- visual-studio-code - 在浏览器中运行 Visual Studio Code 发生了什么?
- huawei-mobile-services - 为什么我在AppGallery Connect中为其他应用更改货币时,我的应用中的应用内产品价格的货币会自动更改?
- docker - Docker compose 删除 webserver 也会删除数据库
- android - 如果响应在响应 android 改造 API 中没有成功,为什么我会得到空值?
- c - 为什么 Clang 找不到我的头文件,而 GCC 可以?
- unity3d - 在统一中,物体在场景中显得非常柔和,但游戏场景完全像素化
- javascript - 如何在编译构建时解决所有 typeScript 构建错误
- python - 使用 selenium 从 highchart 中抓取数据
- git - 删除符号链接macOS的执行权限