administrator
1 year ago
129 changed files with 665479 additions and 3911 deletions
@ -1,2 +1,7 @@ |
|||||
#Ignore all pyc files |
.DS_Store |
||||
|
*.egg-info |
||||
|
*.swp |
||||
|
tags |
||||
|
smart_service/docs/current |
||||
*.pyc |
*.pyc |
||||
|
__pycache__/ |
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,8 +1,161 @@ |
|||||
# Copyright (c) 2021, Hard n Soft Technologies Pvt Ltd and contributors |
# Copyright (c) 2021, Hard n Soft Technologies Pvt Ltd and contributors |
||||
# For license information, please see license.txt |
# For license information, please see license.txt |
||||
|
|
||||
# import frappe |
import frappe |
||||
from frappe.model.document import Document |
from frappe.model.document import Document |
||||
|
|
||||
class Circular(Document): |
class Circular(Document): |
||||
pass |
def validate(self): |
||||
|
if self.description and len(self.description)>500: |
||||
|
frappe.throw("Description should be less than or equal to 850 characters ") |
||||
|
|
||||
|
|
||||
|
|
||||
|
@frappe.whitelist() |
||||
|
def file_validation(image, name): |
||||
|
if image: |
||||
|
res = check_img_ext(image) |
||||
|
res1 = check_png_ext(image) |
||||
|
res2 = check_pdf_ext(image) |
||||
|
if res == True or res1 == True or res2 == True: |
||||
|
return True |
||||
|
else: |
||||
|
return False, 1 |
||||
|
# if res== True: |
||||
|
# pass |
||||
|
# else: |
||||
|
# width, height, size = details_of_image(image) |
||||
|
# if width > 49 or height > 49 or size > 65 and image: |
||||
|
# val = checking_image(image, "Circular","circular_image", name) |
||||
|
# if val: |
||||
|
# return False, 2 |
||||
|
|
||||
|
|
||||
|
|
||||
|
# if res2 == True: |
||||
|
# pass |
||||
|
# else: |
||||
|
# width, height, size = details_of_image(image) |
||||
|
# if width > 49 or height > 49 or size > 65 and image: |
||||
|
# val = checking_image(image, "Circular", |
||||
|
# "circular_image", name) |
||||
|
# if val == True: |
||||
|
# return False, 2 |
||||
|
# else: |
||||
|
# return True |
||||
|
# else: |
||||
|
# val = checking_image(image, "Circular", |
||||
|
# "circular_image", name) |
||||
|
if res == False: |
||||
|
ret = res |
||||
|
elif res1 == False: |
||||
|
ret = res1 |
||||
|
else: |
||||
|
ret = res2 |
||||
|
return ret, 1 |
||||
|
|
||||
|
|
||||
|
@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_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 |
||||
|
|
||||
|
|
||||
|
|
||||
|
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_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,8 @@ |
|||||
|
// Copyright (c) 2023, Hard n Soft Technologies Pvt Ltd and contributors
|
||||
|
// For license information, please see license.txt
|
||||
|
|
||||
|
frappe.ui.form.on('Refresh Token', { |
||||
|
// refresh: function(frm) {
|
||||
|
|
||||
|
// }
|
||||
|
}); |
@ -0,0 +1,77 @@ |
|||||
|
{ |
||||
|
"actions": [], |
||||
|
"allow_rename": 1, |
||||
|
"creation": "2023-02-02 11:54:48.885036", |
||||
|
"doctype": "DocType", |
||||
|
"editable_grid": 1, |
||||
|
"engine": "InnoDB", |
||||
|
"field_order": [ |
||||
|
"access_token", |
||||
|
"refresh_token", |
||||
|
"column_break_3", |
||||
|
"access_expiry_time", |
||||
|
"refresh_expiry_time", |
||||
|
"user", |
||||
|
"device_id" |
||||
|
], |
||||
|
"fields": [ |
||||
|
{ |
||||
|
"fieldname": "access_token", |
||||
|
"fieldtype": "Small Text", |
||||
|
"label": "Access Token" |
||||
|
}, |
||||
|
{ |
||||
|
"fieldname": "refresh_token", |
||||
|
"fieldtype": "Small Text", |
||||
|
"label": "Refresh Token" |
||||
|
}, |
||||
|
{ |
||||
|
"fieldname": "column_break_3", |
||||
|
"fieldtype": "Column Break" |
||||
|
}, |
||||
|
{ |
||||
|
"fieldname": "access_expiry_time", |
||||
|
"fieldtype": "Datetime", |
||||
|
"label": "Access Expiry Time" |
||||
|
}, |
||||
|
{ |
||||
|
"fieldname": "refresh_expiry_time", |
||||
|
"fieldtype": "Datetime", |
||||
|
"label": "Refresh Expiry Time" |
||||
|
}, |
||||
|
{ |
||||
|
"fieldname": "user", |
||||
|
"fieldtype": "Link", |
||||
|
"label": "User", |
||||
|
"options": "User" |
||||
|
}, |
||||
|
{ |
||||
|
"fieldname": "device_id", |
||||
|
"fieldtype": "Data", |
||||
|
"label": "Device ID" |
||||
|
} |
||||
|
], |
||||
|
"index_web_pages_for_search": 1, |
||||
|
"links": [], |
||||
|
"modified": "2023-06-24 12:22:02.491908", |
||||
|
"modified_by": "Administrator", |
||||
|
"module": "Add Ons", |
||||
|
"name": "Refresh Token", |
||||
|
"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 RefreshToken(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 TestRefreshToken(unittest.TestCase): |
||||
|
pass |
@ -0,0 +1,8 @@ |
|||||
|
# Copyright (c) 2023, Hard n Soft Technologies Pvt Ltd and Contributors |
||||
|
# See license.txt |
||||
|
|
||||
|
# import frappe |
||||
|
import unittest |
||||
|
|
||||
|
class TestTokenSettings(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('Token Settings', { |
||||
|
// refresh: function(frm) {
|
||||
|
|
||||
|
// }
|
||||
|
}); |
@ -0,0 +1,48 @@ |
|||||
|
{ |
||||
|
"actions": [], |
||||
|
"allow_rename": 1, |
||||
|
"creation": "2023-02-03 10:17:56.807664", |
||||
|
"doctype": "DocType", |
||||
|
"editable_grid": 1, |
||||
|
"engine": "InnoDB", |
||||
|
"field_order": [ |
||||
|
"access_expiry_time", |
||||
|
"refresh_expiry_time" |
||||
|
], |
||||
|
"fields": [ |
||||
|
{ |
||||
|
"description": "Token Expiry in Minutes e.g. 15", |
||||
|
"fieldname": "access_expiry_time", |
||||
|
"fieldtype": "Int", |
||||
|
"label": "Access Expiry Time" |
||||
|
}, |
||||
|
{ |
||||
|
"description": "Token Expiry in Hours e.g. 1", |
||||
|
"fieldname": "refresh_expiry_time", |
||||
|
"fieldtype": "Int", |
||||
|
"label": "Refresh Expiry Time" |
||||
|
} |
||||
|
], |
||||
|
"index_web_pages_for_search": 1, |
||||
|
"issingle": 1, |
||||
|
"links": [], |
||||
|
"modified": "2023-06-29 09:34:46.212738", |
||||
|
"modified_by": "Administrator", |
||||
|
"module": "Add Ons", |
||||
|
"name": "Token Settings", |
||||
|
"owner": "Administrator", |
||||
|
"permissions": [ |
||||
|
{ |
||||
|
"create": 1, |
||||
|
"delete": 1, |
||||
|
"email": 1, |
||||
|
"print": 1, |
||||
|
"read": 1, |
||||
|
"role": "System Manager", |
||||
|
"share": 1, |
||||
|
"write": 1 |
||||
|
} |
||||
|
], |
||||
|
"sort_field": "modified", |
||||
|
"sort_order": "DESC" |
||||
|
} |
@ -0,0 +1,15 @@ |
|||||
|
# 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 TokenSettings(Document): |
||||
|
|
||||
|
def validate(self): |
||||
|
if self.access_expiry_time <= 0: |
||||
|
frappe.throw("Access exipry time should be valid minutes") |
||||
|
|
||||
|
if self.refresh_expiry_time <= 0: |
||||
|
frappe.throw("Refresh exipry time should be valid hours") |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
@ -0,0 +1,475 @@ |
|||||
|
import frappe |
||||
|
import json |
||||
|
import time |
||||
|
import re |
||||
|
import os |
||||
|
from frappe.utils import cstr |
||||
|
site_name = cstr(frappe.local.site) |
||||
|
|
||||
|
base_path = os.path.expanduser( |
||||
|
"~") + "/frappe-bench/sites/" + site_name + "/public" |
||||
|
|
||||
|
base_url = os.path.expanduser( |
||||
|
"~") + "/frappe-bench/sites/" + site_name + "/public/files" |
||||
|
base_url1 = os.path.expanduser( |
||||
|
"~") + "/frappe-bench/sites/" + site_name + "/public" |
||||
|
|
||||
|
|
||||
|
""" Working """ |
||||
|
# @frappe.whitelist(allow_guest=1) |
||||
|
# def delete_all_publish(): |
||||
|
# try: |
||||
|
# frappe.db.sql('delete from `tabPublish`;') |
||||
|
# time.sleep(1) |
||||
|
# frappe.db.sql('delete from `tabPublish_Docs`;') |
||||
|
# except Exception as e: |
||||
|
# return str(e) |
||||
|
# return True |
||||
|
|
||||
|
""" Working """ |
||||
|
# @frappe.whitelist(allow_guest=1) |
||||
|
# def reset_all_publish_assets(): |
||||
|
# try: |
||||
|
# frappe.db.sql( |
||||
|
# 'update `tabSystem Mapping_System Assets` set published=0;') |
||||
|
# except Exception as e: |
||||
|
# return str(e) |
||||
|
# return True |
||||
|
|
||||
|
|
||||
|
def custom_rate_limit(limit, seconds): |
||||
|
ip_based = True |
||||
|
ip = frappe.local.request_ip if ip_based is True else None |
||||
|
identity = None |
||||
|
|
||||
|
identity = ip |
||||
|
cache_key = f"rl:{frappe.form_dict.cmd}:{identity}" |
||||
|
value = frappe.cache().get(cache_key) or 0 |
||||
|
if not value: |
||||
|
frappe.cache().setex(cache_key, seconds, 0) |
||||
|
|
||||
|
value = frappe.cache().incrby(cache_key, 1) |
||||
|
if value > limit: |
||||
|
frappe.local.response["http_status_code"] = 429 |
||||
|
return "You hit the rate limit because of too many requests. Please try after sometime." |
||||
|
return 1 |
||||
|
|
||||
|
@frappe.whitelist(allow_guest=1) |
||||
|
def change_star_data(): |
||||
|
count = frappe.db.sql(''' |
||||
|
select count(*) from tabProcedure_Details where content like '%**%'; |
||||
|
''', as_dict=1) |
||||
|
print(count) |
||||
|
updated_list = [] |
||||
|
error_list = [] |
||||
|
data = frappe.db.sql(''' |
||||
|
select step_name,content_type,content,name,parent,replace(content,'**','abcxyz ') as new_content from tabProcedure_Details where content like '%**%'; |
||||
|
''', as_dict=1) |
||||
|
for v in data: |
||||
|
try: |
||||
|
result = re.split(r"abcxyz ", v['new_content'], flags=0) |
||||
|
FLAG = 0 |
||||
|
sts = '' |
||||
|
if len(result) > 1: |
||||
|
sts += result[0] |
||||
|
for r in range(1, len(result)): |
||||
|
if FLAG == 0: |
||||
|
sts += '<b>' + result[r] + '</b>' |
||||
|
FLAG = 1 |
||||
|
else: |
||||
|
sts += result[r] |
||||
|
FLAG = 0 |
||||
|
frappe.db.sql( |
||||
|
f'''update tabProcedure_Details set content = "{sts}" where name = '{v['name']}'; ''') |
||||
|
v['new_content'] = sts |
||||
|
except Exception as e: |
||||
|
error_list.append({v['name']: e}) |
||||
|
updated_list.append(v) |
||||
|
|
||||
|
content_file = base_path + "/files/json_files/content_update.json" |
||||
|
error_file = base_path + "/files/json_files/content_error.json" |
||||
|
|
||||
|
with open(error_file, 'w') as outfile: |
||||
|
try: |
||||
|
outfile.write(json.dumps(error_list)) |
||||
|
except: |
||||
|
pass |
||||
|
with open(content_file, 'w') as outfile: |
||||
|
try: |
||||
|
outfile.write(json.dumps(updated_list)) |
||||
|
except: |
||||
|
pass |
||||
|
return content_file |
||||
|
|
||||
|
|
||||
|
def change_file_type(): |
||||
|
folder_path = base_url |
||||
|
count = 0 |
||||
|
for root, dirs, files in os.walk(folder_path): |
||||
|
for file in files: |
||||
|
if file.split('.')[-1] == 'PNG': |
||||
|
count += 1 |
||||
|
f1 = os.path.join(root, file) |
||||
|
f2 = f1[:-3] + 'png' |
||||
|
os.rename(f1, f2) |
||||
|
|
||||
|
if file.split('.')[-1] == 'JPG': |
||||
|
count += 1 |
||||
|
f1 = os.path.join(root, file) |
||||
|
f2 = f1[:-3] + 'jpg' |
||||
|
os.rename(f1, f2) |
||||
|
|
||||
|
return count |
||||
|
|
||||
|
|
||||
|
def change_procedure_ext(): |
||||
|
try: |
||||
|
frappe.db.sql(''' |
||||
|
update tabProcedure_Details set file = concat(substring(file,1,length(file)-3),lower(substring(file,length(file)-2))) |
||||
|
where substring(file,length(file)-2) REGEXP BINARY '[A-Z]'; |
||||
|
''') |
||||
|
frappe.db.commit() |
||||
|
return True |
||||
|
except: |
||||
|
return False |
||||
|
|
||||
|
|
||||
|
def change_file_ext(): |
||||
|
try: |
||||
|
""" File URL Change """ |
||||
|
frappe.db.sql(''' |
||||
|
update tabFile set file_url = concat(substring(file_url,1,length(file_url)-3),lower(substring(file_url,length(file_url)-2))) |
||||
|
where substring(file_url,length(file_url)-2) REGEXP BINARY '[A-Z]'; |
||||
|
''') |
||||
|
frappe.db.commit() |
||||
|
|
||||
|
""" File Name """ |
||||
|
frappe.db.sql(''' |
||||
|
update tabFile set file_name = concat(substring(file_name,1,length(file_name)-3),lower(substring(file_name,length(file_name)-2))) |
||||
|
where substring(file_name,length(file_name)-2) REGEXP BINARY '[A-Z]'; |
||||
|
''') |
||||
|
frappe.db.commit() |
||||
|
except: |
||||
|
return False |
||||
|
return True |
||||
|
|
||||
|
|
||||
|
def delete_file_ext(): |
||||
|
try: |
||||
|
frappe.db.sql(''' |
||||
|
Delete from tabFile where substring(file_url,length(file_url)-2) REGEXP BINARY '[A-Z]'; |
||||
|
''') |
||||
|
frappe.db.commit() |
||||
|
except: |
||||
|
return False |
||||
|
return True |
||||
|
|
||||
|
@frappe.whitelist() |
||||
|
def append_size_file(): |
||||
|
try: |
||||
|
data = frappe.db.sql( |
||||
|
""" SELECT * FROM `tabFile` where file_size = 0 and is_folder!=1; """, as_dict=1) |
||||
|
for d in data: |
||||
|
try: |
||||
|
file_path = base_url1 + d.get("file_url") |
||||
|
isExist=os.path.exists(file_path) |
||||
|
if isExist: |
||||
|
file_size = os.path.getsize(file_path) |
||||
|
frappe.db.sql( |
||||
|
f'''UPDATE `tabFile` SET file_size = '{file_size}' WHERE name = '{d['name']}'; ''', as_dict=1) |
||||
|
frappe.db.commit() |
||||
|
else: |
||||
|
pass |
||||
|
|
||||
|
except Exception as e: |
||||
|
return str(e) |
||||
|
return data |
||||
|
except Exception as e: |
||||
|
frappe.log_error("FIle size ", str(e)) |
||||
|
return e |
||||
|
|
||||
|
|
||||
|
def asset_to_files_path(): |
||||
|
try: |
||||
|
count = frappe.db.sql(''' |
||||
|
select count(*) from tabProcedure_Details where content_type = 'File' and file like '%Asset/%';''') |
||||
|
frappe.db.sql(''' |
||||
|
update tabProcedure_Details set file =concat('/files/',SUBSTRING_INDEX(file,'/',-1)) where content_type = 'File' and file like '%Asset/%'; |
||||
|
''') |
||||
|
frappe.db.commit() |
||||
|
return count |
||||
|
except: |
||||
|
return False |
||||
|
|
||||
|
|
||||
|
def change_file_dir(): |
||||
|
base_path = os.path.expanduser( |
||||
|
"~") + "/frappe-bench/sites/" + site_name + "/public" |
||||
|
file_data = frappe.db.sql(''' |
||||
|
select name,file from tabProcedure_Details where content_type = 'File' ;''', as_dict=1) |
||||
|
changed_file_list = [] |
||||
|
for d in file_data: |
||||
|
path = d['file'] |
||||
|
isExist = os.path.exists(base_path + path) |
||||
|
if not isExist: |
||||
|
ext = path[-3:] |
||||
|
path = path[:-3] |
||||
|
|
||||
|
extension = '' |
||||
|
if ext == 'png': |
||||
|
extension = 'jpg' |
||||
|
|
||||
|
if ext == 'jpg': |
||||
|
extension = 'png' |
||||
|
|
||||
|
new_full_path = path + extension |
||||
|
|
||||
|
new_file_dir = base_path + new_full_path |
||||
|
if os.path.exists(new_file_dir): |
||||
|
changed_file_list.append(str(new_full_path)) |
||||
|
frappe.db.sql(f''' |
||||
|
update tabProcedure_Details set file = '{new_full_path}' where content_type = 'File' and name = '{d['name']}'; |
||||
|
''') |
||||
|
frappe.db.commit() |
||||
|
|
||||
|
frappe.log_error("ALL updated files", str(changed_file_list)) |
||||
|
if file_data: |
||||
|
return file_data |
||||
|
else: |
||||
|
return "Done" |
||||
|
|
||||
|
@frappe.whitelist(allow_guest=1) |
||||
|
def file_not_exists(): |
||||
|
# file_data = frappe.db.sql( |
||||
|
# '''select parent,step_name,file,name from tabProcedure_Details where content_type = 'File' order by parent;''', as_dict=1) |
||||
|
""" Cover Images """ |
||||
|
file_data = frappe.db.sql( |
||||
|
'''selectparent,systems,sub_systems,cover_image from `tabSystem Mapping_Sub System` where order by parent;''', as_dict=1) |
||||
|
|
||||
|
changed_file_list = [] |
||||
|
count = 1 |
||||
|
for d in file_data: |
||||
|
|
||||
|
path = d['file'] |
||||
|
is_exist = os.path.exists(base_path + path) |
||||
|
|
||||
|
if not is_exist: |
||||
|
print(d) |
||||
|
d['id'] = count |
||||
|
changed_file_list.append(d) |
||||
|
count += 1 |
||||
|
|
||||
|
file_path_not_exists = base_path + "/files/json_files/cover_missing.json" |
||||
|
with open(file_path_not_exists, 'w') as outfile: |
||||
|
try: |
||||
|
outfile.write(json.dumps(changed_file_list)) |
||||
|
except Exception as e: |
||||
|
pass |
||||
|
|
||||
|
|
||||
|
@frappe.whitelist(allow_guest=1) |
||||
|
def get_mp4_cover(): |
||||
|
file_data = frappe.db.sql( |
||||
|
'''select parent,systems,sub_systems,cover_image from `tabSystem Mapping_Sub System` where cover_image like '.mp4' order by parent;''', as_dict=1) |
||||
|
|
||||
|
file_path_not_exists = base_path + "/files/json_files/cover_mp4.json" |
||||
|
with open(file_path_not_exists, 'w') as outfile: |
||||
|
try: |
||||
|
outfile.write(json.dumps(file_data)) |
||||
|
except Exception as e: |
||||
|
pass |
||||
|
|
||||
|
|
||||
|
def remove_extra_spaces_in_file_path(): |
||||
|
import re |
||||
|
file_path_not_exists = base_path + "/files/json_files/1.json" |
||||
|
with open(file_path_not_exists, 'r') as outfile: |
||||
|
data = json.load(outfile) |
||||
|
|
||||
|
for d in data: |
||||
|
print(d['file']) |
||||
|
res_str = re.sub("/files/ ", "/files/", d['file']) |
||||
|
# res_str = re.sub("/files/ ", "/files/", res_str) |
||||
|
print(res_str) |
||||
|
|
||||
|
frappe.db.sql(f''' |
||||
|
update tabProcedure_Details set file = '{res_str}' where name = '{d['name']}'; |
||||
|
''') |
||||
|
frappe.db.commit() |
||||
|
|
||||
|
|
||||
|
def return_star_data(): |
||||
|
data = frappe.db.sql(''' |
||||
|
select content_type,content,name,parent,replace(content,'*','abcxyz ') as new_content from tabProcedure_Details where content like "%*%"; |
||||
|
''', as_dict=1) |
||||
|
return data |
||||
|
|
||||
|
|
||||
|
def change_star_data(): |
||||
|
count = frappe.db.sql(''' |
||||
|
select count(*) from tabProcedure_Details where content like '%**%'; |
||||
|
''', as_dict=1) |
||||
|
print(count) |
||||
|
updated_list = [] |
||||
|
error_list = [] |
||||
|
data = frappe.db.sql(''' |
||||
|
select step_name,content_type,content,name,parent,replace(content,'**','abcxyz ') as new_content from tabProcedure_Details where content like '%**%'; |
||||
|
''', as_dict=1) |
||||
|
for v in data: |
||||
|
try: |
||||
|
result = re.split(r"abcxyz ", v['new_content'], flags=0) |
||||
|
FLAG = 0 |
||||
|
sts = '' |
||||
|
if len(result) > 1: |
||||
|
sts += result[0] |
||||
|
for r in range(1, len(result)): |
||||
|
if FLAG == 0: |
||||
|
sts += '<b>' + result[r] + '</b>' |
||||
|
FLAG = 1 |
||||
|
else: |
||||
|
sts += result[r] |
||||
|
FLAG = 0 |
||||
|
frappe.db.sql( |
||||
|
f'''update tabProcedure_Details set content = "{sts}" where name = '{v['name']}'; ''') |
||||
|
v['new_content'] = sts |
||||
|
except Exception as e: |
||||
|
error_list.append({v['name']: e}) |
||||
|
updated_list.append(v) |
||||
|
|
||||
|
content_file = base_path + "/files/json_files/content_update.json" |
||||
|
error_file = base_path + "/files/json_files/content_error.json" |
||||
|
|
||||
|
with open(error_file, 'w') as outfile: |
||||
|
try: |
||||
|
outfile.write(json.dumps(error_list)) |
||||
|
except: |
||||
|
pass |
||||
|
with open(content_file, 'w') as outfile: |
||||
|
try: |
||||
|
outfile.write(json.dumps(updated_list)) |
||||
|
except: |
||||
|
pass |
||||
|
return content_file |
||||
|
|
||||
|
|
||||
|
def change_single_star_data(): |
||||
|
count = frappe.db.sql(''' |
||||
|
select count(*) from tabProcedure_Details where content like "%* %";''', as_dict=1) |
||||
|
print(count) |
||||
|
updated_list = [] |
||||
|
error_list = [] |
||||
|
data = frappe.db.sql(''' |
||||
|
select name,parent,step_name,content_type,content,replace(content,'* ','abcxyz ') as new_content from tabProcedure_Details where content like "%* %"; |
||||
|
''', as_dict=1) |
||||
|
for v in data: |
||||
|
try: |
||||
|
result = re.split(r"abcxyz ", v['new_content'], flags=0) |
||||
|
sts = '<ul>' |
||||
|
if len(result) > 1: |
||||
|
for a in range(1, len(result)): |
||||
|
sts += '<li>' + result[a] + '</li> ' |
||||
|
sts += '</ul>' |
||||
|
frappe.db.sql( |
||||
|
f'''update tabProcedure_Details set content = "{sts}" where name = '{v['name']}'; ''') |
||||
|
frappe.db.commit() |
||||
|
v['new_content'] = sts |
||||
|
updated_list.append(v) |
||||
|
|
||||
|
except Exception as e: |
||||
|
error_list.append({v['name']: e}) |
||||
|
|
||||
|
content_file = base_path + "/files/json_files/content_single_star_update.json" |
||||
|
error_file = base_path + "/files/json_files/content_error_single_star.json" |
||||
|
|
||||
|
with open(error_file, 'w') as outfile: |
||||
|
try: |
||||
|
outfile.write(json.dumps(error_list)) |
||||
|
except: |
||||
|
pass |
||||
|
with open(content_file, 'w') as outfile: |
||||
|
try: |
||||
|
outfile.write(json.dumps(updated_list)) |
||||
|
except: |
||||
|
pass |
||||
|
return content_file |
||||
|
|
||||
|
|
||||
|
def get_single_star_data(): |
||||
|
count = frappe.db.sql(''' |
||||
|
select count(*) from tabProcedure_Details where content like "%*%";''', as_dict=1) |
||||
|
|
||||
|
@frappe.whitelist(allow_guest=1) |
||||
|
def procedure_do(variant,language,system): |
||||
|
data = frappe.db.sql(f'''SELECT min(tmss.idx) as systemdisplayorder,ts.system_name,ts.icon_file,ts.myid,ts.active_status,concat(variant,'-',ts.system_name) FROM |
||||
|
`tabSystem Mapping_Sub System` as tmss inner join `tabSystems` as ts on tmss.systems = ts.system_name |
||||
|
where tmss.parent LIKE "{variant}" and substring(tmss.parent,-5,2) = "{language}" and tmss.systems ="{system}";''',as_dict=1) |
||||
|
return data |
||||
|
|
||||
|
@frappe.whitelist() |
||||
|
def set_procedure_false(): |
||||
|
try: |
||||
|
frappe.db.sql('''update `tabSystem Mapping_Sub System` set procedure_is_published=0; |
||||
|
''') |
||||
|
frappe.db.commit() |
||||
|
return True |
||||
|
except Exception as e: |
||||
|
return False |
||||
|
|
||||
|
|
||||
|
# @frappe.whitelist(allow_guest=1) |
||||
|
# def clear_procedures(): |
||||
|
# try: |
||||
|
# set_procedure_false() |
||||
|
# frappe.db.sql('''delete FROM `tabPublish`;''') |
||||
|
# frappe.db.sql('''delete FROM `tabPublish_Docs`;''') |
||||
|
# frappe.db.sql('''update `tabVariant Mapping_Assets` set published=0;''') |
||||
|
# frappe.db.sql('''update `tabSystem Mapping_Sub System` set procedure_is_published=0;''') |
||||
|
# frappe.db.sql('''update `tabSystem Mapping_System Assets` set published=0;''') |
||||
|
# frappe.db.commit() |
||||
|
# except Exception as e: |
||||
|
# return e |
||||
|
|
||||
|
@frappe.whitelist(allow_guest=1) |
||||
|
def circular_api(): |
||||
|
api = frappe.db.sql( |
||||
|
'''SELECT creation,name,title,status,description,circular_image as FileUrl,valid_till from `tabCircular` WHERE valid_till >='{}' '''.format( |
||||
|
frappe.utils.today()), as_dict=True) |
||||
|
for i in api: |
||||
|
if i["status"] == "Active": |
||||
|
i["status"] = True |
||||
|
else: |
||||
|
i["status"] = False |
||||
|
return api |
||||
|
|
||||
|
@frappe.whitelist(allow_guest=1) |
||||
|
def get_kms_mapping(sub_system,variant,language): |
||||
|
try: |
||||
|
varKMS = variant + "-" + language + "%" |
||||
|
data = frappe.db.sql(f'''SELECT kilometer as kilometer_name, idx as kilometer_IDX, applicable as kilometers_applicable |
||||
|
FROM `tabKilometer Mapping_Items` where sub_systems="{sub_system}" and parent LIKE "{varKMS}" order by kilometer_IDX;''',as_dict=1) |
||||
|
return data |
||||
|
except Exception as e: |
||||
|
return e |
||||
|
|
||||
|
@frappe.whitelist(allow_guest=1) |
||||
|
def remove_html_tags(): |
||||
|
try: |
||||
|
frappe.db.sql('''update tabProcedure_Details set content= replace(content,'>','>'); ''') |
||||
|
frappe.db.sql('''update tabProcedure_Details set content= replace(content,'<','<'); ''') |
||||
|
frappe.db.sql('''update tabProcedure_Details set content= replace(content,'<div class="ql-editor read-mode"><p>',''); ''') |
||||
|
frappe.db.sql('''update tabProcedure_Details set content= replace(content,'</p></div>',''); ''') |
||||
|
frappe.db.sql('''update tabProcedure_Details set content= replace(content,'<div class=\"ql-editor read-mode\"><ol><li data-list=\"bullet\"><span class=\"ql-ui\" contenteditable=\"false\"></span>',''); ''') |
||||
|
frappe.db.sql('''update tabProcedure_Details set content= replace(content,'</li></ol></div>',''); ''') |
||||
|
|
||||
|
frappe.db.commit() |
||||
|
return True, 'Done' |
||||
|
except Exception as e: |
||||
|
return False,e |
||||
|
|
||||
|
@frappe.whitelist() |
||||
|
def clear_tables(table_name): |
||||
|
try: |
||||
|
frappe.db.sql(f'''delete FROM `tab{table_name}`;''') |
||||
|
return 1 |
||||
|
except Exception as e: |
||||
|
return e |
File diff suppressed because it is too large
File diff suppressed because it is too large
File diff suppressed because it is too large
File diff suppressed because it is too large
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
After Width: | Height: | Size: 1.9 KiB |
After Width: | Height: | Size: 34 KiB |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,195 +1,252 @@ |
|||||
# Copyright (c) 2021, Hard n Soft Technologies Pvt Ltd and contributors |
# Copyright (c) 2021, Hard n Soft Technologies Pvt Ltd and contributors |
||||
# For license information, please see license.txt |
# For license information, please see license.txt |
||||
|
|
||||
|
import re |
||||
|
import sys |
||||
import frappe |
import frappe |
||||
from frappe.model.document import Document |
from frappe.model.document import Document |
||||
import frappe,json |
import frappe |
||||
|
import json |
||||
current_db_name = frappe.conf.get("db_name") |
current_db_name = frappe.conf.get("db_name") |
||||
import sys |
sys.tracebacklimit = 0 |
||||
sys.tracebacklimit=0 |
|
||||
|
|
||||
class Procedure(Document): |
class Procedure(Document): |
||||
def validate(self): |
def validate(self): |
||||
if self.procedure_details: |
if self.procedure_details: |
||||
for x in self.get("procedure_details"): |
for x in self.get("procedure_details"): |
||||
if x.content_type == "File": |
if x.content: |
||||
if not x.file: |
|
||||
frappe.throw("Please choose the file in row no " + str(x.idx)) |
res_str = re.sub("–", "—", x.content) |
||||
if x.content_type != "File": |
res_str = re.sub("—", "–", res_str) |
||||
if not x.content: |
res_str = re.sub("‘", "‘", res_str) |
||||
frappe.throw("Please enter the content in row no " + str(x.idx)) |
res_str = re.sub("’", "’", res_str) |
||||
|
res_str = re.sub("“", "“", res_str) |
||||
|
res_str = re.sub("â€", "”", res_str) |
||||
|
res_str = re.sub("Â", "", res_str) |
||||
|
x.content = res_str |
||||
|
|
||||
|
if x.content_type == "File": |
||||
|
if not x.file: |
||||
|
frappe.throw( |
||||
|
"Please choose the file in row no " + str(x.idx)) |
||||
|
if x.content_type != "File": |
||||
|
if not x.content: |
||||
|
frappe.throw( |
||||
|
"Please enter the content in row no " + str(x.idx)) |
||||
|
|
||||
|
if not self.is_new(): |
||||
|
frappe.db.sql( |
||||
|
f"""UPDATE `tabSystem Mapping_Sub System` set procedure_is_published=0,procedure_status='{self.workflow_state}',active_status='{self.active_status}' where `procedure`='{self.name}';""") |
||||
|
frappe.db.commit() |
||||
|
|
||||
|
|
||||
@frappe.whitelist() |
@frappe.whitelist() |
||||
def get_doc_status(docname): |
def get_doc_status(docname): |
||||
self = frappe.get_doc("Procedure",docname) |
self = frappe.get_doc("Procedure", docname) |
||||
return self.workflow_state |
return self.workflow_state |
||||
|
|
||||
|
|
||||
@frappe.whitelist() |
@frappe.whitelist() |
||||
def get_publish_details(procedure_name,status): |
def get_publish_details(procedure_name, status): |
||||
data=frappe.db.sql('''select pd.parent from {0}.`tabPublish_Docs` pd, {0}.`tabPublish` p where pd.procedure_link='{1}' and p.publish_status != '{2}' and pd.parent=p.name'''.format(current_db_name,procedure_name,status), as_list=True) |
data = frappe.db.sql('''select pd.parent from {0}.`tabPublish_Docs` pd, {0}.`tabPublish` p where pd.procedure_link='{1}' and p.publish_status != '{2}' and pd.parent=p.name'''.format( |
||||
return data |
current_db_name, procedure_name, status), as_list=True) |
||||
|
return data |
||||
|
|
||||
|
|
||||
@frappe.whitelist() |
@frappe.whitelist() |
||||
def sub_systems(doctype, txt, searchfield, start, page_len, filters): |
def sub_systems(doctype, txt, searchfield, start, page_len, filters): |
||||
return frappe.db.sql(""" select name |
return frappe.db.sql(""" select name |
||||
FROM {0}.`tabSub Systems` where |
FROM {0}.`tabSub Systems` where |
||||
(name like "%%%(txt)s%%") order by creation desc limit %(start)s, %(page_len)s """.format(current_db_name)%{'txt': txt, 'start': start, 'page_len': page_len}) |
(name like "%%%(txt)s%%") order by creation desc limit %(start)s, %(page_len)s """.format(current_db_name) % {'txt': txt, 'start': start, 'page_len': page_len}) |
||||
|
|
||||
|
|
||||
@frappe.whitelist() |
@frappe.whitelist() |
||||
def variant(doctype, txt, searchfield, start, page_len, filters): |
def variant(doctype, txt, searchfield, start, page_len, filters): |
||||
return frappe.db.sql(""" select name,family_code,fuel,transmission,vehicle_segment,active_status |
return frappe.db.sql(""" select name,family_code,fuel,transmission,vehicle_segment,active_status |
||||
FROM {0}.`tabVariant Mapping` where |
FROM {0}.`tabVariant Mapping` where |
||||
(active_status like "%%%(txt)s%%" or vehicle_segment like "%%%(txt)s%%" or name like "%%%(txt)s%%" or variant like "%%%(txt)s%%" or family_code like "%%%(txt)s%%" or fuel like "%%%(txt)s%%" or transmission like "%%%(txt)s%%") order by modified desc limit %(start)s, %(page_len)s """.format(current_db_name)%{'txt': txt, 'start': start, 'page_len': page_len}) |
(active_status like "%%%(txt)s%%" or vehicle_segment like "%%%(txt)s%%" or name like "%%%(txt)s%%" or variant like "%%%(txt)s%%" or family_code like "%%%(txt)s%%" or fuel like "%%%(txt)s%%" or transmission like "%%%(txt)s%%") order by modified desc limit %(start)s, %(page_len)s """.format(current_db_name) % {'txt': txt, 'start': start, 'page_len': page_len}) |
||||
|
|
||||
|
|
||||
@frappe.whitelist() |
@frappe.whitelist() |
||||
def fuel(doctype, txt, searchfield, start, page_len, filters): |
def fuel(doctype, txt, searchfield, start, page_len, filters): |
||||
return frappe.db.sql(""" select name FROM {0}.tabFuel where |
return frappe.db.sql(""" select name FROM {0}.tabFuel where |
||||
(name like "%%%(txt)s%%") order by modified desc limit %(start)s, %(page_len)s """.format(current_db_name)%{'txt': txt, 'start': start, 'page_len': page_len}) |
(name like "%%%(txt)s%%") order by modified desc limit %(start)s, %(page_len)s """.format(current_db_name) % {'txt': txt, 'start': start, 'page_len': page_len}) |
||||
|
|
||||
|
|
||||
@frappe.whitelist() |
@frappe.whitelist() |
||||
def transmission(doctype, txt, searchfield, start, page_len, filters): |
def transmission(doctype, txt, searchfield, start, page_len, filters): |
||||
return frappe.db.sql(""" select name FROM {0}.tabTransmission where |
return frappe.db.sql(""" select name FROM {0}.tabTransmission where |
||||
(name like "%%%(txt)s%%") order by modified desc limit %(start)s, %(page_len)s """.format(current_db_name)%{'txt': txt, 'start': start, 'page_len': page_len}) |
(name like "%%%(txt)s%%") order by modified desc limit %(start)s, %(page_len)s """.format(current_db_name) % {'txt': txt, 'start': start, 'page_len': page_len}) |
||||
|
|
||||
|
|
||||
@frappe.whitelist() |
@frappe.whitelist() |
||||
def drive(doctype, txt, searchfield, start, page_len, filters): |
def drive(doctype, txt, searchfield, start, page_len, filters): |
||||
return frappe.db.sql(""" select name FROM {0}.tabDrive where |
return frappe.db.sql(""" select name FROM {0}.tabDrive where |
||||
(name like "%%%(txt)s%%") order by modified desc limit %(start)s, %(page_len)s """.format(current_db_name)%{'txt': txt, 'start': start, 'page_len': page_len}) |
(name like "%%%(txt)s%%") order by modified desc limit %(start)s, %(page_len)s """.format(current_db_name) % {'txt': txt, 'start': start, 'page_len': page_len}) |
||||
|
|
||||
|
|
||||
@frappe.whitelist() |
@frappe.whitelist() |
||||
def get_variant(doctype, txt, searchfield, start, page_len, filters): |
def get_variant(doctype, txt, searchfield, start, page_len, filters): |
||||
if not filters: |
if not filters: |
||||
return [] |
return [] |
||||
filters = frappe._dict(filters) |
filters = frappe._dict(filters) |
||||
vm = filters.get('variant_mapping') |
vm = filters.get('variant_mapping') |
||||
lang = filters.get('language') |
lang = filters.get('language') |
||||
if vm: |
if vm: |
||||
vehicle = frappe.db.get_value('Variant Mapping', vm, 'vehicle') |
vehicle = frappe.db.get_value('Variant Mapping', vm, 'vehicle') |
||||
variant = frappe.db.sql("""select name,family_code,fuel,transmission,drive,active_status FROM {0}.`tabVariant Mapping` where vehicle = '{1}' and |
variant = frappe.db.sql("""select name,family_code,fuel,transmission,drive,active_status FROM {0}.`tabVariant Mapping` where vehicle = '{1}' and |
||||
(name like "%%%(txt)s%%" or active_status like "%%%(txt)s%%" or drive like "%%%(txt)s%%" or family_code like "%%%(txt)s%%" or fuel like "%%%(txt)s%%" or transmission like "%%%(txt)s%%") group by name limit %(start)s, %(page_len)s """.format(current_db_name,vehicle)%{'txt': txt, 'start': start, 'page_len': page_len}) |
(name like "%%%(txt)s%%" or active_status like "%%%(txt)s%%" or drive like "%%%(txt)s%%" or family_code like "%%%(txt)s%%" or fuel like "%%%(txt)s%%" or transmission like "%%%(txt)s%%") group by name limit %(start)s, %(page_len)s """.format(current_db_name, vehicle) % {'txt': txt, 'start': start, 'page_len': page_len}) |
||||
if variant: |
if variant: |
||||
return variant |
return variant |
||||
else: |
else: |
||||
return [] |
return [] |
||||
else: |
else: |
||||
return [] |
return [] |
||||
|
|
||||
|
|
||||
@frappe.whitelist() |
@frappe.whitelist() |
||||
def get_systems(doctype, txt, searchfield, start, page_len, filters): |
def get_systems(doctype, txt, searchfield, start, page_len, filters): |
||||
if not filters: |
if not filters: |
||||
return [] |
return [] |
||||
filters = frappe._dict(filters) |
filters = frappe._dict(filters) |
||||
vm = filters.get('variant_mapping') |
vm = filters.get('variant_mapping') |
||||
lang = filters.get('language') |
lang = filters.get('language') |
||||
if vm: |
if vm: |
||||
sys_mapping = frappe.db.sql("""select name from {0}.`tabSystem Mapping` where variant_mapping = '{1}' and language ='{2}'""".format(current_db_name,vm,lang),as_dict=True) |
sys_mapping = frappe.db.sql("""select name from {0}.`tabSystem Mapping` where variant_mapping = '{1}' and language ='{2}'""".format( |
||||
if sys_mapping: |
current_db_name, vm, lang), as_dict=True) |
||||
for x in sys_mapping: |
if sys_mapping: |
||||
doc = frappe.get_doc('System Mapping', x.name) |
for x in sys_mapping: |
||||
systems = frappe.db.sql(""" select systems FROM {0}.`tabSystem Mapping_Sub System` where parent = '{1}' and |
doc = frappe.get_doc('System Mapping', x.name) |
||||
(systems like "%%%(txt)s%%") group by systems limit %(start)s, %(page_len)s """.format(current_db_name,doc.name)%{'txt': txt, 'start': start, 'page_len': page_len},as_list=True) |
systems = frappe.db.sql(""" select systems FROM {0}.`tabSystem Mapping_Sub System` where parent = '{1}' and |
||||
if systems: |
(systems like "%%%(txt)s%%") group by systems limit %(start)s, %(page_len)s """.format(current_db_name, doc.name) % {'txt': txt, 'start': start, 'page_len': page_len}, as_list=True) |
||||
return systems |
if systems: |
||||
else: |
return systems |
||||
return [] |
else: |
||||
else: |
return [] |
||||
return [] |
else: |
||||
else: |
return [] |
||||
return [] |
else: |
||||
|
return [] |
||||
|
|
||||
|
|
||||
@frappe.whitelist() |
@frappe.whitelist() |
||||
def get_subsystems(doctype, txt, searchfield, start, page_len, filters): |
def get_subsystems(doctype, txt, searchfield, start, page_len, filters): |
||||
if not filters: |
if not filters: |
||||
return [] |
return [] |
||||
filters = frappe._dict(filters) |
filters = frappe._dict(filters) |
||||
vm = filters.get('variant_mapping') |
vm = filters.get('variant_mapping') |
||||
systems = filters.get('systems') |
systems = filters.get('systems') |
||||
lang = filters.get('language') |
lang = filters.get('language') |
||||
if vm: |
if vm: |
||||
sys_mapping = frappe.db.sql("""select name from {0}.`tabSystem Mapping` where variant_mapping = '{1}' and language = '{2}'""".format(current_db_name,vm,lang),as_dict=True) |
sys_mapping = frappe.db.sql("""select name from {0}.`tabSystem Mapping` where variant_mapping = '{1}' and language = '{2}'""".format( |
||||
if sys_mapping: |
current_db_name, vm, lang), as_dict=True) |
||||
for x in sys_mapping: |
if sys_mapping: |
||||
doc = frappe.get_doc('System Mapping', x.name) |
for x in sys_mapping: |
||||
systems = frappe.db.sql(""" select sub_systems FROM {0}.`tabSystem Mapping_Sub System` where parent = '{1}' and systems = '{2}' and |
doc = frappe.get_doc('System Mapping', x.name) |
||||
(sub_systems like "%%%(txt)s%%") group by sub_systems limit %(start)s, %(page_len)s """.format(current_db_name,doc.name,systems)%{'txt': txt, 'start': start, 'page_len': page_len}) |
systems = frappe.db.sql(""" select sub_systems FROM {0}.`tabSystem Mapping_Sub System` where parent = '{1}' and systems = '{2}' and |
||||
if systems: |
(sub_systems like "%%%(txt)s%%") group by sub_systems limit %(start)s, %(page_len)s """.format(current_db_name, doc.name, systems) % {'txt': txt, 'start': start, 'page_len': page_len}) |
||||
return systems |
if systems: |
||||
else: |
return systems |
||||
return [] |
else: |
||||
else: |
return [] |
||||
return [] |
else: |
||||
else: |
return [] |
||||
return [] |
else: |
||||
|
return [] |
||||
|
|
||||
|
|
||||
@frappe.whitelist() |
@frappe.whitelist() |
||||
def get_procedure(doctype, txt, searchfield, start, page_len, filters): |
def get_procedure(doctype, txt, searchfield, start, page_len, filters): |
||||
if not filters: |
if not filters: |
||||
return [] |
return [] |
||||
filters = frappe._dict(filters) |
filters = frappe._dict(filters) |
||||
vm = filters.get('variant_mapping') |
vm = filters.get('variant_mapping') |
||||
systems = filters.get('systems') |
systems = filters.get('systems') |
||||
sub_systems = filters.get('sub_systems') |
sub_systems = filters.get('sub_systems') |
||||
lang = filters.get('language') |
lang = filters.get('language') |
||||
if vm: |
if vm: |
||||
sys_mapping = frappe.db.sql("""select name from {0}.`tabSystem Mapping` where variant_mapping = '{1}' and language = '{2}'""".format(current_db_name,vm,lang),as_dict=True) |
sys_mapping = frappe.db.sql("""select name from {0}.`tabSystem Mapping` where variant_mapping = '{1}' and language = '{2}'""".format( |
||||
if sys_mapping: |
current_db_name, vm, lang), as_dict=True) |
||||
for x in sys_mapping: |
if sys_mapping: |
||||
doc = frappe.get_doc('System Mapping', x.name) |
for x in sys_mapping: |
||||
procedure = frappe.db.sql(""" select `procedure` FROM {0}.`tabSystem Mapping_Sub System` where parent = '{1}' and systems = '{2}' and sub_systems = '{3}' and |
doc = frappe.get_doc('System Mapping', x.name) |
||||
(`procedure` like "%%%(txt)s%%") group by `procedure` limit %(start)s, %(page_len)s """.format(current_db_name,doc.name,systems,sub_systems)%{'txt': txt, 'start': start, 'page_len': page_len}) |
procedure = frappe.db.sql(""" select `procedure` FROM {0}.`tabSystem Mapping_Sub System` where parent = '{1}' and systems = '{2}' and sub_systems = '{3}' and |
||||
if procedure: |
(`procedure` like "%%%(txt)s%%") group by `procedure` limit %(start)s, %(page_len)s """.format(current_db_name, doc.name, systems, sub_systems) % {'txt': txt, 'start': start, 'page_len': page_len}) |
||||
return procedure |
if procedure: |
||||
else: |
return procedure |
||||
return [] |
else: |
||||
else: |
return [] |
||||
return [] |
else: |
||||
else: |
return [] |
||||
return [] |
else: |
||||
|
return [] |
||||
@frappe.whitelist() |
|
||||
def get_procedures(variant_mapping,systems,sub_systems,language): |
|
||||
sys_mapping = frappe.db.sql("""select name from {0}.`tabSystem Mapping` where variant_mapping = '{1}' and language = '{2}'""".format(current_db_name,variant_mapping,language),as_dict=True) |
@frappe.whitelist() |
||||
if sys_mapping: |
def get_procedures(variant_mapping, systems, sub_systems, language): |
||||
for x in sys_mapping: |
sys_mapping = frappe.db.sql("""select name from {0}.`tabSystem Mapping` where variant_mapping = '{1}' and language = '{2}'""".format( |
||||
doc = frappe.get_doc('System Mapping', x.name) |
current_db_name, variant_mapping, language), as_dict=True) |
||||
procedure = frappe.db.sql(""" select `procedure` FROM {0}.`tabSystem Mapping_Sub System` where parent = '{1}' and systems = '{2}' and sub_systems = '{3}'""".format(current_db_name,doc.name,systems,sub_systems)) |
if sys_mapping: |
||||
return procedure |
for x in sys_mapping: |
||||
|
doc = frappe.get_doc('System Mapping', x.name) |
||||
|
procedure = frappe.db.sql(""" select `procedure` FROM {0}.`tabSystem Mapping_Sub System` where parent = '{1}' and systems = '{2}' and sub_systems = '{3}'""".format( |
||||
|
current_db_name, doc.name, systems, sub_systems)) |
||||
|
return procedure |
||||
|
|
||||
|
|
||||
@frappe.whitelist() |
@frappe.whitelist() |
||||
def get_systemid(systems): |
def get_systemid(systems): |
||||
system = frappe.db.sql(""" select myid FROM {0}.`tabSystems` where name = '{1}'""".format(current_db_name,systems)) |
system = frappe.db.sql(""" select myid FROM {0}.`tabSystems` where name = '{1}'""".format( |
||||
if system: |
current_db_name, systems)) |
||||
return system |
if system: |
||||
|
return system |
||||
|
|
||||
|
|
||||
@frappe.whitelist() |
@frappe.whitelist() |
||||
def get_subsystemid(systems): |
def get_subsystemid(systems): |
||||
system = frappe.db.sql(""" select myid FROM {0}.`tabSub Systems` where name = '{1}'""".format(current_db_name,systems)) |
system = frappe.db.sql(""" select myid FROM {0}.`tabSub Systems` where name = '{1}'""".format( |
||||
if system: |
current_db_name, systems)) |
||||
return system |
if system: |
||||
|
return system |
||||
|
|
||||
|
|
||||
@frappe.whitelist() |
@frappe.whitelist() |
||||
def procedure_name(doctype, txt, searchfield, start, page_len, filters): |
def procedure_name(doctype, txt, searchfield, start, page_len, filters): |
||||
return frappe.db.sql(""" select name FROM {0}.`tabProcedure Name` where |
return frappe.db.sql(""" select name FROM {0}.`tabProcedure Name` where |
||||
(name like "%%%(txt)s%%") order by modified desc limit %(start)s, %(page_len)s """.format(current_db_name)%{'txt': txt, 'start': start, 'page_len': page_len}) |
(name like "%%%(txt)s%%") order by modified desc limit %(start)s, %(page_len)s """.format(current_db_name) % {'txt': txt, 'start': start, 'page_len': page_len}) |
||||
|
|
||||
|
|
||||
@frappe.whitelist() |
@frappe.whitelist() |
||||
def procedure_step_name(doctype, txt, searchfield, start, page_len, filters): |
def procedure_step_name(doctype, txt, searchfield, start, page_len, filters): |
||||
return frappe.db.sql(""" select name FROM {0}.`tabProcedure Step Name` where |
return frappe.db.sql(""" select name FROM {0}.`tabProcedure Step Name` where |
||||
(name like "%%%(txt)s%%") order by modified desc limit %(start)s, %(page_len)s """.format(current_db_name)%{'txt': txt, 'start': start, 'page_len': page_len}) |
(name like "%%%(txt)s%%") order by modified desc limit %(start)s, %(page_len)s """.format(current_db_name) % {'txt': txt, 'start': start, 'page_len': page_len}) |
||||
|
|
||||
|
|
||||
@frappe.whitelist() |
@frappe.whitelist() |
||||
def update_system_id(name): |
def update_system_id(name): |
||||
doc = frappe.get_doc("Procedure",name) |
doc = frappe.get_doc("Procedure", name) |
||||
for table in doc.get("procedure_details"): |
for table in doc.get("procedure_details"): |
||||
if table.content_type == "Link": |
if table.content_type == "Link": |
||||
procedure = table.temp_cnt |
procedure = table.temp_cnt |
||||
system_mapping = frappe.db.sql("""select name from {0}.`tabSystem Mapping` where variant_mapping = '{1}' and language = '{2}'""".format(current_db_name,doc.variant_mapping,doc.language),as_dict=True) |
system_mapping = frappe.db.sql("""select name from {0}.`tabSystem Mapping` where variant_mapping = '{1}' and language = '{2}'""".format( |
||||
if system_mapping: |
current_db_name, doc.variant_mapping, doc.language), as_dict=True) |
||||
sm = system_mapping[0]['name'] |
if system_mapping: |
||||
sys_procedure = frappe.db.sql("""select systems,sub_systems,system_id,sub_system_id,`procedure` from {0}.`tabSystem Mapping_Sub System` where parent = '{1}' and `procedure` = '{2}'""".format(current_db_name,sm,table.temp_cnt),as_dict=True) |
sm = system_mapping[0]['name'] |
||||
if sys_procedure: |
sys_procedure = frappe.db.sql("""select systems,sub_systems,system_id,sub_system_id,`procedure` from {0}.`tabSystem Mapping_Sub System` where parent = '{1}' and `procedure` = '{2}'""".format( |
||||
if table.temp_cnt == sys_procedure[0]['procedure']: |
current_db_name, sm, table.temp_cnt), as_dict=True) |
||||
sys_id = doc.variant_mapping + ',' + str(sys_procedure[0]['system_id']) + ',' + str(sys_procedure[0]['sub_system_id']) |
if sys_procedure: |
||||
table.system_id = sys_id |
if str(table.temp_cnt) == str(sys_procedure[0]['procedure']): |
||||
frappe.db.sql("""update {0}.`tabProcedure_Details` set system_id = '{1}' where parent = '{2}' and temp_cnt = '{3}'""".format(current_db_name,sys_id,doc.name,table.temp_cnt) ) |
|
||||
frappe.db.commit() |
sys_id = doc.variant_mapping + ',' + \ |
||||
|
str(sys_procedure[0]['system_id']) + ',' + \ |
||||
|
str(sys_procedure[0]['sub_system_id']) |
||||
|
table.system_id = sys_id |
||||
|
frappe.db.sql("""update {0}.`tabProcedure_Details` set system_id = '{1}' where parent = '{2}' and temp_cnt = '{3}'""".format( |
||||
|
current_db_name, sys_id, doc.name, table.temp_cnt)) |
||||
|
frappe.db.commit() |
||||
|
@frappe.whitelist() |
||||
|
def get_path(name): |
||||
|
path = frappe.db.get_single_value("Fish", "path") |
||||
|
if path: |
||||
|
return path |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue