@ -1,6 +1,6 @@
# Copyright (c) 2021, Hard n Soft Technologies Pvt Ltd and contributors
# For license information, please see license.txt
import copy
import sys
from html import unescape
import frappe
@ -10,10 +10,10 @@ import json
from datetime import date
from frappe . utils import cstr
from frappe . utils import logger
current_db_name = frappe . conf . get ( " db_name " )
sys . tracebacklimit = 0
site_name = cstr ( frappe . local . site )
import pandas as pd
base_url = os . path . expanduser (
" ~ " ) + " /frappe-bench/sites/ " + site_name + " /public " + " /files " + " /json_files " + " /phase2 "
@ -27,7 +27,7 @@ module_name = 'feature_finder'
class Publish ( Document ) :
def validate ( self ) :
self . published_date = str ( date . today ( ) )
self . published_by = frappe . session . email
self . published_by = frappe . session . user
# Selected variant and kilometer mapping details list
variant = [ ]
for vm in self . get ( ' publish_documents ' ) :
@ -37,26 +37,24 @@ class Publish(Document):
# variant.append(vm.variant_mapping)
if vm . variant_mapping not in variant :
variant . append ( vm . variant_mapping )
if self . publish_module == ' Feature Finder ' and self . feature_finder_publish_docs :
if self . publish_module == ' Feature Finder ' and self . feature_finder_publish_docs :
for vm in self . get ( ' feature_finder_publish_docs ' ) :
if vm . variant not in variant :
variant . append ( vm . variant )
if vm . variant not in variant :
variant . append ( vm . variant )
self . variant_mapping_details = ' '
self . kilometer_mapping_details = ' '
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 = 1 )
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 '
def on_submit ( self ) :
if self . docstatus == 1 and self . publish_status == ' To Publish ' and self . publish_module == ' Repair service ' and \
self . publish_type == ' Internal ' :
if self . docstatus == 1 and self . publish_status == ' To Publish ' and self . publish_module == ' Repair service ' and self . publish_type == ' Internal ' :
repair_checksheet_publish ( self . vehicle , self . vehicle_id ,
self . language , self . publish_type ,
self . release_description , self . variant ,
@ -64,8 +62,7 @@ class Publish(Document):
update_publish_status = frappe . db . sql (
""" update `tabPublish` set publish_status= ' Published ' where name= ' {0} ' """ . format ( self . name ) )
if self . docstatus == 1 and self . publish_status == ' To Publish ' and self . publish_module == ' Feature Finder ' \
and self . publish_type == ' Internal ' and self . feature_finder_publish_docs :
if self . docstatus == 1 and self . publish_status == ' To Publish ' and self . publish_module == ' Feature Finder ' and self . publish_type == ' Internal ' and self . feature_finder_publish_docs :
feature_finder_publish ( self . vehicle , self . vehicle_id ,
self . language , self . publish_type ,
self . release_description , self . feature_finder_publish_docs , self . variant )
@ -80,17 +77,17 @@ class Publish(Document):
update_feature_published_docs ( self )
update_publish_status = frappe . db . sql (
""" update `tabPublish` set publish_status= ' Published ' where name= ' {0} ' """ . format ( self . name ) )
if self . docstatus == 1 and self . publish_status == ' To Publish ' and self . publish_module == ' Repair service ' \
and self . publish_type == ' Global ' and self . repiar_checksheet_publish_docs :
if self . docstatus == 1 and self . publish_status == ' To Publish ' and self . publish_module == ' Repair service ' and self . publish_type == ' Global ' and self . repiar_checksheet_publish_docs :
repair_checksheet_publish ( self . vehicle , self . vehicle_id ,
self . language , self . publish_type ,
self . release_description , self . variant ,
self . repiar_checksheet_publish_docs )
update_repair_published_docs ( self )
update_publish_status = frappe . db . sql (
""" update `tabPublish` set publish_status= ' Published ' where name= ' {0} ' """ . format ( self . name ) )
variant = self . variant_mapping_details . split ( ' /n ' )
frappe . log_error ( ' variant ' , str ( variant ) )
# for v in variant:
# frappe.log_error('v', str(v))
@ -101,12 +98,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 = 1 )
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 " :
@ -115,24 +110,18 @@ class Publish(Document):
if y . procedure_link :
if x . procedure_link == y . procedure_link and y . update_procedure_status != y . procedure_status :
y . update_procedure_status = x . workflow_state
frappe . db . sql (
""" update `tabPublish_Docs` set update_procedure_status = %s where parent = %s and procedure_link = %s ; """ ,
(
x . workflow_state , self . name , x . procedure_link ) )
frappe . db . sql ( """ update `tabPublish_Docs` set update_procedure_status = %s where parent = %s and procedure_link = %s ; """ , (
x . workflow_state , self . name , x . procedure_link ) )
frappe . db . commit ( )
if x . procedure_link == y . procedure_link and x . workflow_state != y . procedure_status :
y . update_procedure_status = x . workflow_state
frappe . db . sql (
""" update `tabPublish_Docs` set update_procedure_status = %s where parent = %s and procedure_link = %s """ ,
(
x . workflow_state , self . name , x . procedure_link ) )
frappe . db . sql ( """ update `tabPublish_Docs` set update_procedure_status = %s where parent = %s and procedure_link = %s """ , (
x . workflow_state , self . name , x . procedure_link ) )
frappe . db . commit ( )
if y . procedure_status == " Publish Ready " :
if x . procedure_link == y . procedure_link and x . workflow_state != y . procedure_status and not \
y . excluded_global :
if x . procedure_link == y . procedure_link and x . workflow_state != y . procedure_status and not y . excluded_global :
y . excluded_global = " 1 "
if x . procedure_link == y . procedure_link and x . workflow_state != y . procedure_status and \
x . workflow_state == " Draft " and y . procedure_status != " Publish Ready " :
if x . procedure_link == y . procedure_link and x . workflow_state != y . procedure_status and x . workflow_state == " Draft " and y . procedure_status != " Publish Ready " :
y . excluded_internal = " 1 "
y . save ( )
frappe . db . commit ( )
@ -140,9 +129,8 @@ 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 (
current_db_name , self . name ) , as_dict = True )
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 )
@ -167,13 +155,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 = 1 )
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 :
@ -181,16 +167,13 @@ def update_procedure(vehicle, lang, publish_type, doc):
if y . procedure_link :
if x . procedure_link == y . procedure_link and x . workflow_state != y . update_procedure_status :
y . update_procedure_status = x . workflow_state
frappe . db . sql (
""" update `tabPublish_Docs` set update_procedure_status = %s where procedure_link = %s """ , (
x . workflow_state , x . procedure_link ) )
frappe . db . sql ( """ update `tabPublish_Docs` set update_procedure_status = %s where procedure_link = %s """ , (
x . workflow_state , x . procedure_link ) )
frappe . db . commit ( )
if y . procedure_status == " Publish Ready " :
if x . procedure_link == y . procedure_link and x . workflow_state != y . procedure_status and \
not y . excluded_global :
if x . procedure_link == y . procedure_link and x . workflow_state != y . procedure_status and not y . excluded_global :
y . excluded_global = " 1 "
if x . procedure_link == y . procedure_link and x . workflow_state != y . procedure_status and \
x . workflow_state == " Draft " and y . procedure_status != " Publish Ready " :
if x . procedure_link == y . procedure_link and x . workflow_state != y . procedure_status and x . workflow_state == " Draft " and y . procedure_status != " Publish Ready " :
y . excluded_internal = " 1 "
y . save ( )
@ -218,47 +201,57 @@ def update_procedure(vehicle, lang, publish_type, doc):
if str ( table_len ) == str ( len_publish ) :
frappe . throw ( " There is no item for global publish " )
# Generate Publish versions
def update_publish_mapping ( vehicle , variant , language , module ) :
def update_publish_mapping ( vehicle , variant , language , module , publish_type ) :
frappe . set_user ( ' Administrator ' )
pub_data = frappe . db . get_list ( ' Module Publish Mapping ' , filters = {
" vehicle " : vehicle ,
" variant " : variant ,
" language " : language
} , fields = [ ' name ' ] )
if pub_data :
doc = frappe . get_doc ( ' Module Publish Mapping ' , pub_data [ 0 ] [ ' name ' ] )
if module == ' Repair service ' :
pub_data = frappe . db . get_list ( ' Module Publish Mapping ' , filters = {
" vehicle " : vehicle ,
" language " : language ,
" publish_type " : publish_type
} , fields = [ ' name ' ] )
if len ( pub_data ) > 0 :
for d in pub_data :
if d [ ' name ' ] :
frappe . db . sql ( f """ UPDATE `tabModule Publish Mapping` set repairservice_check_sheet= ' 1 ' and publish_type= ' 1 ' where name = ' { d [ ' name ' ] } ' """ , as_dict = 1 )
frappe . db . commit ( )
else :
doc = frappe . get_doc ( {
' doctype ' : ' Module Publish Mapping ' ,
pub_data = frappe . db . get_list ( ' Module Publish Mapping ' , filters = {
" vehicle " : vehicle ,
" variant " : variant ,
" language " : language
} )
if module == ' Automotive System ' :
doc . automotive_system = 1
doc . tsb = 1
doc . fsa = 1
doc . tekalert = 1
elif module == ' Feature Finder ' :
doc . feature_finder = 1
elif module == ' Repair service ' :
doc . repairservice_check_sheet = 1
doc . save ( )
" language " : language ,
" publish_type " : publish_type
} , fields = [ ' name ' ] )
if pub_data :
doc = frappe . get_doc ( ' Module Publish Mapping ' , pub_data [ 0 ] [ ' name ' ] )
else :
doc = frappe . get_doc ( {
' doctype ' : ' Module Publish Mapping ' ,
" vehicle " : vehicle ,
" variant " : variant ,
" language " : language
} )
if module == ' Automotive System ' :
doc . automotive_system = 1
doc . tsb = 1
doc . fsa = 1
doc . tekalert = 1
def update_publish_status ( self ) :
try :
update_status = frappe . db . sql (
""" update `tabPublish` set publish_status= " Published " where name= ' {0} ' """ . format ( self . name ) )
except Exception as e :
return e
elif module == ' Feature Finder ' :
doc . feature_finder = 1
doc . save ( )
# def update_publish_status(self):
# try:
# update_status = frappe.db.sql(
# """update `tabPublish Test` set publish_status="Published" where name='{0}' """.format(self.name))
# except Exception as e:
# return e
@frappe . whitelist ( )
@ -287,7 +280,6 @@ def cal_ver(vehicle, lang, publish_type, doc):
frappe . db . commit ( )
return v
# Create global publish document for publish ready procedures
@ -296,10 +288,10 @@ 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 " )
@ -342,28 +334,28 @@ def global_publish(doc):
@frappe . whitelist ( )
def generate_global_publish ( name , module_name ) :
def generate_global_publish ( name , module_name ) :
try :
res = frappe . get_doc ( " Publish " , name )
if module_name == ' Feature Finder ' :
if module_name == ' Feature Finder ' :
ret = frappe . get_doc ( {
" doctype " : " Publish " ,
" vehicle " : res . vehicle ,
" publish_type " : " Global " ,
" language " : res . language ,
" variant_mapping_details " : res . variant_mapping_details ,
" variant_mapping_details " : res . variant_mapping_details ,
" publish_status " : ' To Publish ' ,
" release_description " : res . release_description ,
" publish_module " : res . publish_module ,
" feature_finder_publish_docs " : res . feature_finder_publish_docs
} )
elif module_name == ' Repair service ' :
ret = frappe . get_doc ( {
ret = frappe . get_doc ( {
" doctype " : " Publish " ,
" vehicle " : res . vehicle ,
" publish_type " : " Global " ,
" language " : res . language ,
" variant_mapping_details " : res . variant_mapping ,
" variant_mapping_details " : res . variant_mapping ,
" publish_status " : ' To Publish ' ,
" release_description " : res . release_description ,
" publish_module " : res . publish_module ,
@ -390,7 +382,6 @@ def old_publish(vehicle, language):
if global_publish_record :
return global_publish_record
# Update System and Variant Mapping and its called from publish client script
@ -405,37 +396,31 @@ 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(current_db_name, variant.variant_mapping, variant.asset_category))
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 = 1 )
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 :
sys_asset . published = ' 1 '
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 . 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 " ) :
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 '
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 ( )
# Set filter for latest modified document
@ -443,37 +428,31 @@ def update_mapping(variant_mapping, doc):
def get_vm_asset ( doc , lang ) :
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 language = ' {2} ' and published = 0 ; """ .format(current_db_name,
doc . name , lang ) ,
as_dict = 1 )
where parent = " {1} " and language = ' {2} ' and published = 0 ; """ .format(current_db_name, doc.name, lang), as_dict=1)
return vm_assets
@frappe . whitelist ( )
def get_sm_asset ( 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 )
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_asset = frappe . db . sql ( """ select systems,language,active_status,system_asset from {0} .`tabSystem Mapping_System Assets`
where parent = " {1} " and language = " {2} " and published = ' 0 ' ; """ .format(current_db_name, s.name,
lang ) , as_dict = 1 )
where parent = " {1} " and language = " {2} " and published = ' 0 ' ; """ .format(current_db_name, s.name, lang), as_dict=1)
return system_asset
@frappe . whitelist ( )
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 )
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_status != " Draft " and
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_status != " Draft " and
procedure_is_published = " 0 " ; """ .format(current_db_name, s.name), as_dict=1)
return system
@ -481,9 +460,8 @@ def get_system(doc, name, lang):
@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 (
current_db_name , doc . vehicle , doc . language ) )
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
@ -492,11 +470,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 ( )
@ -508,12 +484,10 @@ def update_procedure_value(name, file_path):
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
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 )
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 :
@ -522,23 +496,18 @@ def update_procedure_value(name, file_path):
if y . procedure_link :
if x . procedure_link == y . procedure_link and y . update_procedure_status != y . procedure_status :
y . update_procedure_status = x . workflow_state
frappe . db . sql (
""" update `tabPublish_Docs` set update_procedure_status = %s where parent = %s and procedure_link = %s ; """ ,
(
x . workflow_state , self . name , x . procedure_link ) )
frappe . db . sql ( """ update `tabPublish_Docs` set update_procedure_status = %s where parent = %s and procedure_link = %s ; """ , (
x . workflow_state , self . name , x . procedure_link ) )
frappe . db . commit ( )
if x . procedure_link == y . procedure_link and x . workflow_state != y . procedure_status :
y . update_procedure_status = x . workflow_state
frappe . db . sql (
""" update `tabPublish_Docs` set update_procedure_status = %s where parent = %s and procedure_link = %s """ ,
(
x . workflow_state , self . name , x . procedure_link ) )
frappe . db . sql ( """ update `tabPublish_Docs` set update_procedure_status = %s where parent = %s and procedure_link = %s """ , (
x . workflow_state , self . name , x . procedure_link ) )
frappe . db . commit ( )
if y . procedure_status == " Publish Ready " :
if x . procedure_link == y . procedure_link and x . workflow_state != y . procedure_status and not y . excluded_global :
y . excluded_global = " 1 "
if x . procedure_link == y . procedure_link and x . workflow_state != y . procedure_status and \
x . workflow_state == " Draft " and y . procedure_status != " Publish Ready " :
if x . procedure_link == y . procedure_link and x . workflow_state != y . procedure_status and x . workflow_state == " Draft " and y . procedure_status != " Publish Ready " :
y . excluded_internal = " 1 "
y . save ( )
frappe . db . commit ( )
@ -567,6 +536,7 @@ def update_feature_published_docs(self):
try :
for d in self . feature_finder_publish_docs :
frappe . db . sql (
""" UPDATE `tabFeature Finder` set is_published=1 where name= ' {0} ' """ . format ( d . parent1 ) )
frappe . db . commit ( )
@ -579,6 +549,7 @@ def update_repair_published_docs(self):
try :
for d in self . repair_checksheet_publish :
frappe . db . sql (
""" UPDATE `tabRepair Service Mapping` set published=1 where name= ' {0} ' """ . format ( d . parent_name ) )
frappe . db . commit ( )
@ -612,14 +583,29 @@ def get_service_repair(vehicle,
select * from ` tabRepair Service Mapping ` where vehicle = ' {vehicle} ' and language = ' {language_label} ' and published = 0 ;
''' , as_dict=1)
return data
def create_df ( data_set ) :
# with open(base_url+'data.json', 'w') as outfile:
# outfile.write(json.dumps(feature_finder_tmp, indent=4, default=str))
# with open(base_url+'data.json') as f:
# feature_finder_tmp = json.load(f)
feature_finder_tmp = json . dumps ( data_set )
df = pd . DataFrame ( json . loads ( feature_finder_tmp ) )
filter_group = df . groupby ( ' variant ' )
keys = filter_group . groups . keys ( )
res = { }
for i in keys :
res [ i ] = ( filter_group . get_group ( i ) )
res1 = { }
for key , value in res . items ( ) :
res1 [ key ] = value . to_dict ( ' records ' )
return res1
@frappe . whitelist ( )
def get_feature_finder ( vehicle = None , variant = None , language_label = None ) :
try :
data = frappe . db . sql (
f """ select * from `tabFeature Finder` where vehicle= ' { vehicle } ' and variant_id= ' { variant } ' and language= ' { language_label } '
and is_published = 0 """ , as_dict=1)
f """ select * from `tabFeature Finder` where vehicle= ' { vehicle } ' and variant_id= ' { variant } ' and language= ' { language_label } ' and is_published=0 """ , as_dict = 1 )
return data
except Exception as e :
return str ( e )
@ -634,8 +620,7 @@ def repair_checksheet_publish(vehicle, vehicle_id,
logger . info (
f ' Repair Checksheet Started- { vehicle } - { language } - { publish_type } - { parent } ' )
folder_url = base_url + " / " + \
vehicle . replace ( ' ' , ' - ' ) + " / " + language
folder_url = base_url + " / " + vehicle . replace ( ' ' , ' - ' ) + " / " + language
logger . info ( f ' Created Folder- { vehicle } - { language } - { publish_type } ' )
''' Publish Ready Flags '''
@ -672,7 +657,7 @@ def repair_checksheet_publish(vehicle, vehicle_id,
repair_checksheet [ ' data ' ] [ 0 ] )
repair_checksheet_tmp = get_latest_data ( { ' data ' : published_data [ ' data ' ] } , {
' data ' : repair_checksheet_tmp } )
' data ' : repair_checksheet_tmp } )
else :
for i in parent :
@ -714,8 +699,7 @@ def feature_finder_publish(vehicle=None, vehicle_id=None,
logger . info (
f " start of fetching repair checksheet data - { vehicle } - { language } - { module_name } - { variant } " )
folder_url = base_url + " / " + \
vehicle . replace ( ' ' , ' - ' ) + " / " + language
folder_url = base_url + " / " + vehicle . replace ( ' ' , ' - ' ) + " / " + language
logger . info ( f ' Created Folder- { vehicle } - { language } - { publish_type } ' )
''' Final Json '''
@ -751,10 +735,13 @@ def feature_finder_publish(vehicle=None, vehicle_id=None,
publish_repair_checksheet = 1
feature_finder_tmp . append (
feature_finder [ ' data ' ] [ 0 ] )
feature_finder_tmp = create_df ( feature_finder_tmp )
# frappe.msgprint(str(json.dumps(feature_finder_tmp)))
feature_finder_tmp = get_latest_data (
{ ' data ' : published_data [ ' data ' ] } , { ' data ' : feature_finder_tmp } )
# feature_finder_tmp = get_latest_data(
# {'data': published_data['data']}, {'data': feature_finder_tmp})
vehi_data = compare_get_data ( { ' data ' : published_data [ ' data ' ] } , { ' data ' : feature_finder_tmp } )
else :
for i in parent :
@ -771,10 +758,12 @@ def feature_finder_publish(vehicle=None, vehicle_id=None,
feature_finder_tmp = get_latest_data (
{ ' data ' : feature_finder_tmp } , { ' data ' : [ ] } )
vehi_data = create_df ( feature_finder_tmp )
# if publish_feature_finder == 1:
""" Save publish file """
vehicle_data [ ' data ' ] = feature_finder_tmp
vehicle_data [ ' data ' ] = vehi_data
with open ( file_path , ' w ' ) as outfile :
outfile . write ( json . dumps ( vehicle_data , indent = 4 , default = str ) )
logger . info (
@ -801,7 +790,6 @@ def get_latest_data(prev_data, latest_data):
data_dic2 = get_key_value_data ( latest_data )
final_dic = data_dic1 . copy ( )
for d1 in data_dic1 :
if data_dic1 [ d1 ] [ ' active_status ' ] == ' Inactive ' :
final_dic . pop ( d1 )
@ -813,11 +801,30 @@ def get_latest_data(prev_data, latest_data):
final_dic . update ( { d2 : data_dic2 [ d2 ] } )
final_list = list ( final_dic . values ( ) )
return final_list
except Exception as e :
frappe . throw ( str ( e ) )
def compare_get_data ( prev_data , latest_data ) :
try :
final_dic = { }
for key , value in prev_data . items ( ) :
prev_data [ key ] = latest_data . get ( key )
final_dic = copy . deepcopy ( prev_data )
for key , value in final_dic [ " data " ] . items ( ) :
for i in value :
if i [ ' active_status ' ] == " Inactive " :
value . remove ( i )
return final_dic [ " data " ]
except Exception as e :
frappe . throw ( str ( e ) )
def repair_checksheet_data ( vehicle = None , language = None ,
publish_type = None , parent = None ) :
@ -867,59 +874,52 @@ def feature_finder_data(vehicle=None, language=None,
f " start of fetching feature finder checksheet data - { vehicle } - { language } - { variant } - { module_name } " )
feature_finder_details = [ ]
if language == ' en ' :
feature_finder_details = frappe . db . sql ( f """ select ff.name,ff.vehicle,ff.vehicle_id,ff.variant,ff.variant_id,
ff . language , ff . features_names as feature_name , ff . feature_category ,
ff . display_order , ff . active_status , ff m. feature_pdf as pdf from ` tabFeature Finder ` ff
left join ` tabFeature Finder Master ` ffm on ff . features_names = ffm . feature_name
feature_finder_details = frappe . db . sql ( f """ select ff.name,ff.vehicle,ff.vehicle_id,ff.variant,ff.variant_id,ff.language,
ff . features_names as feature_name , ff . feature_category , ff . display_order , ff . active_status ,
ffm . feature_pdf as pdf from ` tabFeature Finder ` ff left join ` tabFeature Finder Master ` ffm on
ff . features_names = ffm . feature_name
where ff . vehicle = " THAR " and ffm . vehicle = " {vehicle} "
and ff . variant = " {variant} " and ff . language = " {language} " and
ffm . language = " {language} " and ff . name = " {parent} " ;
and ff . variant = " {variant} "
and ff . language = " {language} " and ffm . language = " {language} " and ff . name = " {parent} " ;
""" , as_dict=1)
logger . info ( feature_finder_details )
else :
feature_finder_details = frappe . db . sql ( f """ select ff.name,ff.vehicle,ff.vehicle_id,ff.variant,ff.variant_id,
ff . language , ff . translated_feature_name as feature_name ,
ff . feature_category , ff . display_order , ff . active_status ,
ffm . feature_pdf as pdf from ` tabFeature Finder ` ff
feature_finder_details = frappe . db . sql ( f """ select ff.name,ff.vehicle,ff.vehicle_id,ff.variant,ff.variant_id,ff.language,
ff . translated_feature_name as feature_name , ff . feature_category ,
ff . display_order , ff . active_status , ffm . feature_pdf as pdf from ` tabFeature Finder ` ff
left join ` tabFeature Finder Master ` ffm on ff . features_names = ffm . feature_name
where ff . vehicle = " {vehicle} " and ffm . vehicle = " {vehicle} "
and ff . variant = " {variant} " and ff . language = " {language} "
and ff . name = " {parent} " ; """ , as_dict=1)
where ff . vehicle = " {vehicle} " and ffm . vehicle = " {vehicle} " and ff . variant = " {variant} "
and ff . language = " {language} " and ff . name = " {parent} " ; """ , as_dict=1)
for f in feature_finder_details :
f [ ' disclaimer ' ] = frappe . db . sql ( f '''
SELECT name , content , active_status , idx as display_order FROM ` tabFeature Finder Disclaimer `
where parent = ' { str(f[ ' vehicle ' ]) + str( ' - ' ) + str(f[ ' feature_name ' ]) + str( ' - ' ) + str(f[ ' language ' ])} ' ;
where parent = ' { str(f[ ' vehicle ' ])+ str( ' - ' )+ str(f[ ' feature_name ' ]) + str( ' - ' )+str(f[ ' language ' ])} ' ;
''' , as_dict=1)
sop_images = frappe . db . sql ( f """ select image,display_order,active_status from `tabFeature Finder Images` where
parent = ' {f['name']} ' and feature_type = ' SOP ' order by display_order desc ; """ ,
as_dict = 1 )
parent = ' {f['name']} ' and feature_type = ' SOP ' order by display_order desc ; """ , as_dict=1)
sop_content = frappe . db . sql ( f """ select content,display_order, active_status from `tabFeature Finder Content`
where parent = ' {f['name']} ' and feature_type = ' SOP ' order by display_order desc ; """ ,
as_dict = 1 )
where parent = ' {f['name']} ' and feature_type = ' SOP ' order by display_order desc ; """ , as_dict=1)
sop_specification = frappe . db . sql ( f """ select specification,value,display_order,active_status from `tabFeature Finder Specification`
where parent = ' {f['name']} ' and feature_type = ' SOP ' order by display_order desc ; """ ,
as_dict = 1 )
where parent = ' {f['name']} ' and feature_type = ' SOP ' order by display_order desc ; """ , as_dict=1)
f [ ' sop ' ] = { ' content ' : sop_content , ' images ' : sop_images ,
' specificaton ' : sop_specification }
post_vin_data = frappe . db . sql ( f ''' select name,idx as display_order,post_vin_cutoff_name,post_vin_cutoff_id
from ` tabPost Vin Cutoff ID ` where parent = ' {f['name']} ' ; ''' , as_dict=1)
for p in post_vin_data :
vin_content = frappe . db . sql ( f """ select content,display_order, active_status from `tabFeature Finder Content`
where parent = ' {f['name']} ' and post_vin_cutoff_name = ' {p['post_vin_cutoff_name']} ' order by display_order desc ; """ ,
as_dict = 1 )
where parent = ' {f['name']} ' and post_vin_cutoff_name = ' {p['post_vin_cutoff_name']} ' order by display_order desc ; """ , as_dict=1)
vin_images = frappe . db . sql ( f """ select image,display_order,active_status from `tabFeature Finder Images` where
parent = ' {f['name']} ' and post_vin_cutoff_name = ' {p['post_vin_cutoff_name']} ' order by display_order desc ; """ ,
as_dict = 1 )
parent = ' {f['name']} ' and post_vin_cutoff_name = ' {p['post_vin_cutoff_name']} ' order by display_order desc ; """ , as_dict=1)
vin_specification = frappe . db . sql ( f """ select specification,value,display_order,active_status from `tabFeature Finder Specification`
where parent = ' {f['name']} ' and post_vin_cutoff_name = ' {p['post_vin_cutoff_name']} ' order by display_order desc ; """ ,
as_dict = 1 )
where parent = ' {f['name']} ' and post_vin_cutoff_name = ' {p['post_vin_cutoff_name']} ' order by display_order desc ; """ , as_dict=1)
p [ ' content ' ] = vin_content
p [ ' images ' ] = vin_images
p [ ' specificaton ' ] = vin_specification
@ -943,9 +943,8 @@ def feature_finder_data(vehicle=None, language=None,
@frappe . whitelist ( )
def max_publish_new_module ( doc ) :
doc = frappe . get_doc ( " Publish " , doc )
ver = frappe . db . sql (
""" select max(version) from {0} .tabPublish where vehicle = " {1} " and language = " {2} " and publish_module!= " Automotive System " ; """ . format (
current_db_name , doc . vehicle , doc . language ) )
ver = frappe . db . sql ( """ select max(version) from {0} .tabPublish where vehicle = " {1} " and language = " {2} " and publish_module!= " Automotive System " ; """ . format (
current_db_name , doc . vehicle , doc . language ) )
if ver :
return ver
@ -954,9 +953,8 @@ def max_publish_new_module(doc):
def cal_ver_new_module ( 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} " and publish_module!= " Automotive System " ; """
. format ( vehi = vehicle , lang = lang ) )
ver = frappe . db . sql ( """ select max(version) from `tabPublish` where vehicle = " {vehi} " and language = " {lang} " and publish_module!= " Automotive System " ; """
. format ( vehi = vehicle , lang = lang ) )
v = 0.0
if publish_type == ' Global ' :
if ver [ 0 ] [ 0 ] == None :