diff --git a/custom_ui/api/db/clients.py b/custom_ui/api/db/clients.py index 42fc0d8..59281a9 100644 --- a/custom_ui/api/db/clients.py +++ b/custom_ui/api/db/clients.py @@ -92,15 +92,29 @@ def get_client(client_name): ["custom_installation_address", "=", address.address_title], ["custom_address", "=", address.address_title] ], limit_page_length=100) - + contacts = [] + onsite_meetings = [] + quotations = [] + sales_orders = [] projects = [frappe.get_doc("Project", proj["name"]) for proj in project_names] - projects_data = [] + sales_invoices = [] + payment_entries = [] + jobs = [] + for project in projects: + job = [] + jobs.append(job) customer = frappe.get_doc("Customer", customer_name) # get all associated data as needed return { "address": address, "customer": customer, - "projects": projects + "contacts": contacts, + "jobs": jobs, + "sales_invoices": sales_invoices, + "payment_entries": payment_entries, + "sales_orders": sales_orders, + "quotations": quotations, + "onsite_meetings": onsite_meetings, } diff --git a/frontend/src/api.js b/frontend/src/api.js index 5213589..af21730 100644 --- a/frontend/src/api.js +++ b/frontend/src/api.js @@ -1,4 +1,4 @@ -import DataUtils from "./utils"; +import ApiUtils from "./apiUtils"; const ZIPPOPOTAMUS_BASE_URL = "https://api.zippopotam.us/us"; const FRAPPE_PROXY_METHOD = "custom_ui.api.proxy.request"; @@ -12,12 +12,12 @@ const FRAPPE_GET_CLIENT_METHOD = "custom_ui.api.db.clients.get_client"; class Api { static async request(frappeMethod, args = {}) { - args = DataUtils.toSnakeCaseObject(args); + args = ApiUtils.toSnakeCaseObject(args); const request = { method: frappeMethod, args }; console.log("DEBUG: API - Request Args: ", request); try { let response = await frappe.call(request); - response = DataUtils.toCamelCaseObject(response); + response = ApiUtils.toCamelCaseObject(response); console.log("DEBUG: API - Request Response: ", response); return response.message; } catch (error) { @@ -32,7 +32,7 @@ class Api { } static async getClientDetails(clientName) { - return await this.request(FRAPPE_GET_CLIENT_DETAILS_METHOD, { clientName }); + return await this.request(FRAPPE_GET_CLIENT_METHOD, { clientName }); } static async getJobDetails() { diff --git a/frontend/src/apiUtils.js b/frontend/src/apiUtils.js new file mode 100644 index 0000000..b60491b --- /dev/null +++ b/frontend/src/apiUtils.js @@ -0,0 +1,53 @@ +class ApiUtils { + static toSnakeCaseObject(obj) { + console.log("Converting to snake case:", obj); + const newObj = Object.entries(obj).reduce((acc, [key, value]) => { + const snakeKey = key.replace(/[A-Z]/g, (match) => "_" + match.toLowerCase()); + if (key === "sorting") { + value = value + ? value.map((item) => { + const [field, order] = item; + const snakeField = field.replace( + /[A-Z]/g, + (match) => "_" + match.toLowerCase(), + ); + return [snakeField, order]; + }) + : value; + } + if (Array.isArray(value)) { + value = value.map((item) => { + return Object.prototype.toString.call(item) === "[object Object]" + ? this.toSnakeCaseObject(item) + : item; + }); + } else if (Object.prototype.toString.call(value) === "[object Object]") { + value = this.toSnakeCaseObject(value); + } + acc[snakeKey] = value; + return acc; + }, {}); + return newObj; + } + + static toCamelCaseObject(obj) { + const newObj = Object.entries(obj).reduce((acc, [key, value]) => { + const camelKey = key.replace(/_([a-z])/g, (match, p1) => p1.toUpperCase()); + // check if value is an array + if (Array.isArray(value)) { + value = value.map((item) => { + return Object.prototype.toString.call(item) === "[object Object]" + ? this.toCamelCaseObject(item) + : item; + }); + } else if (Object.prototype.toString.call(value) === "[object Object]") { + value = this.toCamelCaseObject(value); + } + acc[camelKey] = value; + return acc; + }, {}); + return newObj; + } +} + +export default ApiUtils; diff --git a/frontend/src/utils.js b/frontend/src/utils.js index d30fb35..711c271 100644 --- a/frontend/src/utils.js +++ b/frontend/src/utils.js @@ -1694,56 +1694,6 @@ class DataUtils { "WI", "WY", ]; - - static toSnakeCaseObject(obj) { - console.log("Converting to snake case:", obj); - const newObj = Object.entries(obj).reduce((acc, [key, value]) => { - const snakeKey = key.replace(/[A-Z]/g, (match) => "_" + match.toLowerCase()); - if (key === "sorting") { - value = value - ? value.map((item) => { - const [field, order] = item; - const snakeField = field.replace( - /[A-Z]/g, - (match) => "_" + match.toLowerCase(), - ); - return [snakeField, order]; - }) - : value; - } - if (Array.isArray(value)) { - value = value.map((item) => { - return Object.prototype.toString.call(item) === "[object Object]" - ? this.toSnakeCaseObject(item) - : item; - }); - } else if (Object.prototype.toString.call(value) === "[object Object]") { - value = this.toSnakeCaseObject(value); - } - acc[snakeKey] = value; - return acc; - }, {}); - return newObj; - } - - static toCamelCaseObject(obj) { - const newObj = Object.entries(obj).reduce((acc, [key, value]) => { - const camelKey = key.replace(/_([a-z])/g, (match, p1) => p1.toUpperCase()); - // check if value is an array - if (Array.isArray(value)) { - value = value.map((item) => { - return Object.prototype.toString.call(item) === "[object Object]" - ? this.toCamelCaseObject(item) - : item; - }); - } else if (Object.prototype.toString.call(value) === "[object Object]") { - value = this.toCamelCaseObject(value); - } - acc[camelKey] = value; - return acc; - }, {}); - return newObj; - } } export default DataUtils;