Browse Source

Field validation in MSTI

version2
venkata akhil 1 year ago
parent
commit
d43123cc87
  1. 6
      smart_service/apis/v2/master.py
  2. 3
      smart_service/phase_2/doctype/feature_finder/feature_finder.js
  3. 3
      smart_service/phase_2/doctype/feature_finder/feature_finder.json
  4. 3
      smart_service/phase_2/doctype/feature_finder_images/feature_finder_images.json
  5. 3
      smart_service/phase_2/doctype/feature_finder_master/feature_finder_master.json
  6. 3
      smart_service/phase_2/doctype/qwik_service/qwik_service.json
  7. 44
      smart_service/phase_2/doctype/special_tool_information/special_tool_information.js
  8. 8
      smart_service/phase_2/doctype/special_tool_information/special_tool_information.json
  9. 29
      smart_service/phase_2/doctype/special_tool_information/special_tool_information.py
  10. 2
      smart_service/phase_2/doctype/training_information_master/training_information_master.js
  11. 3
      smart_service/transactions/doctype/publish/publish.json
  12. 4
      smart_service/transactions/doctype/publish/publish.py

6
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

3
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'
},
// {

3
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",

3
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",

3
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",

3
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",

44
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("<b>Tool Name:</b> Only <b> 100 </b> characters are allowed")
frappe.validated = false;
} else {
if (alphanum.test(field_name) === true) {
} else if (field_name) {
frappe.throw(__("<b>Tool Name:</b> Enter letter or alpha numeric characters only."));
frappe.validated = false;
}
}
} else {
frappe.throw("<b>Tool Names:</b> Single character not allowed")
frappe.validated = false;
}
}
}

8
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",

29
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

2
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("<b>Training Information Master:</b> Only <b> 100 </b> characters are allowed")
frappe.validated = false;
} else {

3
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",

4
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':

Loading…
Cancel
Save