Solved

Custom feature problem: Create Blanket Sales order button

  • 19 July 2023
  • 2 replies
  • 75 views

I have created a shortcut button for Create Blanket Sales Order on the Sales Order Menu and on the Customers three dots menu.

This feature is used to: from creating a customer to creating a blanket sales order in a single click.

However, I have a problem: when I click the "Create Blanket Sales Order" button, it goes to the Sales Orders page then I notice that the "Create Child Orders" button is not displayed.


Also it works properly if I select the order type manually.
 

Please help me see if I am wrong or missing any part of the code. Thank you everyone for your help.

Here is the code
----------------------------------------------------------------------------------------------------------
namespace PX.Objects.AR
{
 
    [PXCacheName("SOOrder Extension")]
    public class SOOrderExt : PXCacheExtension<SOOrder>
    {
        #region UsrCreateChildOrders
        [PXBool]
        [PXUIField(DisplayName = "Create Child Orders")]
        public virtual bool? UsrCreateChildOrders { get; set; }
        public abstract class usrCreateChildOrders : PX.Data.BQL.BqlBool.Field<usrCreateChildOrders> { }
        #endregion
    }
  
          
     public class CustomerMaint_Extension : PXGraphExtension<CustomerMaint>
    {
        public PXAction<Customer> newBlanketSalesOrder;

        [PXUIField(DisplayName = "Create Blanket Sales Order")]
        [PXButton]
        public virtual IEnumerable NewBlanketSalesOrder(PXAdapter adapter)
        {
            Customer customer = Base.BAccount.Current;
            if (customer != null && customer.BAccountID > 0L)
            {
                SOOrderEntry soEntry = PXGraph.CreateInstance<SOOrderEntry>();
                soEntry.Clear();
                SOOrder newDoc = (SOOrder)soEntry.Document.Cache.Insert();
                newDoc.BranchID = null;
                soEntry.Document.Cache.SetValueExt<SOOrder.customerID>(newDoc, customer.BAccountID);
                soEntry.Document.Cache.SetValueExt<SOOrder.orderType>(newDoc, "BL"); // Set SOOrder Type here
                newDoc.ContactID = customer.PrimaryContactID < 0L ? null : customer.PrimaryContactID;
                soEntry.customer.Current.CreditRule = customer.CreditRule;
                if (soEntry.Document.Current.FreightTaxCategoryID != null)
                {
                    SOOrder createdOrder = (SOOrder)soEntry.Document.Cache.CreateCopy(soEntry.Document.Current);
                    soEntry.Document.Current.FreightTaxCategoryID = null;
                    soEntry.Document.Update(createdOrder);
                }

                // Update the order type configuration check
                var orderType = PXSelect<SOOrderType,
                    Where<SOOrderType.orderType, Equal<Required<SOOrderType.orderType>>>>.
                    Select(Base, "BL").FirstOrDefault();

                if (orderType != null && orderType.GetItem<SOOrderType>().Behavior != "BL")
                {
                    throw new PXException("The specified Order Type is not configured as a Blanket Order Type.");
                }

                throw new PXRedirectRequiredException(soEntry, "SO301000");
            }
            return adapter.Get();
        }
    }        
 }
​​​​​​​

icon

Best answer by Zoltan Febert 19 July 2023, 19:25

View original

2 replies

Userlevel 6
Badge +3

Hi @VinhPhat68,

I refactored your code a bit and tested it in 22R207, it worked as expected.

        [PXUIField(DisplayName = "Create Blanket Sales Order")]
[PXButton]
public virtual IEnumerable NewBlanketSalesOrder(PXAdapter adapter)
{
// Update the order type configuration check
var orderType = (SOOrderType)PXSelect<SOOrderType,
Where<SOOrderType.orderType, Equal<Required<SOOrderType.orderType>>>>.
Select(Base, "BL").FirstOrDefault();

if (orderType != null && orderType.Behavior != "BL")
{
throw new PXException("The specified Order Type is not configured as a Blanket Order Type.");
}

var customer = Base.BAccount.Current;
if (customer != null && customer.BAccountID > 0L)
{
var soEntry = PXGraph.CreateInstance<SOOrderEntry>();

var newDoc = soEntry.Document.Insert(new SOOrder
{
BranchID = null,
CustomerID = customer.BAccountID,
OrderType = "BL",
ContactID = customer.PrimaryContactID < 0L ? null : customer.PrimaryContactID,
FreightTaxCategoryID = null
});

throw new PXRedirectRequiredException(soEntry, "SO301000");
}
return adapter.Get();
}

 

Hi @VinhPhat68,

I refactored your code a bit and tested it in 22R207, it worked as expected.

        [PXUIField(DisplayName = "Create Blanket Sales Order")]
[PXButton]
public virtual IEnumerable NewBlanketSalesOrder(PXAdapter adapter)
{
// Update the order type configuration check
var orderType = (SOOrderType)PXSelect<SOOrderType,
Where<SOOrderType.orderType, Equal<Required<SOOrderType.orderType>>>>.
Select(Base, "BL").FirstOrDefault();

if (orderType != null && orderType.Behavior != "BL")
{
throw new PXException("The specified Order Type is not configured as a Blanket Order Type.");
}

var customer = Base.BAccount.Current;
if (customer != null && customer.BAccountID > 0L)
{
var soEntry = PXGraph.CreateInstance<SOOrderEntry>();

var newDoc = soEntry.Document.Insert(new SOOrder
{
BranchID = null,
CustomerID = customer.BAccountID,
OrderType = "BL",
ContactID = customer.PrimaryContactID < 0L ? null : customer.PrimaryContactID,
FreightTaxCategoryID = null
});

throw new PXRedirectRequiredException(soEntry, "SO301000");
}
return adapter.Get();
}

.

 

Hi @zfebert56
Thank you for your help. The above code seems to have worked.

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved