更新通过 PXResultset 检索到的 DAC 值的正确方法是什么? [英] What is the proper way to update values of DAC's retrieved via PXResultset?

查看:16
本文介绍了更新通过 PXResultset 检索到的 DAC 值的正确方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一项业务要求,如果可能,将 SO 退货成本设置为不开具发票的原始成本.我们确定销售订单对于跟踪向我们的客户发出的材料是必要的,我们是成本驱动而不是价格驱动.我们使用 FIFO 成本核算,但因此退货订单似乎不会以原始成本退货,除非开具发票(我们也不以传统方式这样做).

We have a business requirement to set the SO return COST to the original cost issued without invoicing if possible. We determined that Sales Orders are necessary to track issuing materials to our client, and we are cost driven rather than price driven. We use FIFO costing, but SO return orders do not seem to return at the original COST unless invoiced (which we also don't do in a traditional manner).

我发现在 Confirm Shipment 和 Update IN 之前直接在数据库中设置 SO Shipment Line 上的单位/ext 成本似乎可以提供所需的结果.应用自定义菜单选项来简化和强烈控制返回,我克隆了附近的代码作为基础.=== 之间的部分是我设置单位/外部成本的地方.PXTrace 显示了预期值,但在发货记录中显示为 0 美元.我想我可能需要docgraph.Update(sOShipmentLine)"来保存它,但在此范围内无法访问.

I found that setting the unit/ext cost on the SO Shipment Line directly in the database before Confirm Shipment and Update IN appears to provide the results desired. Applying a custom menu option to streamline and strongly control the return, I cloned nearby code as a base. The section between the === is where I set the unit/ext cost. The PXTrace shows the expected value, but it is coming out as $0 on the shipment record. I thought I might need "docgraph.Update(sOShipmentLine)" to save it, but that's not accessible in this scope.

using (var ts = new PXTransactionScope())
{
    PXTimeStampScope.SetRecordComesFirst(typeof(SOOrder), true);
    //Reminder - SOShipmentEntry docgraph = PXGraph.CreateInstance<SOShipmentEntry>();
    docgraph.CreateShipment(order, SiteID, filter.ShipDate, adapter.MassProcess, SOOperation.Receipt, created, adapter.QuickProcessFlow);


    PXTrace.WriteError("Setting Cost");
    //Set Cost on Shipment to Cost On SO Line
    PXResultset<SOShipment> results =
                            PXSelectJoin<SOShipment,
                            InnerJoin <SOShipLine, On<SOShipLine.shipmentNbr, Equal<SOShipment.shipmentNbr>>,
                            InnerJoin <SOLine, On<SOLine.orderType, Equal<SOShipLine.origOrderType>,
                                            And<SOLine.orderNbr, Equal<SOShipLine.origOrderNbr>, And<SOLine.lineNbr, Equal<SOShipLine.origLineNbr>>>>
                            >>,
                                Where<SOShipment.shipmentNbr, Equal<Required<SOShipment.shipmentNbr>>>>
                            .Select(docgraph, docgraph.Document.Current.ShipmentNbr);

    PXTrace.WriteError("Shipment {0} - Records {1}", docgraph.Document.Current.ShipmentNbr, results.Count);

    foreach (PXResult<SOShipment, SOShipLine, SOLine> record in results)
    {
        SOShipment shipment = (SOShipment)record;
        SOShipLine shipmentLine = (SOShipLine)record;
        SOLine sOLine = (SOLine)record;
        ==============================================
        shipmentLine.UnitCost = GetReturnUnitCost(sOLine.OrigOrderType, sOLine.OrigOrderNbr, sOLine.OrigLineNbr, sOLine.CuryInfoID);
        shipmentLine.ExtCost = shipmentLine.Qty * shipmentLine.UnitCost;
        PXTrace.WriteError(string.Format("{0} {1}-{2} = {3} / {4}", shipmentLine.LineType, shipmentLine.ShipmentNbr, shipmentLine.LineNbr, shipmentLine.Qty, shipmentLine.UnitCost));
        ==============================================
    }

    PXAutomation.CompleteSimple(docgraph.Document.View);
    var items = new List<object> { order };
    PXAutomation.RemovePersisted(docgraph, typeof(SOOrder), items);
    PXAutomation.RemoveProcessing(docgraph, typeof(SOOrder), items);
    ts.Complete();
}

仍处于学习曲线上,所以我希望解决方案对于更有经验的人来说可能简单明了.

Still on the learning curve so I'm expecting the solution is likely simple and obvious to someone more experienced.

推荐答案

它分为三个阶段:

  1. 更改值
  2. 更新缓存
  3. 保持缓存

我认为您正在更改该值,但没有保留它.在调用 Confirm Shipment 或 Update IN 操作后它起作用的原因可能是这些操作将通过调用图形保存操作来保留所有更改.

I think you are changing the value but not persisting it. The reason why it works after invoking Confirm Shipment or Update IN action is probably that these actions will persist all changes by calling the graph Save action.

要更改数据视图中的字段值,您可以执行以下操作:

To change a field value in a data view you would do:

DACRecord.Field = value;
DataView.Update(DACRecord);    

您的示例的特殊性在于请求未绑定到数据视图.当您有一个松散的 BQL 请求时,您可以对缓存对象执行相同的操作.在您的示例中,缓存上下文可从 docGraph 获得:

The particularity of your example is that the request is not bound to a data view. When you have a loose BQL request you can do the same operation with a cache object. In your example the Caches context is available from docGraph:

DACRecord.Field = value;
graph.Caches[typeof(DACType)].Update(DACRecord);
graph.Caches[typeof(DACType)].Persist(DACRecord, PXDBOperation.Update);

Update 和 Persist 经常被省略,因为在许多场景中它们稍后会被其他框架机制调用.例如,如果您只对 UI 字段执行更新,则在用户单击保存按钮之前,记录不会保留.

Update and Persist are often omitted because in many scenarios they will be called later on by other framework mechanism. For example if you were to do only Update on a UI field, the record won't be persisted until the user clicks on the save button.

在 UI 上更新值与在缓存中更新有点不同.

Updating value on UI is a bit different than updating in cache.

UI 字段的推荐方法是使用 SetValue:

The recommended approach for UI fields is to use SetValue:

cache.SetValue<DAC.DacField>(DACRecord, fieldValue);

或者当你想在改变字段值时触发像FieldUpdated这样的框架事件时使用SetValueExt:

Or use SetValueExt when you want to trigger the framework events like FieldUpdated when changing the field value:

cache.SetValueExt<DAC.DacField>(DACRecord, fieldValue);

如果您希望更改保留而不需要用户手动保存文档,您仍然需要更新并保留这些更改在缓存中.

You'll still have to update and persist the changes in cache for these too if you want the changes to stick without requiring the user to manually save the document.

这篇关于更新通过 PXResultset 检索到的 DAC 值的正确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆