Try ERPNext Buy Support Partners Foundation

Error when inserting Timesheet using the API

When we try to insert a Timesheet record using the rest-api we get a mandatory field error.
Below is the exact error.

{{"_server_messages":"["{\“message\”: \“Error: Data missing in table: Time Sheets\”}"]",“exc”:"[“Traceback (most recent call last):\n File \”/home/benjamien/frappe-bench/apps/frappe/frappe/app.py\", line 60, in application\n response = frappe.api.handle()\n File \"/home/benjamien/frappe-bench/apps/frappe/frappe/api.py\", line 127, in handle\n \“data\”: frappe.get_doc(data).insert().as_dict()\n File \"/home/benjamien/frappe-bench/apps/frappe/frappe/model/document.py\", line 230, in insert\n self._validate()\n File \"/home/benjamien/frappe-bench/apps/frappe/frappe/model/document.py\", line 460, in _validate\n self._validate_mandatory()\n File \"/home/benjamien/frappe-bench/apps/frappe/frappe/model/document.py\", line 740, in _validate_mandatory\n name=self.name))\nfrappe.exceptions.MandatoryError: [Timesheet, TS-2020-00001]: time_logs\n"]"}}

The json data looks to be correct and contains the time_logs. See below.
What could be the problem ? Is this a bug ?

{{“data”:{“title”:“HR-EMP-00002”,“time_logs”:[{“project”:"GVE ",“activity_type”:“Uitvoering”,“task”:“TASK-2019-00002”,“from_time”:“2020-02-01 12:59”}],“employee”:“HR-EMP-00002”,“start_date”:“2020-02-01”}}}

Anyone ? I’m really stuck.

You should be able to create Timesheet if these fields are present. These are the mandatory fields except project and task.

{"company": "XYZ", "employee": "HR-EMP-00002", "time_logs": [{ "activity_type": "Research", "from_time": "2020-01-03 15:33:00", "company": "XYZ", "project": "ABC Project", "task": "TASK-2019-00001" }] }

This is my json string

{{“data”:{“company”:“BETOWARE BV”,“title”:“HR-EMP-00002”,“employee”:“HR-EMP-00002”,“start_date”:“2020-03-01”,“time_logs”:[{“project”:“GVE”,“activity_type”:“Uitvoering”,“task”:“TASK-2019-00002”,“from_time”:“2020-03-01 11:35”,“company”:“BETOWARE BV” }]}}}

I think this includes all mandatory fields.
But I keep getting the same response.

{{“exc”:"[“Traceback (most recent call last):\n File \”/home/benjamien/frappe-bench/apps/frappe/frappe/app.py\", line 60, in application\n response = frappe.api.handle()\n File \"/home/benjamien/frappe-bench/apps/frappe/frappe/api.py\", line 127, in handle\n \“data\”: frappe.get_doc(data).insert().as_dict()\n File \"/home/benjamien/frappe-bench/apps/frappe/frappe/model/document.py\", line 230, in insert\n self._validate()\n File \"/home/benjamien/frappe-bench/apps/frappe/frappe/model/document.py\", line 460, in _validate\n self._validate_mandatory()\n File \"/home/benjamien/frappe-bench/apps/frappe/frappe/model/document.py\", line 740, in _validate_mandatory\n name=self.name))\nfrappe.exceptions.MandatoryError: [Timesheet, TS-2020-00002]: time_logs\n"]","_server_messages":"["{\“message\”: \“Error: Data missing in table: Time Sheets\”}"]"}}

Can anyone tell me why this isn’t working ?

Is this a bug or am I doing something wrong ?

I cannot get this to work, so I created a whitelist method that does the same thing.
That works well.