Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: REST API "/mos/{id}/produceandconsume" not working and have a confuse behavior #28481

Closed
Humml87 opened this issue Feb 27, 2024 · 8 comments
Labels
Bug This is a bug (something does not work as expected)

Comments

@Humml87
Copy link
Contributor

Humml87 commented Feb 27, 2024

Bug

Hi,.
either I don't understand the API function or it doesn't work.
I tried now a few hours...

id: 21
request_data:
{ "inventorylabel": "Produce and consume using API", "inventorycode": "PRODUCEAPI-YY-MM-DD", "autoclose": 1, "arraytoconsume": [{ "objectid": "203", "fk_warehouse": "677", "qty": "1" }], "arraytoproduce": [] }

The data origin:
image

I hope anyone can help me, its very import for my project.
Thank you together!

Best regards
Christian

Environment Version

17...19...

Environment OS

Ubuntu

Environment Web server

No response

Environment PHP

8.2

Environment Database

mariaDB

Environment URL(s)

http://localhost/dolibarr/htdocs/api/index.php/mos/{ID}/produceandconsume

Expected and actual behavior

No response

Steps to reproduce the behavior

No response

Attached files

No response

@Humml87 Humml87 added the Bug This is a bug (something does not work as expected) label Feb 27, 2024
@JonBendtsen
Copy link
Contributor

What happens when you send the json to the API, and which of the sub parts of the API are you using? Would you mind posting a picture?

@Humml87
Copy link
Contributor Author

Humml87 commented Feb 27, 2024

Hallo JonBendtsen,

the result is:
{ "error": { "code": 500, "message": "Internal Server Error" }, "debug": { "source": "api_mos.class.php:544 at call stage", "stages": { "success": [ "get", "route", "negotiate", "authenticate", "validate" ], "failure": [ "call", "message" ] } } }

image

I found some logical errors:
image
... if a MoLine with already consumed Products are deleted, sometimes the consumed Products don't delete from the DB.

I think its necessary to refactor the ConsumAndProduce:

  • mo_production.php => Move the actions for ConsumAndProduce to a new function in "MoLine" Class.
  • api_mos.class.php => then refactor...

@mdeweerd Hi, you make a PR #26805 at 23.11.2023. You know how the API-function work?
@eldy what you think about this function und structure? I think currently we have no way to call a common valid function from the mo_production.php und the api_mos.class.php

Best Regards
Christian

@Humml87
Copy link
Contributor Author

Humml87 commented Feb 27, 2024

... which of the sub parts of the API are you using? ...

Sorry, what you are meaning?
In generally i use the moste API-Methodes from the MRP-Module.
Best regards Christian

@mdeweerd
Copy link
Contributor

@Humml87 I made a PR because there was an obvious error.

Unit tests seem to be missing for this and I think that is a good way to have a common understanding/demonstration of issues.

I refactored the test case code for APIs a bit so that it can be shared and started a TestAPIMosTest.php #28484 .

Feel free to propose updates - maybe this code could be integrated in the develop branch as a non integrated test (i.e., not adding the test to AllTests.php) - I do not have the intention to work on the API.

@Humml87
Copy link
Contributor Author

Humml87 commented Feb 28, 2024

Some API functions for MRP are necessary
api_mos.class.php:

  • POST => /mos/{id}/lines
  • DELETE => /mos/{id}/lines/{id}
  • GET => /mos/{id}/lines
  • POST => /mos/{id}/lines/{id}/consumeorproduce

Following change is required
mo.class.php (Mo-Class):

  • Add function "hasAllConsumedAndProduced" (<- this is for "autoclose")
  • Add function "setStatusAsProduced" (<- close Mo)

mo.class.php (MoLine-Class):

  • Add function "consumeOrProduce"

Refactor
mo_production.php:
Lines from 237 to 447
... in_array($action, array('confirm_consumeorproduce', 'confirm_consumeandproduceall') ...
to use the class functions from Mo and MoLine classes.

@Humml87
Copy link
Contributor Author

Humml87 commented Feb 28, 2024

@mdeweerd its not a new Feature, so i think its right to make a PR for branch 19.0?

@mdeweerd
Copy link
Contributor

@Humml87 If you are talking about the test case, it has been accepted on the develop branch. I think you can backport it to 19.0 but you'll have to get the CommonClassTest.php, the AbstractRestAPITest.php and RestAPIMosTest.php .

I would do a (cd test/phpunit ; git checkout develop THREE-CLASS-FILES) and commit.
I think all 3 of them are new in 19.0 so that should be fine IMHO.

@JonBendtsen
Copy link
Contributor

Sorry, what you are meaning?
In generally i use the moste API-Methodes from the MRP-Module.
Best regards Christian

What I meant was that in the API's I use I can use GET, POST, PUT, DELETE, and for some I can do it for all entries of some sort or for a single numbered or single referenced entry.

For orders which I use it can be all orders (with a given project id). Or for Thirdparties where I look it up using the email address. But I can also get orders by order ID which I use when they pay.

So that is what I meant with sub parts.

  • GET, POST, PUT, DELETE
  • ALL
  • by id
  • by reference

Humml87 added a commit to HUSCH-GmbH/dolibarr that referenced this issue Feb 29, 2024
Humml87 added a commit to HUSCH-GmbH/dolibarr that referenced this issue Mar 1, 2024
Humml87 added a commit to HUSCH-GmbH/dolibarr that referenced this issue Mar 2, 2024
Humml87 added a commit to HUSCH-GmbH/dolibarr that referenced this issue Mar 2, 2024
Humml87 added a commit to HUSCH-GmbH/dolibarr that referenced this issue May 28, 2024
@Humml87 Humml87 closed this as completed Jun 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This is a bug (something does not work as expected)
Projects
None yet
Development

No branches or pull requests

3 participants