inventree / inventree-python

Python library for communication with inventree via API
https://docs.inventree.org/en/latest/api/python/python/
MIT License
26 stars 34 forks source link

Add sales order shipment #115

Closed miggland closed 2 years ago

miggland commented 2 years ago

Just to let you know I'm working on adding the basic Shipment functionality to the python binding. This is a contribution to #90.

Basic functions include:

This should allow retrieving the allocated items as well.

SchrodingersGat commented 2 years ago

@miggland looks like this has stalled somewhat.. Any further work happening on this one soon?

miggland commented 2 years ago

I had some trouble with the syntax of creating shipments, and a lack of time. I'm just as not as productive as you guys ;) However, it's not completely stalled, just going slow..

SchrodingersGat commented 2 years ago

@miggland looks like there is a pretty critical bug in the current python implementation which is preventing your attempts here to work (as per your discussion in https://github.com/inventree/InvenTree/discussions/3256).

Basically, for the POST method we use data=... rather than json=... - this causes the data sent to the server to be encoded as a string rather than a JSON object. This appears to be OK for flat requests but nested ones fail!

Looking into this now

SchrodingersGat commented 2 years ago

@miggland once https://github.com/inventree/inventree-python/pull/123 is merged, pull master back in to your branch and you should then be able to get it working

SchrodingersGat commented 2 years ago

@miggland #123 is merged in now so you should be able to proceed with this. LMK if you need any assistance.

matmair commented 2 years ago

@miggland ther are still some style issues but looks great otherwise!

miggland commented 2 years ago

Thanks @matmair . The tests are quite working yet either.. I'll get there though! :D

miggland commented 2 years ago

This should allow retrieving the allocated items as well.

This part is covered by 'allocations' field in Shipment item.

matmair commented 2 years ago

@miggland that is normal for working with a new code base. You are down to 1 error so it is looking good. If you require assistance feel free to ping inventree/maintainer inventree/triage

miggland commented 2 years ago

Finally - I'm going to let you review this now, see if you agree with the approach taken.

There are two ways to allocate Items - the simplest way is via the SalesOrderLineItem.allocateToShipment() method, which should be supplied with at least a Shipment object. Further options include limiting which stock items to choose from.

The alternative, which requires defining the items-dict, is to the use the SalesOrderShipment.allocateItems()

SchrodingersGat commented 2 years ago

@miggland looks like a really solid implementation :)

Only request is to add some unit testing for the SalesOrderLineItem.allocateToShipment method - currently this is not being tested.

SchrodingersGat commented 2 years ago

@miggland LMK if you can add this small extra unit test 👍

miggland commented 2 years ago

I will

miggland commented 2 years ago

I broke another test oops

SchrodingersGat commented 2 years ago

I broke another test oops

Not sure what you did, though.. That test does not seem related to your code at all!

miggland commented 2 years ago

Could one of those stock items have been depleted, and automatically deleted, because I assigned and shipped them?

SchrodingersGat commented 2 years ago

Ah, good call! That is probably what is happening :) Probably best to change the test to >= 19 as we cannot guarantee what order the tests run in.

miggland commented 2 years ago

If you say that's OK, sounds like a simple fix :)

Funnily, this test didn't fail on my test machine.

SchrodingersGat commented 2 years ago

Thanks for the fixes, and for your continued contributions :)

matmair commented 2 years ago

@miggland nice landing! FYI: I am not even running the tests on my machine anymore. Just code, run through the thing you changed and let GitHub do its thing - that way you can work on something else meanwhile 😇