Browse Source

Fix publish query

master
venkataakhil 1 year ago
parent
commit
63a4f0ba30
  1. 7
      smart_service/apis/app_user_login.py
  2. 3
      smart_service/transactions/doctype/publish/publish.js
  3. 3
      smart_service/transactions/doctype/publish/publish.json
  4. 105
      smart_service/transactions/doctype/publish/publish.py

7
smart_service/apis/app_user_login.py

@ -13,6 +13,7 @@ from datetime import timedelta
current_db_name = frappe.conf.get("db_name")
def custom_rate_limit(limit, seconds):
ip_based = True
ip = frappe.local.request_ip if ip_based is True else None
@ -31,6 +32,8 @@ def custom_rate_limit(limit, seconds):
return 1
# Temporary Login
@frappe.whitelist(allow_guest=True)
def app_user_validation_test():
dicData = {}
@ -850,6 +853,8 @@ def generate_refresh_token():
""" For Refresh API """
@frappe.whitelist(allow_guest=1, methods=['POST'])
def refresh_token(refresh_token):
""" For Refresh API """
@ -996,7 +1001,7 @@ def deactivate_tokens():
doc_value.access_expiry_time = access_exp_time
doc_value.save()
if d['refresh_expiry_time'] < cur_time:
if d['refresh_expiry_time'] < cur_time:
frappe.delete_doc('Refresh Token', d['name'])
return True

3
smart_service/transactions/doctype/publish/publish.js

@ -344,7 +344,8 @@ frappe.ui.form.on('Publish', {
"method": "smart_service.transactions.doctype.publish.publish.get_system",
"args": {
"doc": frm.doc.variant_mapping,
"name": filter
"name": filter,
"lang": frm.doc.language
},
callback: function (r) {
$.each(r.message, function (index, row) {

3
smart_service/transactions/doctype/publish/publish.json

@ -132,6 +132,7 @@
"fieldtype": "Link",
"in_filter": 1,
"in_list_view": 1,
"in_standard_filter": 1,
"label": "Language",
"options": "Custom Languages",
"read_only_depends_on": "eval:doc.publish_documents",
@ -311,7 +312,7 @@
"index_web_pages_for_search": 1,
"is_submittable": 1,
"links": [],
"modified": "2023-06-12 14:10:56.665241",
"modified": "2023-06-15 11:30:29.844592",
"modified_by": "Administrator",
"module": "Transactions",
"name": "Publish",

105
smart_service/transactions/doctype/publish/publish.py

@ -1,7 +1,6 @@
# Copyright (c) 2021, Hard n Soft Technologies Pvt Ltd and contributors
# For license information, please see license.txt
import time
import sys
from html import unescape
import frappe
@ -28,8 +27,8 @@ class Publish(Document):
for v in variant:
self.variant_mapping_details = self.variant_mapping_details + \
str(v) + '\n'
km_mapping_record = frappe.db.sql("""select name from {0}.`tabKilometer Mapping` where variant_mapping = '{1}' and language = '{2}'""".format(
current_db_name, str(v), self.language), as_dict=True)
km_mapping_record = frappe.db.sql("""select name from {0}.`tabKilometer Mapping` where variant_mapping = "{1}" and
language = '{2}'""".format(current_db_name, str(v), self.language), as_dict=1)
for km_mapping in km_mapping_record:
self.kilometer_mapping_details = self.kilometer_mapping_details + \
str(km_mapping.name) + '\n'
@ -37,9 +36,10 @@ class Publish(Document):
def onload1(self):
current_db_name = frappe.conf.get("db_name")
# To validate updated procedure status
procedure_status = frappe.db.sql("""select p.name,p.update_procedure_status,pro.name,p.variant_mapping,p.system,p.sub_system,p.asset_category,p.item_category,p.variant,p.procedure_link,p.procedure_status,pro.name,pro.workflow_state
from {0}.`tabPublish_Docs` as p,{0}.`tabProcedure` as pro
where p.parent = '{1}' and p.procedure_link = pro.name and p.procedure_link is not null""".format(current_db_name, self.name), as_dict=True)
procedure_status = frappe.db.sql("""select p.name,p.update_procedure_status,pro.name,p.variant_mapping,p.system,p.sub_system,p.asset_category,
p.item_category,p.variant,p.procedure_link,p.procedure_status,pro.name,pro.workflow_state
from {0}.`tabPublish_Docs` as p,{0}.`tabProcedure` as pro where p.parent = '{1}' and
p.procedure_link = pro.name and p.procedure_link is not null""".format(current_db_name, self.name), as_dict=1)
l = len(procedure_status)
if procedure_status and self.publish_status == "Published":
@ -67,7 +67,7 @@ class Publish(Document):
# Update system and variant mapping ststus
if self.publish_status == "Published" and self.publish_type == "Global":
current_db_name = frappe.conf.get("db_name")
global_publish = frappe.db.sql("""select name from {0}.`tabPublish` where global_publish = '{1}'""".format(
global_publish = frappe.db.sql("""select name from {0}.`tabPublish` where global_publish = "{1}"; """.format(
current_db_name, self.name), as_dict=True)
for global_name in global_publish:
update_mapping(self.variant_mapping, global_name.name)
@ -93,9 +93,11 @@ def update_procedure(vehicle, lang, publish_type, doc):
# To validate updated procedure status
doc = frappe.get_doc("Publish", doc)
current_db_name = frappe.conf.get("db_name")
procedure_status = frappe.db.sql("""select p.name,p.update_procedure_status,pro.name,p.variant_mapping,p.system,p.sub_system,p.asset_category,p.item_category,p.variant,p.procedure_link,p.procedure_status,pro.name,pro.workflow_state
from {0}.`tabPublish_Docs` as p,{0}.`tabProcedure` as pro
where p.parent = '{1}' and p.procedure_link = pro.name and pro.workflow_state != p.update_procedure_status and p.procedure_link is not null""".format(current_db_name, doc.name), as_dict=True)
procedure_status = frappe.db.sql("""select p.name,p.update_procedure_status,pro.name,p.variant_mapping,p.system,p.sub_system,p.asset_category,
p.item_category,p.variant,p.procedure_link,p.procedure_status,pro.name,pro.workflow_state
from {0}.`tabPublish_Docs` as p,{0}.`tabProcedure` as pro
where p.parent = "{1}" and p.procedure_link = pro.name and pro.workflow_state != p.update_procedure_status
and p.procedure_link is not null""".format(current_db_name, doc.name), as_dict=1)
l = len(procedure_status)
if procedure_status:
for x in procedure_status:
@ -118,7 +120,8 @@ def update_procedure(vehicle, lang, publish_type, doc):
frappe.msgprint(str(
l) + ' Procedure Status to be updated, Please check the Publish Documents table.')
draft_procedure_status = frappe.db.sql(
"""select name from {0}.`tabPublish_Docs` where parent = '{1}' and update_procedure_status = 'Draft' and procedure_link is not null""".format(current_db_name, doc.name), as_dict=True)
"""select name from {0}.`tabPublish_Docs` where parent = "{1}" and update_procedure_status = 'Draft' and
procedure_link is not null""".format(current_db_name, doc.name), as_dict=1)
publish_table = doc.publish_documents
table_len = len(publish_table)
l1 = len(draft_procedure_status)
@ -128,8 +131,9 @@ def update_procedure(vehicle, lang, publish_type, doc):
if doc.publish_type == "Global":
publish_table = doc.publish_documents
table_len = len(publish_table)
publish_record = frappe.db.sql("""select name from {0}.`tabPublish_Docs` where update_procedure_status != procedure_status and update_procedure_status != 'Publish Ready' and parent = '{1}'""".format(
current_db_name, doc.name), as_dict=True)
publish_record = frappe.db.sql("""select name from {0}.`tabPublish_Docs` where update_procedure_status != procedure_status and
update_procedure_status != 'Publish Ready' and parent = "{1}";
""".format(current_db_name, doc.name), as_dict=1)
if publish_record:
len_publish = len(publish_record)
if str(table_len) == str(len_publish):
@ -143,7 +147,7 @@ def cal_ver(vehicle, lang, publish_type, doc):
update_procedure(vehicle, lang, publish_type, doc)
current_db_name = frappe.conf.get("db_name")
doc = frappe.get_doc("Publish", doc)
ver = frappe.db.sql("""select max(version) from `tabPublish` where vehicle = '{vehi}' and language = '{lang}';"""
ver = frappe.db.sql("""select max(version) from `tabPublish` where vehicle = "{vehi}" and language = "{lang}";"""
.format(vehi=vehicle, lang=lang))
v = 0.0
if publish_type == 'Global':
@ -159,7 +163,7 @@ def cal_ver(vehicle, lang, publish_type, doc):
v = float(ver[0][0]) + 0.01
v = "{:.2f}".format(v)
doc.version = v
frappe.db.sql("""update {0}.`tabPublish` set version = '{1}' where name = '{2}'""".format(
frappe.db.sql("""update {0}.`tabPublish` set version = "{1}" where name = "{2}";""".format(
current_db_name, v, doc.name))
frappe.db.commit()
return v
@ -172,9 +176,11 @@ def global_publish(doc):
doc = frappe.get_doc("Publish", doc)
current_db_name = frappe.conf.get("db_name")
procedure = frappe.db.sql(
"""select parent,name from {0}.`tabPublish_Docs` where parent = '{1}' and update_procedure_status='Publish Ready' and procedure_link is not null""".format(current_db_name, doc.name))
asset = frappe.db.sql("""select parent,name from {0}.`tabPublish_Docs` where parent = '{1}' and variant_mapping is not null and procedure_link is null""".format(
current_db_name, doc.name))
"""select parent,name from {0}.`tabPublish_Docs` where parent = "{1}" and update_procedure_status='Publish Ready' and
procedure_link is not null; """.format(current_db_name, doc.name))
asset = frappe.db.sql("""select parent,name from {0}.`tabPublish_Docs` where parent = "{1}" and variant_mapping is not null
and procedure_link is null""".format(current_db_name, doc.name))
if not procedure and not asset:
frappe.throw("There is no item for global publish")
@ -217,12 +223,14 @@ def global_publish(doc):
@frappe.whitelist()
def old_publish(vehicle, language):
current_db_name = frappe.conf.get("db_name")
publish_record = frappe.db.sql("""select name,publish_type from {0}.`tabPublish` where vehicle = '{1}' and language = '{2}' and publish_status='To Publish' and publish_type = 'Internal' and docstatus != '2'""".format(
current_db_name, vehicle, language), as_dict=True)
publish_record = frappe.db.sql("""select name,publish_type from {0}.`tabPublish` where vehicle = "{1}" and language = "{2}"
and publish_status='To Publish' and publish_type = 'Internal' and docstatus != '2'""".format(
current_db_name, vehicle, language), as_dict=1)
if publish_record:
return publish_record
global_publish_record = frappe.db.sql("""select name,publish_type from {0}.`tabPublish` where vehicle = '{1}' and language = '{2}' and publish_status='To Publish' and publish_type = 'Global' and docstatus != '2'""".format(
current_db_name, vehicle, language), as_dict=True)
global_publish_record = frappe.db.sql("""select name,publish_type from {0}.`tabPublish` where vehicle = "{1}" and language = "{2}"
and publish_status='To Publish' and publish_type = 'Global' and docstatus != '2'""".format(
current_db_name, vehicle, language), as_dict=1)
if global_publish_record:
return global_publish_record
@ -231,6 +239,7 @@ def old_publish(vehicle, language):
@frappe.whitelist()
def update_mapping(variant_mapping, doc):
# frappe.msgprint("call update mapping")
doc = frappe.get_doc("Publish", doc)
current_db_name = frappe.conf.get("db_name")
if doc.publish_documents:
@ -240,27 +249,30 @@ def update_mapping(variant_mapping, doc):
for v in vm.get('assets'):
if v.category == variant.asset_category:
v.published = '1'
frappe.db.sql("""update {0}.`tabVariant Mapping_Assets` set published = '1' where parent = '{1}' and category = '{2}'""".format(
frappe.db.sql("""update {0}.`tabVariant Mapping_Assets` set published = '1' where parent = "{1}" and category = "{2}";""".format(
current_db_name, variant.variant_mapping, variant.asset_category))
frappe.db.commit()
if variant.item_category == "System Mapping":
system_mapping = frappe.db.sql("""select name from {0}.`tabSystem Mapping` where variant_mapping = '{1}' and language = '{2}'""".format(
current_db_name, variant.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(
current_db_name, variant.variant_mapping, doc.language), as_dict=1)
if system_mapping:
for system_map in system_mapping:
sm = frappe.get_doc("System Mapping", system_map.name)
for sys_asset in sm.get('systems_assets'):
if sys_asset.systems == variant.system:
# frappe.msgprint("asset")
sys_asset.published = '1'
frappe.db.sql("""update {0}.`tabSystem Mapping_System Assets` set published = '1' where parent = '{1}' and systems = '{2}'""".format(
frappe.db.sql("""update {0}.`tabSystem Mapping_System Assets` set published = '1' where parent = "{1}" and systems = "{2}";""".format(
current_db_name, sm.name, variant.system))
frappe.db.commit()
for sm_item in sm.get("system_sub_systems"):
# frappe.msgprint("system")
if sm_item.systems == variant.system and sm_item.sub_systems == variant.sub_system and sm_item.procedure == variant.procedure_link:
sm_item.procedure_is_published = '1'
frappe.db.sql("""update {0}.`tabSystem Mapping_Sub System` set procedure_is_published = '1' where parent = '{1}' and systems = '{2}' and sub_systems = '{3}'""".format(
frappe.db.sql("""update {0}.`tabSystem Mapping_Sub System` set procedure_is_published = '1' where parent = "{1}"
and systems = "{2}" and sub_systems = "{3}";""".format(
current_db_name, sm.name, variant.system, variant.sub_system))
frappe.db.commit()
@ -270,39 +282,39 @@ def update_mapping(variant_mapping, doc):
@frappe.whitelist()
def get_vm_asset(doc):
doc = frappe.get_doc("Variant Mapping", doc)
vm_assets = frappe.db.sql("""select category,language,attach_file,active_status from {0}.`tabVariant Mapping_Assets` where parent = '{1}' and published = '0'""".format(
current_db_name, doc.name), as_dict=True)
vm_assets = frappe.db.sql("""select category,language,attach_file,active_status from {0}.`tabVariant Mapping_Assets`
where parent = "{1}" and published = '0'; """.format(current_db_name, doc.name), as_dict=1)
return vm_assets
@frappe.whitelist()
def get_sm_asset(doc, name):
system_map = frappe.db.sql("""select name from {0}.`tabSystem Mapping` where variant_mapping='{1}' and name = '{2}'""".format(
current_db_name, doc, name), as_dict=True)
system_map = frappe.db.sql("""select name from {0}.`tabSystem Mapping` where variant_mapping="{1}" and name = "{2}"; """.format(
current_db_name, doc, name), as_dict=1)
if system_map:
for s in system_map:
doc = frappe.get_doc("System Mapping", s.name)
system_asset = frappe.db.sql("""select systems,language,active_status,system_asset from {0}.`tabSystem Mapping_System Assets` where parent = '{1}' and published = '0'""".format(
current_db_name, s.name), as_dict=True)
system_asset = frappe.db.sql("""select systems,language,active_status,system_asset from {0}.`tabSystem Mapping_System Assets`
where parent = "{1}" and published = '0'; """.format(current_db_name, s.name), as_dict=1)
return system_asset
@frappe.whitelist()
def get_system(doc, name):
system_map = frappe.db.sql("""select name from {0}.`tabSystem Mapping` where variant_mapping='{1}' and name = '{2}'""".format(
current_db_name, doc, name), as_dict=True)
def get_system(doc, name,lang):
system_map = frappe.db.sql("""select name from {0}.`tabSystem Mapping` where variant_mapping="{1}" and name = "{2}" and language = "{3}";""".format(
current_db_name, doc, name,lang), as_dict=1)
if system_map:
for s in system_map:
doc = frappe.get_doc("System Mapping", s.name)
system = frappe.db.sql("""select systems,sub_systems,active_status,symptom,component,estimate_time,rts,component,mat,procedure_status,`procedure` from {0}.`tabSystem Mapping_Sub System` where parent = '{1}' and procedure_is_published = '0'""".format(
current_db_name, s.name), as_dict=True)
system = frappe.db.sql("""select systems,sub_systems,active_status,symptom,component,estimate_time,rts,component,mat,
procedure_status,`procedure` from {0}.`tabSystem Mapping_Sub System` where parent = "{1}" and
procedure_is_published = "0";""".format(current_db_name, s.name), as_dict=1)
return system
@frappe.whitelist()
def max_publish(doc):
doc = frappe.get_doc("Publish", doc)
ver = frappe.db.sql("""select max(version) from {0}.tabPublish where vehicle = '{1}' and language = '{2}';""".format(
ver = frappe.db.sql("""select max(version) from {0}.tabPublish where vehicle = "{1}" and language = "{2}";""".format(
current_db_name, doc.vehicle, doc.language))
if ver:
return ver
@ -312,8 +324,9 @@ def max_publish(doc):
def variant(doctype, txt, searchfield, start, page_len, filters):
vehicle = filters.get('vehicle')
return frappe.db.sql(""" select name,family_code,fuel,transmission,vehicle_segment,active_status
FROM {0}.`tabVariant Mapping` where vehicle = '{1}' and
(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, vehicle) % {'txt': txt, 'start': start, 'page_len': page_len})
FROM {0}.`tabVariant Mapping` where vehicle = "{1}" and
(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, vehicle) % {'txt': txt, 'start': start, 'page_len': page_len})
@frappe.whitelist()
@ -321,14 +334,14 @@ def update_procedure_value(name, file_path):
self = frappe.get_doc("Publish", name)
frappe.db.sql(
f'''update `tabPublish` set file_path = '{file_path}' where name = '{name}';''')
f'''update `tabPublish` set file_path = "{file_path}" where name = "{name}";''')
frappe.db.commit()
current_db_name = frappe.conf.get("db_name")
# To validate updated procedure status
procedure_status = frappe.db.sql("""select p.name,p.update_procedure_status,pro.name,p.variant_mapping,p.system,p.sub_system,
p.asset_category,p.item_category,p.variant,p.procedure_link,p.procedure_status,pro.name,pro.workflow_state
from {0}.`tabPublish_Docs` as p,{0}.`tabProcedure` as pro where p.parent = '{1}' and
p.procedure_link = pro.name and p.procedure_link is not null""".format(current_db_name, self.name), as_dict=True)
from {0}.`tabPublish_Docs` as p,{0}.`tabProcedure` as pro where p.parent = "{1}" and
p.procedure_link = pro.name and p.procedure_link is not null""".format(current_db_name, self.name), as_dict=1)
# l = len(procedure_status)
if procedure_status:
@ -356,7 +369,7 @@ def update_procedure_value(name, file_path):
# Update system and variant mapping ststus
if self.publish_type == "Global":
current_db_name = frappe.conf.get("db_name")
global_publish = frappe.db.sql("""select name from {0}.`tabPublish` where global_publish = '{1}'""".format(
global_publish = frappe.db.sql("""select name from {0}.`tabPublish` where global_publish = "{1}";""".format(
current_db_name, self.name), as_dict=True)
for global_name in global_publish:
update_mapping(self.variant_mapping, global_name.name)

Loading…
Cancel
Save