add the possibility to remove a category from a thirdparty

I don't know if there is a good reason for not proposing to unlink a thirdparty from a category but if it is not the case here is a piece of code allowing to remove a category that works for me and seems general enough to be useful to other people.
The new function is inspired from the addCategory function.

PS : This is the first time i'm trying to contribute on github so don't hesitate to tell me if I did something wrong.
This commit is contained in:
Ysandor 2018-02-10 20:38:53 +01:00 committed by GitHub
parent e25bd56e22
commit b48d369258
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -552,7 +552,45 @@ class Thirdparties extends DolibarrApi
return $this->company;
}
/**
* Delete category to a thirdparty
*
* @param int $id Id of thirdparty
* @param array $request_data Request datas
*
* @return mixed
*
* @url POST {id}/deleteCategory
*/
function deleteCategory($id, $request_data = NULL) {
if (!isset($request_data["category_id"]))
throw new RestException(400, "category_id field missing");
$category_id = $request_data["category_id"];
if(! DolibarrApiAccess::$user->rights->societe->creer) {
throw new RestException(401);
}
$result = $this->company->fetch($id);
if( ! $result ) {
throw new RestException(404, 'Thirdparty not found');
}
$category = new Categorie($this->db);
$result = $category->fetch($category_id);
if( ! $result ) {
throw new RestException(404, 'category not found');
}
if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
if( ! DolibarrApi::_checkAccessToResource('category',$category->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
$category->del_type($this->company,'customer');
return $this->company;
}
/**
* Get outstanding proposals of thirdparty