如何覆盖默认术语更新,从将商机转换为销售订单

时间:2016-08-08 17:20:26

标签: c# acumatica

我已经在机会中添加了自定义字段条款和发货通知,当我将价值传递给销售订单时。它被替换为默认条款&通过。

我使用的以下代码将商机中的值传递给销售订单

public virtual IEnumerable CreateSalesOrder(PXAdapter adapter)
{

    PXGraph.InstanceCreated.AddHandler<SOOrderEntry>((graph) =>
    {
        graph.RowInserted.AddHandler<SOOrder>((cache, args) =>
        {
            var soOrder = (SOOrder)args.Row;
            var soOrderExt = PXCache<SOOrder>.GetExtension<SOOrderExtNV>(soOrder);

            foreach (CROpportunity opportunity in adapter.Get())
            {
                OppertunityExtn extOpprow = PXCache<CROpportunity>.GetExtension<OppertunityExtn>(opportunity);
                soOrderExt.UsrOpportunityID = opportunity.OpportunityID;
                soOrderExt.UsrCustomerContact = opportunity.ContactID;
                soOrderExt.UsrIsEmbroidery = extOpprow.UsrIsEmbroidery;
                soOrderExt.UsrIsPromo = extOpprow.UsrIsPromo;
                soOrderExt.UsrIsBlank = extOpprow.UsrIsBlank;
                soOrderExt.UsrIsService = extOpprow.UsrIsService;
                soOrderExt.UsrIsDigital = extOpprow.UsrIsDigital;
                soOrderExt.UsrIsSample = extOpprow.UsrIsSample;
                soOrderExt.UsrIsScreenPrint = extOpprow.UsrIsScreenPrint;
                soOrderExt.UsrIsRushJob = extOpprow.UsrIsRushJob;
                soOrderExt.UsrHardDate = extOpprow.UsrHardDate;
                soOrderExt.UsrIsInHandsDate = extOpprow.UsrIsInHandsDate;
                soOrderExt.UsrEventDate = extOpprow.UsrEventDate;
                soOrderExt.UsrEventDescription = extOpprow.UsrEventDescription;
                soOrderExt.UsrShipDate = extOpprow.UsrShipDate;
                soOrderExt.UsrHoldUntil = extOpprow.UsrHoldUntil;
                soOrderExt.UsrExactQuantityNeeded = extOpprow.UsrExactQuantityNeeded;
                soOrderExt.UsrIsNewCustomer = extOpprow.UsrIsNewCustomer;
                soOrderExt.UsrBatchShip = extOpprow.UsrBatchShip;
                soOrderExt.UsrInternalRef = extOpprow.UsrInternalRef;
                soOrder.ShipVia = extOpprow.UsrShipVia;
                soOrder.TermsID = extOpprow.UsrTerms;
                soOrder.FreightAmt = extOpprow.UsrFreightEstimate;

            }
        });
        graph.RowPersisting.AddHandler<SOOrder>((cache, args) =>
            {
                var soOrder = (SOOrder)args.Row;
                foreach (CROpportunity opportunity in adapter.Get())
                {
                    OppertunityExtn extOpprow = PXCache<CROpportunity>.GetExtension<OppertunityExtn>(opportunity);
                    soOrder.TermsID = extOpprow.UsrTerms;
                }

            });
    });
    return Base.createSalesOrder.Press(adapter);
}

1 个答案:

答案 0 :(得分:2)

插入TermsID行后,将替换

SOOrder。您可以参考下面OpportunityMaint.DoCreateSalesOrder的代码。这就是为什么它被客户级别的价值所取代。

enter image description here

您应该实现如下逻辑。您也可以对用户字段使用类似的方法。

public class OpportunityMaintPXExt : PXGraphExtension<OpportunityMaint>
{
    public override void Initialize()
    {
        PXGraph.InstanceCreated.AddHandler<SOOrderEntry>((graph) =>
        {
            graph.RowUpdating.AddHandler<SOOrder>((sender, e) =>
            {
                SOOrder soData = e.NewRow as SOOrder;
                if (soData != null)
                {
                    if (sender.GetStatus(soData) == PXEntryStatus.Inserted)
                    {
                        CROpportunity opData = Base.Opportunity.Current;
                        CROpportunityPXExt opDataExt = PXCache<CROpportunity>.GetExtension<CROpportunityPXExt>(opData);

                        soData.TermsID = opDataExt.UsrTermsID;
                        soData.ShipVia = opDataExt.UsrShipVia;
                    }
                }
            });
        });
    }
}