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