Browse Source

MST file Validation

version2
venkata akhil 12 months ago
parent
commit
18db2c99b1
  1. 11
      smart_service/masters/doctype/role_master/role_master.json
  2. 50
      smart_service/phase_2/doctype/special_tool_information/special_tool_information.js
  3. 12
      smart_service/phase_2/doctype/special_tool_information/special_tool_information.json
  4. 113
      smart_service/phase_2/doctype/special_tool_information/special_tool_information.py
  5. 2
      smart_service/transactions/doctype/publish/publish.py

11
smart_service/masters/doctype/role_master/role_master.json

@ -1,5 +1,4 @@
{ {
"_liked_by": "[\"Administrator\"]",
"actions": [], "actions": [],
"allow_rename": 1, "allow_rename": 1,
"autoname": "format:{role}", "autoname": "format:{role}",
@ -23,7 +22,8 @@
"in_list_view": 1, "in_list_view": 1,
"in_standard_filter": 1, "in_standard_filter": 1,
"label": "Role", "label": "Role",
"reqd": 1 "reqd": 1,
"set_only_once": 1
}, },
{ {
"fieldname": "column_break_ffrrr", "fieldname": "column_break_ffrrr",
@ -48,7 +48,10 @@
{ {
"fieldname": "skill_id", "fieldname": "skill_id",
"fieldtype": "Data", "fieldtype": "Data",
"label": "Skill Id" "in_list_view": 1,
"label": "Skill Id",
"reqd": 1,
"set_only_once": 1
}, },
{ {
"fieldname": "section_break_bkwnr", "fieldname": "section_break_bkwnr",
@ -57,7 +60,7 @@
], ],
"index_web_pages_for_search": 1, "index_web_pages_for_search": 1,
"links": [], "links": [],
"modified": "2023-08-16 14:50:58.500228", "modified": "2023-10-09 12:02:23.458890",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Masters", "module": "Masters",
"name": "Role Master", "name": "Role Master",

50
smart_service/phase_2/doctype/special_tool_information/special_tool_information.js

@ -18,7 +18,7 @@ frappe.ui.form.on('Special Tool Information', {
validate:function(frm){ validate:function(frm){
check_field_character(frm.doc.tool_name) check_field_character(frm.doc.tool_name)
check_field_character(frm.doc.aggregate_name) check_field_character(frm.doc.aggregate_name)
//for display_order // for display_order
if (frm.doc.display_order == null || typeof (frm.doc.display_order) == String) { if (frm.doc.display_order == null || typeof (frm.doc.display_order) == String) {
frappe.validated = false; frappe.validated = false;
frm.doc.display_order = original_display_order frm.doc.display_order = original_display_order
@ -33,7 +33,7 @@ frappe.ui.form.on('Special Tool Information', {
cur_frm.refresh_fields("display_order") cur_frm.refresh_fields("display_order")
frappe.throw(__("<b>Display Order:</b> Zero or Negative values not allowed.")); frappe.throw(__("<b>Display Order:</b> Zero or Negative values not allowed."));
} }
//For Display Order // For Display Order
cur_frm.refresh_fields("display_order") cur_frm.refresh_fields("display_order")
if (frm.doc.display_order && frm.doc.name && !frm.is_new()) { if (frm.doc.display_order && frm.doc.name && !frm.is_new()) {
//***check if there is same display_order //***check if there is same display_order
@ -57,15 +57,15 @@ frappe.ui.form.on('Special Tool Information', {
}, 5); }, 5);
}); });
} else { } else {
if (frm.doc.display_order >= vehicle_count) { // if (frm.doc.display_order >= vehicle_count) {
let display_vehicle_count = vehicle_count - 1; // let display_vehicle_count = vehicle_count - 1;
msgprint('There are only ' + display_vehicle_count + " " + frm.doc.doctype); // msgprint('There are only ' + display_vehicle_count + " " + frm.doc.doctype);
frappe.validated = false; // frappe.validated = false;
} // }
} }
}); });
} }
frm.doc.name = frm.doc.vehicle + "-" + frm.doc.tool_type + "-" + frm.doc.category + "-" + frm.doc.aggregate_name
if (frm.doc.image) { if (frm.doc.image) {
frappe.call({ frappe.call({
@ -94,7 +94,7 @@ frappe.ui.form.on('Special Tool Information', {
} }
if (frm.doc.aggregate_image) { if (frm.doc.aggregate_image) {
frappe.call({ frappe.call({
method: "smart_service.phase_2.doctype.special_tool_information.special_tool_information.file_validation", method: "smart_service.phase_2.doctype.special_tool_information.special_tool_information.file_validation1",
args: { args: {
image: frm.doc.aggregate_image, image: frm.doc.aggregate_image,
name: frm.doc.name, name: frm.doc.name,
@ -119,10 +119,10 @@ frappe.ui.form.on('Special Tool Information', {
} }
if (frm.doc.pdf){ if (frm.doc.pdf){
frappe.call({ frappe.call({
method: "smart_service.phase_2.doctype.special_tool_information.special_tool_information.file_validation1", method: "smart_service.phase_2.doctype.special_tool_information.special_tool_information.file_validation2",
args: { args: {
image: frm.doc.pdf, pdf: frm.doc.pdf
name:frm.doc.name // name:frm.doc.name
}, },
callback: function (r) { callback: function (r) {
console.log(r.message, "r.message") console.log(r.message, "r.message")
@ -130,6 +130,7 @@ frappe.ui.form.on('Special Tool Information', {
if (r.message[1] == 1) { if (r.message[1] == 1) {
frappe.validated = false; frappe.validated = false;
frappe.msgprint("Invalid file type") frappe.msgprint("Invalid file type")
frm.reload_doc()
} }
} }
@ -139,7 +140,7 @@ frappe.ui.form.on('Special Tool Information', {
} }
if (frm.doc.video){ if (frm.doc.video){
frappe.call({ frappe.call({
method: "smart_service.phase_2.doctype.special_tool_information.special_tool_information.file_validation1", method: "smart_service.phase_2.doctype.special_tool_information.special_tool_information.file_validation3",
args: { args: {
video: frm.doc.video, video: frm.doc.video,
name:frm.doc.name name:frm.doc.name
@ -189,7 +190,23 @@ frappe.ui.form.on('Special Tool Information', {
}, },
}); });
function teb_validation(frm){ function teb_validation(frm){
if(frm.is_new()){
cur_frm.clear_table("instructions");
cur_frm.refresh_fields('instructions');
cur_frm.refresh_fields()
}
// frm.reload_doc()
if(frm.doc.category == "TEB"){ if(frm.doc.category == "TEB"){
//to nullify the table
if (frm.doc.instructions && frm.doc.instructions.length > 0) {
cur_frm.clear_table("instructions");
cur_frm.refresh_fields('instructions');
cur_frm.refresh_fields();
}
//to set df property to child readonly based on main doc //to set df property to child readonly based on main doc
cur_frm.refresh_fields("instructions"); cur_frm.refresh_fields("instructions");
var df = frappe.meta.get_docfield("Instructions", "content", cur_frm.doc.name); var df = frappe.meta.get_docfield("Instructions", "content", cur_frm.doc.name);
@ -207,7 +224,6 @@ function teb_validation(frm){
is_pdf=0 is_pdf=0
} }
}) })
} }
if(is_pdf==1){ if(is_pdf==1){
var childTable = cur_frm.add_child("instructions"); var childTable = cur_frm.add_child("instructions");
@ -220,12 +236,6 @@ function teb_validation(frm){
//end //end
} }
//to nullify the table
if (frm.doc.Instructions && frm.doc.Instructions.length > 0) {
cur_frm.clear_table("Instructions");
cur_frm.refresh_fields('instructions');
cur_frm.refresh_fields();
}
} }

12
smart_service/phase_2/doctype/special_tool_information/special_tool_information.json

@ -45,8 +45,7 @@
"fieldtype": "Int", "fieldtype": "Int",
"in_list_view": 1, "in_list_view": 1,
"label": "Display Order", "label": "Display Order",
"non_negative": 1, "non_negative": 1
"reqd": 1
}, },
{ {
"fieldname": "my_id", "fieldname": "my_id",
@ -98,7 +97,6 @@
"in_list_view": 1, "in_list_view": 1,
"in_standard_filter": 1, "in_standard_filter": 1,
"label": "Aggregate Name", "label": "Aggregate Name",
"reqd": 1,
"set_only_once": 1 "set_only_once": 1
}, },
{ {
@ -108,7 +106,6 @@
"in_standard_filter": 1, "in_standard_filter": 1,
"label": "Category", "label": "Category",
"options": "Maintenance Service Category(MS)\nRepair Service Category(RS)\nOverhaul Service Category(OS)\nTEB", "options": "Maintenance Service Category(MS)\nRepair Service Category(RS)\nOverhaul Service Category(OS)\nTEB",
"reqd": 1,
"set_only_once": 1 "set_only_once": 1
}, },
{ {
@ -129,8 +126,7 @@
"fieldname": "instructions", "fieldname": "instructions",
"fieldtype": "Table", "fieldtype": "Table",
"label": "Instructions", "label": "Instructions",
"options": "Instructions", "options": "Instructions"
"reqd": 1
}, },
{ {
"fieldname": "tool_type", "fieldname": "tool_type",
@ -139,7 +135,6 @@
"in_standard_filter": 1, "in_standard_filter": 1,
"label": "Tool Type", "label": "Tool Type",
"options": "New Tool\nCarry Over", "options": "New Tool\nCarry Over",
"reqd": 1,
"set_only_once": 1 "set_only_once": 1
}, },
{ {
@ -170,6 +165,7 @@
"options": "image" "options": "image"
}, },
{ {
"depends_on": "eval:doc.category !='TEB';",
"fieldname": "tool_name", "fieldname": "tool_name",
"fieldtype": "Data", "fieldtype": "Data",
"in_list_view": 1, "in_list_view": 1,
@ -187,7 +183,7 @@
], ],
"index_web_pages_for_search": 1, "index_web_pages_for_search": 1,
"links": [], "links": [],
"modified": "2023-10-06 16:54:21.868057", "modified": "2023-10-09 13:48:14.303807",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Phase-2", "module": "Phase-2",
"name": "Special Tool Information", "name": "Special Tool Information",

113
smart_service/phase_2/doctype/special_tool_information/special_tool_information.py

@ -32,39 +32,73 @@ class SpecialToolInformation(Document):
@frappe.whitelist() @frappe.whitelist()
def file_validation(image, name, value=None): def file_validation(image, name):
from smart_service.apis.utils import check_png_ext, check_img_ext, check_zip_ext, check_pdf_ext, checking_image, details_of_image, check_mp4_ext, get_file_size from smart_service.apis.utils import check_png_ext, check_img_ext, check_zip_ext, check_pdf_ext, details_of_image, checking_image
if image: if image:
res = check_img_ext(image) res = check_img_ext(image)
res1 = check_png_ext(image) res1 = check_png_ext(image)
if res == True: if res == True or res1 == True:
(width, height, size) = details_of_image(image) width, height, size = details_of_image(image)
if value == 'image':
if width > 1280 or height > 720 or size > 1*1024 and image: if width > 1280 or height > 720 or size > 1*1024 and image:
val = checking_image(image, 'Special Tool Information', val = checking_image(image, "Special Tool Information", "image", name)
value, name)
if val == True: if val == True:
return (False, 2) return False, 2
else: else:
return True return True
else:
val = checking_image(image, "Special Tool Information", "image", name)
if res == False:
ret = res
else:
ret = res1
return ret, 1
if value == 'aggregate_image': @frappe.whitelist()
def file_validation1(image, name):
from smart_service.apis.utils import check_png_ext, check_img_ext, check_zip_ext, check_pdf_ext, details_of_image, checking_image
if image:
res = check_img_ext(image)
res1 = check_png_ext(image)
if res == True or res1 == True:
width, height, size = details_of_image(image)
if width > 1280 or height > 720 or size > 1*1024 and image: if width > 1280 or height > 720 or size > 1*1024 and image:
val = checking_image(image, 'Special Tool Information', val = checking_image(image, "Special Tool Information", "aggregate_image", name)
value, name)
if val == True: if val == True:
return (False, 2) return False, 2
else: else:
return True return True
else: else:
val = checking_image( val = checking_image(image, "Special Tool Information", "aggregate_image", name)
image, 'Special Tool Information', value, name)
if res == False: if res == False:
ret = res ret = res
else: else:
ret = res1 ret = res1
return ret, 1 return ret, 1
@frappe.whitelist()
def file_validation2(pdf = None):
from smart_service.apis.utils import check_png_ext, check_img_ext, check_zip_ext, check_pdf_ext, get_file_size
if pdf:
res = check_pdf_ext(pdf)
if res == True:
size = get_file_size(pdf)
if size > 1*1024 and pdf:
return True, 1
else:
return False, 2
@frappe.whitelist()
def file_validation3(video=None):
from smart_service.apis.utils import check_pdf_ext, details_of_image, checking_image, get_file_size,check_mp4_ext
if video:
res = check_mp4_ext(video)
if res == True:
size = get_file_size(video)
if size > 100*1024 and video:
return True, 1
else:
return False, 2
@frappe.whitelist() @frappe.whitelist()
def file_validation_child(name, value=None): def file_validation_child(name, value=None):
@ -120,46 +154,11 @@ def file_validation_child(name, value=None):
return (ret, d['idx']) return (ret, d['idx'])
# def delete_file(file_url, attached_to_doctype, attached_to_field, docname, is_child=None):
@frappe.whitelist() # image_name = frappe.db.get_list("File", fields={"name"}, filters={"file_url": file_url,
def file_validation1(image,video, name, value=None): # "attached_to_doctype": attached_to_doctype,
from smart_service.apis.utils import check_pdf_ext,details_of_image,check_mp4_ext,get_file_size # "attached_to_field": attached_to_field,
if image: # "attached_to_name": docname})
res = check_pdf_ext(image) # if len(image_name) > 0:
if res == True: # frappe.delete_doc('File', image_name[0]['name'])
(width,height,size) = details_of_image(image) # return True
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
if video:
res1=check_mp4_ext(video)
if res1== True:
video_size_mb = get_file_size(video)
if video_size_mb > 100:
val= delete_file(video)
return (False,2)
else:
val = delete_file(video, 'Special Tool Information',
"video", name)
if res == False:
ret = res1
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/transactions/doctype/publish/publish.py

@ -208,6 +208,7 @@ def update_publish_mapping(vehicle, variant, language, module, publish_type):
frappe.db.sql( frappe.db.sql(
f"""UPDATE `tabModule Publish Mapping` set repairservice_check_sheet='1' and publish_type='1' where name ='{d['name']}'""", as_dict=1) f"""UPDATE `tabModule Publish Mapping` set repairservice_check_sheet='1' and publish_type='1' where name ='{d['name']}'""", as_dict=1)
frappe.db.commit() frappe.db.commit()
else: else:
pub_data = frappe.db.get_list('Module Publish Mapping', filters={ pub_data = frappe.db.get_list('Module Publish Mapping', filters={
"vehicle": vehicle, "vehicle": vehicle,
@ -233,6 +234,7 @@ def update_publish_mapping(vehicle, variant, language, module, publish_type):
elif module == 'Feature Finder': elif module == 'Feature Finder':
doc.feature_finder = 1 doc.feature_finder = 1
elif module == 'QWIK Service'
doc.save() doc.save()

Loading…
Cancel
Save