Browse Source

Publish version update

version2
venkataakhil 1 year ago
parent
commit
38e81834bd
  1. 58
      smart_service/apis/master_api.py
  2. 6
      smart_service/apis/v2/master.py
  3. 56
      smart_service/transactions/doctype/publish/publish.js
  4. 59
      smart_service/transactions/doctype/publish/publish.py

58
smart_service/apis/master_api.py

@ -7,6 +7,13 @@ from frappe.utils import cstr
import datetime
from smart_service.apis.app_user_login import input_validation
import os
import json
from frappe import utils
from frappe.utils import logger
import copy
frappe.utils.logger.set_log_level("DEBUG")
date_format = "%Y-%m-%d %H:%M:%S.%f"
current_db_name = frappe.conf.get("db_name")
site_name = cstr(frappe.local.site)
@ -391,3 +398,54 @@ def app_modules(LSD):
except Exception as e:
frappe.local.response['http_status_code'] = 400
return {"status": 0, "error": e, 'data': None}
@frappe.whitelist(methods=["POST"], allow_guest=1)
def role_mapping():
# logger_file = f'Role Mapping'
# logger = frappe.logger(logger_file, allow_site=True, file_count=100)
# logger.info(f'Start')
req = json.loads(frappe.request.data)
try:
lsdt = req['LSD']
if lsdt != '':
try:
datetime.datetime.strptime(lsdt, date_format)
except:
frappe.local.response['http_status_code'] = 400
return {"status": 0, "error": "Invalid date format", 'data': None}
except Exception as e:
frappe.local.response['http_status_code'] = 403
return {"status": 0, "error": e}
data = {}
try:
module_details = frappe.db.sql(f"""select module_name,case when active_status= 'Active' Then true else false end as active_status,
app_menu_id from `tabModule Master`
where modified >= '{lsdt}' order by display_order;""", as_dict=1)
module_details1 = frappe.db.sql(f"""select module_name,0 as active_status,app_menu_id from `tabModule Master`
where modified >= '{lsdt}' order by display_order;""", as_dict=1)
data['module'] = module_details
role_maping_details = frappe.db.sql(f"""SELECT role,skill_id,modules from `tabRole Master`
where modified>='{lsdt}' order by display_order;""", as_dict=1)
for r in role_maping_details:
role_list = r['modules'].split(",")
# logger.info(f'Module data-{module_details1}')
modules = copy.deepcopy(module_details1)
# logger.info(f'Module-{modules}')
for m in modules:
if m['module_name'] in role_list:
m['active_status'] = 1
r['modules'] = modules
data['role_mapping'] = role_maping_details
return {"status": 1, "error": None, 'lsdt': utils.now(), "data": data}
except Exception as e:
return {"status": 0, "error": e, 'lsdt': utils.now(), "data": None}

6
smart_service/apis/v2/master.py

@ -33,8 +33,8 @@ def get_role_mapping():
where modified >= '{lsdt}' order by display_order;""", as_dict=1)
data['module'] = module_details
if lsdt:
role_maping_details = frappe.db.sql(f"""SELECT role,my_id,display_order,modules,active_status,modified from `tabRole Master` where modified>='{lsdt}'
order by display_order;""", as_dict=1)
role_maping_details = frappe.db.sql(f"""SELECT role,my_id,display_order,modules,active_status,modified from `tabRole Master`
where modified>='{lsdt}' order by display_order;""", as_dict=1)
else:
role_maping_details = frappe.db.sql(f"""SELECT role,my_id,display_order,modules,active_status,modified from `tabRole Master`
order by display_order;""", as_dict=1)
@ -50,7 +50,7 @@ def get_role_mapping():
def get_repair_service_mapping(vehicle, language):
try:
repair_service_details = []
if language != 'en':
if language == 'en':
repair_service_details = frappe.db.sql(f""" select vehicle,vehicle_id,name,language,check_list_name,active_status,display_order,my_id from
`tabRepair Service Mapping` where vehicle = '{vehicle}' and language = '{language}'; """, as_dict=1)
else:

56
smart_service/transactions/doctype/publish/publish.js

@ -53,11 +53,13 @@ frappe.ui.form.on('Publish', {
},
refresh: function (frm) {
if (frm.doc.docstatus == 0 && !frm.is_new() && frm.doc.publish_type != "Global") {
console.log("calling")
if (frm.doc.docstatus == 0 && !frm.is_new() && frm.doc.publish_type != "Global" && frm.doc.publish_module!="Automotive System") {
debugger
$('[data-route="Form/Publish/' + frm.doc.name + '"]').find('.primary-action').html("Internal Publish")
}
if (frm.doc.docstatus == 0 && frm.doc.publish_type == "Global") {
if (frm.doc.docstatus == 0 && frm.doc.publish_type == "Global" && frm.doc.publish_module!="Automotive System") {
debugger
$('[data-route="Form/Publish/' + frm.doc.name + '"]').find('.primary-action').html("Global Publish")
}
if (frm.doc.publish_module == 'Automotive System') {
@ -90,7 +92,8 @@ frappe.ui.form.on('Publish', {
document.querySelectorAll("[data-fieldname='km_report']")[1].style.color = "#FFFFFF";
document.querySelectorAll("[data-fieldname='add_variant_mapping_to_publish']")[1].style.backgroundColor = "#e31a37";
document.querySelectorAll("[data-fieldname='add_variant_mapping_to_publish']")[1].style.color = "#FFFFFF";
if (frm.doc.docstatus === 1 && frm.doc.publish_type == "Internal" && frm.doc.publish_status == 'Published' && !frm.doc.global_publish && frappe.user.has_role('_Publisher')) {
if (frm.doc.docstatus === 1 && frm.doc.publish_type == "Internal" && frm.doc.publish_status == 'Published' && frm.doc.publish_module=='Automotive System' && !frm.doc.global_publish && frappe.user.has_role('_Publisher')) {
frappe.call({
method: "smart_service.transactions.doctype.publish.publish.max_publish",
args: {
@ -98,6 +101,7 @@ frappe.ui.form.on('Publish', {
},
callback: function (r) {
if (r.message) {
debugger
if (r.message == frm.doc.version) {
frm.add_custom_button(__('Global Publish'), function () {
frappe.call({
@ -117,8 +121,9 @@ frappe.ui.form.on('Publish', {
}
if (frm.doc.docstatus === 1 && frm.doc.publish_status == 'To Publish' && frappe.user.has_role('_Publisher') && frm.doc.publish_module == 'Automotive System') {
if (frm.doc.docstatus === 1 && frm.doc.publish_status == 'To Publish' && frappe.user.has_role('_Publisher') && frm.doc.publish_module == 'Automotive System') {
debugger
frm.add_custom_button(__('Publish'), function () {
frappe.confirm('Are you sure you want to Publish?',
() => {
@ -221,7 +226,8 @@ frappe.ui.form.on('Publish', {
// action to perform if No is selected
});
}).addClass("btn-warning").css({ 'background-color': '#f5b0cd', 'color': 'black' });
} else if (frm.doc.publish_status == 'Published') {
}
else if (frm.doc.publish_status == 'Published') {
frm.set_read_only();
frm.set_df_property('add_variant_mapping_to_publish', 'hidden', 1);
}
@ -302,11 +308,44 @@ frappe.ui.form.on('Publish', {
if (frm.doc.docstatus == 1) {
$(".grid-buttons").hide();
}
}
if (frm.doc.docstatus == 1 && !frm.is_new() && frm.doc.publish_type != "Global" && frm.doc.publish_module != 'Automotive System') {
if (frm.doc.docstatus == 1 && frm.doc.publish_status == 'Published' && !frm.is_new() && frm.doc.publish_type != "Global" && frm.doc.publish_module != 'Automotive System') {
debugger
frappe.call({
method: "smart_service.transactions.doctype.publish.publish.max_publish_new_module",
args: {
"doc": frm.doc.name
},
callback: function (r) {
debugger
if (r.message) {
debugger
if (r.message) {
frm.add_custom_button(__('Global Publish'), function () {
frappe.call({
method: "smart_service.transactions.doctype.publish.publish.generate_global_publish",
args: {
name: frm.doc.name
},
callback: function (r) {
if (r.message.status == "success") {
window.location.href = r.message.url + "/app/publish" + "/" + r.message.message
}
}
})
}).addClass("btn-primary");
}
}
}
})
frappe.call({
method: "smart_service.transactions.doctype.publish.publish.max_publish_new_module",
args: {
@ -327,7 +366,7 @@ frappe.ui.form.on('Publish', {
if (r.message.status == "success") {
window.location.href = r.message.url + "/app/publish" + "/" + r.message.message
window.location.href = r.message.url + "/app/publish" + "/" + r.message.message
}
}
})
@ -340,6 +379,7 @@ frappe.ui.form.on('Publish', {
}
},
validate: function (frm) {
if (frm.doc.publish_module == 'Automotive System') {

59
smart_service/transactions/doctype/publish/publish.py

@ -50,11 +50,12 @@ class Publish(Document):
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':
repair_checksheet_publish(self.vehicle, self.vehicle_id,
self.language, self.publish_type,
self.release_description, self.variant,
self.repair_checksheet_publish)
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:
feature_finder_publish(self.vehicle, self.vehicle_id,
@ -62,7 +63,6 @@ class Publish(Document):
self.release_description,self.feature_finder_publish,self.variant)
if self.docstatus == 1 and self.publish_module =='Feature Finder' and self.publish_type == 'Global':
feature_finder_publish(self.vehicle, self.vehicle_id,
self.language, self.publish_type,
self.release_description,self.feature_finder_publish,
@ -76,8 +76,8 @@ class Publish(Document):
self.release_description, self.variant,
self.repair_checksheet_publish)
update_repair_published_docs(self)
update_publish_status = frappe.db.sql(
"""update `tabPublish` set publish_status='Published' where name='{0}'""".format(self.name))
# update_publish_status = frappe.db.sql(
# """update `tabPublish` set publish_status='Published' where name='{0}'""".format(self.name))
def onload1(self):
current_db_name = frappe.conf.get("db_name")
# To validate updated procedure status
@ -244,6 +244,7 @@ def global_publish(doc):
publish_record.vehicle = doc.vehicle
publish_record.vehicle_id = doc.vehicle_id
publish_record.variant_mapping = doc.variant_mapping
publish_record.publish_module=doc.publish_module
publish_record.variant_mapping_status = doc.variant_mapping_status
publish_record.kilometer_mapping = doc.kilometer_mapping
publish_record.km_active_status = doc.km_active_status
@ -353,7 +354,7 @@ 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
@ -827,28 +828,26 @@ def max_publish_new_module(doc):
return ver
@frappe.whitelist()
def cal_ver_new_module(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(creation) from `tabPublish` where vehicle = "{vehi}" and language = "{lang}";"""
.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
# @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(f"""select max(creation) from `tabPublish` where vehicle = "{vehicle}" and language = "{lang}";""",as_dict=1)
# 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
Loading…
Cancel
Save