Page 1 of 1

Copying a sales line to new line, serialised

PostPosted: Tue Jul 01, 2025 7:08 pm
by DannyC
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;
}

Re: Copying a sales line to new line, serialised

PostPosted: Wed Jul 02, 2025 8:28 am
by SBarnes

Re: Copying a sales line to new line, serialised

PostPosted: Wed Jul 02, 2025 12:50 pm
by DannyC
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

Re: Copying a sales line to new line, serialised

PostPosted: Wed Jul 02, 2025 12:54 pm
by Mike.Sheen
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.

Re: Copying a sales line to new line, serialised

PostPosted: Wed Jul 02, 2025 12:57 pm
by Mike.Sheen
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.

Re: Copying a sales line to new line, serialised

PostPosted: Wed Jul 02, 2025 1:00 pm
by DannyC
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?

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

PostPosted: Wed Jul 02, 2025 1:13 pm
by Mike.Sheen
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.

Re: Copying a sales line to new line, serialised

PostPosted: Wed Jul 02, 2025 3:37 pm
by DannyC
Awesome Mike.

Thx for the tips.

Re: Copying a sales line to new line, serialised

PostPosted: Wed Jul 02, 2025 4:02 pm
by Scott.Pearce
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;
}