refactor: use reportview get_count implementation

Count reported should be according to permissions
This commit is contained in:
Ankush Menat 2023-09-11 11:36:04 +05:30
parent 47538f7601
commit dfcb69ab21
3 changed files with 13 additions and 10 deletions

View file

@ -80,6 +80,14 @@ def document_list(doctype: str):
return frappe.call(frappe.client.get_list, doctype, **frappe.form_dict)
def count(doctype: str) -> int:
from frappe.desk.reportview import get_count
frappe.form_dict.doctype = doctype
return get_count()
def create_doc(doctype: str):
data = frappe.form_dict
data.pop("doctype", None)
@ -155,15 +163,8 @@ def run_doc_method(method: str, document: dict[str, Any] | str, kwargs=None):
return response
def count(doctype: str) -> int:
from frappe.desk.reportview import get_count
# TODO: Rewrite
frappe.form_dict.doctype = doctype
return get_count()
url_rules = [
# RPC calls
Rule("/method/login", endpoint=login),
Rule("/method/logout", endpoint=logout),
Rule("/method/ping", endpoint=frappe.ping),
@ -174,6 +175,7 @@ url_rules = [
endpoint=lambda: frappe.call(run_doc_method, **frappe.form_dict),
),
Rule("/method/<doctype>/<method>", endpoint=handle_rpc_call),
# Document level APIs
Rule("/document/<doctype>", methods=["GET"], endpoint=document_list),
Rule("/document/<doctype>", methods=["POST"], endpoint=create_doc),
Rule("/document/<doctype>/<path:name>/", methods=["GET"], endpoint=read_doc),
@ -184,6 +186,7 @@ url_rules = [
methods=["GET", "POST"],
endpoint=execute_doc_method,
),
# Collection level APIs
Rule("/doctype/<doctype>/meta", methods=["GET"], endpoint=frappe.get_meta),
Rule("/doctype/<doctype>/count", methods=["GET"], endpoint=count),
]

View file

@ -65,7 +65,7 @@ def execute(doctype, *args, **kwargs):
def get_form_params():
"""Stringify GET request parameters."""
"""parse GET request parameters."""
data = frappe._dict(frappe.local.form_dict)
clean_params(data)
validate_args(data)

View file

@ -152,7 +152,7 @@ class TestResourceAPI(FrappeAPITestCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
for _ in range(10):
for _ in range(20):
doc = frappe.get_doc({"doctype": "ToDo", "description": frappe.mock("paragraph")}).insert()
cls.GENERATED_DOCUMENTS.append(doc.name)
frappe.db.commit()