Closed Elitearcanist closed 11 months ago
I am not using po.receiveAll() because it doesn't quite work for my use case.
@Elitearcanist would you be willing to submit a PR to address the issue?
Consider this first:
There are many cases where the API does not do any error checking before submitting data to the server. I think this applies to most commands.
Functions like "Receive All" have basic logic, because they should be straight forward to use and shouldn't break down in simple cases.
I think it makes sense to leave the logic and input checking mostly to the server. Otherwise, the logic will have to be implemented twice - which is a mess to keep track of.
In your case, you could check the amount remaining first in your script, or catch and handle the error.
On 9 August 2023 01:51:00 CEST, Oliver @.***> wrote:
@Elitearcanist would you be willing to submit a PR to address the issue?
-- Reply to this email directly or view it on GitHub: https://github.com/inventree/inventree-python/issues/200#issuecomment-1670457986 You are receiving this because you are subscribed to this thread.
Message ID: @.***>
@miggland makes a good point here. The error message received here does contain all the information you need! I agree that wherever possible we should lean on the validation performed by the server
Fair enough closing...
I have some code that receives line items one by one on a purchase order.
(This is very simplified but shows the point)
I noticed however that if it tried to receive a line item that had already been fully received it would create an API error.
requests.exceptions.HTTPError: {'detail': 'Error occurred during API request', 'method': 'POST', 'status_code': 400, 'body': '{"items":[{"quantity":["Quantity must be greater than zero"]}]}', 'params': {'format': 'json'}, 'data': {'items': [{'line_item': 8828, 'supplier_part': 4147, 'quantity': 0.0, 'status': 10, 'location': 6, 'batch_code': '99999999', 'serial_numbers': ''}], 'location': 6}}
(removed url and token for security)The API wont accept receiving 0 stock but the python library does. It would make sense to have the library skip over these receive requests. I also noticed that po.recieveAll() does check that a line item has more than 0 to receive
Steps to Recreate: