Browse Source

Publish fix, mst field validation

version2
venkata akhil 11 months ago
parent
commit
7123cc49db
  1. 12
      smart_service/apis/master_api.py
  2. 8
      smart_service/apis/v2/master.py
  3. 2
      smart_service/phase_2/doctype/instructions/instructions.json
  4. 4
      smart_service/phase_2/doctype/module_publish_mapping/module_publish_mapping.json
  5. 24
      smart_service/phase_2/doctype/qwik_service/qwik_service.js
  6. 2
      smart_service/phase_2/doctype/qwik_service/qwik_service.json
  7. 34
      smart_service/phase_2/doctype/qwik_service/qwik_service.py
  8. 7
      smart_service/phase_2/doctype/special_tool_information/special_tool_information.js
  9. 13
      smart_service/phase_2/doctype/special_tool_information/special_tool_information.json
  10. 2
      smart_service/phase_2/doctype/special_tool_information/special_tool_information.py
  11. 36
      smart_service/transactions/doctype/publish/publish.js
  12. 202
      smart_service/transactions/doctype/publish/publish.py

12
smart_service/apis/master_api.py

@ -355,6 +355,7 @@ def variant(LSD, language, iid=None):
datetime.datetime.strptime(LSD, date_format)
except:
return {"status": 0, "error": " 'LSD' format error"}
publish_type = check_pub_type(iid)
try:
data = frappe.db.sql(f'''
select name,vehicle,vehicle_id,name as variant_name,variant,variant_id,fuel,fuel_id,transmission,transmission_id,
@ -363,12 +364,11 @@ def variant(LSD, language, iid=None):
FROM `tabVariant Mapping` where modified >='{LSD}';''', as_dict=1)
for d in data:
modules = frappe.db.sql(f'''select automotive_system as 'Automotive System',tsb as 'TSB',fsa as 'FSA',tekalert as 'TEKalert',
feature_finder as 'Feature Finder',repairservice_check_sheet as 'Repair/Service Check Sheet',
mahindra_special_tool_information as 'Mahindra Special Tool Information',training_information as
'Training Information',qwik_service as 'QWIK Service',pdi_inspection as 'PDI Inspection',
torque_information_nm as 'Torque Information NM'
FROM `tabModule Publish Mapping` where vehicle= '{d['vehicle']}' and variant="{d['variant_name']}" ;''',
as_dict=1)
feature_finder as 'Feature Finder',repairservice_check_sheet as 'Repair/Service Check Sheet',
mahindra_special_tool_information as 'Mahindra Special Tool Information',training_information as 'Training Information',
qwik_service as 'QWIK Service',pdi_inspection as 'PDI Inspection',torque_information_nm as 'Torque Information NM'
FROM `tabModule Publish Mapping` where vehicle= '{d['vehicle']}' and variant='{d['variant_name']}'
and language = "{language}" and publish_type = '{publish_type}';''', as_dict=1)
if modules:
d['modules'] = [{'title': k, 'active_status': v, 'app_menu_id':
frappe.db.sql(f'''select app_menu_id from `tabModule Master` where module_name = '{k}' ;''', as_dict=1)[0]['app_menu_id']}

8
smart_service/apis/v2/master.py

@ -173,12 +173,13 @@ def new_publish():
flag, data = get_qwik_service(variant, language)
CLEANR = re.compile('<.*?>')
for dt in data:
if dt['consumables']:
if len(dt['consumables'])>0:
for con in dt['consumables']:
con['content'] = re.sub(CLEANR, '', con['content'])
if con['content']:
con['content'] = re.sub(CLEANR, '', con['content'])
elif module == 'Training Information':
# flag, data = get_training_information(vehicle, language)
pass
@ -203,6 +204,7 @@ def new_publish():
return {'status': 0, 'error': data, 'data': None}
except Exception as e:
frappe.log_error(str(e))
frappe.local.response['http_status_code'] = 400
return {'status': 0, 'error': "Parameter's missing: " + str(e), 'data': None}

2
smart_service/phase_2/doctype/instructions/instructions.json

@ -49,7 +49,7 @@
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2023-10-11 10:23:12.256705",
"modified": "2023-10-16 16:18:23.081846",
"modified_by": "Administrator",
"module": "Phase-2",
"name": "Instructions",

4
smart_service/phase_2/doctype/module_publish_mapping/module_publish_mapping.json

@ -119,7 +119,7 @@
"in_list_view": 1,
"in_standard_filter": 1,
"label": "Publish Type",
"options": "\nInternal\nGlobal",
"options": "Internal\nGlobal",
"set_only_once": 1
},
{
@ -145,7 +145,7 @@
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2023-10-06 18:04:11.661649",
"modified": "2023-10-16 18:46:53.445411",
"modified_by": "Administrator",
"module": "Phase-2",
"name": "Module Publish Mapping",

24
smart_service/phase_2/doctype/qwik_service/qwik_service.js

@ -31,11 +31,11 @@ frappe.ui.form.on('Qwik Service', {
frappe.call({
method: "smart_service.phase_2.doctype.qwik_service.qwik_service.file_validation",
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")
// console.log(r.message, "r.message")
if (r.message && r.message[0] == false) {
if (r.message[1] == 1) {
frappe.validated = false;
@ -79,15 +79,17 @@ frappe.ui.form.on('Qwik Service', {
filters: {
display_order: frm.doc.display_order,
name: ["!=", frm.doc.name],
vehicle: frm.doc.vehicle,
language: frm.doc.language,
variant: frm.doc.variant,
language: frm.doc.language,
kilometers:frm.doc.kilometers
}
}).then(records => {
console.log(records)
if (records.length) {
frappe.db.set_value('Qwik Service', records[0].name, {
display_order: original_display_order
}).then(r => {
// console.log("display",str(r))
let doc = r.message;
frappe.show_alert({
message: __('Swapped display order with: ' + records[0].name),
@ -303,9 +305,9 @@ function custom_tab_html(frm){
//individual delete button
$(res).find('.qwik_probl').find('.qwik_d').find('.qwikcheck').change(function () {
console.log("working",this.checked)
// console.log("working",this.checked)
if (this.checked) {
console.log("checked")
// console.log("checked")
$(res).find('.qwik_probl').find('.qwik_custom_delete').css("display", "inline-block")
} else {
$(res).find('.qwik_probl').find('.qwik_custom_delete').css("display", "None")
@ -377,7 +379,7 @@ function custom_tab_html(frm){
primary_action_label: 'Submit',
primary_action(values) {
if (values && values.level && values.content.length >0) {
console.log()
// console.log()
frappe.call({
method: "smart_service.phase_2.doctype.qwik_service.qwik_service.insert_qwik_data",
args: {
@ -417,12 +419,10 @@ function set_display_order(frm){
frappe.db.count('Qwik Service', {
filters: {
"variant": frm.doc.variant,
"language": frm.doc.language,
"vehicle": frm.doc.vehicle,
"kilometers":cur_frm.doc.kilometers
"language": frm.doc.language
}
}).then(count => {
// console.log("counts",count)
console.log("counts",count)
vehicle_count = count + 1;
if (frm.is_new()) {
frm.set_value("display_order", vehicle_count);

2
smart_service/phase_2/doctype/qwik_service/qwik_service.json

@ -145,7 +145,7 @@
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2023-10-13 11:25:55.189777",
"modified": "2023-10-16 12:22:46.875043",
"modified_by": "Administrator",
"module": "Phase-2",
"name": "Qwik Service",

34
smart_service/phase_2/doctype/qwik_service/qwik_service.py

@ -105,24 +105,22 @@ def get_kilometer(vehicle=None):
@frappe.whitelist()
def file_validation(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)
def file_validation(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:
pass
size = get_file_size(pdf)
if size > 1*1024 and pdf:
return True, 1
else:
val = delete_file(image, 'Qwik Service',
"pdf", name)
if res == False:
ret = res
return ret, 1
return False, 2
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

7
smart_service/phase_2/doctype/special_tool_information/special_tool_information.js

@ -34,7 +34,6 @@ frappe.ui.form.on('Special Tool Information', {
frappe.throw(__("<b>Display Order:</b> Zero or Negative values not allowed."));
}
// 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
frappe.db.get_list('Special Tool Information', {
@ -65,7 +64,7 @@ frappe.ui.form.on('Special Tool Information', {
}
});
}
cur_frm.refresh_fields("display_order")
if (frm.doc.image) {
frappe.call({
@ -267,7 +266,7 @@ function set_display_order(frm){
});
}
frappe.ui.form.on('Instructions', {
// child table depends_on based on main doctype
// child table depends_on based on main doctype
instructions_add: function (frm, cdt, cdn) {
refresh_field("instructions")
var child = locals[cdt][cdn];
@ -288,7 +287,7 @@ frappe.ui.form.on('Instructions', {
refresh_field("instructions");
},
content_type: function (frm, cdt, cdn) {
cur_frm.refresh_field("content_type")
cur_frm.refresh_fields("content_type")
var select_value = locals[cdt][cdn];
var x = select_value.idx - 1;
if (select_value.content_type == 'Image' || select_value.content_type == 'Video' || select_value.content_type == 'PDF'){

13
smart_service/phase_2/doctype/special_tool_information/special_tool_information.json

@ -97,6 +97,7 @@
"in_list_view": 1,
"in_standard_filter": 1,
"label": "Aggregate Name",
"reqd": 1,
"set_only_once": 1
},
{
@ -110,10 +111,11 @@
},
{
"depends_on": "eval:doc.category !='TEB';",
"description": "Upload *.png(1920x1080 pixel) 1 MB",
"description": "Upload *.png(1280x720 pixel) 1 MB",
"fieldname": "aggregate_image",
"fieldtype": "Attach Image",
"label": "Aggregate Image"
"label": "Aggregate Image",
"reqd": 1
},
{
"depends_on": "eval:doc.category !='TEB';",
@ -140,7 +142,7 @@
},
{
"depends_on": "eval:doc.category!=\"TEB\";",
"description": "Upload *.png(1920x1080 pixel) 1 MB",
"description": "Upload *.png(1280x720 pixel) 1 MB",
"fieldname": "image",
"fieldtype": "Attach Image",
"label": "Image",
@ -174,7 +176,8 @@
"fieldtype": "Data",
"in_list_view": 1,
"in_standard_filter": 1,
"label": "Tool Name"
"label": "Tool Name",
"reqd": 1
},
{
"depends_on": "eval:doc.aggregate_image && doc.category!=\"TEB\";;",
@ -186,7 +189,7 @@
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2023-10-13 17:10:45.217112",
"modified": "2023-10-16 17:24:43.937085",
"modified_by": "Administrator",
"module": "Phase-2",
"name": "Special Tool Information",

2
smart_service/phase_2/doctype/special_tool_information/special_tool_information.py

@ -76,7 +76,7 @@ def file_validation1(image, name):
return ret, 1
@frappe.whitelist()
def file_validation2(pdf = None):
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)

36
smart_service/transactions/doctype/publish/publish.js

@ -19,6 +19,12 @@ cur_frm.fields_dict["vehicle"].get_query = function (doc, cdt, cdn) {
let lang_set_first_time = true;
frappe.ui.form.on("Publish", {
onload: function (frm) {
setTimeout(function mysam(){
$('[data-fieldname="special_tool_publish"]').find('.grid-add-row').css('display', 'none')
$('[data-fieldname="qwik_service_publish"]').find('.grid-add-row').css('display', 'none')
}, 500);
if (
frm.doc.hasOwnProperty("repiar_checksheet_publish_docs") &&
frm.doc.repiar_checksheet_publish_docs.length > 0
@ -203,6 +209,11 @@ frappe.ui.form.on("Publish", {
}
},
refresh: function (frm) {
setTimeout(function mysam(){
$('[data-fieldname="special_tool_publish"]').find('.grid-add-row').css('display', 'none')
$('[data-fieldname="qwik_service_publish"]').find('.grid-add-row').css('display', 'none')
}, 500);
if (
frm.doc.docstatus == 0 &&
!frm.is_new() &&
@ -339,14 +350,14 @@ frappe.ui.form.on("Publish", {
document.querySelectorAll(
"[data-fieldname='km_report']"
)[1].style.backgroundColor = "#e31a37";
document.querySelectorAll("[data-fieldname='km_report']")[1].style.color =
"#FFFFFF";
document.querySelectorAll(
"[data-fieldname='add_variant_mapping_to_publish']"
)[1].style.backgroundColor = "#e31a37";
document.querySelectorAll(
"[data-fieldname='add_variant_mapping_to_publish']"
)[1].style.color = "#FFFFFF";
// document.querySelectorAll("[data-fieldname='km_report']")[1].style.color =
// "#FFFFFF";
// document.querySelectorAll(
// "[data-fieldname='add_variant_mapping_to_publish']"
// )[1].style.backgroundColor = "#e31a37";
// document.querySelectorAll(
// "[data-fieldname='add_variant_mapping_to_publish']"
// )[1].style.color = "#FFFFFF";
if (
frm.doc.docstatus === 1 &&
frm.doc.publish_type == "Internal" &&
@ -657,6 +668,11 @@ frappe.ui.form.on("Publish", {
}
},
variant_mapping: function (frm) {
setTimeout(function mysam(){
$('[data-fieldname="special_tool_publish"]').find('.grid-add-row').css('display', 'none')
$('[data-fieldname="qwik_service_publish"]').find('.grid-add-row').css('display', 'none')
}, 100);
if (frm.doc.docstatus === 0 && frm.doc.publish_status == "To Publish") {
frm
.get_field("system_mapping")
@ -1032,6 +1048,10 @@ frappe.ui.form.on("Publish", {
},
vehicle: function (frm) {
setTimeout(function mysam(){
$('[data-fieldname="special_tool_publish"]').find('.grid-add-row').css('display', 'none')
$('[data-fieldname="qwik_service_publish"]').find('.grid-add-row').css('display', 'none')
}, 100);
frm.set_df_property("vehicle", "set_only_once", "1");
frm.refresh_fields("vehicle");
if (frm.doc.publish_module == "Automotive System") {

202
smart_service/transactions/doctype/publish/publish.py

@ -19,7 +19,7 @@ site_name = cstr(frappe.local.site)
base_url = os.path.expanduser(
"~") + "/frappe-bench/sites/" + site_name + "/public" + "/files" + "/json_files" + "/phase2"
frappe.utils.logger.set_log_level("DEBUG")
frappe.utils.logger.set_log_level("DEBUG")
success_reponse = {"status": 1, "data": "", "message": ""}
failure_reponse = {"status": 0, "data": "", "error": ""}
module_name = 'feature_finder'
@ -59,25 +59,24 @@ 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_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)
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':
qwik_service_publish(self.vehicle, self.vehicle_id,self.variant,
self.language,self.publish_type,
self.release_description,self.qwik_service_publish_docs)
qwik_service_publish(self.vehicle, self.vehicle_id, self.variant,
self.language, self.publish_type,
self.release_description, self.qwik_service_publish_docs)
update_publish_status = frappe.db.sql(
"""update `tabPublish` set publish_status='Published' where name='{0}'""".format(self.name))
"""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 == 'Global' and self.qwik_service_publish_docs:
qwik_service_publish(self.vehicle, self.vehicle_id,self.variant,
self.language,self.publish_type,
self.release_description,self.qwik_service_publish_docs)
qwik_service_publish(self.vehicle, self.vehicle_id, self.variant,
self.language, self.publish_type,
self.release_description, self.qwik_service_publish_docs)
update_publish_status = frappe.db.sql(
"""update `tabPublish` set publish_status='Published' where name='{0}'""".format(self.name))
@ -107,25 +106,27 @@ class Publish(Document):
update_repair_published_docs(self)
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 == 'Special Tool' and self.publish_type == 'Internal':
special_tool_publish(self.vehicle, self.vehicle_id,
self.publish_type,
self.release_description,
self.special_tool_publish_docs)
self.publish_type,
self.release_description,
self.special_tool_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 == 'Special Tool' and self.publish_type == 'Global' and self.special_tool_publish_docs:
special_tool_publish(self.vehicle, self.vehicle_id,
self.publish_type,
self.release_description,
self.special_tool_publish_docs)
self.publish_type,
self.release_description,
self.special_tool_publish_docs)
update_special_tool_publish_docs(self)
update_publish_status = frappe.db.sql(
"""update `tabPublish` set publish_status='Published' where name='{0}'""".format(self.name))
variant = self.variant_mapping_details.split('/n')
variant = self.variant_mapping_details.split('/n')
frappe.log_error('publish type', str(self.publish_type))
update_publish_mapping(self.vehicle, self.variant_mapping,
self.language, self.publish_module, self.publish_type)
def on_cancel(self):
# Published document should not allow to cancel
@ -184,16 +185,19 @@ def update_procedure(vehicle, lang, publish_type, doc):
frappe.throw("There is no item for global publish")
# Generate Publish versions
def update_qwik_published_docs(self):
try:
for d in self.qwik_service_publish_docs:
frappe.db.sql(
"""UPDATE `tabQwik Service` set is_published=1 where name='{0}'""".format(d.parent1))
"""UPDATE `tabQwik Service` set is_published=1 where name='{0}'; """.format(d.parent1))
frappe.db.commit()
except Exception as ex:
return str(ex)
def update_publish_mapping(vehicle, variant, language, module, publish_type):
frappe.set_user('Administrator')
if module == 'Repair service':
@ -208,7 +212,19 @@ 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()
elif module == 'Special Tool':
pub_data = frappe.db.get_list('Module Publish Mapping', filters={
"vehicle": vehicle,
"language": language,
"publish_type": publish_type
}, fields=['name'])
if len(pub_data) > 0:
for d in pub_data:
if d['name']:
frappe.db.sql(
f"""UPDATE `tabModule Publish Mapping` set mahindra_special_tool_information='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,
@ -224,7 +240,8 @@ def update_publish_mapping(vehicle, variant, language, module, publish_type):
'doctype': 'Module Publish Mapping',
"vehicle": vehicle,
"variant": variant,
"language": language
"language": language,
"publish_type": publish_type
})
if module == 'Automotive System':
doc.automotive_system = 1
@ -234,7 +251,9 @@ def update_publish_mapping(vehicle, variant, language, module, publish_type):
elif module == 'Feature Finder':
doc.feature_finder = 1
elif module == 'Qwik Service':
doc.qwik_service = 1
doc.save()
@ -370,7 +389,7 @@ def generate_global_publish(name, module_name):
"publish_status": 'To Publish',
"release_description": res.release_description,
"publish_module": res.publish_module
})
elif module_name == 'Special Tool':
ret = frappe.get_doc({
@ -381,7 +400,7 @@ def generate_global_publish(name, module_name):
"publish_status": 'To Publish',
"release_description": res.release_description,
"publish_module": res.publish_module
})
ret.save()
return {"status": "success", "message": ret.name, "url": frappe.utils.get_url()}
@ -555,9 +574,7 @@ def update_procedure_value(name, file_path):
def update_feature_published_docs(self):
try:
for d in self.feature_finder_publish_docs:
frappe.db.sql(
"""UPDATE `tabFeature Finder` set is_published=1 where name='{0}'""".format(d.parent1))
frappe.db.commit()
@ -568,9 +585,7 @@ def update_feature_published_docs(self):
def update_repair_published_docs(self):
try:
for d in self.repair_checksheet_publish:
frappe.db.sql(
"""UPDATE `tabRepair Service Mapping` set published=1 where name='{0}'""".format(d.parent_name))
frappe.db.commit()
@ -578,11 +593,10 @@ def update_repair_published_docs(self):
except Exception as e:
frappe.throw(str(e))
def update_special_tool_publish_docs(self):
try:
def update_special_tool_publish_docs(self):
try:
for d in self.special_tool_publish_docs:
frappe.db.sql(
"""UPDATE `tabSpecial Tool Information` set published=1 where name='{0}'""".format(d.parent1))
frappe.db.commit()
@ -592,7 +606,6 @@ def update_special_tool_publish_docs(self):
def create_publish_folders(folder_url):
try:
if not os.path.isdir(folder_url + "/" + "Global"):
os.makedirs(folder_url + "/" + "Global")
@ -604,6 +617,7 @@ def create_publish_folders(folder_url):
frappe.throw(str(e))
return False
'''New Module Publish Section'''
@ -717,8 +731,6 @@ def repair_checksheet_publish(vehicle, vehicle_id,
frappe.throw('Failed To Publish')
def feature_finder_publish(vehicle=None, vehicle_id=None,
language=None, publish_type=None,
release_description=None, parent=None,
@ -830,9 +842,10 @@ def feature_finder_publish(vehicle=None, vehicle_id=None,
f'{vehicle} - {language} - {publish_type} - {module_name} error in json creation' + str(e))
frappe.throw('Failed To Publish')
def qwik_service_publish(vehicle = None , vehicle_id = None,variant = None,
language = None,publish_type = None,
release_description=None,parent = None):
def qwik_service_publish(vehicle=None, vehicle_id=None, variant=None,
language=None, publish_type=None,
release_description=None, parent=None):
try:
logger_file = f'{variant} - {language} - {publish_type} - Qwik_service'
logger = frappe.logger(logger_file, allow_site=True, file_count=100)
@ -845,7 +858,7 @@ def qwik_service_publish(vehicle = None , vehicle_id = None,variant = None,
'''Publish Ready Flags'''
publish_qwik_service = 0
qwik_service_tmp = []
qwik_service=''
qwik_service = ''
'''Create Folder For Publish'''
create_publish_folders(folder_url)
@ -861,21 +874,21 @@ def qwik_service_publish(vehicle = None , vehicle_id = None,variant = None,
vehicle_data = {
'vehicle': vehicle,
'vehicle_myid': vehicle_id,
'variant':variant,
'variant': variant,
'publish_type': publish_type,
'publish_description': release_description,
'publish_language': language,
'data': ''
}
if os.path.isfile(global_file_path) and publish_type == 'Internal':
with open(global_file_path) as f:
published_data = json.load(f)
for i in parent:
qwik_service = qwik_service_data(
language,publish_type,i.variant,i.parent1,vehicle)
if qwik_service['status'] == 1 and len(qwik_service['data'])>0:
language, publish_type, i.variant, i.parent1, vehicle)
if qwik_service['status'] == 1 and len(qwik_service['data']) > 0:
publish_qwik_service = 1
qwik_service_tmp.append(
qwik_service['data'][0])
@ -894,15 +907,14 @@ def qwik_service_publish(vehicle = None , vehicle_id = None,variant = None,
published_data = json.load(f)
for i in parent:
qwik_service = qwik_service_data(
language,publish_type,i.variant,i.parent1,vehicle)
if qwik_service['status'] == 1 and len(qwik_service['data'])>0:
language, publish_type, i.variant, i.parent1, vehicle)
if qwik_service['status'] == 1 and len(qwik_service['data']) > 0:
publish_qwik_service = 1
qwik_service_tmp.append(
qwik_service['data'][0])
qwik_service_tmp = create_df(qwik_service_tmp)
vehi_data = compare_get_data({'data': published_data['data']}, {
'data': qwik_service_tmp})
if vehi_data:
@ -914,18 +926,18 @@ def qwik_service_publish(vehicle = None , vehicle_id = None,variant = None,
else:
for i in parent:
qwik_service = qwik_service_data(
language,publish_type,i.variant,i.parent1,vehicle)
language, publish_type, i.variant, i.parent1, vehicle)
if qwik_service['status'] == 1 and len(qwik_service['data'])>0:
if qwik_service['status'] == 1 and len(qwik_service['data']) > 0:
publish_qwik_service = 1
qwik_service_tmp.append(
qwik_service['data'][0])
qwik_service['data'][0])
else:
frappe.throw('failed to publish')
qwik_service_tmp = get_latest_data(
{'data': qwik_service_tmp}, {'data': []})
vehi_data = create_df(qwik_service_tmp)
""" Save publish file """
@ -933,13 +945,14 @@ def qwik_service_publish(vehicle = None , vehicle_id = None,variant = None,
with open(file_path, 'w') as outfile:
outfile.write(json.dumps(vehicle_data, indent=4, default=str))
except Exception as e:
logger.error(f'{variant} - {language} - {publish_type} - Qwik_service'+str(e))
logger.error(
f'{variant} - {language} - {publish_type} - Qwik_service'+str(e))
def special_tool_publish(vehicle, vehicle_id,
publish_type, release_description,
parent=None):
publish_type, release_description,
parent=None):
try:
logger_file = f'{vehicle} - {publish_type} - special tool'
logger = frappe.logger(logger_file, allow_site=True, file_count=100)
@ -957,7 +970,7 @@ def special_tool_publish(vehicle, vehicle_id,
create_publish_folders(folder_url)
file_path = folder_url + "/" + publish_type + "/" + \
vehicle.replace(' ', '-') + '-special_tool' + '.json'
existing_global= folder_url + "/" + "Global" + "/" + \
existing_global = folder_url + "/" + "Global" + "/" + \
vehicle.replace(' ', '-') + '-special_tool' + '.json'
'''Append Published Data to Json'''
@ -972,45 +985,47 @@ def special_tool_publish(vehicle, vehicle_id,
}
'''update existing global json file'''
if os.path.isfile(existing_global) and publish_type=='Internal':
if os.path.isfile(existing_global) and publish_type == 'Internal':
with open(existing_global) as f:
published_data = json.load(f)
for i in parent:
special_tool = special_tool_data(vehicle,publish_type, i.parent1)
if special_tool['status'] == 1 and len(special_tool['data'])>0:
special_tool = special_tool_data(
vehicle, publish_type, i.parent1)
if special_tool['status'] == 1 and len(special_tool['data']) > 0:
publish_special_tool = 1
special_tool_tmp.append(
special_tool['data'][0])
special_tool_tmp = get_latest_data({'data': published_data['data']}, {
'data': special_tool_tmp})
elif os.path.isfile(file_path) and publish_type=='Global':
'data': special_tool_tmp})
elif os.path.isfile(file_path) and publish_type == 'Global':
with open(existing_global) as f:
published_data = json.load(f)
for i in parent:
special_tool = special_tool_data(vehicle,publish_type, i.parent1)
if special_tool['status'] == 1 and len(special_tool['data'])>0:
special_tool = special_tool_data(
vehicle, publish_type, i.parent1)
if special_tool['status'] == 1 and len(special_tool['data']) > 0:
publish_special_tool = 1
special_tool_tmp.append(
special_tool['data'][0])
special_tool_tmp = get_latest_data({'data': published_data['data']}, {
'data': special_tool_tmp})
'data': special_tool_tmp})
else:
for i in parent:
special_tool = special_tool_data(
vehicle, publish_type, i.parent1)
if special_tool['status'] == 1:
publish_special_tool = 1
if len(special_tool['data'])>0:
if len(special_tool['data']) > 0:
special_tool_tmp.append(
special_tool['data'][0])
special_tool_tmp = get_latest_data(
{'data': special_tool_tmp}, {'data': []})
if publish_special_tool== 1:
if publish_special_tool == 1:
""" Save publish file """
vehicle_data['data'] = special_tool_tmp
@ -1262,18 +1277,20 @@ def feature_finder_data(vehicle=None, language=None,
e)
logger.error('error in repair checksheet' + str(e))
return failure_reponse
def qwik_service_data(language,publish_type,variant,parent,vehicle):
def qwik_service_data(language, publish_type, variant, parent, vehicle):
try:
logger_file = f'fetch qwik data {variant} - {language}'
logger = frappe.logger(logger_file,
allow_site=True, file_count=100)
logger.info(
f"start of qwik service data {variant} - {language}")
qwik_service_details = frappe.db.sql('''select name,variant,vehicle,kilometers,language,service_time,active_status,
pdf,display_order,keywords,my_id from `tabQwik Service` where name='%s';''' %
(parent), as_dict=1)
pdf,display_order,keywords,my_id from `tabQwik Service` where name='%s';''' %
(parent), as_dict=1)
for q in qwik_service_details:
q['pre_work'] = frappe.db.sql('''select idx as 'display_order', content from `tabQwik Service Content` where parent='%s'
&& content_type = 'Pre-work' order by display_order;''' % (q['name']), as_dict=1)
@ -1296,13 +1313,14 @@ def qwik_service_data(language,publish_type,variant,parent,vehicle):
success_reponse['data'] = qwik_service_details
success_reponse[
'message'] = f'Qwik Service Fecthed Succesfully for {vehicle} - {language}'
return success_reponse
return success_reponse
except Exception as e:
logger.error('error in qwik service data' + str(e))
def special_tool_data(vehicle=None,
publish_type=None, parent=None):
publish_type=None, parent=None):
try:
logger_file = f'special_tool_data start'
logger = frappe.logger(logger_file,
@ -1310,7 +1328,6 @@ def special_tool_data(vehicle=None,
logger.info(
f"start of fetching special tool data - {parent}")
special_tool_information = frappe.db.sql(''' select name,vehicle,tool_type,
category,tool_name,aggregate_name,aggregate_image,
pdf,keywords,display_order,my_id,active_status from
@ -1335,13 +1352,14 @@ def special_tool_data(vehicle=None,
e)
logger.error('error in special tool' + str(e))
return failure_reponse
@frappe.whitelist()
def max_publish_new_module(doc):
doc = frappe.get_doc("Publish", doc)
ver = frappe.db.sql("""select max(version) from {0}.tabPublish where vehicle = "{1}" and language = "{2}" and publish_module!="Automotive System";""".format(
current_db_name, doc.vehicle, doc.language))
if ver:
return ver
@ -1372,18 +1390,20 @@ def cal_ver_new_module(vehicle, lang, publish_type, doc):
frappe.db.commit()
return v
@frappe.whitelist()
def get_qwik_service(variant=None,language_label=None,kilometers=None):
def get_qwik_service(variant=None, language_label=None, kilometers=None):
try:
data = frappe.db.sql("""select * from `tabQwik Service` where variant='%s'
and language = '%s' and is_published = '%s';"""%(variant,language_label,0),as_dict=1)
and language = '%s' and is_published = '%s';""" % (variant, language_label, 0), as_dict=1)
return data
except Exception as e:
return e
@frappe.whitelist()
def get_special_tool(vehicle=None, publish_type=None):
data = frappe.db.sql('''
select * from `tabSpecial Tool Information` where vehicle ='%s' and published = '%s';'''%(vehicle,0), as_dict=1)
return data
select * from `tabSpecial Tool Information` where vehicle ='%s' and published = '%s';''' % (vehicle, 0), as_dict=1)
return data

Loading…
Cancel
Save