I have created an inventory tracking app, with an edit-post form that allows for users to edit out-going shipments. Part of the form is a drop down selector for the parent cpt which keeps a tally of the total inventory in the container. I set up a one to many relationship between Inbound Transactions (inventory), and outbound transactions (parcels) the slug is 'transaction-parcel'.
I also created function called 'ylstracking_edit_parcel' that takes the outbound shipment, and adds it back into inventory using 'cred_before_save_data' before processing the edit-post form. This way the app has an accurate inventory count before validating the new values in the form and processing the new shipment information.
Everything works without issue, unless you change the parent value to different Inbound Transaction. If it is changed, the inventory is never added back to the original Inbound Transaction thus throwing the numbers off.
This is a fairly complicated issue due to the multiple screens and how the inventory is shown on the front end as well as the hamhanded coding I've put together. So I created a duplicator package and that has a very small amount of sample data and provided it here.
Link to a page where the issue can be seen:
To see the issue you should first open the inventory by PO page (Dashboard->Product Inventory->Inventory By PO) to view the two inbound transactions (Test001 and Test002).
Use the edit shipment page (Outbound Workflow->Edit Shipment) to modify the test shipment. If you simply modify the numbers for the shipment (say from 5 to 2), then refresh the Inventory By PO page, you will see that it edits correctly. But if you change the "Darby PO" field (aka the Inbound Transaction) the inventory numbers do not update at all.
I'm understand that this may not be easy to walk through with this info alone. If needed we can schedule a chat or screenshare so I can walk through with you.
I can install your duplicator package in my localhost.
I assume we are talking about the problem page: hidden link
and post form "Edit Outbound Shipment": hidden link
I have tried it, but there isn't similar problem as you mentioned above: But if you change the "Darby PO" field (aka the Inbound Transaction) the inventory numbers do not update at all.
Here are detail steps. please correct me if there is anything missing:
1) Login as an administrator user
2) Open URL hidden link
in the edit form:
- field "Select Darby PO" choose option "TEST002"
- there isn't any field with name "numbers for the shipment" as you mentioned above, so I have tried to change field "Totes" value change to 2
submit the form
3) open URL hidden link
There isn't any text "inventory numbers", see screenshot: inventory-by-po.JPG
please provide detail steps to duplicate the same problem, thanks
Apologies for not describing the issue very clearly. I'm going to walk through in screens to show you how the issue takes place.
1 - open the hidden link page and you should see two 'Darby PO', TEST001 and TEST002. In my example Test001 has 8 DT80 totes, and 10 DT80 bags (screenshot001).
2 - open hidden link and the Customer PO of JDH001 shows 2 totes of DT80 coming out of the Darby PO TEST001 (screenshot002).
3 - Click JDH001 to enter the edit form hidden link, and change the Darby PO field from TEST001 to TEST002 (screenshot003) and submit the edit.
4 - Go back to or refresh the hidden link page and you'll see that TEST001 still has 8 DT80 totes, and TEST002 still has 10 DT80 totes (screenshot004).
This is the issue, the edit made in step 3 should have added two totes of dt80 back to TEST001 and then subtracted 2 totes of DT80 from TEST002 due to the code in function 'ylstracking_edit_parcel'.
To make this a little more confusing, if you don't change the Darby PO at step 3, and instead just adjust the number of totes or bags the logic holds true and updates correctly. For instance, if I edit JDH001 to have 0 totes but increase bags to 2 (screenshot005), the function places 2 totes of DT80 back into TEST001, and then removes two bags of DT80 from TEST001 (screenshot006).
I hope I was able to articulate that a little better this go around, please let me know what you think may be going on here. I'm going to continue to try to debug on my end. Your help is, as always, greatly appreciated.
3) Compare above two ID values, if they are different, then do as what you want: places 2 totes of DT80 back into TEST001, and then removes two bags of DT80 from TEST001