Solved

Open Purchase Order Form and add Detail lines from Inventory

  • 1 March 2023
  • 7 replies
  • 212 views

Userlevel 1
Badge

Hello,

I am working on a customization for the Stock Items Inventory. I am trying to add an action to the page that would create a new Purchase order and fill in the vendor fields and insert a line into the Details section for the Inventory Item. I have been able to open the form, and add the vendor, but cannot figure out how to insert the detail line.

So I want to take the part that is circled in red in the first image and create a line where the red is in the second image.

icon

Best answer by Leonardo Justiniano 2 March 2023, 16:33

View original

7 replies

Userlevel 6
Badge +4

Hi @DoShawhan 

 

Assuming you are invoking the POOrderEntry graph, this is an example to insert new lines on the PO

...

public PXAction<InventoryItem> UpdatePOExample;
[PXUIField(DisplayName = "Update PO Example", Enabled = true)]
[PXButton(CommitChanges = true)]
protected virtual IEnumerable updatePOExample(PXAdapter adapter)
{
InventoryItem item = .... // From Adapter or Context

POOrderEntry poGraph = CreateInstance<POOrderEntry>();

// Get a PO Header
POOrder po = ...

poGraph.Document.Current = po;
...
// Header Fields
...

poGraph.Document.Update(po);
poGraph.Actions.PressSave();


POLine poline = poGraph.Transactions.Insert(new POLine() {InventoryID = item.InventoryID });

poGraph.Transactions.Current = poline;
...
// Line Fields
...

poGraph.Transactions.Update(poline);
poGraph.Actions.PressSave();

...
}

...

I hope this skeleton of code helps

Userlevel 1
Badge

@Leonardo Justiniano

 

Where do I put this code? I am in the customization Project Editor and I am not sure where to put it.

I created a new business method but am not sure if this is where I put it.

Also, where you have the comment to get a PO Header, how do I specify that I want a new PO?

Thanks

 

Userlevel 6
Badge +4

Hi @DoShawhan 

Now I have more insights about what you want, you have to extend the Inventory Item screen to add the button. By inspecting the page you can get the graph class:

 

this is the whole snippet:

namespace PX.Objects.IN
{
public class InventoryItemMaint_Extension : PXGraphExtension<PX.Objects.IN.InventoryItemMaint>
{
#region Event Handlers
public PXAction<InventoryItem> UpdatePOExample;
[PXUIField(DisplayName = "Update PO Example", Enabled = true)]
[PXButton(CommitChanges = true)]
protected virtual IEnumerable updatePOExample(PXAdapter adapter)
{
InventoryItem item = Base.Item.Current;

POOrderEntry poGraph = CreateInstance<POOrderEntry>();

// Create a PO
POOrder po = poGraph.Document.Insert(new POOrder() { OrderType = POOrderType.POOrderType.RegularOrder });
poGraph.Document.Current = po;
...
// Header Fields
...

poGraph.Document.Update(po);
poGraph.Actions.PressSave();


POLine poline = poGraph.Transactions.Insert(new POLine() {InventoryID = item.InventoryID });

poGraph.Transactions.Current = poline;
...
// Line Fields
...

poGraph.Transactions.Update(poline);
poGraph.Actions.PressSave();

...
}
#endregion
}
}

Hope is more clear

Userlevel 1
Badge

@Leonardo Justiniano 

I tried your suggestion and now I am getting this error.

Here is the code.

Any Ideas?

Thanks

Userlevel 6
Badge +4

Hi @DoShawhan 

You are missing

return adapter.Get();

As you can see it returns an IEnumerable

Any PXAction delegate receives and returns an adapter. The code I provided is just a description. I omitted some lines.

Userlevel 1
Badge

@Leonardo Justiniano 

 

This works fine now. However, I have another error. We have fields in the InventoryItem DAC that are custom defined. However, when I try to access this field I get this error:

Here is the DAC:

And the code where I am calling it:

Thanks for your help. I am relatively new to this and your help has been incredible.

Userlevel 6
Badge +4

Hi @DoShawhan 

To access the extended fields you get the extension from the cache:

 

...
InventoryItem item = Base.Item.Current;

//Assuming this is your extension class
InventoryItemExt itemExt = Base.Item.GetExtension<InventoryItemExt>(item);
...
itemExt.AMMinOrdQty = ... ;

 

Also in BQL you have to put the extended class to refer to the extended fields.

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