46 lines
1.4 KiB
Python
46 lines
1.4 KiB
Python
import frappe
|
|
import json
|
|
|
|
@frappe.whitelist()
|
|
def get_items(filters=None, fields=None, limit=20, offset=0, order_by="creation desc"):
|
|
import json
|
|
|
|
if isinstance(filters, str):
|
|
filters = json.loads(filters)
|
|
if isinstance(fields, str):
|
|
fields = json.loads(fields)
|
|
if isinstance(limit, str):
|
|
limit = int(limit)
|
|
if isinstance(offset, str):
|
|
offset = int(offset)
|
|
|
|
if not fields:
|
|
fields = ["name", "item_code", "item_name", "item_group", "stock_uom",
|
|
"custom_hospital_name", "custom_serial_no", "custom_date_in",
|
|
"custom_code", "custom_type", "custom_volts", "custom_w",
|
|
"custom_delete_status", "creation", "modified", "owner", "docstatus",
|
|
"custom_technical_department", "disabled", "is_stock_item"]
|
|
|
|
data = frappe.get_all(
|
|
"Item",
|
|
filters=filters or [],
|
|
fields=fields,
|
|
limit_start=offset,
|
|
limit_page_length=limit,
|
|
order_by=order_by,
|
|
ignore_permissions=False
|
|
)
|
|
|
|
total_count = len(frappe.get_all(
|
|
"Item",
|
|
filters=filters or [],
|
|
fields=["name"],
|
|
limit_page_length=0, # 0 = no limit = all
|
|
ignore_permissions=False
|
|
))
|
|
|
|
return {
|
|
"data": data,
|
|
"total": total_count,
|
|
"has_more": (offset + limit) < total_count
|
|
} |