@ -12,6 +12,7 @@ import json
from datetime import date
from frappe . utils import cstr
from frappe . utils import logger
import re
current_db_name = frappe . conf . get ( " db_name " )
sys . tracebacklimit = 0
site_name = cstr ( frappe . local . site )
@ -199,64 +200,70 @@ def update_qwik_published_docs(self):
def update_publish_mapping ( vehicle , variant , language , module , publish_type ) :
frappe . set_user ( ' Administrator ' )
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 ( )
elif module == ' Special Tool ' :
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 mahindra_special_tool_information= ' 1 ' and publish_type= ' 1 ' where name = ' { d [ ' name ' ] } ' """ , as_dict = 1 )
frappe . db . commit ( )
else :
pub_data = frappe . db . get_list ( ' Module Publish Mapping ' , filters = {
" vehicle " : vehicle ,
" variant " : variant ,
" language " : language ,
" publish_type " : publish_type
} , fields = [ ' name ' ] )
if pub_data :
doc = frappe . get_doc ( ' Module Publish Mapping ' , pub_data [ 0 ] [ ' name ' ] )
# frappe.set_user('Administrator')
try :
frappe . log_error ( " calling module " , str ( module ) )
if module == ' Repair service ' :
pub_data = frappe . db . get_list ( ' Module Publish Mapping ' , filters = {
" vehicle " : vehicle ,
" language " : language ,
" publish_type " : publish_type
} , fields = [ ' name ' ] )
frappe . log_error ( " pub_data " , str ( pub_data ) )
if len ( pub_data ) > 0 :
for d in pub_data :
if d [ ' name ' ] :
frappe . log_error ( " kkkkkkkkkk " )
frappe . db . sql (
f """ UPDATE `tabModule Publish Mapping` set repairservice_check_sheet= ' 1 ' ,publish_type= ' { publish_type } ' where name = ' { d [ ' name ' ] } ' """ )
frappe . db . commit ( )
elif module == ' Special Tool ' :
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 mahindra_special_tool_information= ' 1 ' ,publish_type= ' { publish_type } ' 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 ,
" publish_type " : publish_type
} )
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 == ' Qwik Service ' :
doc . qwik_service = 1
doc . save ( )
} , 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 ,
" publish_type " : publish_type
} )
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 == ' Qwik Service ' :
doc . qwik_service = 1
doc . save ( )
except Exception as e :
frappe . log_error ( " update_publish_mapping " , str ( e ) )
# def update_publish_status(self):
# try:
@ -1290,22 +1297,40 @@ def qwik_service_data(language, publish_type, variant, parent, vehicle):
qwik_service_details = frappe . db . sql ( ''' select name,variant,vehicle,kilometers,language,service_time,active_status,
pdf , display_order , keywords , my_id from ` tabQwik Service ` where name = ' %s ' ; ''' %
( parent ) , as_dict = 1 )
( parent ) , as_dict = 1 )
CLEANR = re . compile ( ' <.*?> ' )
for q in qwik_service_details :
q [ ' pre_work ' ] = frappe . db . sql ( ''' select idx as ' display_order ' , content from `tabQwik Service Content` where parent= ' %s '
& & content_type = ' Pre-work ' order by display_order ; ''' % (q[ ' name ' ]), as_dict=1)
# if q['pre_work']:
# for con in q['pre_work']:
# if con['content']:
# con['content'] = re.sub(CLEANR, '', con['content'])
q [ ' consumables ' ] = frappe . db . sql ( ''' select idx as ' display_order ' , content from `tabQwik Service Content` where
parent = ' %s ' & & content_type = ' Consumables ' order by display_order ; ''' % (q[ ' name ' ]), as_dict=1)
# if q['consumables']:
# for con in q['consumables']:
# if con['content']:
# con['content'] = re.sub(CLEANR, '', con['content'])
q [ ' tools ' ] = frappe . db . sql ( ''' select idx as ' display_order ' , content from `tabQwik Service Content` where
parent = ' %s ' & & content_type = ' Tools ' order by display_order ; ''' % (q[ ' name ' ]), as_dict=1)
# if q['tools']:
# for con in q['tools']:
# if con['content']:
# con['content'] = re.sub(CLEANR, '', con['content'])
for p in qwik_service_details :
# p['qwik_procedure'] = frappe.db.sql('''select idx as 'display_order',side,level,content from `tabQwik Procedure`
# where parent ='%s';''' % (p['name']), as_dict=1)
LHS = frappe . db . sql ( ''' select idx as ' display_order ' ,side,level,content from `tabQwik Procedure`
where parent = ' %s ' and side = ' LHS ' ; ''' % (p[ ' name ' ]), as_dict=1)
# if LHS:
# for con in LHS:
# if con['content']:
# con['content'] = re.sub(CLEANR, '', con['content'])
RHS = frappe . db . sql ( ''' select idx as ' display_order ' ,side,level,content from `tabQwik Procedure`
where parent = ' %s ' and side = ' RHS ' ; ''' % (p[ ' name ' ]), as_dict=1)
# if RHS:
# for con in RHS:
# if con['content']:
# con['content'] = re.sub(CLEANR, '', con['content'])
p [ ' qwik_procedure ' ] = { ' LHS ' : LHS , ' RHS ' : RHS }
logger . info (
@ -1366,29 +1391,32 @@ def max_publish_new_module(doc):
@frappe . whitelist ( )
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 ) )
v = 0.0
if publish_type == ' Global ' :
if ver [ 0 ] [ 0 ] == None :
v = 1.0
else :
v = int ( float ( ver [ 0 ] [ 0 ] ) ) + 1.0
try :
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 ) )
v = 0.0
if publish_type == ' Global ' :
if ver [ 0 ] [ 0 ] == None :
v = 1.0
else :
v = int ( float ( ver [ 0 ] [ 0 ] ) ) + 1.0
elif publish_type == ' Internal ' :
if ver [ 0 ] [ 0 ] == None :
v = 0.01
else :
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 (
current_db_name , v , doc . name ) )
frappe . db . commit ( )
return v
elif publish_type == ' Internal ' :
if ver [ 0 ] [ 0 ] == None :
v = 0.01
else :
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 (
current_db_name , v , doc . name ) )
frappe . db . commit ( )
return { " status " : 1 , " data " : v }
except Exception as e :
return { " status " : 0 , " data " : " None " , " error " : str ( e ) }
@frappe . whitelist ( )