Copying a sales line to new line, serialised  Topic is solved

Discussions relating to Jiwa 7 plugin development, and the Jiwa 7 API.

Copying a sales line to new line, serialised

Postby DannyC » Tue Jul 01, 2025 7:08 pm

Currently writing a plugin which will be copying (or really just adding) a sales order line for what would most typically be serialised stock.
Just the quantities will be different but it's essential the new line comes from the same SOH line, i.e the same batch/serialNo.

Currently I have
Code: Select all
object newKey = "";
salesOrder.SalesOrderLines.AddInventoryItem(soLine.InventoryID, JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrderLineCollection.SalesOrderLineInventorySeedTypes.e_SalesOrderLineInventoryID, ref newKey);
JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrderLine newsalesOrderLine = salesOrder.SalesOrderLines[(string)newKey];
newsalesOrderLine.UseSerials = false;  //should this stop the batch selection dialog?
newsalesOrderLine.QuantityOrdered = newQty;

but the batch selection screen comes up when I don't want it to. I just want it to automatically add a new line, same partno, same SOHID as the source line.
I want to be able to set my own calculated quantity (worked out earlier in the plugin) but that's about it.
What's the trick for that?

I am holding the SOHID in case I need it from the source line. I know the below code would only be reliable if there is just 1 details line, but for now I am OK with that.
Code: Select all
string SOHID = "";
foreach(JiwaFinancials.Jiwa.JiwaSales.SalesOrder.LineDetail soLineDetail in soLine.LineDetails)
{
   SOHID = soLineDetail.SOHID;
}
User avatar
DannyC
Senpai
Senpai
 
Posts: 718
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 31

Re: Copying a sales line to new line, serialised

Postby SBarnes » Wed Jul 02, 2025 8:28 am

Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1696
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 191

Re: Copying a sales line to new line, serialised

Postby DannyC » Wed Jul 02, 2025 12:50 pm

Bugger, that doesn't work.

Maybe because it was way back in 2017 and probably applicable to the version at that time? Anyway, no good for 7.2.1.
No compilation errors on the plugin but I still get the serial selection dialog.

EDIT: Ah ha! ForceInventorySelection is ticked.
So I am now doing
Code: Select all
salesOrder.SystemSettings.ForceInventorySelection = false;
//my code
salesOrder.SystemSettings.ForceInventorySelection = true;


All good for now :D
Last edited by DannyC on Wed Jul 02, 2025 12:58 pm, edited 1 time in total.
User avatar
DannyC
Senpai
Senpai
 
Posts: 718
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 31

Re: Copying a sales line to new line, serialised

Postby Mike.Sheen » Wed Jul 02, 2025 12:54 pm

DannyC wrote:Bugger, that doesn't work.

Maybe because it was way back in 2017 and probably applicable to the version at that time? Anyway, no good for 7.2.1.
No compilation errors on the plugin but I still get the serial selection dialog.


It should still work - I know we have customisations for 7.2.1 which rely on the overriding of the serial selection behaviour using the SalesOrderSerialStockSelectionType property.

I'll test that plugin now on demo data and let you know how it goes for me.
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2583
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 807

Re: Copying a sales line to new line, serialised

Postby Mike.Sheen » Wed Jul 02, 2025 12:57 pm

Mike.Sheen wrote:I'll test that plugin now on demo data and let you know how it goes for me.


Yep - works fine for me.

My test was to add part 1089-J-SN in demo data (which is serialised) to a sales order BEFORE importing the plugin - serial dialog appears as expected - then import the plugin, save, exit and log back in and repeat my test - no dialog.
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2583
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 807

Re: Copying a sales line to new line, serialised

Postby DannyC » Wed Jul 02, 2025 1:00 pm

You're too quick, which is very appreciated.

I have edited my prior post. I found that ForceInventorySelection is set to true.
Just flicking that off, doing my code and flicking it on again did the trick.

In the newly added line, do I just grab the newLineDetails and set each property?
Like Quantity, SOHID, Bin etc?
User avatar
DannyC
Senpai
Senpai
 
Posts: 718
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 31

Re: Copying a sales line to new line, serialised  Topic is solved

Postby Mike.Sheen » Wed Jul 02, 2025 1:13 pm

DannyC wrote:In the newly added line, do I just grab the newLineDetails and set each property?
Like Quantity, SOHID, Bin etc?


The sales order line has a property, LineDetails - which is a collection of LineDetail - create a new LineDetail for each stock record and add that to the LineDetails collection, and then invoke the ReAdjustDelivered method of the line once you're done messing with the LineDetails so it adjusts the quantity and backorder amount and stuff.

You need to be sure when manually providing the line details that you don't try to take more stock than available - we only check that on save to ensure no IN_SOH.QuantityLeft goes into negative - but you can mess up whilst adding / editing / removing from the LineDetails collection and we won't let you know until save.

Our DTO_Deserialise mothod of the LineDetails collection (which the API uses, but you can also leverage), does a lot of checking and heavy lifting for you which would let you avoid getting the linedetails wrong - so you can for instance just provide a serial no and a quantity and it'll do the rest, or you can provide a serial no AND A bin location and quantity, and it will work it all out - or just a bin location and a quantity and it will get the appropriate stock. It also lets you provide a IN_SOH.LinkID and quantity and it'll correctly adjust the line details - which it sounds like that's what you want.

But if you're sure you aren't going to mess up the line details, just do it like you described.
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2583
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 807

Re: Copying a sales line to new line, serialised

Postby DannyC » Wed Jul 02, 2025 3:37 pm

Awesome Mike.

Thx for the tips.
User avatar
DannyC
Senpai
Senpai
 
Posts: 718
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 31

Re: Copying a sales line to new line, serialised

Postby Scott.Pearce » Wed Jul 02, 2025 4:02 pm

DannyC wrote:Bugger, that doesn't work.
Code: Select all
salesOrder.SystemSettings.ForceInventorySelection = false;
//my code
salesOrder.SystemSettings.ForceInventorySelection = true;



You should be preserving the original state of that setting, not just assuming it is "true".

Code: Select all
bool oldForceInventorySelection = salesOrder.SystemSettings.ForceInventorySelection

try
{
  salesOrder.SystemSettings.ForceInventorySelection = false;
  //Your code
}
finally
{
  salesOrder.SystemSettings.ForceInventorySelection = oldForceInventorySelection;
}
Scott Pearce
Senior Analyst/Programmer
Jiwa Financials
User avatar
Scott.Pearce
Senpai
Senpai
 
Posts: 765
Joined: Tue Feb 12, 2008 11:27 am
Location: New South Wales, Australia
Topics Solved: 230


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 1 guest