Browse Source

Vehicle master publish flag

master
venkataakhil 1 year ago
parent
commit
64d7d5752e
  1. 7
      smart_service/apis/app_user_login.py
  2. 55
      smart_service/apis/master_api.py
  3. 29
      smart_service/apis/publish_api.py
  4. 21
      smart_service/masters/doctype/vehicle/vehicle.json
  5. 42
      smart_service/transactions/doctype/publish/publish.js

7
smart_service/apis/app_user_login.py

@ -859,13 +859,14 @@ def generate_refresh_token():
def refresh_token():
""" For Refresh API """
rate_res = custom_rate_limit(limit=5, seconds=15)
if rate_res != 1:
return rate_res
# rate_res = custom_rate_limit(limit=5, seconds=15)
# if rate_res != 1:
# return rate_res
frappe.set_user("Administrator")
req = frappe.request.data
req = json.loads(req)
refresh_token= req['refresh_token']
if refresh_token:
device_id= req['DeviceID']

55
smart_service/apis/master_api.py

@ -3,13 +3,10 @@
import frappe
from frappe.model.document import Document
import json
from frappe.utils import cstr
import datetime
from smart_service.apis.app_user_login import input_validation
import os
import re
current_db_name = frappe.conf.get("db_name")
site_name = cstr(frappe.local.site)
@ -40,7 +37,7 @@ def custom_rate_limit(limit, seconds):
@frappe.whitelist()
def masters(args=None, LSD=None):
def masters(args=None, LSD=None,iid=None):
rate = custom_rate_limit(limit=20, seconds=5)
if rate != 1:
return rate
@ -49,13 +46,6 @@ def masters(args=None, LSD=None):
if val != '':
return {"status": 0, "error": "Parameter's missing:"+val}
# if args == None and LSD == None:
# return {"status": 0, "error": "Parameter's missing: args & LSD"}
# if args == None:
# return {"status": 0, "error": "Parameter missing: args"}
# if LSD == None:
# return {"status": 0, "error": "Parameter missing: LSD"}
date_format = "%Y-%m-%d %H:%M:%S.%f"
if LSD != "":
@ -66,21 +56,23 @@ def masters(args=None, LSD=None):
try:
if args == "vehicle":
api = frappe.db.get_list(
"Vehicle",
fields=[
"name as vehicle",
"vehicle_segment",
"vehicle_segment_id",
"image",
"active_status",
"display_order",
"myid as vechile_id",
"display_order",
"modified",
],
filters={"modified": [">", LSD]},
)
val = input_validation(iid=iid)
if val != '':
return {"status": 0, "error": "Parameter's missing:"+val}
publish_type = check_pub_type(iid)
api = []
if publish_type == 'Global':
api = frappe.db.sql(f'''
select name as vehicle,vehicle_segment,vehicle_segment_id,image,active_status,display_order,
myid as vechile_id,display_order,modified from _a9b9faaf89312ce4.tabVehicle
where modified > '{LSD}' and global_publish = 1;
''',as_dict=1)
else:
api = frappe.db.sql(f'''
select name as vehicle,vehicle_segment,vehicle_segment_id,image,active_status,display_order,
myid as vechile_id,display_order,modified from _a9b9faaf89312ce4.tabVehicle
where modified > '{LSD}' and internal_publish = 1;
''',as_dict=1)
for i in api:
if i["active_status"] == "Active":
i["active_status"] = True
@ -287,3 +279,14 @@ def masters(args=None, LSD=None):
api = {"status": 0, "error": e}
return api
def check_pub_type(iid):
if not iid:
return False
device_pub_type = frappe.db.sql(f'''
select publish_type from `tabApp Device` where name = '{iid}' and active_status = 'Active';''')
if not device_pub_type:
return False
return device_pub_type[0][0]

29
smart_service/apis/publish_api.py

@ -482,11 +482,14 @@ def new_publish(args, publish_type, vehicle, language, version):
file_flag, final_update_file = merge_json_files(
prev_full_update_file, file_name, full_update_file_name)
get_step_total_count(final_update_file)
set_publish_flag(publish_type,vehicle)
if file_flag:
return True, file_name.split("public")[1]
# return True, file_name
else:
return False, "File save issue"
set_publish_flag(publish_type,vehicle)
return True, file_name.split("public")[1]
# return True, file_name
@ -496,6 +499,30 @@ def new_publish(args, publish_type, vehicle, language, version):
return False, str(frappe.get_traceback())
def set_publish_flag(publish_type,vehicle):
try:
if publish_type == 'Internal':
data = frappe.db.sql(f'''
SELECT * FROM tabVehicle where vehicle = '{vehicle}' and internal_publish=1;
''')
if not data:
frappe.db.sql(f'''
update tabVehicle set internal_publish = 1 where vehicle = '{vehicle}';
''')
frappe.db.commit()
else:
data = frappe.db.sql(f'''
SELECT * FROM tabVehicle where vehicle = '{vehicle}' and global_publish = 1;
''')
if not data:
frappe.db.sql(f'''
update tabVehicle set global_publish=1 where vehicle = '{vehicle}';
''')
frappe.db.commit()
except Exception as e:
frappe.log_error(str(e))
@frappe.whitelist()
def old_merge_json_files(old_json_path, new_json_path, out_file_path):
try:
@ -769,7 +796,7 @@ def merge_json_files(old_json_path, new_json_path, out_file_path):
outfile.write(json_object)
return True, out_file_path
except:
return False,frappe.log_error("Merge JSON:",frappe.get_traceback())
return False, frappe.log_error("Merge JSON:",frappe.get_traceback())
def check_key(key_name, old_data, type=None):

21
smart_service/masters/doctype/vehicle/vehicle.json

@ -19,8 +19,8 @@
"myid",
"display_order",
"service_kilometers",
"global_publish_flag",
"internal_publish_flag"
"internal_publish",
"global_publish"
],
"fields": [
{
@ -103,24 +103,19 @@
},
{
"default": "0",
"fieldname": "global_publish_flag",
"fieldname": "internal_publish",
"fieldtype": "Check",
"hidden": 1,
"label": "Global Publish Flag",
"read_only": 1
"label": "Internal Publish"
},
{
"default": "0",
"fieldname": "internal_publish_flag",
"fieldtype": "Check",
"hidden": 1,
"label": "Internal Publish Flag",
"read_only": 1
"fieldname": "global_publish",
"fieldtype": "Data",
"label": "Global Publish"
}
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2022-04-01 17:41:13.606316",
"modified": "2023-07-11 10:29:42.916784",
"modified_by": "Administrator",
"module": "Masters",
"name": "Vehicle",

42
smart_service/transactions/doctype/publish/publish.js

@ -124,28 +124,28 @@ frappe.ui.form.on('Publish', {
},
callback: function (r) {
// if (r.message[0]) {
frm.set_value('publish_status', 'Published');
frm.page.clear_primary_action("Publish");
frm.set_value('actual_published_date', frappe.datetime.nowdate());
frappe.call({
method: "smart_service.transactions.doctype.publish.publish.update_procedure_value",
args: {
"name": frm.doc.name,
"file_path": r.message[1],
},
callback: (r) => {
// frm.save('Update');
frm.set_value('publish_status', 'Published');
frm.page.clear_primary_action("Publish");
frm.set_value('actual_published_date', frappe.datetime.nowdate());
frappe.call({
method: "smart_service.transactions.doctype.publish.publish.update_procedure_value",
args: {
"name": frm.doc.name,
"file_path": r.message[1],
},
callback: (r) => {
// frm.save('Update');
}
})
frappe.msgprint({
title: __('Notification'),
message: __('<b>Successfully Published:</b> ' + r.message[1]),
primary_action: {
action(values) {
frm.save('Update');
}
})
frappe.msgprint({
title: __('Notification'),
message: __('<b>Successfully Published:</b> ' + r.message[1]),
primary_action: {
action(values) {
frm.save('Update');
}
}
});
}
});
// }
// else {
// frappe.msgprint({

Loading…
Cancel
Save