From a685f83804c787c7a37e1e4d23d570bed749eb88 Mon Sep 17 00:00:00 2001 From: Deepak Barwal Date: Tue, 9 Jan 2024 10:49:02 +0530 Subject: [PATCH] refactor: removed client scripts --- autoinscribe/fixtures/client_script.json | 24 ------------------------ autoinscribe/fixtures/server_script.json | 2 +- autoinscribe/hooks.py | 1 - 3 files changed, 1 insertion(+), 26 deletions(-) delete mode 100644 autoinscribe/fixtures/client_script.json diff --git a/autoinscribe/fixtures/client_script.json b/autoinscribe/fixtures/client_script.json deleted file mode 100644 index becbcde..0000000 --- a/autoinscribe/fixtures/client_script.json +++ /dev/null @@ -1,24 +0,0 @@ -[ - { - "docstatus": 0, - "doctype": "Client Script", - "dt": "Contact", - "enabled": 1, - "modified": "2024-01-02 16:56:34.580365", - "module": "AutoInscribe", - "name": "Extract Text From Image & Fill Contact Details", - "script": "let once_refreshed = false\nlet error_encountered = false\n\nfrappe.ui.form.on('Contact', {\n custom_upload_image(frm) {\n if(frm.selected_doc.custom_upload_image) {\n frappe.call({\n method: \"autoinscribe.inscribe.api.extract_text_from_img\",\n args: {\n 'img_url': window.location.href.split('/app')[0] + frm.selected_doc.custom_upload_image\n },\n callback(res) {\n const resArr = res.message.split('\\n')\n\n const first_name = resArr[0].split(':')[1].trim()\n const middle_name = resArr[1].split(':')[1].trim()\n const last_name = resArr[2].split(':')[1].trim()\n first_name !== \"NULL\" && frm.set_value('first_name', first_name)\n middle_name !== \"NULL\" && frm.set_value('middle_name', middle_name)\n last_name !== \"NULL\" && frm.set_value('last_name', last_name)\n const company_name = resArr[8].split(':')[1].trim()\n company_name !== \"NULL\" && frm.set_value('company_name', company_name)\n const designation = resArr[5].split(':')[1].trim()\n designation !== \"NULL\" && frm.set_value('designation', designation)\n const email_ids = resArr[7].split(':')[1].trim().split(',')\n email_ids.forEach(email => {\n email.trim() !== \"NULL\" && frm.add_child('email_ids', {\n email_id: email.trim()\n })\n })\n frm.refresh_field('email_ids')\n const contact_numbers = resArr[6].split(':')[1].trim().split(',')\n contact_numbers.forEach(phone_no => {\n phone_no.trim() !== \"NULL\" && frm.add_child('phone_nos', {\n phone: phone_no.trim()\n })\n })\n frm.refresh_field('phone_nos')\n \n let gender = resArr[3].split(':')[1].trim()\n gender = gender.charAt(0).toUpperCase() + gender.slice(1)\n frappe.db.exists(\"Gender\", gender).then(gender_exists => {\n if(gender_exists) {\n frm.set_value(\"gender\", gender)\n } \n })\n frm.refresh_field('gender')\n let salutation = resArr[4].split(':')[1].trim()\n salutation = salutation.charAt(0).toUpperCase() + salutation.slice(1, salutation[salutation.length-1] === '.' ? salutation.length-1 : salutation.length)\n frappe.db.exists(\"Salutation\", salutation).then(salutation_exists => {\n if (salutation_exists) {\n frm.set_value(\"salutation\", salutation)\n }\n })\n frm.refresh_field('salutation')\n \n const address = resArr[10].split(':')[1].trim()\n if (address !== \"NULL\") {\n frappe.call({\n method: \"autoinscribe.inscribe.api.create_address\",\n args: {\n 'address': address\n },\n callback(res) {\n if(res.message) {\n frm.set_value('address', `${address}-Office`)\n }\n }\n }) \n }\n },\n error: function(r) {\n error_encountered = true\n },\n })\n }\n },\n refresh(frm) {\n if (error_encountered && !once_refreshed) {\n frappe.msgprint(\"Please enter a valid OpenAI API key in AutoInscribe Settings\", title=\"Missing OpenAI API Key\", indicator=\"red\")\n once_refreshed = true\n }\n }\n})", - "view": "Form" - }, - { - "docstatus": 0, - "doctype": "Client Script", - "dt": "Lead", - "enabled": 1, - "modified": "2024-01-02 16:51:45.882969", - "module": "AutoInscribe", - "name": "Extract Text From Image & Fill Lead Details", - "script": "frappe.ui.form.on('Lead', {\n custom_upload_business_card(frm) {\n if(frm.selected_doc.custom_upload_business_card) {\n frappe.call({\n method: \"autoinscribe.inscribe.api.extract_text_from_img\",\n args: {\n 'img_url': window.location.href.split('/app')[0] + frm.selected_doc.custom_upload_business_card\n },\n callback(res) {\n const resArr = res.message.split('\\n')\n\n const first_name = resArr[0].split(':')[1].trim()\n const middle_name = resArr[1].split(':')[1].trim()\n const last_name = resArr[2].split(':')[1].trim()\n first_name !== \"NULL\" && frm.set_value('first_name', first_name)\n middle_name !== \"NULL\" && frm.set_value('middle_name', middle_name)\n last_name !== \"NULL\" && frm.set_value('last_name', last_name)\n const company_name = resArr[8].split(':')[1].trim()\n company_name !== \"NULL\" && frm.set_value('company_name', company_name)\n const designation = resArr[5].split(':')[1].trim()\n designation !== \"NULL\" && frm.set_value('job_title', designation)\n const email_ids = resArr[7].split(':')[1].trim().split(',')\n frm.set_value('email_id', email_ids[0] || '')\n\n const mobile_no = resArr[11].split(':')[1].trim()\n mobile_no !== \"NULL\" && frm.set_value('mobile_no', mobile_no)\n const phone = resArr[12].split(':')[1].trim()\n phone !== \"NULL\" && frm.set_value('phone', phone)\n \n const possibleGenders = [\"Male\", \"Female\", \"Prefer not to say\", \"Non-Conforming\", \"Genderqueer\", \"Transgender\", \"Other\"]\n let gender = resArr[3].split(':')[1].trim()\n gender = gender.charAt(0).toUpperCase() + gender.slice(1)\n gender !== \"NULL\" && possibleGenders.includes(gender) && frm.set_value(\"gender\", gender)\n frm.refresh_field('gender')\n \n const possibleSalutations = [\"Mr\", \"Ms\", \"Mx\", \"Dr\", \"Mrs\", \"Madam\", \"Miss\", \"Master\", \"Prof\"]\n let salutation = resArr[4].split(':')[1].trim()\n salutation = salutation.charAt(0).toUpperCase() + salutation.slice(1, salutation[salutation.length-1] === '.' ? salutation.length-1 : salutation.length)\n salutation !== \"NULL\" && possibleSalutations.includes(salutation) && frm.set_value(\"salutation\", salutation)\n frm.refresh_field('salutation')\n \n let website = resArr[9].split(':')[1].trim()\n frm.set_value(\"website\", website)\n \n const city = resArr[13].split(':')[1].trim()\n city !== \"NULL\" && frm.set_value('city', city)\n \n const state = resArr[14].split(':')[1].trim()\n state !== \"NULL\" && frm.set_value('state', state)\n \n const country = resArr[15].split(':')[1].trim()\n frappe.db.exists(\"Country\", country).then(country_exists => {\n if (country_exists) {\n frm.set_value(\"country\", country)\n } else {\n frm.set_value(\"country\", \"\")\n }\n })\n frm.refresh_field('country')\n },\n })\n }\n },\n})", - "view": "Form" - } -] \ No newline at end of file diff --git a/autoinscribe/fixtures/server_script.json b/autoinscribe/fixtures/server_script.json index 2082ec9..6b13c76 100644 --- a/autoinscribe/fixtures/server_script.json +++ b/autoinscribe/fixtures/server_script.json @@ -9,7 +9,7 @@ "doctype_event": "Before Save", "enable_rate_limit": 0, "event_frequency": "All", - "modified": "2024-01-05 14:32:56.543165", + "modified": "2024-01-09 10:46:38.224414", "module": "AutoInscribe", "name": "AutoInscribe Contact Error", "rate_limit_count": 5, diff --git a/autoinscribe/hooks.py b/autoinscribe/hooks.py index 5cc20e6..dc5c05d 100644 --- a/autoinscribe/hooks.py +++ b/autoinscribe/hooks.py @@ -233,7 +233,6 @@ fixtures = [ { - "doctype": "Client Script", "doctype": "Server Script", }, {