Compare commits
129 Commits
272 changed files with 24245 additions and 661960 deletions
@ -0,0 +1,8 @@ |
|||
# Copyright (c) 2023, Hard n Soft Technologies Pvt Ltd and Contributors |
|||
# See license.txt |
|||
|
|||
# import frappe |
|||
import unittest |
|||
|
|||
class TestTorqueTableColumn(unittest.TestCase): |
|||
pass |
@ -0,0 +1,8 @@ |
|||
// Copyright (c) 2023, Hard n Soft Technologies Pvt Ltd and contributors
|
|||
// For license information, please see license.txt
|
|||
|
|||
frappe.ui.form.on('Torque Table Column', { |
|||
// refresh: function(frm) {
|
|||
|
|||
// }
|
|||
}); |
@ -0,0 +1,65 @@ |
|||
{ |
|||
"actions": [], |
|||
"allow_rename": 1, |
|||
"creation": "2023-12-08 14:40:14.464142", |
|||
"doctype": "DocType", |
|||
"editable_grid": 1, |
|||
"engine": "InnoDB", |
|||
"field_order": [ |
|||
"variant", |
|||
"vehicle", |
|||
"section_break_bytf4", |
|||
"torque_table_columns" |
|||
], |
|||
"fields": [ |
|||
{ |
|||
"fieldname": "torque_table_columns", |
|||
"fieldtype": "Table", |
|||
"label": "Torque Table Columns", |
|||
"options": "Torque Table Column Child Table" |
|||
}, |
|||
{ |
|||
"fieldname": "variant", |
|||
"fieldtype": "Link", |
|||
"in_list_view": 1, |
|||
"label": "Variant", |
|||
"options": "Variant Mapping", |
|||
"reqd": 1 |
|||
}, |
|||
{ |
|||
"fetch_from": "variant.vehicle", |
|||
"fieldname": "vehicle", |
|||
"fieldtype": "Data", |
|||
"in_list_view": 1, |
|||
"label": "Vehicle", |
|||
"reqd": 1 |
|||
}, |
|||
{ |
|||
"fieldname": "section_break_bytf4", |
|||
"fieldtype": "Section Break" |
|||
} |
|||
], |
|||
"index_web_pages_for_search": 1, |
|||
"links": [], |
|||
"modified": "2023-12-08 14:53:30.505533", |
|||
"modified_by": "Administrator", |
|||
"module": "Add Ons", |
|||
"name": "Torque Table Column", |
|||
"owner": "Administrator", |
|||
"permissions": [ |
|||
{ |
|||
"create": 1, |
|||
"delete": 1, |
|||
"email": 1, |
|||
"export": 1, |
|||
"print": 1, |
|||
"read": 1, |
|||
"report": 1, |
|||
"role": "System Manager", |
|||
"share": 1, |
|||
"write": 1 |
|||
} |
|||
], |
|||
"sort_field": "modified", |
|||
"sort_order": "DESC" |
|||
} |
@ -0,0 +1,8 @@ |
|||
# Copyright (c) 2023, Hard n Soft Technologies Pvt Ltd and contributors |
|||
# For license information, please see license.txt |
|||
|
|||
# import frappe |
|||
from frappe.model.document import Document |
|||
|
|||
class TorqueTableColumn(Document): |
|||
pass |
@ -0,0 +1,8 @@ |
|||
# Copyright (c) 2023, Hard n Soft Technologies Pvt Ltd and Contributors |
|||
# See license.txt |
|||
|
|||
# import frappe |
|||
import unittest |
|||
|
|||
class TestTorqueTableColumnChildTable(unittest.TestCase): |
|||
pass |
@ -0,0 +1,8 @@ |
|||
// Copyright (c) 2023, Hard n Soft Technologies Pvt Ltd and contributors
|
|||
// For license information, please see license.txt
|
|||
|
|||
frappe.ui.form.on('Torque Table Column Child Table', { |
|||
// refresh: function(frm) {
|
|||
|
|||
// }
|
|||
}); |
@ -0,0 +1,36 @@ |
|||
{ |
|||
"actions": [], |
|||
"allow_rename": 1, |
|||
"creation": "2023-12-08 14:39:31.936009", |
|||
"doctype": "DocType", |
|||
"editable_grid": 1, |
|||
"engine": "InnoDB", |
|||
"field_order": [ |
|||
"column_number", |
|||
"column_name" |
|||
], |
|||
"fields": [ |
|||
{ |
|||
"fieldname": "column_number", |
|||
"fieldtype": "Data", |
|||
"label": "Column Number" |
|||
}, |
|||
{ |
|||
"fieldname": "column_name", |
|||
"fieldtype": "Data", |
|||
"in_list_view": 1, |
|||
"label": "Column Name" |
|||
} |
|||
], |
|||
"index_web_pages_for_search": 1, |
|||
"istable": 1, |
|||
"links": [], |
|||
"modified": "2023-12-08 14:48:55.346403", |
|||
"modified_by": "Administrator", |
|||
"module": "Add Ons", |
|||
"name": "Torque Table Column Child Table", |
|||
"owner": "Administrator", |
|||
"permissions": [], |
|||
"sort_field": "modified", |
|||
"sort_order": "DESC" |
|||
} |
@ -0,0 +1,8 @@ |
|||
# Copyright (c) 2023, Hard n Soft Technologies Pvt Ltd and contributors |
|||
# For license information, please see license.txt |
|||
|
|||
# import frappe |
|||
from frappe.model.document import Document |
|||
|
|||
class TorqueTableColumnChildTable(Document): |
|||
pass |
File diff suppressed because it is too large
@ -0,0 +1,439 @@ |
|||
import frappe |
|||
from frappe.model.document import Document |
|||
import json |
|||
import os |
|||
from frappe.utils import cstr |
|||
|
|||
from smart_service.apis.app_user_login import input_validation |
|||
|
|||
""" Constants """ |
|||
|
|||
JSON_EXT = ".json" |
|||
JSON_INT_PATH = "/files/json_files/internal/" |
|||
JSON_FULL_INT_PATH = "/files/json_files/full_update/internal/" |
|||
JSON_GLOABL_PATH = "/files/json_files/global/" |
|||
JSON_FULL_GLOBAL_PATH = "/files/json_files/full_update/" |
|||
STATUS = "status" |
|||
ERROR = "error" |
|||
UPDATE_AVAILABLE = 'IsUpdateAvailable' |
|||
UPDATE_FAILED = "Update checking Failed" |
|||
PARAM_MISSING = "Parameter missing :" |
|||
VERSION = 'Version' |
|||
CUR_VERSION = 'CurrentVersion' |
|||
DIS = 'Discription' |
|||
FILE_ERROR = 'File failed to load' |
|||
LANGUAGE = 'Language' |
|||
FILE_SIZE = 'FileSize' |
|||
JSON_URL = 'JsonURL' |
|||
|
|||
site_name = cstr(frappe.local.site) |
|||
base_url = os.path.expanduser( |
|||
"~") + "/frappe-bench/sites/" + site_name + "/public" |
|||
|
|||
|
|||
@frappe.whitelist(allow_guest=1) |
|||
def check_vehicle_update(vehicle_list=None): |
|||
""" Rate Limiting """ |
|||
# rate_res = custom_rate_limit(limit=5, seconds=15) |
|||
# if rate_res != 1: |
|||
# return rate_res |
|||
|
|||
""" Validate Inputs """ |
|||
val = input_validation(vehicle_list=vehicle_list) |
|||
|
|||
""" Validate Input response """ |
|||
if val != '': |
|||
return {"Vehicle": None, |
|||
"VehicleReqList": [], |
|||
STATUS: 0, ERROR: PARAM_MISSING+val} |
|||
|
|||
response = {} |
|||
""" Iterate Vehicle List """ |
|||
if vehicle_list: |
|||
try: |
|||
""" Read Request Body """ |
|||
req_list = json.loads(vehicle_list) |
|||
response['Vehicle'] = req_list['Vehicle'] |
|||
vehicle = req_list['Vehicle'] |
|||
iid = req_list['InstallationId'] |
|||
vehicle_data = req_list['VehicleReqList'] |
|||
|
|||
""" Get Publish Type based on IID """ |
|||
publish_type = frappe.db.get_list( |
|||
'App Device', filters={'name': iid}, fields='publish_type') |
|||
|
|||
if publish_type: |
|||
publish_type = publish_type[0]['publish_type'] |
|||
VehicleReqList = [] |
|||
for v in vehicle_data: |
|||
l_id = v['LanguageID'] |
|||
current_version = float(v[CUR_VERSION]) |
|||
|
|||
""" New function to validate publish version and get file path """ |
|||
pulish_response = get_vehicle_publish_data(vehicle=vehicle, |
|||
l_id=l_id, current_version=current_version, publish_type=publish_type) |
|||
|
|||
""" Append to Main Vehicle Request Response List """ |
|||
VehicleReqList.append(pulish_response) |
|||
|
|||
return { |
|||
"Vehicle": vehicle, "VehicleReqList": VehicleReqList, STATUS: 1, ERROR: "No error"} |
|||
except Exception as e: |
|||
return {"Vehicle": None, "VehicleReqList": [], STATUS: 0, ERROR: str(e)} |
|||
else: |
|||
return {"Vehicle": None, "VehicleReqList": [], STATUS: 0, ERROR: "Check Parameter: vehicle list"} |
|||
|
|||
|
|||
def get_file_size(file_name): |
|||
return os.path.getsize(base_url + file_name) |
|||
|
|||
|
|||
def get_vehicle_publish_data(vehicle, l_id, current_version, publish_type): |
|||
""" Response Structure """ |
|||
vehicle_response_data = { |
|||
"Name": None, |
|||
"Version": 0, |
|||
"Vehicle": None, |
|||
"Language": l_id, |
|||
"Description": None, |
|||
"JsonURL": None, |
|||
"FileSize": None, |
|||
"Error": None, |
|||
"IsUpdateAvailable": False, |
|||
"CurrentVersion": current_version |
|||
} |
|||
latest_global_version = frappe.db.sql('''SELECT name as Name,format(version,2) as version,vehicle_id,language,release_description as Description |
|||
FROM `tabPublish` where vehicle='{0}' and language='{1}' and publish_status='Published' and vehicle_status='Active' |
|||
and publish_module='Automotive System' and version = (select max(version) as version from `tabPublish` |
|||
where publish_module='Automotive System' and vehicle='{0}' and publish_type='Global' and language='{1}'); |
|||
'''.format(vehicle, l_id), as_dict=1) |
|||
|
|||
latest_publish_version = frappe.db.sql('''SELECT name as Name,format(version,2) as version,vehicle_id,language,release_description as Description |
|||
FROM `tabPublish` where vehicle='{0}' and language='{1}' and publish_status='Published' and vehicle_status='Active' |
|||
and publish_module='Automotive System' and version = (select max(version) as version from `tabPublish` |
|||
where publish_module='Automotive System' and vehicle='{0}' and language='{1}' and version >= {2}); |
|||
'''.format(vehicle, l_id, current_version), as_dict=1) |
|||
|
|||
if not latest_publish_version: |
|||
""" Latest File already downloaded Global/Internal """ |
|||
|
|||
vehicle_response_data['IsUpdateAvailable'] = False |
|||
vehicle_response_data['Remarks'] = "Latest Version" |
|||
|
|||
else: |
|||
if not latest_global_version or (current_version >= float(latest_global_version[0]['version'])): |
|||
""" Only First Internal available """ |
|||
|
|||
if publish_type == 'Internal': |
|||
value = round( |
|||
float(latest_publish_version[0]['version']) - current_version, 2) |
|||
|
|||
if value == 0.01: |
|||
# frappe.log_error('Inside 1 Internal') |
|||
""" 1 Internal File """ |
|||
data = frappe.db.sql('''SELECT name as Name,format(version,2) as Version,vehicle_id as Vehicle,language as Language, |
|||
release_description as Description FROM `tabPublish` where vehicle='{0}' and language='{1}' and |
|||
publish_status='Published' and vehicle_status='Active' and publish_module='Automotive System' |
|||
and version = (select max(version) as version from `tabPublish` |
|||
where publish_module='Automotive System' and publish_type='Internal' |
|||
and vehicle='{0}' and language='{1}'); |
|||
'''.format(vehicle, l_id), as_dict=1) |
|||
# frappe.log_error('data', str(data)) |
|||
# data = latest_publish_version |
|||
# frappe.log_error("data",str(data)) |
|||
if data: |
|||
file_name = JSON_INT_PATH+vehicle+"/"+vehicle + \ |
|||
"-" + l_id + "_v" + \ |
|||
str(data[0][VERSION]) + JSON_EXT |
|||
if os.path.exists(base_url + file_name): |
|||
vehicle_response_data['Name'] = data[0]['Name'] |
|||
vehicle_response_data['Vehicle'] = data[0]['Vehicle'] |
|||
vehicle_response_data['Version'] = data[0]['Version'] |
|||
vehicle_response_data['Language'] = data[0]['Language'] |
|||
vehicle_response_data['Description'] = data[0]['Description'] |
|||
vehicle_response_data['FileSize'] = get_file_size( |
|||
file_name) |
|||
vehicle_response_data['JsonURL'] = file_name |
|||
vehicle_response_data['IsUpdateAvailable'] = True |
|||
vehicle_response_data['Remarks'] = "Internal available" |
|||
|
|||
else: |
|||
vehicle_response_data['IsUpdateAvailable'] = False |
|||
vehicle_response_data['Remarks'] = "Internal available" |
|||
vehicle_response_data['Error'] = "Failed to read file" |
|||
else: |
|||
vehicle_response_data['IsUpdateAvailable'] = False |
|||
vehicle_response_data['Remarks'] = "Internal available" |
|||
vehicle_response_data['Error'] = "Failed to get Publish version" |
|||
|
|||
else: |
|||
""" Full Internal File """ |
|||
# same as latest_publish_version |
|||
data = frappe.db.sql('''SELECT name as Name,format(version,2) as Version,vehicle_id as Vehicle,language as Language, |
|||
release_description as Description FROM `tabPublish` where vehicle='{0}' and language='{1}' and |
|||
publish_status='Published' and vehicle_status='Active' and publish_module='Automotive System' |
|||
and version = (select max(version) as version from `tabPublish` |
|||
where publish_module='Automotive System' and publish_type='Internal' |
|||
and vehicle='{0}' and language='{1}' ); |
|||
'''.format(vehicle, l_id), as_dict=1) |
|||
# data = latest_publish_version |
|||
if data: |
|||
file_name = JSON_FULL_INT_PATH+vehicle+"/"+vehicle + \ |
|||
"-" + l_id + "-"+"full_v" + \ |
|||
str(data[0][VERSION] |
|||
) + JSON_EXT |
|||
if os.path.exists(base_url + file_name): |
|||
vehicle_response_data['Name'] = data[0]['Name'] |
|||
vehicle_response_data['Vehicle'] = data[0]['Vehicle'] |
|||
vehicle_response_data['Version'] = data[0]['Version'] |
|||
vehicle_response_data['Language'] = data[0]['Language'] |
|||
vehicle_response_data['Description'] = data[0]['Description'] |
|||
vehicle_response_data['FileSize'] = get_file_size( |
|||
file_name) |
|||
vehicle_response_data['JsonURL'] = file_name |
|||
|
|||
vehicle_response_data['IsUpdateAvailable'] = True |
|||
vehicle_response_data['Remarks'] = "Internal Full Update available" |
|||
|
|||
else: |
|||
vehicle_response_data['IsUpdateAvailable'] = False |
|||
vehicle_response_data['Remarks'] = "Internal Full Update available" |
|||
vehicle_response_data['Error'] = "Failed to read file" |
|||
else: |
|||
vehicle_response_data['IsUpdateAvailable'] = False |
|||
vehicle_response_data['Remarks'] = "Internal Full Update available" |
|||
vehicle_response_data['Error'] = "Failed to get Publish version" |
|||
else: |
|||
vehicle_response_data['IsUpdateAvailable'] = False |
|||
vehicle_response_data['Remarks'] = "No Update available" |
|||
|
|||
elif current_version < float(latest_global_version[0]['version']): |
|||
""" Only Global available """ |
|||
|
|||
if (float(latest_global_version[0]['version']) - int(current_version)) > 1: |
|||
""" Full Global File """ |
|||
data = frappe.db.sql('''SELECT name as Name,format(version,2) as Version,vehicle_id as Vehicle,language as Language, |
|||
release_description as Description FROM `tabPublish` where vehicle='{0}' and language='{1}' and |
|||
publish_status='Published' and vehicle_status='Active' and publish_module='Automotive System' |
|||
and version = (select max(version) as version from `tabPublish` |
|||
where publish_module='Automotive System' |
|||
and vehicle='{0}' and language='{1}' and publish_type ='Global'); |
|||
'''.format(vehicle, l_id), as_dict=1) |
|||
if data: |
|||
file_name = JSON_FULL_GLOBAL_PATH + vehicle + "/" + vehicle + \ |
|||
"-" + l_id + "-"+"full_v" + \ |
|||
str(data[0][VERSION] |
|||
) + JSON_EXT |
|||
|
|||
if os.path.exists(base_url + file_name): |
|||
|
|||
vehicle_response_data['Name'] = data[0]['Name'] |
|||
vehicle_response_data['Vehicle'] = data[0]['Vehicle'] |
|||
vehicle_response_data['Version'] = data[0]['Version'] |
|||
vehicle_response_data['Language'] = data[0]['Language'] |
|||
vehicle_response_data['Description'] = data[0]['Description'] |
|||
|
|||
vehicle_response_data['FileSize'] = get_file_size( |
|||
file_name) |
|||
vehicle_response_data['JsonURL'] = file_name |
|||
|
|||
vehicle_response_data['IsUpdateAvailable'] = True |
|||
vehicle_response_data['Remarks'] = "Global Full Update available" |
|||
|
|||
else: |
|||
vehicle_response_data['IsUpdateAvailable'] = False |
|||
vehicle_response_data['Remarks'] = "Global Full Update available" |
|||
vehicle_response_data['Error'] = "Failed to read file" |
|||
else: |
|||
vehicle_response_data['IsUpdateAvailable'] = False |
|||
vehicle_response_data['Remarks'] = "Global Full Update available" |
|||
vehicle_response_data['Error'] = "Failed to get Publish version" |
|||
|
|||
# vehicle_response_data['IsUpdateAvailable'] = True |
|||
# vehicle_response_data['Remarks'] = "Full Update Global available" |
|||
else: |
|||
|
|||
""" Single Global File """ |
|||
# vehicle_response_data['IsUpdateAvailable'] = True |
|||
# vehicle_response_data['Remarks'] = "Global available" |
|||
|
|||
data = frappe.db.sql('''SELECT name as Name,format(version,2) as Version,vehicle_id as Vehicle,language as Language, |
|||
release_description as Description FROM `tabPublish` where vehicle='{0}' and language='{1}' and |
|||
publish_status='Published' and vehicle_status='Active' and publish_module='Automotive System' |
|||
and version = (select max(version) as version from `tabPublish` |
|||
where publish_module='Automotive System' |
|||
and vehicle='{0}' and language='{1}' and publish_type ='Global'); |
|||
'''.format(vehicle, l_id), as_dict=1) |
|||
|
|||
if data: |
|||
file_name = JSON_GLOABL_PATH+vehicle+"/"+vehicle + \ |
|||
"-" + l_id + "_v" + \ |
|||
str(data[0][VERSION]) + JSON_EXT |
|||
|
|||
if os.path.exists(base_url + file_name): |
|||
|
|||
vehicle_response_data['Name'] = data[0]['Name'] |
|||
vehicle_response_data['Vehicle'] = data[0]['Vehicle'] |
|||
vehicle_response_data['Version'] = data[0]['Version'] |
|||
vehicle_response_data['Language'] = data[0]['Language'] |
|||
vehicle_response_data['Description'] = data[0]['Description'] |
|||
|
|||
vehicle_response_data['FileSize'] = get_file_size( |
|||
file_name) |
|||
vehicle_response_data['JsonURL'] = file_name |
|||
|
|||
vehicle_response_data['IsUpdateAvailable'] = True |
|||
vehicle_response_data['Remarks'] = "Global available" |
|||
|
|||
else: |
|||
vehicle_response_data['IsUpdateAvailable'] = False |
|||
vehicle_response_data['Remarks'] = "Global available" |
|||
vehicle_response_data['Error'] = "Failed to read file" |
|||
else: |
|||
vehicle_response_data['IsUpdateAvailable'] = False |
|||
vehicle_response_data['Remarks'] = "Global available" |
|||
vehicle_response_data['Error'] = "Failed to get Publish version" |
|||
|
|||
else: |
|||
""" Unknow condition Dont Know Yet """ |
|||
value = {'latest_publish_version': latest_publish_version[0]['version'], |
|||
" latest_global_version": latest_global_version[0]['version']} |
|||
frappe.log_error('New check Update', str( |
|||
f'Unknow Condition{value}')) |
|||
vehicle_response_data['IsUpdateAvailable'] = True |
|||
vehicle_response_data['Remarks'] = "New Condition" |
|||
|
|||
return vehicle_response_data |
|||
|
|||
|
|||
@frappe.whitelist(allow_guest=1) |
|||
def check_all_vehicle_updates(vehicle_list=None): |
|||
|
|||
val = input_validation(vehicle_list=vehicle_list) |
|||
if val != '': |
|||
return {STATUS: 0, ERROR: PARAM_MISSING+val} |
|||
|
|||
if vehicle_list: |
|||
try: |
|||
vehicle_req_list = [] |
|||
response = {} |
|||
v_list = json.loads(vehicle_list) |
|||
lang = v_list['LanguageID'] |
|||
iid = v_list['InstallationId'] |
|||
vehicle_data = v_list['VehicleReqList'] |
|||
publish_type = frappe.db.sql( |
|||
'''SELECT publish_type FROM `tabApp Device` where name='{}';'''.format(iid), as_list=1) |
|||
|
|||
if publish_type[0][0] is not None: |
|||
if vehicle_data: |
|||
for v in vehicle_data: |
|||
v_id = v['Vehicle'] |
|||
current_version = float(v[CUR_VERSION]) |
|||
data1_global = frappe.db.sql('''SELECT name,format(version,2) as version,vehicle_id,language,release_description as description |
|||
FROM `tabPublish` where vehicle='{}' and language='{}' and publish_status='Published' |
|||
and publish_type='Global' |
|||
and vehicle_status='Active' and publish_module='Automotive System' and version = (select max(version) as version |
|||
from `tabPublish` where publish_module='Automotive System' |
|||
and vehicle='{}' and publish_type='Global' and language='{}');'''.format(v_id, lang, v_id, lang), as_dict=1) |
|||
|
|||
data1 = frappe.db.sql('''SELECT name,format(max(version),2) as version,vehicle_id,language,release_description as description |
|||
FROM `tabPublish` where vehicle='{}' and language='{}' |
|||
and publish_status='Published' and vehicle_status='Active' and publish_module='Automotive System' |
|||
and vehicle='{}' and language='{}' |
|||
;'''.format(v_id, lang, v_id, lang), as_dict=1) |
|||
|
|||
if data1[0]['version'] is not None: |
|||
if current_version == float(data1[0]['version']): |
|||
|
|||
data1[0][CUR_VERSION] = current_version |
|||
data1[0][UPDATE_AVAILABLE] = "false" |
|||
vehicle_req_list.append(data1) |
|||
elif len(data1_global) == 0: |
|||
|
|||
if current_version < float(data1[0]['version']): |
|||
data = frappe.db.sql('''SELECT name,format(version,2) as version,vehicle_id,language,release_description as description |
|||
FROM `tabPublish` where vehicle='{}' and language='{}' and publish_status='Published' and |
|||
publish_type='{}' and vehicle_status='Active' and publish_module='Automotive System' and |
|||
version = (select max(version) as version from `tabPublish` where publish_module='Automotive System' |
|||
and vehicle='{}' and language='{}')'''.format(v_id, lang, publish_type[0][0], v_id, lang), as_dict=1) |
|||
data_append = [] |
|||
rd = [] |
|||
try: |
|||
for d in data: |
|||
d[UPDATE_AVAILABLE] = 'true' |
|||
|
|||
d[CUR_VERSION] = current_version |
|||
data_append.append(d) |
|||
vehicle_req_list.append(data_append) |
|||
|
|||
except: |
|||
pass |
|||
else: |
|||
if current_version < float(data1_global[0]['version']): |
|||
data = frappe.db.sql('''SELECT name,format(version,2) as version,vehicle_id,language,release_description as description |
|||
FROM `tabPublish` where vehicle='{}' and language='{}' |
|||
and publish_status='Published' and publish_type='Global' and vehicle_status='Active' |
|||
and publish_module='Automotive System' |
|||
and version = (select max(version) as version from `tabPublish` |
|||
where publish_module='Automotive System' |
|||
and vehicle='{}' and language='{}')'''.format(v_id, lang, v_id, lang), as_dict=1) |
|||
|
|||
elif current_version == float(data1_global[0]['version']): |
|||
|
|||
if current_version < float(data1[0]['version']): |
|||
data = frappe.db.sql('''SELECT name,format(version,2) as version,vehicle_id,language,release_description as description |
|||
FROM `tabPublish` where vehicle='{}' and language='{}' and publish_status='Published' and publish_type='{}' |
|||
and vehicle_status='Active' and publish_module='Automotive System' |
|||
and version = (select max(version) as version from `tabPublish` where publish_module='Automotive System' |
|||
and vehicle='{}' and language='{}')'''.format(v_id, lang, publish_type[0][0], v_id, lang), as_dict=1) |
|||
|
|||
elif current_version > float(data1_global[0]['version']): |
|||
|
|||
if current_version < float(data1[0]['version']): |
|||
data = frappe.db.sql('''SELECT name,format(version,2) as version,vehicle_id,language,release_description as description |
|||
FROM `tabPublish` where vehicle='{}' and language='{}' and publish_status='Published' and |
|||
publish_type='{}' and vehicle_status='Active' and publish_module='Automotive System' and |
|||
version = (select max(version) as version from `tabPublish` where publish_module='Automotive System' |
|||
and vehicle='{}' and language='{}')'''.format(v_id, lang, publish_type[0][0], v_id, lang), as_dict=1) |
|||
|
|||
# return data |
|||
data_append = [] |
|||
rd = [] |
|||
try: |
|||
for d in data: |
|||
d[UPDATE_AVAILABLE] = 'true' |
|||
|
|||
d[CUR_VERSION] = current_version |
|||
data_append.append(d) |
|||
vehicle_req_list.append(data_append) |
|||
|
|||
# for note in publish_dec: |
|||
# rd.append(note) |
|||
# vehicle_req_list.append(rd) |
|||
# for n in publish_dec: |
|||
# rd.append(n['release_description']) |
|||
# vehicle_req_list.append(rd) |
|||
except: |
|||
pass |
|||
|
|||
response['LanguageID'] = lang |
|||
|
|||
if len(vehicle_req_list) != 0: |
|||
data = [vu[0] for vu in vehicle_req_list] |
|||
|
|||
# publish_dec_txt = [pd[0] for pd in publish_dec] |
|||
response['VehicleReqList'] = data |
|||
# response['release_description'] = publish_dec_txt['release_description'] |
|||
return response |
|||
else: |
|||
return {STATUS: 0, ERROR: "No Vehicles in criteria"} |
|||
else: |
|||
return {STATUS: 0, ERROR: "Invalid Publish Details"} |
|||
else: |
|||
return {STATUS: 0, ERROR: "Invalid Publish Details"} |
|||
|
|||
except Exception as e: |
|||
|
|||
return {STATUS: 0, ERROR: str(e)} |
|||
else: |
|||
return {STATUS: 0, ERROR: "Check argument: vehicle list"} |
File diff suppressed because it is too large
@ -0,0 +1,177 @@ |
|||
import frappe |
|||
import os |
|||
|
|||
@frappe.whitelist() |
|||
def check_img_ext(path): |
|||
if path: |
|||
ext = path.split()[-1] |
|||
if ext.lower().endswith('.jpg') or ext.lower().endswith('.jpeg'): |
|||
return True |
|||
else: |
|||
return False |
|||
else: |
|||
return False |
|||
|
|||
|
|||
@frappe.whitelist() |
|||
def check_png_ext(path): |
|||
if path: |
|||
ext = path.split()[-1] |
|||
if ext.lower().endswith('.png'): |
|||
return True |
|||
else: |
|||
return False |
|||
else: |
|||
return False |
|||
|
|||
|
|||
@frappe.whitelist() |
|||
def check_zip_ext(path): |
|||
if path: |
|||
ext = path.split()[-1] |
|||
if ext.lower().endswith('.zip'): |
|||
return True |
|||
else: |
|||
return False |
|||
else: |
|||
return False |
|||
|
|||
|
|||
@frappe.whitelist() |
|||
def check_pdf_ext(path): |
|||
if path: |
|||
ext = path.split()[-1] |
|||
if ext.lower().endswith('.pdf'): |
|||
return True |
|||
else: |
|||
return False |
|||
else: |
|||
return False |
|||
|
|||
|
|||
@frappe.whitelist() |
|||
def check_mp4_ext(path): |
|||
if path: |
|||
ext = path.split()[-1] |
|||
if ext.lower().endswith('.mp4'): |
|||
return True |
|||
else: |
|||
return False |
|||
|
|||
@frappe.whitelist() |
|||
def check_html_ext(path): |
|||
if path: |
|||
ext = path.split()[-1] |
|||
if ext.lower().endswith('.html'): |
|||
return True |
|||
else: |
|||
return False |
|||
|
|||
|
|||
@frappe.whitelist() |
|||
def check_ppt_ext(path): |
|||
if path: |
|||
ext = path.split()[-1] |
|||
if ext.lower().endswith('.pptx'): |
|||
return True |
|||
elif ext.lower().endswith('.pptm'): |
|||
return True |
|||
elif ext.lower().endswith('.ppt'): |
|||
return True |
|||
|
|||
else: |
|||
return False |
|||
|
|||
@frappe.whitelist() |
|||
def check_web_link(path): |
|||
if path.lower().startswith("http:") or path.lower().startswith("https:"): |
|||
return True |
|||
else: |
|||
return False |
|||
def details_of_image(image_file): |
|||
try: |
|||
# Image dimension validation |
|||
import os |
|||
from PIL import Image |
|||
if image_file.startswith('/private/'): |
|||
filepath = get_absolute_path(image_file, True) |
|||
else: |
|||
filepath = get_absolute_path(image_file) |
|||
img = Image.open(filepath) |
|||
width = img.width |
|||
height = img.height |
|||
size = os.stat(filepath) |
|||
size=size[6]/1024 |
|||
return width, height,size |
|||
except Exception as e: |
|||
raise e |
|||
|
|||
def get_file_size(filepath): |
|||
if filepath.startswith('/private/'): |
|||
file_dir = get_absolute_path(filepath, True) |
|||
else: |
|||
file_dir = get_absolute_path(filepath) |
|||
|
|||
size_in_bytes = os.path.getsize(file_dir) |
|||
size_in_megabytes = size_in_bytes / (1024 * 1024) |
|||
return size_in_megabytes |
|||
|
|||
|
|||
def get_image_size(filepath): |
|||
if filepath.startswith('/private/'): |
|||
file_dir = get_absolute_path(filepath, True) |
|||
else: |
|||
file_dir = get_absolute_path(filepath) |
|||
|
|||
size_in_bytes = os.path.getsize(file_dir) |
|||
size_in_kilobytes = size_in_bytes / 1024 |
|||
return size_in_kilobytes |
|||
|
|||
|
|||
def get_absolute_path(file_name, is_private=False): |
|||
try: |
|||
if file_name.startswith('/files/'): |
|||
file_name = file_name[7:] |
|||
else: |
|||
file_name = file_name[15:] |
|||
return frappe.utils.get_bench_path() + "/sites/" + frappe.utils.get_path('private' if is_private else 'public', |
|||
'files', file_name)[2:] |
|||
except Exception as e: |
|||
frappe.log_error("get_absolute_path", frappe.get_traceback()) |
|||
|
|||
|
|||
|
|||
def checking_image(file_url, attached_to_doctype, attached_to_field, docname, is_child=None): |
|||
try: |
|||
import time |
|||
time.sleep(1) |
|||
if docname.startswith('new'): |
|||
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}) |
|||
|
|||
else: |
|||
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}) |
|||
|
|||
image_name = frappe.db.sql(f"""select name from `tabFile` where file_url='{file_url}' and attached_to_doctype='{attached_to_doctype}' and |
|||
attached_to_field='{attached_to_field}'""",as_dict=1) |
|||
# frappe.msgprint("data-"+str(file_url)+"-"+str(attached_to_doctype)+"-"+str(attached_to_field)+"-"+str(docname)) |
|||
if not attached_to_doctype == "Symbol Scanner" and is_child != 1: |
|||
frappe.db.sql( |
|||
'''UPDATE `tab{0}` SET {2} = '' where name = "{1}"'''.format(attached_to_doctype, docname, |
|||
attached_to_field)) |
|||
frappe.db.commit() |
|||
if attached_to_doctype == "Symbol Scanner": |
|||
frappe.db.set_value( |
|||
"Symbol Scanner", "Symbol Scanner", attached_to_field, "") |
|||
|
|||
if len(image_name) > 0: |
|||
frappe.delete_doc('File', image_name[0]['name']) |
|||
return True |
|||
|
|||
except Exception as e: |
|||
frappe.log_error("Checking images", frappe.get_traceback()) |
|||
|
@ -0,0 +1,751 @@ |
|||
from frappe.utils import cstr |
|||
import frappe |
|||
import re |
|||
from urllib import request |
|||
import datetime |
|||
from frappe import utils |
|||
import json |
|||
import html |
|||
import os |
|||
import shutil |
|||
import zipfile |
|||
success_reponse = {"status": 1, "data": "", "message": ""} |
|||
|
|||
|
|||
site_name = cstr(frappe.local.site) |
|||
BASE_URL = os.path.expanduser( |
|||
"~") + "/frappe-bench/sites/" + site_name + "/public" |
|||
# base = os.path.expanduser( |
|||
# "~") + "/frappe-bench/sites/" + site_name |
|||
|
|||
|
|||
date_format = "%Y-%m-%d %H:%M:%S.%f" |
|||
current_db_name = frappe.conf.get("db_name") |
|||
|
|||
# style="""<style> |
|||
# ul { |
|||
# margin: 0.75em 0; |
|||
# padding: 0 1em; |
|||
# list-style: none; |
|||
# } |
|||
# li:before { |
|||
# content: ""; |
|||
# border-color: transparent #FF0000; |
|||
# border-style: solid; |
|||
# border-width: 0.35em 0 0.35em 0.45em; |
|||
# display: block; |
|||
# height: 0; |
|||
# width: 0; |
|||
# left: -1em; |
|||
# top: 0.9em; |
|||
# position: relative; |
|||
# } |
|||
# </style>""" |
|||
|
|||
|
|||
@frappe.whitelist(methods=["POST"], allow_guest=1) |
|||
def get_role_mapping(): |
|||
req = json.loads(frappe.request.data) |
|||
try: |
|||
lsdt = req['lsdt'] |
|||
if lsdt != '': |
|||
try: |
|||
datetime.datetime.strptime(lsdt, date_format) |
|||
except: |
|||
frappe.local.response['http_status_code'] = 400 |
|||
return {"status": 0, "error": "Invalid date format", 'data': None} |
|||
|
|||
except Exception as e: |
|||
frappe.local.response['http_status_code'] = 403 |
|||
return {"status": 0, "error": e} |
|||
|
|||
data = {} |
|||
try: |
|||
module_details = frappe.db.sql(f"""select module_name,active_status,my_id,display_order,modified from `tabModule Master` |
|||
where modified >= '{lsdt}' order by display_order;""", as_dict=1) |
|||
data['module'] = module_details |
|||
if lsdt: |
|||
role_maping_details = frappe.db.sql(f"""SELECT role,my_id,display_order,modules,active_status,modified from `tabRole Master` |
|||
where active_status = 'Active' and modified>='{lsdt}' order by display_order;""", as_dict=1) |
|||
else: |
|||
role_maping_details = frappe.db.sql(f"""SELECT role,my_id,display_order,modules,active_status,modified from `tabRole Master` |
|||
where active_status = 'Active' order by display_order;""", as_dict=1) |
|||
|
|||
data['role_mapping'] = role_maping_details |
|||
return {"status": 1, "error": None, 'lsdt': utils.now(), "data": data} |
|||
|
|||
except Exception as e: |
|||
return {"status": 0, "error": e, 'lsdt': utils.now(), "data": None} |
|||
|
|||
|
|||
@frappe.whitelist(methods=["POST"], allow_guest=1) |
|||
def get_repair_service_mapping(vehicle, language): |
|||
try: |
|||
repair_service_details = [] |
|||
if language == 'en': |
|||
repair_service_details = frappe.db.sql(f""" select vehicle,vehicle_id,name,language,check_list_name,active_status,display_order,my_id,keywords from |
|||
`tabRepair Service Mapping` where vehicle = '{vehicle}' and language = '{language}'; """, as_dict=1) |
|||
else: |
|||
repair_service_details = frappe.db.sql(f""" select vehicle,vehicle_id,name,language,translated_check_list_name as check_list_name,active_status,keywords, |
|||
display_order,my_id from `tabRepair Service Mapping` where vehicle = '{vehicle}' and |
|||
language = '{language}'; """, as_dict=1) |
|||
|
|||
for d in repair_service_details: |
|||
d['complaint'] = frappe.db.sql(f""" select complaint,remedial_action_ok,remedial_action_not_ok,idx as display_order from |
|||
`tabRepair Service Child` where parent = '{d['name']}' order by display_order ;""", as_dict=1) |
|||
return True, repair_service_details |
|||
|
|||
except Exception as e: |
|||
return False, e |
|||
|
|||
|
|||
@frappe.whitelist(methods=["POST"], allow_guest=1) |
|||
def get_feature_finder(vehicle, variant, language): |
|||
try: |
|||
feature_finder_details = [] |
|||
if language == 'en': |
|||
feature_finder_details = frappe.db.sql(f"""select ff.name,ff.vehicle,ff.vehicle_id,ff.variant,ff.variant_id,ff.language, |
|||
ff.keywords,ff.sop_name, |
|||
ff.features_names as feature_name,ff.feature_category,ff.display_order,ff.active_status, |
|||
ffm.feature_pdf as pdf from `tabFeature Finder` ff left join `tabFeature Finder Master` ffm on |
|||
ff.features_names = ffm.feature_name |
|||
where ff.vehicle = "{vehicle}" and ffm.vehicle = "{vehicle}" and ff.variant = "{variant}" |
|||
and ff.language = "{language}" and ffm.language = "{language}"; |
|||
""", as_dict=1) |
|||
else: |
|||
feature_finder_details = frappe.db.sql(f"""select ff.name,ff.vehicle,ff.vehicle_id,ff.variant,ff.variant_id,ff.language, |
|||
ff.keywords,ff.sop_name, |
|||
ff.translated_feature_name as feature_name,ff.feature_category, |
|||
ff.display_order,ff.active_status,ffm.feature_pdf as pdf from `tabFeature Finder` ff |
|||
left join `tabFeature Finder Master` ffm on ff.features_names = ffm.feature_name |
|||
where ff.vehicle = "{vehicle}" and ffm.vehicle = "{vehicle}" and ff.variant = "{variant}" |
|||
and ff.language = "{language}"; """, as_dict=1) |
|||
|
|||
for f in feature_finder_details: |
|||
f['disclaimer'] = frappe.db.sql(f''' |
|||
SELECT name,content,idx as display_order FROM `tabFeature Finder Disclaimer` |
|||
where parent = '{str(f['vehicle'])+ str('-')+ str(f['feature_name']) +str('-')+str(f['language'])}' |
|||
order by display_order; |
|||
''', as_dict=1) |
|||
|
|||
sop_images = frappe.db.sql(f""" select image,idx as display_order from `tabFeature Finder Images` where |
|||
parent = '{f['name']}' and feature_type ='SOP' order by display_order;""", as_dict=1) |
|||
|
|||
sop_content = frappe.db.sql(f"""select content,idx as display_order from `tabFeature Finder Content` |
|||
where parent = '{f['name']}' and feature_type ='SOP' order by display_order;""", as_dict=1) |
|||
|
|||
sop_specification = frappe.db.sql(f"""select specification,value,idx as display_order from `tabFeature Finder Specification` |
|||
where parent = '{f['name']}' and feature_type ='SOP' order by display_order;""", as_dict=1) |
|||
|
|||
f['sop'] = {'content': sop_content, 'images': sop_images, |
|||
'specificaton': sop_specification, 'sop_name': f['sop_name']} |
|||
post_vin_data = frappe.db.sql(f'''select name,idx as display_order,post_vin_cutoff_name,post_vin_cutoff_id |
|||
from `tabPost Vin Cutoff ID` where parent = '{f['name']}' order by display_order;''', as_dict=1) |
|||
for p in post_vin_data: |
|||
|
|||
vin_content = frappe.db.sql(f"""select content,idx as display_order from `tabFeature Finder Content` |
|||
where parent = '{f['name']}' |
|||
and post_vin_cutoff_name ='{p['post_vin_cutoff_name']}' |
|||
order by display_order;""", as_dict=1) |
|||
|
|||
vin_images = frappe.db.sql(f""" select image,idx as display_order from `tabFeature Finder Images` where |
|||
parent = '{f['name']}' and post_vin_cutoff_name ='{p['post_vin_cutoff_name']}' |
|||
order by display_order;""", as_dict=1) |
|||
|
|||
vin_specification = frappe.db.sql(f"""select specification,value,idx as display_order from `tabFeature Finder Specification` |
|||
where parent = '{f['name']}' and post_vin_cutoff_name ='{p['post_vin_cutoff_name']}' |
|||
order by display_order;""", as_dict=1) |
|||
p['content'] = vin_content |
|||
p['images'] = vin_images |
|||
p['specificaton'] = vin_specification |
|||
|
|||
f['post_vin'] = post_vin_data |
|||
return True, feature_finder_details |
|||
except Exception as e: |
|||
return False, e |
|||
|
|||
|
|||
@frappe.whitelist(methods=["POST"], allow_guest=1) |
|||
def get_training_information(vehicle, language): |
|||
try: |
|||
training_information = frappe.db.sql(f"""select name,vehicle,category,topic,language,active_status,keywords from`tabTraining Information` |
|||
where vehicle = "{vehicle}" and language = "{language}"; """, as_dict=1) |
|||
|
|||
for t in training_information: |
|||
t['content'] = frappe.db.sql(f''' select content_type,content,image_video,idx as display_order,active_status from |
|||
`tabTraining Information Content Reference` where parent = '{t['name']}';''', as_dict=1) |
|||
return True, training_information |
|||
except Exception as e: |
|||
return False, e |
|||
|
|||
|
|||
@frappe.whitelist(methods=['POST'], allow_guest=1) |
|||
def new_publish_old(): |
|||
req = json.loads(frappe.request.data) |
|||
try: |
|||
module = req['module'] |
|||
iid = req['iid'] |
|||
vehicle = req['vehicle'] |
|||
variant = req['variant'] |
|||
language = req['language'] |
|||
|
|||
data = [] |
|||
|
|||
if module == 'Feature Finder': |
|||
|
|||
flag, data = get_feature_finder(vehicle, variant, language) |
|||
|
|||
elif module == 'Repair/Service Check Sheet': |
|||
flag, data = get_repair_service_mapping(vehicle, language) |
|||
|
|||
elif module == 'QWIK Service': |
|||
flag, data = get_qwik_service(variant, language) |
|||
CLEANR = re.compile('<.*?>') |
|||
CLEANR_back_slash = re.compile("\"") |
|||
ul_html = '<ul style="list-style-type: none; padding-left: 0px;"><span style="width: 0;height: 0;border-top: 6px solid transparent;border-left: 8px solid red;border-bottom: 6px solid transparent;position: absolute;margin-top: 3px;"></span>' |
|||
li_html = '<li style="margin-left: 15px;padding: 0px 1px 5px 0px;"data-list=\"bullet\">' |
|||
cling_li = '</li><span style="width: 0;height: 0;border-top: 6px solid transparent;border-left: 8px solid red;border-bottom: 6px solid transparent;position: absolute;margin-top: 3px;"></span>' |
|||
cling_last = '</ul>' |
|||
find_last_ul = '<span style="width: 0;height: 0;border-top: 6px solid transparent;border-left: 8px solid red;border-bottom: 6px solid transparent;position: absolute;margin-top: 3px;"></span></ul>' |
|||
|
|||
for dt in data: |
|||
|
|||
if len(dt['consumables']) > 0: |
|||
|
|||
for con in dt['consumables']: |
|||
if con['content']: |
|||
con['content'] = re.sub(CLEANR, '', con['content']) |
|||
# if len(dt['pre_work'])>0: |
|||
for pw in dt['pre_work']: |
|||
reg_str = "<p>" |
|||
reg_str1 = "<div>" |
|||
|
|||
if pw['content']: |
|||
res = str(pw['content']).find('<div>') |
|||
res1 = str(pw['content']).find('<p>') |
|||
if res == 1: |
|||
pw['content'] = re.sub( |
|||
'<div>', '', pw['content']) |
|||
pw['content'] = re.sub( |
|||
'</div>', '', pw['content']) |
|||
pw['content'] = re.sub( |
|||
'<p>', '<div style="color: #fff;margin:0px !important;">', pw['content']) |
|||
pw['content'] = re.sub( |
|||
'</p>', '</div>', pw['content']) |
|||
cnverted_data = re.sub( |
|||
CLEANR_back_slash, "'", pw['content']) |
|||
pw['content'] = cnverted_data |
|||
else: |
|||
pw['content'] = '<div style="color: #fff;margin:0px !important;">' + \ |
|||
pw['content']+'</div>' |
|||
cnverted_data = re.sub( |
|||
CLEANR_back_slash, "'", pw['content']) |
|||
|
|||
pw['content'] = cnverted_data |
|||
if res1 == 1: |
|||
pw['content'] = re.sub( |
|||
'<div>', '', pw['content']) |
|||
pw['content'] = re.sub( |
|||
'</div>', '', pw['content']) |
|||
pw['content'] = re.sub( |
|||
'<p>', '<div style="color: #fff;margin:0px !important;">', pw['content']) |
|||
pw['content'] = re.sub( |
|||
'</p>', '</div>', pw['content']) |
|||
cnverted_data = re.sub( |
|||
CLEANR_back_slash, "'", pw['content']) |
|||
pw['content'] = cnverted_data |
|||
else: |
|||
|
|||
pw['content'] = '<div style="color: #fff;margin:0px !important;">' + \ |
|||
pw['content']+'</div>' |
|||
cnverted_data = re.sub( |
|||
CLEANR_back_slash, "'", pw['content']) |
|||
|
|||
pw['content'] = cnverted_data |
|||
|
|||
if dt['qwik_procedure']: |
|||
for qp in dt['qwik_procedure']['LHS']: |
|||
if qp['content']: |
|||
qp['content'] = re.sub( |
|||
'<ul>', ul_html, qp['content']) |
|||
qp['content'] = re.sub( |
|||
'<li data-list="bullet">', li_html, qp['content']) |
|||
clsing_li_tag = re.sub( |
|||
'</li>', cling_li, qp['content']) |
|||
qp['content'] = clsing_li_tag |
|||
res = re.sub( |
|||
find_last_ul, cling_last, qp['content']) |
|||
qp['content'] = res |
|||
|
|||
cnverted_data = re.sub( |
|||
CLEANR_back_slash, "'", qp['content']) |
|||
qp['content'] = cnverted_data |
|||
|
|||
for qp_rhs in dt['qwik_procedure']['RHS']: |
|||
if qp_rhs: |
|||
qp_rhs['content'] = re.sub( |
|||
'<ul>', ul_html, qp_rhs['content']) |
|||
qp_rhs['content'] = re.sub( |
|||
'<li data-list="bullet">', li_html, qp_rhs['content']) |
|||
qp_rhs['content'] = re.sub( |
|||
'</li>', cling_li, qp_rhs['content']) |
|||
qp_rhs['content'] = re.sub( |
|||
find_last_ul, cling_last, qp_rhs['content']) |
|||
cnverted_data = re.sub( |
|||
CLEANR_back_slash, "'", qp_rhs['content']) |
|||
qp_rhs['content'] = cnverted_data |
|||
|
|||
elif module == 'Training Information': |
|||
base_path = BASE_URL + "/" + "training" + "/" + vehicle |
|||
scrom_path = base_path + "/" + "scrom" |
|||
# html_path = base_path +"/"+ "/html" |
|||
flag, data = get_training_information(vehicle, language) |
|||
# for d in data: |
|||
# if d['content']: |
|||
# for ch in d['content']: |
|||
# if ch['topic'] == 'SCROM' and ch['content']!=None: |
|||
# scrom_folder_path = base_path +"/"+ "scrom" + "/" + ch['content'].split("/")[2].split(".")[0] |
|||
# if not os.path.exists(scrom_folder_path): |
|||
# os.makedirs(scrom_folder_path) |
|||
# if ch['content']: |
|||
# frappe.log_error(str(ch['content'])) |
|||
# with zipfile.ZipFile(BASE_URL+ch['content'], 'r') as zip_ref: |
|||
# zip_ref.extractall(path=scrom_folder_path) |
|||
# ch['content'] = scrom_folder_path + ch['content'].split("/")[2].split(".")[0] |
|||
# cont=frappe.db.sql('''select content from `tabTraining Information Content Reference` where parent = %s and topic = 'SCROM' '''%(d['name']),as_dict=1) |
|||
|
|||
elif module == 'Mahindra Special Tool Information': |
|||
CLEANR_back_slash = re.compile("\"") |
|||
html_code_ul = '<ul style="list-style-type: none; padding-left: 0px;"><span style="width: 0;height: 0;border-top: 6px solid transparent;border-left: 8px solid red;border-bottom: 6px solid transparent;position: absolute;margin-top: 3px;"></span>' |
|||
html_code_li = '<li style="margin-left: 15px;padding: 0px 1px 5px 0px;"data-list="bullet">' |
|||
flag, data = get_special_tool_information(vehicle) |
|||
for dt in data: |
|||
if len(dt['instructions']) > 0: |
|||
for c_t in dt['instructions']: |
|||
if c_t['content_type'] == 'Description': |
|||
if c_t['content']: |
|||
c_t['content'] = html_code_ul + \ |
|||
html_code_li+c_t['content']+'</li>'+'</ul>' |
|||
cnverted_data = re.sub( |
|||
CLEANR_back_slash, "'", c_t['content']) |
|||
c_t['content'] = cnverted_data |
|||
|
|||
elif module == 'PDI Inspection': |
|||
pass |
|||
|
|||
elif module == 'Torque Information': |
|||
flag, data = get_torque_information(variant, language) |
|||
|
|||
else: |
|||
flag = False |
|||
data = 'No Module found' |
|||
|
|||
if flag: |
|||
return {'status': 1, 'error': None, 'data': data} |
|||
else: |
|||
return {'status': 0, 'error': data, 'data': None} |
|||
|
|||
except Exception as e: |
|||
frappe.local.response['http_status_code'] = 400 |
|||
return {'status': 0, 'error': "Parameter's missing: " + str(e), 'data': None} |
|||
|
|||
|
|||
@frappe.whitelist(methods=['POST'], allow_guest=1) |
|||
def new_publish(): |
|||
req = json.loads(frappe.request.data) |
|||
try: |
|||
module = req['module'] |
|||
iid = req['iid'] |
|||
vehicle_name = req['vehicle'] |
|||
vehicle = req['vehicle'].replace(' ','-') |
|||
variant = req['variant'] |
|||
language = req['language'] |
|||
|
|||
|
|||
val = input_validation(req) |
|||
|
|||
# if val != '' or val != "": |
|||
# return {"status": 0, "error": "Input parameter Missing: " + val} |
|||
data = [] |
|||
# Get Publish Type |
|||
publish_type = frappe.db.get_list( |
|||
'App Device', filters={'name': iid}, fields='publish_type') |
|||
|
|||
|
|||
if len(publish_type) > 0: |
|||
publish_type = publish_type[0]['publish_type'] |
|||
else: |
|||
return {"status": 0, "error": "Publish Type Not Set For: " + iid,"data":None} |
|||
BASE_PATH = BASE_URL + "/files/json_files/phase2/" + \ |
|||
str(vehicle) + '/' + str(language) + '/' + str(publish_type) + '/' |
|||
if module == 'Feature Finder': |
|||
FULL_UPDATE_PATH = BASE_URL + "/files/json_files/phase2/" + \ |
|||
str(vehicle) + '/' + str(language) + '/' + \ |
|||
"{}".format(publish_type)+"_Full_Update/" |
|||
|
|||
FULL_UPDATE_PATH_FILE = FULL_UPDATE_PATH + \ |
|||
vehicle.replace(' ', '-') + \ |
|||
'-feature_finder_full_update' + '.json' |
|||
LATEST_GLOBAL_PATH = BASE_URL + "/files/json_files/phase2/" + \ |
|||
str(vehicle) + '/' + str(language) + \ |
|||
'/' + "Global_Full_Update/" |
|||
LATEST_GLOBAL_FILE = LATEST_GLOBAL_PATH + \ |
|||
vehicle.replace(' ', '-') + \ |
|||
'-feature_finder_full_update' + '.json' |
|||
|
|||
# if publish_type == 'Internal': |
|||
if os.path.isfile(FULL_UPDATE_PATH_FILE): |
|||
with open(FULL_UPDATE_PATH_FILE) as outfile: |
|||
data = json.load(outfile) |
|||
# data = data['data'] |
|||
# filter_json = filter_publish_json(data, variant) |
|||
# data = filter_json |
|||
data = data.get('data') |
|||
data = data.get(variant) |
|||
elif os.path.isfile(LATEST_GLOBAL_FILE): |
|||
with open(LATEST_GLOBAL_FILE) as outfile: |
|||
data = json.load(outfile) |
|||
data = data.get('data') |
|||
data = data.get(variant) |
|||
else: |
|||
frappe.local.response['http_status_code'] = 200 |
|||
return {'status': 0, 'error':"No Data Published", 'data':None } |
|||
|
|||
elif module == 'Repair/Service Check Sheet': |
|||
FULL_UPDATE_FOLDER = BASE_URL + "/files/json_files/phase2/" + \ |
|||
str(vehicle) + '/' + str(language) + '/' + \ |
|||
"{}".format(publish_type)+"/" |
|||
FULL_UPDATE_PATH_FILE = FULL_UPDATE_FOLDER + \ |
|||
vehicle.replace(' ', '-') + '-repair_check_sheet.json' |
|||
LATEST_GLOBAL_PATH = BASE_URL + "/files/json_files/phase2/" + \ |
|||
str(vehicle) + '/' + str(language) + '/' + "Global/" |
|||
LATEST_GLOBAL_FILE = LATEST_GLOBAL_PATH + \ |
|||
vehicle.replace(' ', '-') + '-repair_check_sheet.json' |
|||
|
|||
if os.path.isfile(FULL_UPDATE_PATH_FILE): |
|||
with open(FULL_UPDATE_PATH_FILE) as outfile: |
|||
data = json.load(outfile) |
|||
|
|||
data = data.get('data') |
|||
# data = data.get(variant) |
|||
elif os.path.isfile(LATEST_GLOBAL_FILE): |
|||
|
|||
with open(LATEST_GLOBAL_FILE) as outfile: |
|||
data = json.load(outfile) |
|||
|
|||
data = data.get('data') |
|||
else: |
|||
frappe.local.response['http_status_code'] = 200 |
|||
return {'status': 0, 'error': "No Data Published", 'data':None } |
|||
|
|||
elif module == 'QWIK Service': |
|||
|
|||
FULL_UPDATE_PATH = BASE_URL + "/files/json_files/phase2/" + \ |
|||
str(vehicle) + '/' + str(language) + '/' + \ |
|||
"{}".format(publish_type)+"_Full_Update/" |
|||
|
|||
FULL_UPDATE_PATH_FILE = FULL_UPDATE_PATH + \ |
|||
vehicle.replace(' ', '-') + '-qwik_service_full_update.json' |
|||
LATEST_GLOBAL_PATH = BASE_URL + "/files/json_files/phase2/" + \ |
|||
str(vehicle) + '/' + str(language) + \ |
|||
'/' + "Global_Full_Update/" |
|||
LATEST_GLOBAL_FILE = LATEST_GLOBAL_PATH + \ |
|||
vehicle.replace(' ', '-') + '-qwik_service_full_update.json' |
|||
|
|||
# if publish_type == 'Internal': |
|||
if os.path.isfile(FULL_UPDATE_PATH_FILE): |
|||
with open(FULL_UPDATE_PATH_FILE) as outfile: |
|||
data = json.load(outfile) |
|||
# data = data['data'] |
|||
# filter_json = filter_publish_json(data, variant) |
|||
# data = filter_json |
|||
data = data.get('data') |
|||
data = data.get(variant) |
|||
elif os.path.isfile(LATEST_GLOBAL_FILE): |
|||
|
|||
with open(LATEST_GLOBAL_FILE) as outfile: |
|||
data = json.load(outfile) |
|||
# data = data['data'] |
|||
# filter_json = filter_publish_json(data, variant) |
|||
# data = filter_json |
|||
data = data.get('data') |
|||
data = data.get(variant) |
|||
else: |
|||
frappe.local.response['http_status_code'] = 200 |
|||
return {'status': 0, 'error': "No Data Published", 'data':None } |
|||
|
|||
elif module == 'Training Information': |
|||
FULL_UPDATE_FOLDER = BASE_URL + "/files/json_files/phase2/" + \ |
|||
str(vehicle) + '/' + str(language) + '/' + \ |
|||
"{}".format(publish_type)+"/" |
|||
FULL_UPDATE_PATH_FILE = FULL_UPDATE_FOLDER + \ |
|||
vehicle.replace(' ', '-') + '-training_information.json' |
|||
LATEST_GLOBAL_PATH = BASE_URL + "/files/json_files/phase2/" + \ |
|||
str(vehicle) + '/' + str(language) + '/' + "Global/" |
|||
LATEST_GLOBAL_FILE = LATEST_GLOBAL_PATH + \ |
|||
vehicle.replace(' ', '-') + '-training_information.json' |
|||
|
|||
if os.path.isfile(FULL_UPDATE_PATH_FILE): |
|||
with open(FULL_UPDATE_PATH_FILE) as outfile: |
|||
data = json.load(outfile) |
|||
|
|||
data = data.get('data') |
|||
elif os.path.isfile(LATEST_GLOBAL_FILE): |
|||
|
|||
with open(LATEST_GLOBAL_FILE) as outfile: |
|||
data = json.load(outfile) |
|||
|
|||
data = data.get('data') |
|||
else: |
|||
frappe.local.response['http_status_code'] = 200 |
|||
return {'status': 0, 'error': "No Data Published", 'data':None } |
|||
|
|||
|
|||
elif module == 'Mahindra Special Tool Information': |
|||
FULL_UPDATE_PATH = BASE_URL + "/files/json_files/phase2/" + \ |
|||
str(vehicle) + '/' + \ |
|||
"{}".format(publish_type)+"_Full_Update/" |
|||
|
|||
FULL_UPDATE_PATH_FILE = FULL_UPDATE_PATH + \ |
|||
vehicle.replace(' ', '-') + '-special_tool.json' |
|||
LATEST_GLOBAL_PATH = BASE_URL + "/files/json_files/phase2/" + \ |
|||
str(vehicle) + '/' + "Global_Full_Update/" |
|||
LATEST_GLOBAL_FILE = LATEST_GLOBAL_PATH + \ |
|||
vehicle.replace(' ', '-') + '-special_tool.json' |
|||
if os.path.isfile(FULL_UPDATE_PATH_FILE): |
|||
with open(FULL_UPDATE_PATH_FILE) as outfile: |
|||
data = json.load(outfile) |
|||
|
|||
data = data.get('data') |
|||
|
|||
elif os.path.isfile(LATEST_GLOBAL_FILE): |
|||
|
|||
with open(LATEST_GLOBAL_FILE) as outfile: |
|||
data = json.load(outfile) |
|||
data = data.get('data') |
|||
else: |
|||
frappe.local.response['http_status_code'] = 200 |
|||
return {'status': 0, 'error': "No Data Published", 'data':None } |
|||
|
|||
elif module == 'PDI Inspection': |
|||
pass |
|||
|
|||
elif module == 'Torque Manual': |
|||
|
|||
FULL_UPDATE_PATH = BASE_URL + "/files/json_files/phase2/" + \ |
|||
str(vehicle) + '/' + str(language) + '/' + \ |
|||
"{}".format(publish_type)+"_Full_Update/" |
|||
|
|||
FULL_UPDATE_PATH_FILE = FULL_UPDATE_PATH + \ |
|||
vehicle.replace(' ', '-') + '-torque_manual_full_update.json' |
|||
LATEST_GLOBAL_PATH = BASE_URL + "/files/json_files/phase2/" + \ |
|||
str(vehicle) + '/' + str(language) + \ |
|||
'/' + "Global_Full_Update/" |
|||
LATEST_GLOBAL_FILE = LATEST_GLOBAL_PATH + \ |
|||
vehicle.replace(' ', '-') + '-torque_manual_full_update.json' |
|||
if os.path.isfile(FULL_UPDATE_PATH_FILE): |
|||
with open(FULL_UPDATE_PATH_FILE) as outfile: |
|||
data = json.load(outfile) |
|||
data = data.get('data') |
|||
data = data.get(variant) |
|||
elif os.path.isfile(LATEST_GLOBAL_FILE): |
|||
with open(LATEST_GLOBAL_FILE) as outfile: |
|||
data = json.load(outfile) |
|||
data = data.get('data') |
|||
data = data.get(variant) |
|||
else: |
|||
frappe.local.response['http_status_code'] = 200 |
|||
return {'status': 0, 'error': "No Data Published", 'data':None } |
|||
frappe.log_error(str(vehicle_name)) |
|||
torque_column_mapping = frappe.db.sql( |
|||
f'''select idx as display_order, concat('col',idx) as column_id,column_name from `tabTorque Column Mapping` where parent = "{vehicle_name}" order by idx; ''', as_dict=1) |
|||
data = {'torque_manual_mapping': torque_column_mapping, |
|||
'torque_manual_data': data} |
|||
|
|||
return {'status': 1, 'error': None, 'data': data} |
|||
|
|||
except Exception as e: |
|||
frappe.local.response['http_status_code'] = 400 |
|||
return {'status': 0, 'error': str(e), 'data': None} |
|||
|
|||
|
|||
@frappe.whitelist(methods=['POST'], allow_guest=1) |
|||
def get_special_tool_information(vehicle): |
|||
try: |
|||
special_tool_information = frappe.db.sql('''select name,vehicle,tool_type,category,aggregate_name,tool_name,aggregate_image as 'tool_image', |
|||
pdf,image,video,keywords,display_order,category_display_order,my_id,active_status from `tabSpecial Tool Information` |
|||
where vehicle= '%s' ;''' % (vehicle), as_dict=1) |
|||
for s in special_tool_information: |
|||
s['instructions'] = frappe.db.sql('''select idx as 'display_order',step_name, content_type, content,attach_file,title |
|||
from `tabInstructions` where parent = '%s' order by display_order;''' % (s['name']), as_dict=1) |
|||
return True, special_tool_information |
|||
except Exception as e: |
|||
return False, e |
|||
|
|||
|
|||
# @frappe.whitelist(methods=['POST'], allow_guest=1) |
|||
def get_qwik_service(variant, language): |
|||
try: |
|||
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 variant='%s' && |
|||
language='%s';''' % (variant, language), 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) |
|||
q['consumables'] = frappe.db.sql('''select idx as 'display_order', content from `tabQwik Service Content` where |
|||
parent='%s' && content_type = 'Consumables' order by display_order;''' % (q['name']), as_dict=1) |
|||
q['tools'] = frappe.db.sql('''select idx as 'display_order', content from `tabQwik Service Content` where |
|||
parent='%s' && content_type = 'Tools' order by display_order;''' % (q['name']), as_dict=1) |
|||
|
|||
for p in qwik_service_details: |
|||
LHS = frappe.db.sql('''select idx as 'display_order',side,level,content from `tabQwik Procedure` |
|||
where parent ='%s' and side = 'LHS';''' % (p['name']), as_dict=1) |
|||
RHS = frappe.db.sql('''select idx as 'display_order',side,level,content from `tabQwik Procedure` |
|||
where parent ='%s' and side = 'RHS';''' % (p['name']), as_dict=1) |
|||
|
|||
p['qwik_procedure'] = {'LHS': LHS, 'RHS': RHS} |
|||
return True, qwik_service_details |
|||
except Exception as e: |
|||
return False, e |
|||
|
|||
|
|||
@frappe.whitelist(methods=["POST"], allow_guest=1) |
|||
def get_torque_information(variant, language): |
|||
try: |
|||
|
|||
torque_manual_details = frappe.db.sql('''select name,variant,vehicle,language,active_status,category,sub_category,display_order,keywords,my_id |
|||
from `tabTorque Manual` where variant ='%s' && language= '%s';''' % (variant, language), as_dict=1) |
|||
frappe |
|||
for t in torque_manual_details: |
|||
t['torque_table'] = frappe.db.sql('''select name,idx as display_order from |
|||
`tabTorque Manual Details` where parent = '%s' order by idx;''' % (t['name']), as_dict=1) |
|||
for d in t['torque_table']: |
|||
|
|||
torque_data = frappe.db.sql('''select col1,col2,col3,col4,col5,col6,col7,col8,col9,col10 from |
|||
`tabTorque Manual Details` where name = '%s' order by idx;''' % (d['name']), as_dict=1) |
|||
# return torque_data |
|||
tor_list = [] |
|||
for i in torque_data: |
|||
for k, v in i.items(): |
|||
tor_list.append({'column_title': k, 'column_value': v}) |
|||
d['torque_data'] = tor_list |
|||
success_reponse['data'] = torque_manual_details |
|||
return success_reponse |
|||
except Exception as e: |
|||
return False, e |
|||
|
|||
|
|||
@frappe.whitelist(methods=["POST"], allow_guest=1) |
|||
def get_training_information(vehicle, language): |
|||
try: |
|||
training_information_details = frappe.db.sql('''select name,vehicle,category,display_order,active_status,my_id,keywords from |
|||
`tabTraining Information` where vehicle = '%s' && language = '%s';''' % (vehicle, language), as_dict=1) |
|||
for i in training_information_details: |
|||
i['content'] = frappe.db.sql('''select idx as 'display_order',topic as file_type,file_url,file_name,scrom_file_url from `tabTraining Information Content Reference` |
|||
where parent = '%s' order by display_order;''' % (i['name']), as_dict=1) |
|||
|
|||
return True, training_information_details |
|||
except Exception as e: |
|||
raise e |
|||
|
|||
|
|||
# @frappe.whitelist(allow_guest=1) |
|||
# def test_html(vehicle): |
|||
# base_path = BASE_URL + "/" + "/training" +"/"+ vehicle |
|||
# # Folder creation |
|||
# scrom_path = base_path +"/"+ "/scrom" |
|||
# html_path = base_path +"/"+ "/html" |
|||
# try: |
|||
# # if not os.path.exists(base_path): |
|||
# # os.makedirs(base_path) |
|||
|
|||
# if not os.path.exists(scrom_path): |
|||
# os.makedirs(scrom_path) |
|||
|
|||
# if not os.path.exists(html_path): |
|||
# os.makedirs(html_path) |
|||
|
|||
# # Create zip file |
|||
# # try: |
|||
# # if path: |
|||
# # ext = path.split()[-1] |
|||
# # if ext.lower().endswith('.zip'): |
|||
# # shutil.unpack_archive(scrom_path, 'zip', base_path) |
|||
# # if path: |
|||
# # ext = path.split()[-1] |
|||
# # if ext.lower().endswith('.html'): |
|||
# # shutil.unpack_archive(html_path, 'html', base_path) |
|||
# # except: |
|||
# # return False, "Failed to create file" |
|||
# except Exception as e: |
|||
# return e |
|||
|
|||
# @frappe.whitelist() |
|||
# def unzip_package(file_path): |
|||
# old_path = BASE_URL + file_path |
|||
# new_path = BASE_URL + "/training_information" |
|||
# shutil.unpack_archive(old_path, new_path) |
|||
|
|||
@frappe.whitelist(allow_guest=1) |
|||
def update_publish_mapping(vehicle, variant, language, module): |
|||
frappe.set_user('Administrator') |
|||
pub_data = frappe.db.get_list('Module Publish Mapping', filters={ |
|||
"vehicle": vehicle, |
|||
"variant": variant, |
|||
"language": language |
|||
}, fields=['name']) |
|||
|
|||
if pub_data: |
|||
doc = frappe.get_doc('Module Publish Mapping', pub_data[0]['name']) |
|||
else: |
|||
doc = frappe.get_doc({ |
|||
'doctype': 'Module Publish Mapping', |
|||
"vehicle": vehicle, |
|||
"variant": variant, |
|||
"language": language |
|||
}) |
|||
if module == 'Automotive System': |
|||
doc.automotive_system = 1 |
|||
doc.tsb = 1 |
|||
doc.fsa = 1 |
|||
doc.tekalert = 1 |
|||
|
|||
elif module == 'Feature Finder': |
|||
doc.feature_finder = 1 |
|||
|
|||
elif module == 'Repair service': |
|||
doc.repairservice_check_sheet = 1 |
|||
doc.save() |
|||
return 1 |
|||
|
|||
|
|||
def filter_publish_json(src_json, filter_cond): |
|||
try: |
|||
filtered_json = [src_json.get(filter_cond, None) for d in src_json] |
|||
|
|||
return filtered_json[0] |
|||
except Exception as e: |
|||
frappe.throw("fil", str(e)) |
|||
|
|||
|
|||
def input_validation(req): |
|||
sts = "" |
|||
i = 0 |
|||
for key, value in req.items(): |
|||
if value is None or value == "" or value == '': |
|||
if i != 0: |
|||
sts += ',' |
|||
sts += str(key) + "" |
|||
i += 1 |
|||
|
|||
return sts |
|||
|
|||
|
|||
@frappe.whitelist() |
|||
def get_published_data(): |
|||
data = frappe.db.sql("""select vehicle,variant,language,publish_type from `tabPublish` where not in (select vehicle,variant,language,publish_type from |
|||
`tabModule Publish Mapping`)""", as_dict=1) |
|||
return data |
|||
|
|||
|
|||
|
@ -0,0 +1,137 @@ |
|||
import frappe |
|||
import re |
|||
from urllib import request |
|||
import datetime |
|||
from frappe import utils |
|||
import json |
|||
import html |
|||
import os |
|||
from frappe.utils import logger |
|||
from frappe.utils import cstr |
|||
frappe.utils.logger.set_log_level("DEBUG") |
|||
|
|||
site_name = cstr(frappe.local.site) |
|||
BASE_URL = os.path.expanduser( |
|||
"~") + "/frappe-bench/sites/" + site_name + "/public" |
|||
|
|||
|
|||
date_format = "%Y-%m-%d %H:%M:%S.%f" |
|||
current_db_name = frappe.conf.get("db_name") |
|||
@frappe.whitelist(allow_guest = 1,methods = ['POST']) |
|||
def repair_checksheet_publish(vehicle = None, language = None |
|||
, publish_type = None , parent = None): |
|||
try: |
|||
req = json.loads(frappe.request.data) |
|||
logger_file = f'{vehicle} - {language} - {publish_type} - repair checksheet' |
|||
logger = frappe.logger(logger_file, allow_site=True, file_count=100) |
|||
logger.info( |
|||
f'Repair Checksheet Started-{vehicle}-{language}-{publish_type}-{parent}') |
|||
|
|||
folder_url = base_url+"/"+vehicle.replace(' ', '-')+"-TEST" + "/"+language |
|||
logger.info(f'Created Folder-{vehicle}-{language}-{publish_type}') |
|||
|
|||
'''Publish Ready Flags''' |
|||
publish_repair_checksheet = 0 |
|||
repair_checksheet_tmp = [] |
|||
|
|||
'''Create Folder For Publish''' |
|||
create_publish_folders(folder_url) |
|||
file_path = folder_url + "/" + publish_type + "/" + \ |
|||
vehicle.replace(' ', '-') + '-repair_check_sheet' + '.json' |
|||
|
|||
full_update_path = folder_url + "/" + publish_type + "/" + \ |
|||
vehicle.replace(' ', '-') + '-repair_check_sheet_full_update' + '.json' |
|||
|
|||
'''Append Published Data to Json''' |
|||
logger.info( |
|||
f'Repair Checksheet Data Append Start::{vehicle}-{language}-{publish_type}') |
|||
vehicle_data = { |
|||
'vehicle': vehicle, |
|||
'vehicle_myid': vehicle_id, |
|||
'publish_type': publish_type, |
|||
'publish_description': release_description, |
|||
'publish_language': language, |
|||
'data': '' |
|||
} |
|||
|
|||
'''update existing global json file''' |
|||
if os.path.isfile(file_path): |
|||
with open(file_path) as f: |
|||
published_data = json.load(f) |
|||
for i in parent: |
|||
repair_checksheet = repair_checksheet_data(vehicle, language, |
|||
publish_type, i.parent_name) |
|||
if repair_checksheet['status'] == 1: |
|||
publish_repair_checksheet = 1 |
|||
repair_checksheet_tmp.append( |
|||
repair_checksheet['data'][0]) |
|||
|
|||
repair_checksheet_tmp = get_latest_data({'data': published_data['data']}, { |
|||
'data': repair_checksheet_tmp}) |
|||
|
|||
else: |
|||
for i in parent.repiar_checksheet_publish_docs: |
|||
repair_checksheet = repair_checksheet_data( |
|||
vehicle, language, publish_type, i.parent_name) |
|||
|
|||
if repair_checksheet['status'] == 1: |
|||
publish_repair_checksheet = 1 |
|||
if len(repair_checksheet['data']): |
|||
repair_checksheet_tmp.append( |
|||
repair_checksheet['data'][0]) |
|||
|
|||
repair_checksheet_tmp = get_latest_data( |
|||
{'data': repair_checksheet_tmp}, {'data': []}) |
|||
|
|||
if publish_repair_checksheet == 1: |
|||
""" Save publish file """ |
|||
vehicle_data['data'] = repair_checksheet_tmp |
|||
|
|||
with open(file_path, 'w') as outfile: |
|||
outfile.write(json.dumps(vehicle_data, indent=4, default=str)) |
|||
|
|||
return 1, file_path |
|||
|
|||
except Exception as e: |
|||
logger.info( |
|||
f'{vehicle} - {language} - {publish_type} error in json creation' + str(e)) |
|||
frappe.throw('Failed To Publish') |
|||
|
|||
|
|||
|
|||
def repair_checksheet_data(vehicle=None, language=None, |
|||
publish_type=None, parent=None): |
|||
try: |
|||
logger_file = f'{vehicle} - {language} - {publish_type} - repair_checksheet_data' |
|||
logger = frappe.logger(logger_file, |
|||
allow_site=True, file_count=100) |
|||
logger.info( |
|||
f"start of fetching repair checksheet data - {vehicle} - {language}") |
|||
|
|||
repair_service_details = frappe.db.sql(f"""select vehicle,vehicle_id, |
|||
name,language,check_list_name, |
|||
keywords, |
|||
active_status,display_order,my_id |
|||
from `tabRepair Service Mapping` |
|||
where vehicle = '{vehicle}' |
|||
and language = '{language}' |
|||
and name = '{parent}'""", as_dict=1) |
|||
|
|||
for d in repair_service_details: |
|||
d['complaint'] = frappe.db.sql(f"""select complaint,remedial_action_ok, |
|||
remedial_action_not_ok,idx as display_order from `tabRepair Service Child` |
|||
where parent = '{d['name']}' |
|||
order by display_order ;""", as_dict=1) |
|||
|
|||
logger.info( |
|||
f"end of fetching repair checksheet data {vehicle} - {language}") |
|||
success_reponse['data'] = repair_service_details |
|||
success_reponse[ |
|||
'message'] = f'Repair Checksheet Fecthed Succesfully for {vehicle} - {language} - repair_checksheet_data ' |
|||
return success_reponse |
|||
|
|||
except Exception as e: |
|||
failure_reponse['error'] = f"{vehicle} - {language} has following error - " + str( |
|||
e) |
|||
logger.error('error in repair checksheet' + str(e)) |
|||
return failure_reponse |
File diff suppressed because it is too large
File diff suppressed because it is too large
@ -0,0 +1,55 @@ |
|||
// Copyright (c) 2023, Hard n Soft Technologies Pvt Ltd and contributors
|
|||
// For license information, please see license.txt
|
|||
var original_display_order = 0; |
|||
var module_name_count=0; |
|||
frappe.require('assets/smart_service/js/utils.js', () => {}) |
|||
|
|||
frappe.ui.form.on('Module Master', { |
|||
onload: function (frm) { |
|||
// Set Display Order
|
|||
if (frm.is_new()) { |
|||
frm.set_df_property('display_order', 'read_only', 1); |
|||
} else { |
|||
frm.set_df_property('display_order', 'read_only', 0); |
|||
} |
|||
frappe.db.count('Module Master') |
|||
.then(count => { |
|||
module_name_count = count + 1; |
|||
if (frm.is_new()) { |
|||
frm.set_value("display_order", module_name_count); |
|||
} else { |
|||
original_display_order = frm.doc.display_order; |
|||
} |
|||
}); |
|||
}, |
|||
|
|||
refresh: function (frm) { |
|||
// Set Display Order
|
|||
if (frm.is_new()) { |
|||
frm.set_df_property('display_order', 'read_only', 1); |
|||
} else { |
|||
frm.set_df_property('display_order', 'read_only', 0); |
|||
} |
|||
frappe.db.count('Module Master') |
|||
.then(count => { |
|||
module_name_count = count + 1; |
|||
if (frm.is_new()) { |
|||
frm.set_value("display_order", module_name_count); |
|||
} else { |
|||
original_display_order = frm.doc.display_order; |
|||
} |
|||
}); |
|||
}, |
|||
|
|||
after_save:function(frm){ |
|||
cur_frm.refresh_fields("display_order") |
|||
}, |
|||
|
|||
validate: function (frm) { |
|||
|
|||
//For Display Order
|
|||
cur_frm.refresh_fields("display_order") |
|||
// console.log(module_name_count,"----",original_display_order)
|
|||
display_order_validation(frm, module_name_count, original_display_order,frm.doc.module_name) |
|||
} |
|||
}); |
@ -0,0 +1,73 @@ |
|||
{ |
|||
"actions": [], |
|||
"allow_rename": 1, |
|||
"autoname": "format:{module_name}", |
|||
"creation": "2023-07-19 13:36:02.668693", |
|||
"doctype": "DocType", |
|||
"editable_grid": 1, |
|||
"engine": "InnoDB", |
|||
"field_order": [ |
|||
"module_name", |
|||
"active_status", |
|||
"display_order", |
|||
"app_menu_id" |
|||
], |
|||
"fields": [ |
|||
{ |
|||
"fieldname": "module_name", |
|||
"fieldtype": "Data", |
|||
"in_list_view": 1, |
|||
"in_standard_filter": 1, |
|||
"label": "Module Name", |
|||
"reqd": 1, |
|||
"set_only_once": 1 |
|||
}, |
|||
{ |
|||
"fieldname": "active_status", |
|||
"fieldtype": "Select", |
|||
"in_list_view": 1, |
|||
"in_standard_filter": 1, |
|||
"label": "Active Status", |
|||
"options": "Active\nInactive", |
|||
"reqd": 1 |
|||
}, |
|||
{ |
|||
"fieldname": "display_order", |
|||
"fieldtype": "Int", |
|||
"in_list_view": 1, |
|||
"in_standard_filter": 1, |
|||
"label": "Display Order", |
|||
"reqd": 1 |
|||
}, |
|||
{ |
|||
"fieldname": "app_menu_id", |
|||
"fieldtype": "Int", |
|||
"label": "App Menu Id", |
|||
"reqd": 1 |
|||
} |
|||
], |
|||
"index_web_pages_for_search": 1, |
|||
"links": [], |
|||
"modified": "2024-01-03 16:04:06.524640", |
|||
"modified_by": "Administrator", |
|||
"module": "Masters", |
|||
"name": "Module Master", |
|||
"owner": "Administrator", |
|||
"permissions": [ |
|||
{ |
|||
"create": 1, |
|||
"delete": 1, |
|||
"email": 1, |
|||
"export": 1, |
|||
"print": 1, |
|||
"read": 1, |
|||
"report": 1, |
|||
"role": "System Manager", |
|||
"share": 1, |
|||
"write": 1 |
|||
} |
|||
], |
|||
"sort_field": "modified", |
|||
"sort_order": "DESC", |
|||
"title_field": "module_name" |
|||
} |
@ -0,0 +1,21 @@ |
|||
# Copyright (c) 2023, Hard n Soft Technologies Pvt Ltd and contributors |
|||
# For license information, please see license.txt |
|||
|
|||
import frappe |
|||
from frappe.model.document import Document |
|||
|
|||
class ModuleMaster(Document): |
|||
def validate(self): |
|||
if self.module_name: |
|||
self.module_name = self.module_name.strip() |
|||
|
|||
# def autoname(self): |
|||
# if self.is_new(): |
|||
# count = frappe.db.sql( |
|||
# '''select max(my_id) as max_count from `tabModule Master`;''') |
|||
# if count[0][0] is not None: |
|||
# self.my_id = count[0][0] + 1 |
|||
# else: |
|||
# self.my_id = 1 |
|||
|
|||
|
@ -0,0 +1,8 @@ |
|||
# Copyright (c) 2023, Hard n Soft Technologies Pvt Ltd and Contributors |
|||
# See license.txt |
|||
|
|||
# import frappe |
|||
import unittest |
|||
|
|||
class TestModuleMaster(unittest.TestCase): |
|||
pass |
@ -0,0 +1,122 @@ |
|||
// Copyright (c) 2023, Hard n Soft Technologies Pvt Ltd and contributors
|
|||
// For license information, please see license.txt
|
|||
var original_display_order = 0; |
|||
var role_name_count = 0; |
|||
frappe.require('assets/smart_service/js/utils.js', () => { }) |
|||
|
|||
frappe.ui.form.on('Role Master', { |
|||
onload: function (frm) { |
|||
// Set Display Order
|
|||
// if (frm.is_new()) {
|
|||
// frm.set_df_property('display_order', 'read_only', 1);
|
|||
// } else {
|
|||
// frm.set_df_property('display_order', 'read_only', 0);
|
|||
// }
|
|||
// frappe.db.count('Role Master')
|
|||
// .then(count => {
|
|||
// role_name_count = count + 1;
|
|||
// if (frm.is_new()) {
|
|||
// frm.set_value("display_order", role_name_count);
|
|||
// } else {
|
|||
// original_display_order = frm.doc.display_order;
|
|||
// }
|
|||
// });
|
|||
}, |
|||
|
|||
refresh: function (frm) { |
|||
// Set Display Order
|
|||
// if (frm.is_new()) {
|
|||
// frm.set_df_property('display_order', 'read_only', 1);
|
|||
// } else {
|
|||
// frm.set_df_property('display_order', 'read_only', 0);
|
|||
// }
|
|||
// frappe.db.count('Role Master')
|
|||
// .then(count => {
|
|||
// role_name_count = count + 1;
|
|||
// if (frm.is_new()) {
|
|||
// frm.set_value("display_order", role_name_count);
|
|||
// } else {
|
|||
// original_display_order = frm.doc.display_order;
|
|||
// }
|
|||
// });
|
|||
|
|||
//for Module Master
|
|||
// frappe.db.get_list('Module Master', {
|
|||
// fields: ['module_name', 'name'],
|
|||
// filters: {
|
|||
// }
|
|||
// }).then(records => {
|
|||
frappe.call({ |
|||
method: "smart_service.masters.doctype.role_master.role_master.get_module_names", |
|||
args: { vehicle: frm.doc.vehicle, language_label: frm.doc.language_label, publish_type: frm.doc.publish_type }, |
|||
callback: function (r) { |
|||
if (r.message) { |
|||
let res = cur_frm.fields_dict.module_master_html.$wrapper.empty() |
|||
let module_html = "<div class='module-container' style='float:left;display:flex'>" |
|||
module_html += "<div class='row' style='margin-left:5px !important;'>" |
|||
r.message.map(val => { |
|||
var id_name = (val.name).replace(" ","_") |
|||
id_name = id_name.toLowerCase() |
|||
if (!frm.is_new() && frm.doc.modules && frm.doc.modules.includes(val.module_name)) { |
|||
module_html += "<div class='col-3' style='padding-left:0px !important;padding-right:0px !important'>" |
|||
module_html += "<input type='checkbox' id=" + "'" + id_name + "'" + " name='vehicle1' value=" + "'" + val.module_name + "'" + " checked>" |
|||
module_html += "<label for=" + val.name + " style='padding-right:20px'>" + val.module_name + "</label></div>" |
|||
} else { |
|||
module_html += "<div class='col-3' style='padding-left:0px !important;padding-right:0px !important'>" |
|||
module_html += "<input type='checkbox' id=" + "'" + id_name + "'" + " name='vehicle1' value=" + "'" + val.module_name + "'" + " >" |
|||
module_html += "<label for=" + val.name + " style='padding-right:20px'>" + val.module_name + "</label></div>" |
|||
} |
|||
}) |
|||
res.append(module_html) |
|||
|
|||
// $( document ).ready(function() {
|
|||
// console.log(":hiiiii")
|
|||
// console.log( $("#automotive_system input:checkbox"))
|
|||
// $("#automotive_system").click(function(){
|
|||
// if($(this).is(':checked')){
|
|||
// $("#component").prop('checked', true);
|
|||
// $("#feature_finder").prop('checked', true);
|
|||
// $("#symptom").prop('checked', true);
|
|||
|
|||
// }
|
|||
// else{
|
|||
// $("#component").prop('checked', false)
|
|||
// $("#feature_finder").prop('checked', false);
|
|||
// $("#symptom").prop('checked', false);
|
|||
// }
|
|||
// });
|
|||
// });
|
|||
|
|||
|
|||
} |
|||
} |
|||
}) |
|||
}, |
|||
|
|||
after_save: function (frm) { |
|||
cur_frm.refresh_fields("display_order") |
|||
}, |
|||
|
|||
validate: function (frm) { |
|||
//check html if has Module name value
|
|||
|
|||
|
|||
|
|||
var val = "" |
|||
$(':checkbox:checked').each(function (i) { |
|||
let value = $(this).val(); |
|||
val += $(this).val() + "," |
|||
}); |
|||
val = val.substring(0, val.length - 1); |
|||
// console.log(val,"val")
|
|||
frm.set_value('modules', val); |
|||
cur_frm.refresh_fields(); |
|||
|
|||
|
|||
|
|||
//For Display Order
|
|||
// cur_frm.refresh_fields("display_order")
|
|||
// console.log(module_name_count,"----",original_display_order)
|
|||
// display_order_validation(frm, role_name_count, original_display_order,frm.doc.role)
|
|||
} |
|||
}); |
@ -0,0 +1,93 @@ |
|||
{ |
|||
"actions": [], |
|||
"allow_rename": 1, |
|||
"autoname": "format:{role}", |
|||
"creation": "2023-07-19 13:42:52.880565", |
|||
"doctype": "DocType", |
|||
"editable_grid": 1, |
|||
"engine": "InnoDB", |
|||
"field_order": [ |
|||
"role", |
|||
"column_break_ffrrr", |
|||
"modules", |
|||
"skill_id", |
|||
"active_status", |
|||
"section_break_bkwnr", |
|||
"module_name_configuration", |
|||
"module_master_html" |
|||
], |
|||
"fields": [ |
|||
{ |
|||
"fieldname": "role", |
|||
"fieldtype": "Data", |
|||
"in_list_view": 1, |
|||
"in_standard_filter": 1, |
|||
"label": "Role", |
|||
"reqd": 1, |
|||
"set_only_once": 1 |
|||
}, |
|||
{ |
|||
"fieldname": "column_break_ffrrr", |
|||
"fieldtype": "Column Break" |
|||
}, |
|||
{ |
|||
"fieldname": "module_master_html", |
|||
"fieldtype": "HTML", |
|||
"label": "Module Master", |
|||
"read_only": 1 |
|||
}, |
|||
{ |
|||
"fieldname": "module_name_configuration", |
|||
"fieldtype": "Heading", |
|||
"label": "Module Name Configuration" |
|||
}, |
|||
{ |
|||
"fieldname": "modules", |
|||
"fieldtype": "Small Text", |
|||
"hidden": 1, |
|||
"label": "Modules" |
|||
}, |
|||
{ |
|||
"fieldname": "skill_id", |
|||
"fieldtype": "Data", |
|||
"in_list_view": 1, |
|||
"label": "Skill Id", |
|||
"reqd": 1, |
|||
"set_only_once": 1 |
|||
}, |
|||
{ |
|||
"fieldname": "section_break_bkwnr", |
|||
"fieldtype": "Section Break" |
|||
}, |
|||
{ |
|||
"fieldname": "active_status", |
|||
"fieldtype": "Select", |
|||
"label": "Active Status", |
|||
"options": "Active\nInactive" |
|||
} |
|||
], |
|||
"index_web_pages_for_search": 1, |
|||
"links": [], |
|||
"modified": "2024-01-09 18:00:03.439171", |
|||
"modified_by": "Administrator", |
|||
"module": "Masters", |
|||
"name": "Role Master", |
|||
"owner": "Administrator", |
|||
"permissions": [ |
|||
{ |
|||
"create": 1, |
|||
"delete": 1, |
|||
"email": 1, |
|||
"export": 1, |
|||
"print": 1, |
|||
"read": 1, |
|||
"report": 1, |
|||
"role": "System Manager", |
|||
"share": 1, |
|||
"write": 1 |
|||
} |
|||
], |
|||
"sort_field": "modified", |
|||
"sort_order": "DESC", |
|||
"title_field": "role" |
|||
} |
@ -0,0 +1,25 @@ |
|||
# Copyright (c) 2023, Hard n Soft Technologies Pvt Ltd and contributors |
|||
# For license information, please see license.txt |
|||
|
|||
import frappe |
|||
from frappe.model.document import Document |
|||
|
|||
class RoleMaster(Document): |
|||
pass |
|||
# def validate(self): |
|||
# if self.is_new(): |
|||
# count = frappe.db.sql( |
|||
# '''select max(my_id) as max_count from `tabRole Master`;''') |
|||
# if count[0][0] is not None: |
|||
# self.my_id = count[0][0] + 1 |
|||
# else: |
|||
# self.my_id = 1 |
|||
|
|||
# if self.role: |
|||
# self.role = self.role.strip() |
|||
|
|||
@ frappe.whitelist() |
|||
def get_module_names(): |
|||
data = frappe.db.sql(f''' |
|||
select name,module_name from `tabModule Master`''', as_dict=1) |
|||
return data |
@ -0,0 +1,8 @@ |
|||
# Copyright (c) 2023, Hard n Soft Technologies Pvt Ltd and Contributors |
|||
# See license.txt |
|||
|
|||
# import frappe |
|||
import unittest |
|||
|
|||
class TestRoleMaster(unittest.TestCase): |
|||
pass |
@ -1,4 +1,5 @@ |
|||
Add Ons |
|||
Masters |
|||
Reports |
|||
Transactions |
|||
Transactions |
|||
Phase-2 |
File diff suppressed because it is too large
@ -0,0 +1,233 @@ |
|||
{ |
|||
"actions": [], |
|||
"allow_rename": 1, |
|||
"autoname": "format:{variant}-{features_names}-{language}", |
|||
"creation": "2023-07-21 13:31:57.705945", |
|||
"doctype": "DocType", |
|||
"editable_grid": 1, |
|||
"engine": "InnoDB", |
|||
"field_order": [ |
|||
"is_published", |
|||
"section_break_o8kze", |
|||
"variant", |
|||
"language", |
|||
"display_order", |
|||
"active_status", |
|||
"column_break_mmuuc", |
|||
"vehicle", |
|||
"feature_name", |
|||
"features_names", |
|||
"translated_feature_name", |
|||
"feature_category", |
|||
"sop_name", |
|||
"keywords", |
|||
"section_break_u9bx1", |
|||
"image_html", |
|||
"create_feature_finder_images", |
|||
"post_vin_cutoff_id_tab", |
|||
"test_html", |
|||
"specification", |
|||
"feature_finder_images", |
|||
"feature_finder_content", |
|||
"vehicle_id", |
|||
"variant_id", |
|||
"tab_ref" |
|||
], |
|||
"fields": [ |
|||
{ |
|||
"fetch_from": "variant.vehicle", |
|||
"fieldname": "vehicle", |
|||
"fieldtype": "Data", |
|||
"in_list_view": 1, |
|||
"in_standard_filter": 1, |
|||
"label": "Vehicle", |
|||
"read_only": 1, |
|||
"reqd": 1 |
|||
}, |
|||
{ |
|||
"fieldname": "language", |
|||
"fieldtype": "Link", |
|||
"in_list_view": 1, |
|||
"in_standard_filter": 1, |
|||
"label": "Language", |
|||
"options": "Custom Languages", |
|||
"reqd": 1, |
|||
"set_only_once": 1 |
|||
}, |
|||
{ |
|||
"fieldname": "column_break_mmuuc", |
|||
"fieldtype": "Column Break" |
|||
}, |
|||
{ |
|||
"fieldname": "variant", |
|||
"fieldtype": "Link", |
|||
"in_list_view": 1, |
|||
"in_standard_filter": 1, |
|||
"label": "Variant", |
|||
"options": "Variant Mapping", |
|||
"reqd": 1, |
|||
"set_only_once": 1 |
|||
}, |
|||
{ |
|||
"fieldname": "feature_name", |
|||
"fieldtype": "Link", |
|||
"hidden": 1, |
|||
"in_list_view": 1, |
|||
"label": "Feature Name1", |
|||
"options": "Feature Finder Master", |
|||
"read_only": 1, |
|||
"set_only_once": 1 |
|||
}, |
|||
{ |
|||
"description": "Upload *.png(1920x1080 pixel) 1 MB", |
|||
"fieldname": "feature_finder_images", |
|||
"fieldtype": "Table", |
|||
"hidden": 1, |
|||
"label": "Feature Finder Images", |
|||
"options": "Feature Finder Images" |
|||
}, |
|||
{ |
|||
"fieldname": "feature_finder_content", |
|||
"fieldtype": "Table", |
|||
"hidden": 1, |
|||
"label": "Feature Finder Content", |
|||
"options": "Feature Finder Content" |
|||
}, |
|||
{ |
|||
"fieldname": "section_break_u9bx1", |
|||
"fieldtype": "Section Break" |
|||
}, |
|||
{ |
|||
"fieldname": "image_html", |
|||
"fieldtype": "HTML", |
|||
"label": "Image HTML" |
|||
}, |
|||
{ |
|||
"fieldname": "create_feature_finder_images", |
|||
"fieldtype": "Button", |
|||
"hidden": 1, |
|||
"label": "Add Feature Finder Images" |
|||
}, |
|||
{ |
|||
"fieldname": "display_order", |
|||
"fieldtype": "Int", |
|||
"in_list_view": 1, |
|||
"label": "Display Order", |
|||
"read_only_depends_on": "eval:doc.language!=\"en\"" |
|||
}, |
|||
{ |
|||
"fieldname": "active_status", |
|||
"fieldtype": "Select", |
|||
"in_list_view": 1, |
|||
"in_standard_filter": 1, |
|||
"label": "Active Status", |
|||
"options": "Active\nInactive" |
|||
}, |
|||
{ |
|||
"fieldname": "specification", |
|||
"fieldtype": "Table", |
|||
"hidden": 1, |
|||
"label": "Specification", |
|||
"options": "Feature Finder Specification" |
|||
}, |
|||
{ |
|||
"depends_on": "eval:doc.feature_name", |
|||
"fetch_from": "feature_name.feature_category", |
|||
"fieldname": "feature_category", |
|||
"fieldtype": "Data", |
|||
"in_list_view": 1, |
|||
"in_standard_filter": 1, |
|||
"label": "Feature Category" |
|||
}, |
|||
{ |
|||
"depends_on": "eval:doc.variant", |
|||
"fieldname": "features_names", |
|||
"fieldtype": "Select", |
|||
"label": "Feature Name", |
|||
"reqd": 1, |
|||
"set_only_once": 1 |
|||
}, |
|||
{ |
|||
"fieldname": "test_html", |
|||
"fieldtype": "HTML", |
|||
"label": "Test Html" |
|||
}, |
|||
{ |
|||
"fieldname": "post_vin_cutoff_id_tab", |
|||
"fieldtype": "Table", |
|||
"label": "Post Vin Cutoff ID", |
|||
"options": "Post Vin Cutoff ID" |
|||
}, |
|||
{ |
|||
"fetch_from": "variant.vehicle_id", |
|||
"fieldname": "vehicle_id", |
|||
"fieldtype": "Int", |
|||
"hidden": 1, |
|||
"label": "Vehicle Id" |
|||
}, |
|||
{ |
|||
"fetch_from": "variant.name", |
|||
"fieldname": "variant_id", |
|||
"fieldtype": "Data", |
|||
"hidden": 1, |
|||
"label": "Variant Id" |
|||
}, |
|||
{ |
|||
"fieldname": "translated_feature_name", |
|||
"fieldtype": "Data", |
|||
"label": "Translated Feature Name", |
|||
"mandatory_depends_on": "eval:doc.language!=\"en\"", |
|||
"read_only_depends_on": "eval:doc.language==\"en\"" |
|||
}, |
|||
{ |
|||
"default": "0", |
|||
"fieldname": "is_published", |
|||
"fieldtype": "Check", |
|||
"label": "Published", |
|||
"read_only": 1 |
|||
}, |
|||
{ |
|||
"fieldname": "section_break_o8kze", |
|||
"fieldtype": "Section Break" |
|||
}, |
|||
{ |
|||
"fieldname": "tab_ref", |
|||
"fieldtype": "Data", |
|||
"hidden": 1, |
|||
"label": "Tab Ref" |
|||
}, |
|||
{ |
|||
"fieldname": "keywords", |
|||
"fieldtype": "Small Text", |
|||
"label": "Keywords" |
|||
}, |
|||
{ |
|||
"fieldname": "sop_name", |
|||
"fieldtype": "Data", |
|||
"label": "SOP Name" |
|||
} |
|||
], |
|||
"index_web_pages_for_search": 1, |
|||
"links": [], |
|||
"modified": "2023-11-24 16:28:33.427222", |
|||
"modified_by": "Administrator", |
|||
"module": "Phase-2", |
|||
"name": "Feature Finder", |
|||
"owner": "Administrator", |
|||
"permissions": [ |
|||
{ |
|||
"create": 1, |
|||
"delete": 1, |
|||
"email": 1, |
|||
"export": 1, |
|||
"print": 1, |
|||
"read": 1, |
|||
"report": 1, |
|||
"role": "System Manager", |
|||
"share": 1, |
|||
"write": 1 |
|||
} |
|||
], |
|||
"sort_field": "modified", |
|||
"sort_order": "DESC" |
|||
} |
@ -0,0 +1,334 @@ |
|||
# Copyright (c) 2023, Hard n Soft Technologies Pvt Ltd and contributors |
|||
# For license information, please see license.txt |
|||
|
|||
import frappe |
|||
from frappe.model.document import Document |
|||
import json |
|||
|
|||
|
|||
class FeatureFinder(Document): |
|||
# def validate(self): |
|||
# if self.feature_name and self.feature_type=="SOP": |
|||
# check_existing = frappe.db.sql(f"""select name from `tabFeature Finder` where feature_name='{self.feature_name}' and feature_type='SOP' |
|||
# and name!='{self.name}'""",as_dict=1) |
|||
# if len(check_existing)>0: |
|||
# frappe.throw("This Feature Name and Feature Type already exists") |
|||
|
|||
# def autoname(self): |
|||
# if self.feature_type == "SOP": |
|||
# self.name = self.variant+"-"+self.features_names + \ |
|||
# "-"+self.language+"-"+self.feature_type |
|||
# else: |
|||
# self.name = self.variant+"-"+self.features_names+"-" + \ |
|||
# self.language+"-"+self.feature_type+"-"+self.post_vin_cutoff_id |
|||
|
|||
def validate(self): |
|||
try: |
|||
if self.sop_name: |
|||
self.sop_name = self.sop_name.strip() |
|||
if self.is_new(): |
|||
self.tab_ref = "SOP" |
|||
if self.variant and self.language and self.feature_name: |
|||
# check_exe = frappe.db.get_list("Feature Finder", |
|||
# filters={"variant": self.variant, "language": "en", |
|||
# "features_names": self.features_names, |
|||
# "name": ["!=", self.name]}, |
|||
# fields={"name", "language", "display_order", "active_status"}) |
|||
# check_exe = frappe.db.sql(f''' select * from `tabFeature Finder` where variant='{self.variant}' and features_names='{self.features_names}' |
|||
# and language='en' and name != '{self.name}' ; |
|||
# ''', as_dict=1) |
|||
check_exe = frappe.db.sql(''' select * from `tabFeature Finder` where variant='%s' and features_names='%s' |
|||
and language='en' and name != '%s' ; |
|||
''' % (self.variant, self.features_names, self.name), as_dict=1) |
|||
# frappe.log_error("check_exe",str(check_exe)) |
|||
if check_exe: |
|||
if self.language != "en": |
|||
for d in check_exe: |
|||
self.display_order = d['display_order'] |
|||
self.active_status = d['active_status'] |
|||
|
|||
if not check_exe: |
|||
if self.language != "en": |
|||
frappe.throw("First language will be english only") |
|||
|
|||
if not self.is_new() and self.is_published == 1: |
|||
self.is_published = 0 |
|||
|
|||
# if len(self.specification)>0: |
|||
# specification = frappe.db.sql(f"""select * from `tabFeature Finder Specification` where parent = '{self.name}'""",as_dict=1) |
|||
# for d in self.specification: |
|||
# specification.append(d) |
|||
# set_idx = 0 |
|||
# for k in specification: |
|||
# set_idx +=1 |
|||
# k[''] |
|||
|
|||
except Exception as e: |
|||
raise e |
|||
|
|||
def on_update(self): |
|||
if self.language == "en": |
|||
try: |
|||
check_exe = frappe.db.get_list("Feature Finder", |
|||
filters={"variant": self.variant, "language": ["!=", "en"], |
|||
"feature_name": self.feature_name, |
|||
"name": ["!=", self.name]}, |
|||
fields={"name", "language", "display_order", "active_status"}) |
|||
if check_exe: |
|||
for i in check_exe: |
|||
res = frappe.get_doc( |
|||
"Feature Finder", i['name']) |
|||
res.display_order = self.display_order |
|||
res.active_status = self.active_status |
|||
res.save() |
|||
except Exception as e: |
|||
raise e |
|||
|
|||
|
|||
@frappe.whitelist() |
|||
def get_feature_list(vehicle, language): |
|||
features_list = frappe.db.sql( |
|||
"""select feature_name from `tabFeature Finder Master` where vehicle='%s' and language = '%s';""" % (vehicle, language), as_list=1) |
|||
return features_list |
|||
|
|||
|
|||
@frappe.whitelist() |
|||
def get_list_data(name, val): |
|||
specification = frappe.db.sql( |
|||
"""select *,'Feature Finder Specification' as doctype from `tabFeature Finder Specification` where parent = '%s' and |
|||
post_vin_cutoff_name='%s'""" % (name, val), as_dict=1) |
|||
feature_finder_images = frappe.db.sql( |
|||
"""select * from `tabFeature Finder Images` where parent = '%s' and post_vin_cutoff_name='%s'""" % (name, val), as_dict=1) |
|||
feature_finder_content = frappe.db.sql( |
|||
"""select * from `tabFeature Finder Content` where parent = '%s' and post_vin_cutoff_name='%s'""" % (name, val), as_dict=1) |
|||
return specification, feature_finder_images, feature_finder_content |
|||
|
|||
|
|||
@frappe.whitelist() |
|||
def insert_spec_data(doc_name, values, tab_ref=None): |
|||
try: |
|||
val = json.loads(values) |
|||
get_count = frappe.db.sql("""select name from `tabFeature Finder Specification` where parent='%s' and feature_type='%s'""" % ( |
|||
doc_name, val.get('feature_type')), as_dict=1) |
|||
get_count = len(get_count)+1 |
|||
result = frappe.get_doc("Feature Finder", doc_name) |
|||
result.tab_ref = tab_ref |
|||
result.save() |
|||
frappe.db.commit() |
|||
if val.get('name') != None: |
|||
doc = frappe.get_doc("Feature Finder Specification", val['name']) |
|||
doc.specification = val.get('specification') |
|||
doc.value = val.get('value') |
|||
# doc.active_status = val.get('active_status') |
|||
doc.feature_type = val.get('feature_type') |
|||
doc.display_order = val.get('display_order') |
|||
doc.save() |
|||
frappe.db.commit() |
|||
|
|||
else: |
|||
res = frappe.get_doc("Feature Finder", doc_name) |
|||
val['display_order'] = get_count |
|||
res.append("specification", val) |
|||
res.save() |
|||
|
|||
return {"status": "success"} |
|||
except Exception as e: |
|||
frappe.log_error("insert_spec_data", str(e)) |
|||
return {"status": "failure"} |
|||
|
|||
|
|||
@frappe.whitelist() |
|||
def delete_spec_data(values,doc_name): |
|||
try: |
|||
val = json.loads(values) |
|||
if len(val) > 0: |
|||
for d in val: |
|||
frappe.delete_doc("Feature Finder Specification", d) |
|||
frappe.db.commit() |
|||
if doc_name: |
|||
frappe.db.sql("""UPDATE `tabFeature Finder` set is_published='0' WHERE name ='%s'""" % (doc_name)) |
|||
frappe.db.commit() |
|||
return {"status": "success"} |
|||
except Exception as e: |
|||
frappe.log_error("delete_spec_data", str(e)) |
|||
|
|||
|
|||
@frappe.whitelist() |
|||
def insert_image_data(doc_name, values, tab_ref): |
|||
try: |
|||
val = json.loads(values) |
|||
get_count = frappe.db.sql("""select name from `tabFeature Finder Images` where parent='%s' and |
|||
feature_type='%s'""" % (doc_name, val.get('feature_type')), as_dict=1) |
|||
get_count = len(get_count)+1 |
|||
result = frappe.get_doc("Feature Finder", doc_name) |
|||
result.tab_ref = tab_ref |
|||
result.save() |
|||
frappe.db.commit() |
|||
if val.get('name') != None: |
|||
doc = frappe.get_doc("Feature Finder Images", val['name']) |
|||
doc.image = val.get('image') |
|||
# doc.active_status = val.get('active_status') |
|||
doc.feature_type = val.get('feature_type') |
|||
doc.display_order = val.get('display_order') |
|||
doc.save() |
|||
frappe.db.commit() |
|||
|
|||
else: |
|||
res = frappe.get_doc("Feature Finder", doc_name) |
|||
val['display_order'] = get_count |
|||
res.append("feature_finder_images", val) |
|||
res.save() |
|||
frappe.db.commit() |
|||
|
|||
return {"status": "success"} |
|||
except Exception as e: |
|||
frappe.log_error("insert_image_data", str(e)) |
|||
return {"status": "failure"} |
|||
|
|||
|
|||
@frappe.whitelist() |
|||
def delete_image_data(values,doc_name): |
|||
try: |
|||
val = json.loads(values) |
|||
if len(val) > 0: |
|||
for d in val: |
|||
frappe.delete_doc("Feature Finder Images", d) |
|||
frappe.db.commit() |
|||
if doc_name: |
|||
frappe.db.sql("""UPDATE `tabFeature Finder` set is_published='0' WHERE name ='%s'""" % (doc_name)) |
|||
frappe.db.commit() |
|||
return {"status": "success"} |
|||
except Exception as e: |
|||
frappe.log_error("delete_image_data", str(e)) |
|||
|
|||
|
|||
@frappe.whitelist() |
|||
def insert_content_data(doc_name, values, tab_ref=None): |
|||
try: |
|||
val = json.loads(values) |
|||
get_count = frappe.db.sql("""select name from `tabFeature Finder Content` where parent='%s' and |
|||
feature_type='%s'""" % (doc_name, val.get('feature_type')), as_dict=1) |
|||
get_count = len(get_count)+1 |
|||
result = frappe.get_doc("Feature Finder", doc_name) |
|||
result.tab_ref = tab_ref |
|||
result.save() |
|||
frappe.db.commit() |
|||
if val.get('name') != None: |
|||
doc = frappe.get_doc("Feature Finder Content", val['name']) |
|||
doc.content = val.get('content') |
|||
# doc.active_status = val.get('active_status') |
|||
doc.feature_type = val.get('feature_type') |
|||
doc.display_order = val.get('display_order') |
|||
doc.save() |
|||
frappe.db.commit() |
|||
|
|||
else: |
|||
res = frappe.get_doc("Feature Finder", doc_name) |
|||
val['display_order'] = get_count |
|||
res.append("feature_finder_content", val) |
|||
res.save() |
|||
frappe.db.commit() |
|||
|
|||
return {"status": "success"} |
|||
except Exception as e: |
|||
frappe.log_error("insert_content_data", str(e)) |
|||
return {"status": "failure"} |
|||
|
|||
|
|||
@frappe.whitelist() |
|||
def delete_content_data(values,doc_name): |
|||
try: |
|||
val = json.loads(values) |
|||
if len(val) > 0: |
|||
for d in val: |
|||
frappe.delete_doc("Feature Finder Content", d) |
|||
frappe.db.commit() |
|||
if doc_name: |
|||
frappe.db.sql("""UPDATE `tabFeature Finder` set is_published='0' WHERE name ='%s'""" % (doc_name)) |
|||
frappe.db.commit() |
|||
return {"status": "success"} |
|||
except Exception as e: |
|||
frappe.log_error("delete_image_data", str(e)) |
|||
|
|||
|
|||
# res.append("specification",{ |
|||
# "specification":val.get('specification'), |
|||
# "value":val.get('value'), |
|||
# "active_status":val.get('active_status'), |
|||
# "feature_type":val.get('feature_type') |
|||
# }) |
|||
|
|||
|
|||
@frappe.whitelist() |
|||
def set_display_order(doctype_name, values): |
|||
try: |
|||
if len(values) > 0: |
|||
val = json.loads(values) |
|||
if len(val) > 0: |
|||
count_val = 0 |
|||
for k in val: |
|||
count_val += 1 |
|||
frappe.log_error("k", (str(k))) |
|||
if k: |
|||
res = frappe.get_doc(doctype_name, k) |
|||
# frappe.msgprint(str(k)+"-"+str(count_val)) |
|||
res.display_order = count_val |
|||
res.save() |
|||
frappe.db.commit() |
|||
return {"status": "success"} |
|||
else: |
|||
return {"status": "fail"} |
|||
except Exception as e: |
|||
frappe.log_error("set_display_order", frappe.get_traceback()) |
|||
pass |
|||
|
|||
|
|||
@frappe.whitelist() |
|||
def get_specification_list(): |
|||
res = frappe.db.sql( |
|||
"""select name from `tabFeature Finder Specification Master`""", as_dict=1) |
|||
return res |
|||
|
|||
|
|||
@frappe.whitelist() |
|||
def insert_tab_ref(docname, tab_ref): |
|||
try: |
|||
if docname and tab_ref: |
|||
frappe.db.sql("""UPDATE `tabFeature Finder` set tab_ref='%s' WHERE name ='%s'""" % ( |
|||
tab_ref, docname)) |
|||
frappe.db.commit() |
|||
except Exception as e: |
|||
frappe.log_error("insert_tab", frappe.get_traceback()) |
|||
|
|||
|
|||
|
|||
@frappe.whitelist() |
|||
def file_validation(image=None): |
|||
from smart_service.apis.utils import check_png_ext, check_img_ext,details_of_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 > 1920 or height > 1080 and image: |
|||
val = delete_feature_image(image) |
|||
if val == True: |
|||
return (False, 2) |
|||
else: |
|||
return True |
|||
|
|||
else: |
|||
val = delete_feature_image(image) |
|||
if res == False: |
|||
ret = res |
|||
else: |
|||
ret = res1 |
|||
return ret, 1 |
|||
|
|||
|
|||
def delete_feature_image(file_url): |
|||
image_name = frappe.db.sql(f"""select name from `tabFile` where file_url='{file_url}'""",as_dict=1) |
|||
if len(image_name) > 0: |
|||
frappe.delete_doc('File', image_name[0]['name']) |
|||
return True |
@ -0,0 +1,8 @@ |
|||
# Copyright (c) 2023, Hard n Soft Technologies Pvt Ltd and Contributors |
|||
# See license.txt |
|||
|
|||
# import frappe |
|||
import unittest |
|||
|
|||
class TestFeatureFinder(unittest.TestCase): |
|||
pass |
@ -0,0 +1,29 @@ |
|||
// Copyright (c) 2023, Hard n Soft Technologies Pvt Ltd and contributors
|
|||
// For license information, please see license.txt
|
|||
|
|||
frappe.ui.form.on('Feature Finder Category Master', { |
|||
validate: function (frm) { |
|||
check_field_character(frm.doc.feature_category) |
|||
check_field_character(frm.doc.feature_name) |
|||
} |
|||
}); |
|||
function check_field_character(field_name) { |
|||
if (field_name) { |
|||
var alphanum = /^[a-zA-Z]+/; |
|||
if (field_name.length > 1) { |
|||
if (field_name.length > 50) { |
|||
frappe.throw("<b>Feature Finder Category Master:</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>Feature Finder Category Master:</b> Enter letter or alpha numeric characters only.")); |
|||
frappe.validated = false; |
|||
} |
|||
} |
|||
} else { |
|||
frappe.throw("<b>Feature Finder Category Master:</b> Single character not allowed") |
|||
frappe.validated = false; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,75 @@ |
|||
{ |
|||
"_comments": "[]", |
|||
"_liked_by": "[]", |
|||
"actions": [], |
|||
"allow_rename": 1, |
|||
"autoname": "format:{feature_name}", |
|||
"creation": "2023-08-04 11:36:36.503213", |
|||
"doctype": "DocType", |
|||
"editable_grid": 1, |
|||
"engine": "InnoDB", |
|||
"field_order": [ |
|||
"feature_category", |
|||
"feature_name", |
|||
"column_break_qkvjq", |
|||
"active_status" |
|||
], |
|||
"fields": [ |
|||
{ |
|||
"fieldname": "feature_category", |
|||
"fieldtype": "Data", |
|||
"in_list_view": 1, |
|||
"in_standard_filter": 1, |
|||
"label": "Feature Category", |
|||
"reqd": 1, |
|||
"set_only_once": 1 |
|||
}, |
|||
{ |
|||
"fieldname": "feature_name", |
|||
"fieldtype": "Data", |
|||
"in_list_view": 1, |
|||
"in_standard_filter": 1, |
|||
"label": "Feature Name", |
|||
"reqd": 1, |
|||
"set_only_once": 1, |
|||
"unique": 1 |
|||
}, |
|||
{ |
|||
"fieldname": "active_status", |
|||
"fieldtype": "Select", |
|||
"in_list_view": 1, |
|||
"in_standard_filter": 1, |
|||
"label": "Active Status", |
|||
"options": "Active\nInactive" |
|||
}, |
|||
{ |
|||
"fieldname": "column_break_qkvjq", |
|||
"fieldtype": "Column Break" |
|||
} |
|||
], |
|||
"index_web_pages_for_search": 1, |
|||
"links": [], |
|||
"modified": "2023-09-04 17:40:56.588347", |
|||
"modified_by": "Administrator", |
|||
"module": "Phase-2", |
|||
"name": "Feature Finder Category Master", |
|||
"owner": "Administrator", |
|||
"permissions": [ |
|||
{ |
|||
"create": 1, |
|||
"delete": 1, |
|||
"email": 1, |
|||
"export": 1, |
|||
"print": 1, |
|||
"read": 1, |
|||
"report": 1, |
|||
"role": "System Manager", |
|||
"share": 1, |
|||
"write": 1 |
|||
} |
|||
], |
|||
"search_fields": "feature_name", |
|||
"sort_field": "modified", |
|||
"sort_order": "DESC", |
|||
"title_field": "feature_name" |
|||
} |
@ -0,0 +1,8 @@ |
|||
# Copyright (c) 2023, Hard n Soft Technologies Pvt Ltd and contributors |
|||
# For license information, please see license.txt |
|||
|
|||
# import frappe |
|||
from frappe.model.document import Document |
|||
|
|||
class FeatureFinderCategoryMaster(Document): |
|||
pass |
@ -0,0 +1,8 @@ |
|||
# Copyright (c) 2023, Hard n Soft Technologies Pvt Ltd and Contributors |
|||
# See license.txt |
|||
|
|||
# import frappe |
|||
import unittest |
|||
|
|||
class TestFeatureFinderCategoryMaster(unittest.TestCase): |
|||
pass |
@ -0,0 +1,50 @@ |
|||
{ |
|||
"actions": [], |
|||
"allow_rename": 1, |
|||
"creation": "2023-07-21 13:55:18.779535", |
|||
"doctype": "DocType", |
|||
"editable_grid": 1, |
|||
"engine": "InnoDB", |
|||
"field_order": [ |
|||
"content", |
|||
"feature_type", |
|||
"post_vin_cutoff_name", |
|||
"display_order" |
|||
], |
|||
"fields": [ |
|||
{ |
|||
"fieldname": "content", |
|||
"fieldtype": "Small Text", |
|||
"in_list_view": 1, |
|||
"label": "Content" |
|||
}, |
|||
{ |
|||
"fieldname": "feature_type", |
|||
"fieldtype": "Data", |
|||
"label": "Feature Type" |
|||
}, |
|||
{ |
|||
"fieldname": "post_vin_cutoff_name", |
|||
"fieldtype": "Data", |
|||
"in_list_view": 1, |
|||
"label": "Post Vin Cutoff Name" |
|||
}, |
|||
{ |
|||
"fieldname": "display_order", |
|||
"fieldtype": "Data", |
|||
"in_list_view": 1, |
|||
"label": "Display Order" |
|||
} |
|||
], |
|||
"index_web_pages_for_search": 1, |
|||
"istable": 1, |
|||
"links": [], |
|||
"modified": "2023-09-01 14:53:19.397112", |
|||
"modified_by": "Administrator", |
|||
"module": "Phase-2", |
|||
"name": "Feature Finder Content", |
|||
"owner": "Administrator", |
|||
"permissions": [], |
|||
"sort_field": "modified", |
|||
"sort_order": "DESC" |
|||
} |
@ -0,0 +1,8 @@ |
|||
# Copyright (c) 2023, Hard n Soft Technologies Pvt Ltd and contributors |
|||
# For license information, please see license.txt |
|||
|
|||
# import frappe |
|||
from frappe.model.document import Document |
|||
|
|||
class FeatureFinderContent(Document): |
|||
pass |
@ -0,0 +1,30 @@ |
|||
{ |
|||
"actions": [], |
|||
"allow_rename": 1, |
|||
"creation": "2023-07-21 14:37:31.662625", |
|||
"doctype": "DocType", |
|||
"editable_grid": 1, |
|||
"engine": "InnoDB", |
|||
"field_order": [ |
|||
"content" |
|||
], |
|||
"fields": [ |
|||
{ |
|||
"fieldname": "content", |
|||
"fieldtype": "Small Text", |
|||
"in_list_view": 1, |
|||
"label": "Content" |
|||
} |
|||
], |
|||
"index_web_pages_for_search": 1, |
|||
"istable": 1, |
|||
"links": [], |
|||
"modified": "2023-09-01 16:56:05.940778", |
|||
"modified_by": "Administrator", |
|||
"module": "Phase-2", |
|||
"name": "Feature Finder Disclaimer", |
|||
"owner": "Administrator", |
|||
"permissions": [], |
|||
"sort_field": "modified", |
|||
"sort_order": "DESC" |
|||
} |
@ -0,0 +1,8 @@ |
|||
# Copyright (c) 2023, Hard n Soft Technologies Pvt Ltd and contributors |
|||
# For license information, please see license.txt |
|||
|
|||
# import frappe |
|||
from frappe.model.document import Document |
|||
|
|||
class FeatureFinderDisclaimer(Document): |
|||
pass |
@ -0,0 +1,51 @@ |
|||
{ |
|||
"actions": [], |
|||
"allow_rename": 1, |
|||
"creation": "2023-07-21 13:53:04.565458", |
|||
"doctype": "DocType", |
|||
"editable_grid": 1, |
|||
"engine": "InnoDB", |
|||
"field_order": [ |
|||
"image", |
|||
"feature_type", |
|||
"post_vin_cutoff_name", |
|||
"display_order" |
|||
], |
|||
"fields": [ |
|||
{ |
|||
"description": "Upload *.png(1920x1080 pixel) 1 MB", |
|||
"fieldname": "image", |
|||
"fieldtype": "Attach", |
|||
"in_list_view": 1, |
|||
"label": "Image" |
|||
}, |
|||
{ |
|||
"fieldname": "feature_type", |
|||
"fieldtype": "Data", |
|||
"label": "Feature Type" |
|||
}, |
|||
{ |
|||
"fieldname": "post_vin_cutoff_name", |
|||
"fieldtype": "Data", |
|||
"in_list_view": 1, |
|||
"label": "Post Vin Cutoff Name" |
|||
}, |
|||
{ |
|||
"fieldname": "display_order", |
|||
"fieldtype": "Data", |
|||
"in_list_view": 1, |
|||
"label": "Display Order" |
|||
} |
|||
], |
|||
"index_web_pages_for_search": 1, |
|||
"istable": 1, |
|||
"links": [], |
|||
"modified": "2023-10-06 11:51:56.748496", |
|||
"modified_by": "Administrator", |
|||
"module": "Phase-2", |
|||
"name": "Feature Finder Images", |
|||
"owner": "Administrator", |
|||
"permissions": [], |
|||
"sort_field": "modified", |
|||
"sort_order": "DESC" |
|||
} |
@ -0,0 +1,8 @@ |
|||
# Copyright (c) 2023, Hard n Soft Technologies Pvt Ltd and contributors |
|||
# For license information, please see license.txt |
|||
|
|||
# import frappe |
|||
from frappe.model.document import Document |
|||
|
|||
class FeatureFinderImages(Document): |
|||
pass |
@ -0,0 +1,35 @@ |
|||
// Copyright (c) 2023, Hard n Soft Technologies Pvt Ltd and contributors
|
|||
// For license information, please see license.txt
|
|||
|
|||
frappe.ui.form.on('Feature Finder Master', { |
|||
refresh: function(frm) { |
|||
frm.set_query("feature_name", function() { |
|||
return { |
|||
"filters": { |
|||
"active_status": "Active", |
|||
} |
|||
}; |
|||
}); |
|||
}, |
|||
validate:function(frm){ |
|||
frappe.call({ |
|||
method: "smart_service.phase_2.doctype.feature_finder_master.feature_finder_master.file_validation", |
|||
args: { |
|||
image: frm.doc.feature_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") |
|||
} |
|||
|
|||
} |
|||
|
|||
} |
|||
}) |
|||
} |
|||
}); |
|||
|
@ -0,0 +1,103 @@ |
|||
{ |
|||
"actions": [], |
|||
"allow_rename": 1, |
|||
"autoname": "format:{vehicle}-{feature_name}-{language}", |
|||
"creation": "2023-07-21 14:37:42.551453", |
|||
"doctype": "DocType", |
|||
"editable_grid": 1, |
|||
"engine": "InnoDB", |
|||
"field_order": [ |
|||
"vehicle", |
|||
"feature_name", |
|||
"feature_pdf", |
|||
"column_break_5ksna", |
|||
"language", |
|||
"feature_category", |
|||
"section_break_lyzco", |
|||
"feature_finder_disclaimer" |
|||
], |
|||
"fields": [ |
|||
{ |
|||
"fieldname": "feature_name", |
|||
"fieldtype": "Link", |
|||
"in_list_view": 1, |
|||
"in_standard_filter": 1, |
|||
"label": "Feature Name", |
|||
"options": "Feature Finder Category Master", |
|||
"reqd": 1, |
|||
"set_only_once": 1 |
|||
}, |
|||
{ |
|||
"description": "Upload *.pdf 1 MB", |
|||
"fieldname": "feature_pdf", |
|||
"fieldtype": "Attach", |
|||
"label": "Compare PDF" |
|||
}, |
|||
{ |
|||
"fieldname": "feature_finder_disclaimer", |
|||
"fieldtype": "Table", |
|||
"label": "Feature Finder Disclaimer", |
|||
"options": "Feature Finder Disclaimer", |
|||
"reqd": 1 |
|||
}, |
|||
{ |
|||
"fieldname": "column_break_5ksna", |
|||
"fieldtype": "Column Break" |
|||
}, |
|||
{ |
|||
"fieldname": "section_break_lyzco", |
|||
"fieldtype": "Section Break" |
|||
}, |
|||
{ |
|||
"fieldname": "vehicle", |
|||
"fieldtype": "Link", |
|||
"in_list_view": 1, |
|||
"in_standard_filter": 1, |
|||
"label": "Vehicle", |
|||
"options": "Vehicle", |
|||
"reqd": 1 |
|||
}, |
|||
{ |
|||
"fieldname": "language", |
|||
"fieldtype": "Link", |
|||
"in_list_view": 1, |
|||
"in_standard_filter": 1, |
|||
"label": "Language", |
|||
"options": "Custom Languages", |
|||
"reqd": 1 |
|||
}, |
|||
{ |
|||
"fetch_from": "feature_name.feature_category", |
|||
"fieldname": "feature_category", |
|||
"fieldtype": "Data", |
|||
"in_list_view": 1, |
|||
"in_standard_filter": 1, |
|||
"label": "Feature Category" |
|||
} |
|||
], |
|||
"index_web_pages_for_search": 1, |
|||
"links": [], |
|||
"modified": "2023-10-06 11:50:42.654103", |
|||
"modified_by": "Administrator", |
|||
"module": "Phase-2", |
|||
"name": "Feature Finder Master", |
|||
"owner": "Administrator", |
|||
"permissions": [ |
|||
{ |
|||
"create": 1, |
|||
"delete": 1, |
|||
"email": 1, |
|||
"export": 1, |
|||
"print": 1, |
|||
"read": 1, |
|||
"report": 1, |
|||
"role": "System Manager", |
|||
"share": 1, |
|||
"write": 1 |
|||
} |
|||
], |
|||
"search_fields": "feature_name", |
|||
"sort_field": "modified", |
|||
"sort_order": "DESC", |
|||
"title_field": "feature_name" |
|||
} |
@ -0,0 +1,42 @@ |
|||
# Copyright (c) 2023, Hard n Soft Technologies Pvt Ltd and contributors |
|||
# For license information, please see license.txt |
|||
|
|||
import frappe |
|||
from frappe.model.document import Document |
|||
|
|||
class FeatureFinderMaster(Document): |
|||
pass |
|||
|
|||
|
|||
@frappe.whitelist() |
|||
def file_validation(image =None, name=None, 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: |
|||
pass |
|||
# (width, height, size) = details_of_image(image) |
|||
|
|||
# if width > 640 or height > 360 and image: |
|||
# val = delete_feature_image(image) |
|||
# if val == True: |
|||
# return (False, 2) |
|||
# else: |
|||
# return True |
|||
|
|||
else: |
|||
val = delete_file(image, 'Feature Finder Master', |
|||
"feature_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 |
@ -0,0 +1,8 @@ |
|||
# Copyright (c) 2023, Hard n Soft Technologies Pvt Ltd and Contributors |
|||
# See license.txt |
|||
|
|||
# import frappe |
|||
import unittest |
|||
|
|||
class TestFeatureFinderMaster(unittest.TestCase): |
|||
pass |
@ -0,0 +1,137 @@ |
|||
{ |
|||
"actions": [], |
|||
"allow_rename": 1, |
|||
"creation": "2023-08-10 22:37:14.844640", |
|||
"doctype": "DocType", |
|||
"editable_grid": 1, |
|||
"engine": "InnoDB", |
|||
"field_order": [ |
|||
"is_published", |
|||
"variant", |
|||
"language", |
|||
"display_order", |
|||
"column_break_mmuuc", |
|||
"vehicle", |
|||
"feature_name", |
|||
"features_names", |
|||
"feature_category", |
|||
"vehicle_id", |
|||
"variant_id", |
|||
"parent1", |
|||
"data_9xkxt" |
|||
], |
|||
"fields": [ |
|||
{ |
|||
"default": "0", |
|||
"fieldname": "is_published", |
|||
"fieldtype": "Check", |
|||
"label": "Published", |
|||
"read_only": 1 |
|||
}, |
|||
{ |
|||
"fieldname": "variant", |
|||
"fieldtype": "Link", |
|||
"in_list_view": 1, |
|||
"in_standard_filter": 1, |
|||
"label": "Variant", |
|||
"options": "Variant Mapping", |
|||
"read_only": 1, |
|||
"set_only_once": 1 |
|||
}, |
|||
{ |
|||
"fieldname": "language", |
|||
"fieldtype": "Link", |
|||
"in_list_view": 1, |
|||
"in_standard_filter": 1, |
|||
"label": "Language", |
|||
"options": "Custom Languages", |
|||
"read_only": 1, |
|||
"set_only_once": 1 |
|||
}, |
|||
{ |
|||
"fieldname": "display_order", |
|||
"fieldtype": "Int", |
|||
"label": "Display Order", |
|||
"read_only": 1, |
|||
"read_only_depends_on": "eval:doc.language!=\"en\"" |
|||
}, |
|||
{ |
|||
"fieldname": "column_break_mmuuc", |
|||
"fieldtype": "Column Break" |
|||
}, |
|||
{ |
|||
"fetch_from": "variant.vehicle", |
|||
"fieldname": "vehicle", |
|||
"fieldtype": "Data", |
|||
"in_list_view": 1, |
|||
"in_standard_filter": 1, |
|||
"label": "Vehicle", |
|||
"read_only": 1 |
|||
}, |
|||
{ |
|||
"depends_on": "eval:doc.variant!=\"\"", |
|||
"fieldname": "feature_name", |
|||
"fieldtype": "Link", |
|||
"hidden": 1, |
|||
"label": "Feature Name1", |
|||
"options": "Feature Finder Master", |
|||
"read_only": 1, |
|||
"set_only_once": 1 |
|||
}, |
|||
{ |
|||
"depends_on": "eval:doc.variant", |
|||
"fieldname": "features_names", |
|||
"fieldtype": "Data", |
|||
"label": "Feature Name", |
|||
"read_only": 1, |
|||
"set_only_once": 1 |
|||
}, |
|||
{ |
|||
"depends_on": "eval:doc.feature_name", |
|||
"fetch_from": "feature_name.feature_category", |
|||
"fieldname": "feature_category", |
|||
"fieldtype": "Data", |
|||
"label": "Feature Category", |
|||
"read_only": 1 |
|||
}, |
|||
{ |
|||
"fetch_from": "variant.vehicle_id", |
|||
"fieldname": "vehicle_id", |
|||
"fieldtype": "Int", |
|||
"hidden": 1, |
|||
"label": "Vehicle Id", |
|||
"read_only": 1 |
|||
}, |
|||
{ |
|||
"fetch_from": "variant.name", |
|||
"fieldname": "variant_id", |
|||
"fieldtype": "Data", |
|||
"hidden": 1, |
|||
"label": "Variant Id", |
|||
"read_only": 1 |
|||
}, |
|||
{ |
|||
"fieldname": "parent1", |
|||
"fieldtype": "Link", |
|||
"in_list_view": 1, |
|||
"label": "Parent", |
|||
"options": "Feature Finder", |
|||
"read_only": 1 |
|||
}, |
|||
{ |
|||
"fieldname": "data_9xkxt", |
|||
"fieldtype": "Data" |
|||
} |
|||
], |
|||
"index_web_pages_for_search": 1, |
|||
"istable": 1, |
|||
"links": [], |
|||
"modified": "2023-09-01 15:49:01.572389", |
|||
"modified_by": "Administrator", |
|||
"module": "Phase-2", |
|||
"name": "Feature Finder Publish Data", |
|||
"owner": "Administrator", |
|||
"permissions": [], |
|||
"sort_field": "modified", |
|||
"sort_order": "DESC" |
|||
} |
@ -0,0 +1,8 @@ |
|||
# Copyright (c) 2023, Hard n Soft Technologies Pvt Ltd and contributors |
|||
# For license information, please see license.txt |
|||
|
|||
# import frappe |
|||
from frappe.model.document import Document |
|||
|
|||
class FeatureFinderPublishData(Document): |
|||
pass |
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue