kbancerz / kimai-python

Kimai REST Client for Python
MIT License
7 stars 6 forks source link

Add budget and timeBudget to class CustomerEditForm #1

Closed MPW1412 closed 4 years ago

MPW1412 commented 4 years ago

Hello,

budget and timeBudget are required fields in the Kimai Rest API to create a new customer.

Workaround: Export the CustomerEditForm.to_dict and append the fields.

Best, Matthias

kevinpapst commented 4 years ago

I am certain that they are not required.

First of all: these fields are only visible to users with the budget_customer permission. If you add them for users without that permission, the call will fail with validation error ("this form should not contain extra fields").

And if the users has this permission, then they are not required : https://github.com/kevinpapst/kimai2/blob/master/src/Form/EntityFormTrait.php#L33

MPW1412 commented 4 years ago

Well, I got this when trying to create a customer via the API:

HTTP response headers: HTTPHeaderDict({'Content-Type': 'application/json', 'X-Powered-By': 'PHP/7.4.5', 'Transfer-Encoding': 'chunked', 'Set-Cookie': 'PHPSESSID=nf3f4afk3o7o7kvg1f12qq4one; path=/; HttpOnly', 'Connection': 'keep-alive', 'Cache-Control': 'max-age=0, must-revalidate, private', 'Server': 'nginx', 'pragma': 'no-cache', 'Date': 'Sat, 16 May 2020 23:08:32 GMT', 'Expires': 'Sat, 16 May 2020 23:08:32 GMT'})
HTTP response body: {"code":400,"message":"Validation Failed","errors":{"children":{"name":{},"number":{},"comment":{},"company":{},"vatId":{},"contact":{},"address":{},"country":{},"currency":{},"phone":{},"fax":{},"mobile":{},"email":{},"homepage":{},"timezone":{},"color":{},"budget":{"errors":["This value should not be null."]},"timeBudget":{"errors":["This value should not be null."]},"visible":{}}}}

After adding those fields, it worked.

As those fields exist the CustomerEditForm should be extended by these values, optional or not.

kevinpapst commented 4 years ago

I just tested it: the form behaves wrong in the API, you should not be forced to set a value for these fields. The project and activity endpoint are affected as well.

Introduced by: https://github.com/kevinpapst/kimai2/pull/1658

Can you please raise a bug report in the Kimai repo?

MPW1412 commented 4 years ago

Done: https://github.com/kevinpapst/kimai2/issues/1713