|
@ -32,38 +32,35 @@ class Publish(Document): |
|
|
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' |
|
|
|
|
|
|
|
|
def onload(self): |
|
|
def onload1(self): |
|
|
current_db_name = frappe.conf.get("db_name") |
|
|
current_db_name = frappe.conf.get("db_name") |
|
|
if self.child_table_updated == "1": |
|
|
# 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 |
|
|
# To validate updated procedure status |
|
|
from {0}.`tabPublish_Docs` as p,{0}.`tabProcedure` as pro |
|
|
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 |
|
|
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 |
|
|
l = len(procedure_status) |
|
|
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) |
|
|
|
|
|
l = len(procedure_status) |
|
|
if procedure_status and self.publish_status == "Published": |
|
|
|
|
|
for x in procedure_status: |
|
|
if procedure_status and self.publish_status == "Published": |
|
|
for y in self.get("publish_documents"): |
|
|
for x in procedure_status: |
|
|
if y.procedure_link: |
|
|
for y in self.get("publish_documents"): |
|
|
if x.procedure_link == y.procedure_link and y.update_procedure_status != y.procedure_status: |
|
|
if y.procedure_link: |
|
|
y.update_procedure_status = x.workflow_state |
|
|
if x.procedure_link == y.procedure_link and y.update_procedure_status != y.procedure_status: |
|
|
frappe.db.sql("""update `tabPublish_Docs` set update_procedure_status = %s where parent = %s and procedure_link = %s ; """, ( |
|
|
y.update_procedure_status = x.workflow_state |
|
|
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 ; """, ( |
|
|
frappe.db.commit() |
|
|
x.workflow_state, self.name, x.procedure_link)) |
|
|
if x.procedure_link == y.procedure_link and x.workflow_state != y.procedure_status: |
|
|
frappe.db.commit() |
|
|
y.update_procedure_status = x.workflow_state |
|
|
if x.procedure_link == y.procedure_link and x.workflow_state != y.procedure_status: |
|
|
frappe.db.sql("""update `tabPublish_Docs` set update_procedure_status = %s where parent = %s and procedure_link = %s""", ( |
|
|
y.update_procedure_status = x.workflow_state |
|
|
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""", ( |
|
|
frappe.db.commit() |
|
|
x.workflow_state, self.name, x.procedure_link)) |
|
|
if y.procedure_status == "Publish Ready": |
|
|
frappe.db.commit() |
|
|
if x.procedure_link == y.procedure_link and x.workflow_state != y.procedure_status and not y.excluded_global: |
|
|
if y.procedure_status == "Publish Ready": |
|
|
y.excluded_global = "1" |
|
|
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 x.workflow_state == "Draft" and y.procedure_status != "Publish Ready": |
|
|
y.excluded_global = "1" |
|
|
y.excluded_internal = "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": |
|
|
y.save() |
|
|
y.excluded_internal = "1" |
|
|
frappe.db.commit() |
|
|
self.child_table_updated = '0' |
|
|
|
|
|
y.save() |
|
|
|
|
|
frappe.db.commit() |
|
|
|
|
|
|
|
|
|
|
|
# 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": |
|
@ -316,3 +313,55 @@ def variant(doctype, txt, searchfield, start, page_len, filters): |
|
|
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() |
|
|
|
|
|
def update_procedure_value(name): |
|
|
|
|
|
self = frappe.get_doc("Publish",name) |
|
|
|
|
|
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=True) |
|
|
|
|
|
l = len(procedure_status) |
|
|
|
|
|
|
|
|
|
|
|
if procedure_status: |
|
|
|
|
|
for x in procedure_status: |
|
|
|
|
|
for y in self.get("publish_documents"): |
|
|
|
|
|
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.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.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": |
|
|
|
|
|
y.excluded_internal = "1" |
|
|
|
|
|
y.save() |
|
|
|
|
|
frappe.db.commit() |
|
|
|
|
|
|
|
|
|
|
|
# Update system and variant mapping ststus |
|
|
|
|
|
if 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) |
|
|
|
|
|
for global_name in global_publish: |
|
|
|
|
|
update_mapping(self.variant_mapping, global_name.name) |
|
|
|
|
|
|
|
|
|
|
|
u_id = frappe.get_all( |
|
|
|
|
|
"User", filters={"name": frappe.session.user}, fields=["username"]) |
|
|
|
|
|
if u_id: |
|
|
|
|
|
for i in u_id: |
|
|
|
|
|
name = i.username |
|
|
|
|
|
if not self.published_by: |
|
|
|
|
|
self.published_by = str(name) |
|
|
|
|
|
frappe.db.set_value( |
|
|
|
|
|
"Publish", self.name, "published_by", str(name)) |
|
|
|
|
|
frappe.db.commit() |
|
|