From d43123cc87f6d1238212dfc252fae9d59f5e01f8 Mon Sep 17 00:00:00 2001 From: venkata akhil Date: Fri, 6 Oct 2023 14:56:16 +0530 Subject: [PATCH] Field validation in MSTI --- smart_service/apis/v2/master.py | 6 ++- .../doctype/feature_finder/feature_finder.js | 3 +- .../feature_finder/feature_finder.json | 3 +- .../feature_finder_images.json | 3 +- .../feature_finder_master.json | 3 +- .../doctype/qwik_service/qwik_service.json | 3 +- .../special_tool_information.js | 44 ++++++++++++++++++- .../special_tool_information.json | 8 ++-- .../special_tool_information.py | 29 ++++++++++++ .../training_information_master.js | 2 +- .../transactions/doctype/publish/publish.json | 3 +- .../transactions/doctype/publish/publish.py | 4 +- 12 files changed, 98 insertions(+), 13 deletions(-) diff --git a/smart_service/apis/v2/master.py b/smart_service/apis/v2/master.py index 3a56848..db4b6d4 100644 --- a/smart_service/apis/v2/master.py +++ b/smart_service/apis/v2/master.py @@ -245,7 +245,11 @@ def new_publish1(): pass elif module == 'Mahindra Special Tool Information': - pass + with open(BASE_PATH + str(vehicle) + '-special_tool_information.json') as outfile: + data = json.load(outfile) + data = data['data'] + filter_json = filter_publish_json(data, variant) + data = filter_json elif module == 'PDI Inspection': pass diff --git a/smart_service/phase_2/doctype/feature_finder/feature_finder.js b/smart_service/phase_2/doctype/feature_finder/feature_finder.js index d786754..f02455c 100644 --- a/smart_service/phase_2/doctype/feature_finder/feature_finder.js +++ b/smart_service/phase_2/doctype/feature_finder/feature_finder.js @@ -1010,7 +1010,8 @@ function custom_tab_html(frm) { label: 'Image', fieldname: 'image', fieldtype: 'Attach', - default: image_dialog_value.image + default: image_dialog_value.image, + description: 'Upload *.png(1920x1080 pixel) 1 MB' }, // { diff --git a/smart_service/phase_2/doctype/feature_finder/feature_finder.json b/smart_service/phase_2/doctype/feature_finder/feature_finder.json index 4dc9f19..2ff5bcb 100644 --- a/smart_service/phase_2/doctype/feature_finder/feature_finder.json +++ b/smart_service/phase_2/doctype/feature_finder/feature_finder.json @@ -79,6 +79,7 @@ "set_only_once": 1 }, { + "description": "Upload *.png(1920x1080 pixel) 1 MB", "fieldname": "feature_finder_images", "fieldtype": "Table", "hidden": 1, @@ -208,7 +209,7 @@ ], "index_web_pages_for_search": 1, "links": [], - "modified": "2023-10-03 10:31:40.954062", + "modified": "2023-10-06 11:11:09.968138", "modified_by": "Administrator", "module": "Phase-2", "name": "Feature Finder", diff --git a/smart_service/phase_2/doctype/feature_finder_images/feature_finder_images.json b/smart_service/phase_2/doctype/feature_finder_images/feature_finder_images.json index fa6a5d2..0bdfc00 100644 --- a/smart_service/phase_2/doctype/feature_finder_images/feature_finder_images.json +++ b/smart_service/phase_2/doctype/feature_finder_images/feature_finder_images.json @@ -13,6 +13,7 @@ ], "fields": [ { + "description": "Upload *.png(1920x1080 pixel) 1 MB", "fieldname": "image", "fieldtype": "Attach", "in_list_view": 1, @@ -39,7 +40,7 @@ "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2023-09-01 14:52:57.774369", + "modified": "2023-10-06 11:51:56.748496", "modified_by": "Administrator", "module": "Phase-2", "name": "Feature Finder Images", diff --git a/smart_service/phase_2/doctype/feature_finder_master/feature_finder_master.json b/smart_service/phase_2/doctype/feature_finder_master/feature_finder_master.json index baab5c0..b79aaea 100644 --- a/smart_service/phase_2/doctype/feature_finder_master/feature_finder_master.json +++ b/smart_service/phase_2/doctype/feature_finder_master/feature_finder_master.json @@ -28,6 +28,7 @@ "set_only_once": 1 }, { + "description": "Upload *.pdf 1 MB", "fieldname": "feature_pdf", "fieldtype": "Attach", "label": "Compare PDF" @@ -76,7 +77,7 @@ ], "index_web_pages_for_search": 1, "links": [], - "modified": "2023-09-26 10:50:41.276397", + "modified": "2023-10-06 11:50:42.654103", "modified_by": "Administrator", "module": "Phase-2", "name": "Feature Finder Master", diff --git a/smart_service/phase_2/doctype/qwik_service/qwik_service.json b/smart_service/phase_2/doctype/qwik_service/qwik_service.json index 354e314..72441eb 100644 --- a/smart_service/phase_2/doctype/qwik_service/qwik_service.json +++ b/smart_service/phase_2/doctype/qwik_service/qwik_service.json @@ -115,6 +115,7 @@ "reqd": 1 }, { + "description": "Upload *.pdf 1 MB", "fieldname": "pdf", "fieldtype": "Attach", "label": "PDF" @@ -143,7 +144,7 @@ ], "index_web_pages_for_search": 1, "links": [], - "modified": "2023-09-28 10:59:46.184734", + "modified": "2023-10-06 12:00:17.840332", "modified_by": "Administrator", "module": "Phase-2", "name": "Qwik Service", diff --git a/smart_service/phase_2/doctype/special_tool_information/special_tool_information.js b/smart_service/phase_2/doctype/special_tool_information/special_tool_information.js index ff1f1b8..95ebe79 100644 --- a/smart_service/phase_2/doctype/special_tool_information/special_tool_information.js +++ b/smart_service/phase_2/doctype/special_tool_information/special_tool_information.js @@ -16,6 +16,8 @@ frappe.ui.form.on('Special Tool Information', { }, validate:function(frm){ + check_field_character(frm.doc.tool_name) + check_field_character(frm.doc.aggregate_name) //for display_order if (frm.doc.display_order == null || typeof (frm.doc.display_order) == String) { frappe.validated = false; @@ -64,7 +66,7 @@ frappe.ui.form.on('Special Tool Information', { }); } frm.doc.name = frm.doc.vehicle + "-" + frm.doc.tool_type + "-" + frm.doc.category + "-" + frm.doc.aggregate_name - + // field validation if (frm.doc.image) { frappe.call({ method: "smart_service.phase_2.doctype.special_tool_information.special_tool_information.file_validation", @@ -115,6 +117,26 @@ frappe.ui.form.on('Special Tool Information', { } }) } + if (frm.doc.pdf){ + frappe.call({ + method: "smart_service.phase_2.doctype.special_tool_information.special_tool_information.file_validation1", + args: { + image: frm.doc.pdf, + name:frm.doc.name + }, + callback: function (r) { + console.log(r.message, "r.message") + if (r.message && r.message[0] == false) { + if (r.message[1] == 1) { + frappe.validated = false; + frappe.msgprint("Invalid file type") + } + + } + + } + }) + } }, category: function (frm, cdt, cdn) { @@ -252,3 +274,23 @@ frappe.ui.form.on('Instructions', { refresh_field("instructions"); }, }) +function check_field_character(field_name) { + if (field_name) { + var alphanum = /^[a-zA-Z]+/; + if (field_name.length > 1) { + if (field_name.length > 100) { + frappe.throw("Tool Name: Only 100 characters are allowed") + frappe.validated = false; + } else { + if (alphanum.test(field_name) === true) { + } else if (field_name) { + frappe.throw(__("Tool Name: Enter letter or alpha numeric characters only.")); + frappe.validated = false; + } + } + } else { + frappe.throw("Tool Names: Single character not allowed") + frappe.validated = false; + } + } +} \ No newline at end of file diff --git a/smart_service/phase_2/doctype/special_tool_information/special_tool_information.json b/smart_service/phase_2/doctype/special_tool_information/special_tool_information.json index caecece..d848eb2 100644 --- a/smart_service/phase_2/doctype/special_tool_information/special_tool_information.json +++ b/smart_service/phase_2/doctype/special_tool_information/special_tool_information.json @@ -27,8 +27,7 @@ "image_preview", "my_id", "section_break_e91wx", - "instructions", - "image_preview" + "instructions" ], "fields": [ { @@ -114,12 +113,14 @@ }, { "depends_on": "eval:doc.category !='TEB';", + "description": "Upload *.png(1920x1080 pixel) 1 MB", "fieldname": "aggregate_image", "fieldtype": "Attach Image", "label": "Aggregate Image" }, { "depends_on": "eval:doc.category !='TEB';", + "description": "Upload *.pdf 1 MB", "fieldname": "pdf", "fieldtype": "Attach", "label": "PDF" @@ -142,6 +143,7 @@ "set_only_once": 1 }, { + "description": "Upload *.png(1920x1080 pixel) 1 MB", "fieldname": "image", "fieldtype": "Attach Image", "label": "Image" @@ -184,7 +186,7 @@ ], "index_web_pages_for_search": 1, "links": [], - "modified": "2023-10-04 17:45:57.350572", + "modified": "2023-10-06 12:05:44.002461", "modified_by": "Administrator", "module": "Phase-2", "name": "Special Tool Information", diff --git a/smart_service/phase_2/doctype/special_tool_information/special_tool_information.py b/smart_service/phase_2/doctype/special_tool_information/special_tool_information.py index 28b7b56..8fe53ac 100644 --- a/smart_service/phase_2/doctype/special_tool_information/special_tool_information.py +++ b/smart_service/phase_2/doctype/special_tool_information/special_tool_information.py @@ -115,3 +115,32 @@ def file_validation_child(name, value=None): +@frappe.whitelist() +def file_validation1(image, name, value=None): + from smart_service.apis.utils import check_png_ext, check_img_ext,check_pdf_ext,details_of_image + if image: + res = check_pdf_ext(image) + if res == True: + (width,height,size) = details_of_image(image) + + if size > 1*1024 and image: + val = delete_file(image) + if val == True: + return (False, 2) + else: + return True + else: + val = delete_file(image, 'Special Tool Information', + "pdf", name) + if res == False: + ret = res + return ret, 1 + +def delete_file(file_url, attached_to_doctype, attached_to_field, docname, is_child=None): + image_name = frappe.db.get_list("File", fields={"name"}, filters={"file_url": file_url, + "attached_to_doctype": attached_to_doctype, + "attached_to_field": attached_to_field, + "attached_to_name": docname}) + if len(image_name) > 0: + frappe.delete_doc('File', image_name[0]['name']) + return True \ No newline at end of file diff --git a/smart_service/phase_2/doctype/training_information_master/training_information_master.js b/smart_service/phase_2/doctype/training_information_master/training_information_master.js index 36ac496..7882fd1 100644 --- a/smart_service/phase_2/doctype/training_information_master/training_information_master.js +++ b/smart_service/phase_2/doctype/training_information_master/training_information_master.js @@ -14,7 +14,7 @@ function check_field_character(field_name) { if (field_name) { var alphanum = /^[a-zA-Z]+/; if (field_name.length > 1) { - if (field_name.length > 50) { + if (field_name.length > 100) { frappe.throw("Training Information Master: Only 100 characters are allowed") frappe.validated = false; } else { diff --git a/smart_service/transactions/doctype/publish/publish.json b/smart_service/transactions/doctype/publish/publish.json index eebf368..c3d9b0e 100644 --- a/smart_service/transactions/doctype/publish/publish.json +++ b/smart_service/transactions/doctype/publish/publish.json @@ -135,6 +135,7 @@ "read_only": 1 }, { + "depends_on": "eval:doc.publish_module !='Special Tool'", "fieldname": "language", "fieldtype": "Link", "in_filter": 1, @@ -391,7 +392,7 @@ "index_web_pages_for_search": 1, "is_submittable": 1, "links": [], - "modified": "2023-09-26 17:30:50.606211", + "modified": "2023-10-06 11:58:47.207441", "modified_by": "Administrator", "module": "Transactions", "name": "Publish", diff --git a/smart_service/transactions/doctype/publish/publish.py b/smart_service/transactions/doctype/publish/publish.py index c22f4d2..bef006e 100644 --- a/smart_service/transactions/doctype/publish/publish.py +++ b/smart_service/transactions/doctype/publish/publish.py @@ -59,10 +59,12 @@ class Publish(Document): def on_submit(self): if self.docstatus == 1 and self.publish_status == 'To Publish' and self.publish_module == 'Repair service' and self.publish_type == 'Internal': - repair_checksheet_publish(self.vehicle, self.vehicle_id, + repair_res_obj=repair_checksheet_publish(self.vehicle, self.vehicle_id, self.language, self.publish_type, self.release_description, self.variant, self.repiar_checksheet_publish_docs) + + update_publish_status = frappe.db.sql( """update `tabPublish` set publish_status='Published' where name='{0}'""".format(self.name)) if self.docstatus == 1 and self.publish_status == 'To Publish' and self.publish_module == 'Qwik Service' and self.publish_type == 'Internal':