Browse Source

MST file Validation

version2
venkata akhil 1 year ago
parent
commit
18db2c99b1
  1. 11
      smart_service/masters/doctype/role_master/role_master.json
  2. 52
      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. 129
      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": [],
"allow_rename": 1,
"autoname": "format:{role}",
@ -23,7 +22,8 @@
"in_list_view": 1,
"in_standard_filter": 1,
"label": "Role",
"reqd": 1
"reqd": 1,
"set_only_once": 1
},
{
"fieldname": "column_break_ffrrr",
@ -48,7 +48,10 @@
{
"fieldname": "skill_id",
"fieldtype": "Data",
"label": "Skill Id"
"in_list_view": 1,
"label": "Skill Id",
"reqd": 1,
"set_only_once": 1
},
{
"fieldname": "section_break_bkwnr",
@ -57,7 +60,7 @@
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2023-08-16 14:50:58.500228",
"modified": "2023-10-09 12:02:23.458890",
"modified_by": "Administrator",
"module": "Masters",
"name": "Role Master",

52
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){
check_field_character(frm.doc.tool_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) {
frappe.validated = false;
frm.doc.display_order = original_display_order
@ -33,7 +33,7 @@ frappe.ui.form.on('Special Tool Information', {
cur_frm.refresh_fields("display_order")
frappe.throw(__("<b>Display Order:</b> Zero or Negative values not allowed."));
}
//For Display Order
// For Display Order
cur_frm.refresh_fields("display_order")
if (frm.doc.display_order && frm.doc.name && !frm.is_new()) {
//***check if there is same display_order
@ -57,15 +57,15 @@ frappe.ui.form.on('Special Tool Information', {
}, 5);
});
} else {
if (frm.doc.display_order >= vehicle_count) {
let display_vehicle_count = vehicle_count - 1;
msgprint('There are only ' + display_vehicle_count + " " + frm.doc.doctype);
frappe.validated = false;
}
// if (frm.doc.display_order >= vehicle_count) {
// let display_vehicle_count = vehicle_count - 1;
// msgprint('There are only ' + display_vehicle_count + " " + frm.doc.doctype);
// frappe.validated = false;
// }
}
});
}
frm.doc.name = frm.doc.vehicle + "-" + frm.doc.tool_type + "-" + frm.doc.category + "-" + frm.doc.aggregate_name
if (frm.doc.image) {
frappe.call({
@ -94,7 +94,7 @@ frappe.ui.form.on('Special Tool Information', {
}
if (frm.doc.aggregate_image) {
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: {
image: frm.doc.aggregate_image,
name: frm.doc.name,
@ -119,10 +119,10 @@ 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",
method: "smart_service.phase_2.doctype.special_tool_information.special_tool_information.file_validation2",
args: {
image: frm.doc.pdf,
name:frm.doc.name
pdf: frm.doc.pdf
// name:frm.doc.name
},
callback: function (r) {
console.log(r.message, "r.message")
@ -130,6 +130,7 @@ frappe.ui.form.on('Special Tool Information', {
if (r.message[1] == 1) {
frappe.validated = false;
frappe.msgprint("Invalid file type")
frm.reload_doc()
}
}
@ -139,7 +140,7 @@ frappe.ui.form.on('Special Tool Information', {
}
if (frm.doc.video){
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: {
video: frm.doc.video,
name:frm.doc.name
@ -189,7 +190,23 @@ frappe.ui.form.on('Special Tool Information', {
},
});
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"){
//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
cur_frm.refresh_fields("instructions");
var df = frappe.meta.get_docfield("Instructions", "content", cur_frm.doc.name);
@ -207,25 +224,18 @@ function teb_validation(frm){
is_pdf=0
}
})
}
if(is_pdf==1){
var childTable = cur_frm.add_child("instructions");
childTable.content_type="PDF"
var df = frappe.meta.get_docfield("Instructions", "content_type", cur_frm.doc.name);
df.read_only = 1;
df.read_only = 1;
cur_frm.refresh_fields("category");
cur_frm.refresh_fields("instructions");
}
//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",
"in_list_view": 1,
"label": "Display Order",
"non_negative": 1,
"reqd": 1
"non_negative": 1
},
{
"fieldname": "my_id",
@ -98,7 +97,6 @@
"in_list_view": 1,
"in_standard_filter": 1,
"label": "Aggregate Name",
"reqd": 1,
"set_only_once": 1
},
{
@ -108,7 +106,6 @@
"in_standard_filter": 1,
"label": "Category",
"options": "Maintenance Service Category(MS)\nRepair Service Category(RS)\nOverhaul Service Category(OS)\nTEB",
"reqd": 1,
"set_only_once": 1
},
{
@ -129,8 +126,7 @@
"fieldname": "instructions",
"fieldtype": "Table",
"label": "Instructions",
"options": "Instructions",
"reqd": 1
"options": "Instructions"
},
{
"fieldname": "tool_type",
@ -139,7 +135,6 @@
"in_standard_filter": 1,
"label": "Tool Type",
"options": "New Tool\nCarry Over",
"reqd": 1,
"set_only_once": 1
},
{
@ -170,6 +165,7 @@
"options": "image"
},
{
"depends_on": "eval:doc.category !='TEB';",
"fieldname": "tool_name",
"fieldtype": "Data",
"in_list_view": 1,
@ -187,7 +183,7 @@
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2023-10-06 16:54:21.868057",
"modified": "2023-10-09 13:48:14.303807",
"modified_by": "Administrator",
"module": "Phase-2",
"name": "Special Tool Information",

129
smart_service/phase_2/doctype/special_tool_information/special_tool_information.py

@ -32,39 +32,73 @@ class SpecialToolInformation(Document):
@frappe.whitelist()
def file_validation(image, name, value=None):
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
def file_validation(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:
(width, height, size) = details_of_image(image)
if value == 'image':
if width > 1280 or height > 720 or size > 1*1024 and image:
val = checking_image(image, 'Special Tool Information',
value, name)
if val == True:
return (False, 2)
else:
return True
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:
val = checking_image(image, "Special Tool Information", "image", name)
if val == True:
return False, 2
else:
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':
if width > 1280 or height > 720 or size > 1*1024 and image:
val = checking_image(image, 'Special Tool Information',
value, name)
if val == True:
return (False, 2)
else:
return True
@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:
val = checking_image(image, "Special Tool Information", "aggregate_image", name)
if val == True:
return False, 2
else:
return True
else:
val = checking_image(
image, 'Special Tool Information', value, name)
val = checking_image(image, "Special Tool Information", "aggregate_image", name)
if res == False:
ret = res
else:
ret = res1
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()
def file_validation_child(name, value=None):
@ -120,46 +154,11 @@ def file_validation_child(name, value=None):
return (ret, d['idx'])
@frappe.whitelist()
def file_validation1(image,video, name, value=None):
from smart_service.apis.utils import check_pdf_ext,details_of_image,check_mp4_ext,get_file_size
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
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
# 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(
f"""UPDATE `tabModule Publish Mapping` set repairservice_check_sheet='1' and publish_type='1' where name ='{d['name']}'""", as_dict=1)
frappe.db.commit()
else:
pub_data = frappe.db.get_list('Module Publish Mapping', filters={
"vehicle": vehicle,
@ -233,6 +234,7 @@ def update_publish_mapping(vehicle, variant, language, module, publish_type):
elif module == 'Feature Finder':
doc.feature_finder = 1
elif module == 'QWIK Service'
doc.save()

Loading…
Cancel
Save