从销售报价单创建销售订单时出错 (CR304500)

Error While creating Sales Order from Sales Quote (CR304500)

我在销售报价 (CR304500) 屏幕中创建了一个名为“CREATE SO”的操作来创建销售订单。我创建了一个 ComboBox udf“销售订单类型”到要创建的销售订单的 select“文档类型”。

  1. 当我 selecting DocType 为“SO”时,它给出错误“Unit 缺少转换”。(见图)

  2. 当我 selecting 任何其他 DocType 时,它​​给出错误“RevisionID 不能为空”。(见图)

“SO”是 SO 首选项中的默认订单类型。我无法使用调试器跟踪错误。请建议。谢谢。以下是我的代码。

       #region Create Sales Order

        public PXAction<CRQuote> createSalesOrder;
        [PXUIField(DisplayName = "Create SO", MapEnableRights = PXCacheRights.Update, MapViewRights = PXCacheRights.Update)]
        [PXProcessButton(CommitChanges = true)]
        public IEnumerable CreateSalesOrder(PXAdapter adapter)
        {
            QuoteMaint graphObject = PXGraph.CreateInstance<QuoteMaint>();

            foreach (CRQuote quote in adapter.Get())
            {
                //Create resultset for Quote Details
                PXResultset<CROpportunityProducts> PXSetLine = PXSelect<CROpportunityProducts,
                Where<CROpportunityProducts.quoteID,
                Equal<Required<CROpportunityProducts.quoteID>>>>.Select(this.Base, quote.QuoteID);
                List<CROpportunityProducts> QuoteList = new List<CROpportunityProducts>();
                foreach (CROpportunityProducts line in PXSetLine)
                {
                    QuoteList.Add(line);
                }
              
                bool var_orderCreated = false;
                bool erroroccured = false;
                string ErrMsg = "";

                SOOrderEntry orderGraphObjet = PXGraph.CreateInstance<SOOrderEntry>();
                SOOrder orderHeaderObject = new SOOrder();
                QuoteMaint currGRPH = PXGraph.CreateInstance<QuoteMaint>();
                CRQuoteExt _quoteExt = PXCache<CRQuote>.GetExtension<CRQuoteExt>(quote); 
                var Extension = this.Base.GetExtension<QuoteMaint_Extension>();

                orderHeaderObject = orderGraphObjet.CurrentDocument.Insert(orderHeaderObject);
                BAccount customer = PXSelect<BAccount, Where<BAccount.bAccountID, Equal<Current<CRQuote.bAccountID>>>>.Select(this.Base, quote.BAccountID);
                if (customer.Type == "CU")
                {
                    orderHeaderObject.CustomerID = quote.BAccountID;
                    orderHeaderObject.CustomerLocationID = quote.LocationID;
                }
                else
                {
                    throw new PXException("Business Account not converted to Customer yet");
                }
                if (quote.CuryProductsAmount != 0)
                {
                    orderHeaderObject.CuryOrderTotal = quote.CuryProductsAmount;
                }
                else
                {
                    throw new PXException("Total cannot be 0");
                }
                orderHeaderObject.CuryOrderTotal = quote.CuryProductsAmount;
                orderHeaderObject.CuryTaxTotal = quote.CuryTaxTotal;
                orderHeaderObject.OrderDesc = quote.Subject;
                orderHeaderObject.OrderType = _quoteExt.UsrOrderNbr;

                orderGraphObjet.Document.Update(orderHeaderObject);


                orderGraphObjet.CurrentDocument.Current = orderHeaderObject;
                orderGraphObjet.Actions.PressSave();

                orderHeaderObject = orderGraphObjet.CurrentDocument.Current;

                foreach (CROpportunityProducts tran in QuoteList)
                {
                    SOLine transline = new SOLine();

                    orderGraphObjet.Transactions.Insert(transline);
                    transline.OrderNbr = orderHeaderObject.OrderNbr;
                    transline.BranchID = orderHeaderObject.BranchID;
                    transline.InventoryID = tran.InventoryID;
                    transline.TranDesc = tran.Descr;
                    transline.UOM = tran.UOM;
                    transline.OrderQty = tran.Quantity;
                    transline.SiteID = tran.SiteID;
                    transline.CuryUnitPrice = tran.CuryUnitPrice;
                    transline.CuryExtPrice = tran.CuryExtPrice;
                    transline.CuryLineAmt = tran.CuryAmount;

                    CROpportunityProductsExt xOppProductExt = PXCache<CROpportunityProducts>.GetExtension<CROpportunityProductsExt>(tran);
                    SOLineExt _soLext = PXCache<SOLine>.GetExtension<SOLineExt>(transline); 
                    _soLext.UsrXSeqID = xOppProductExt.UsrXSequenceID;
                    _soLext.UsrXGroupID = xOppProductExt.UsrXGroupID;
                    _soLext.UsrInternalRemk = xOppProductExt.UsrInternalRemk;
                    orderGraphObjet.Transactions.Update(transline);

                }
                orderGraphObjet.Actions.PressSave(); //This is the line where both the error is showing
                    
                if (orderGraphObjet != null && orderHeaderObject != null)
                {
                    orderGraphObjet.Document.Current = orderHeaderObject;
                    throw new PXRedirectRequiredException(orderGraphObjet, "Document") { Mode = PXBaseRedirectException.WindowMode.NewWindow };
                }


                yield return quote;
            }
        }


############## DAC FIELD #####################
    [PXDBString(50)]
        [PXUIField(DisplayName = "Sales Order Type")]
        [PXDefault()]
        [PXStringList(new string[] { "SO", "SP", "SS" }, new string[] { "SO - Sales Order", "SP - Sales Of Project", "SS - Sales Of Service" })]
        public virtual string UsrOrderNbr { get; set; }
        public abstract class usrOrderNbr : PX.Data.BQL.BqlString.Field<usrOrderNbr> { }

我建议当您将新对象插入缓存时,插入一个已输入其关键元素的对象。例如,我会将 CustomerID 和 CustomerLocationID 添加到 orderHeaderObject,然后将其插入到文档缓存中。当您这样做时,Acumatica 验证将触发,所有默认值将在您尝试编辑它们之前设置在您的文档中。您的线级对象也是如此,我认为这就是您遇到这两个错误的原因。另外,我注意到您试图为一些计算字段设置值。如果可能的话,我会尽量让这些按设计计算。