diff --git a/bloomstack_core/bloomstack_core/custom/delivery_trip.json b/bloomstack_core/bloomstack_core/custom/delivery_trip.json new file mode 100644 index 000000000..6c5e8bc7e --- /dev/null +++ b/bloomstack_core/bloomstack_core/custom/delivery_trip.json @@ -0,0 +1,565 @@ +{ + "custom_fields": [ + { + "_assign": null, + "_comments": null, + "_liked_by": null, + "_user_tags": null, + "allow_on_submit": 1, + "bold": 0, + "collapsible": 0, + "collapsible_depends_on": null, + "columns": 0, + "creation": "2019-06-25 03:13:16.371830", + "default": null, + "depends_on": null, + "description": null, + "docstatus": 0, + "dt": "Delivery Trip", + "fetch_from": null, + "fetch_if_empty": 0, + "fieldname": "odometer_stop_time", + "fieldtype": "Datetime", + "hidden": 0, + "idx": 20, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "insert_after": "odometer_stop_value", + "label": "Odometer Stop Time", + "modified": "2019-06-25 03:13:16.371830", + "modified_by": "Administrator", + "name": "Delivery Trip-odometer_stop_time", + "no_copy": 0, + "options": null, + "owner": "Administrator", + "parent": null, + "parentfield": null, + "parenttype": null, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": null, + "read_only": 1, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "translatable": 0, + "unique": 0, + "width": null + }, + { + "_assign": null, + "_comments": null, + "_liked_by": null, + "_user_tags": null, + "allow_on_submit": 1, + "bold": 0, + "collapsible": 0, + "collapsible_depends_on": null, + "columns": 0, + "creation": "2019-06-25 03:13:15.798111", + "default": null, + "depends_on": null, + "description": null, + "docstatus": 0, + "dt": "Delivery Trip", + "fetch_from": null, + "fetch_if_empty": 0, + "fieldname": "odometer_stop_value", + "fieldtype": "Int", + "hidden": 0, + "idx": 19, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "insert_after": "column_break_17", + "label": "Odometer Stop Value", + "modified": "2019-06-25 03:13:15.798111", + "modified_by": "Administrator", + "name": "Delivery Trip-odometer_stop_value", + "no_copy": 0, + "options": null, + "owner": "Administrator", + "parent": null, + "parentfield": null, + "parenttype": null, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": null, + "read_only": 1, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "translatable": 0, + "unique": 0, + "width": null + }, + { + "_assign": null, + "_comments": null, + "_liked_by": null, + "_user_tags": null, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "collapsible_depends_on": null, + "columns": 0, + "creation": "2019-06-25 03:13:15.536284", + "default": null, + "depends_on": null, + "description": null, + "docstatus": 0, + "dt": "Delivery Trip", + "fetch_from": null, + "fetch_if_empty": 0, + "fieldname": "column_break_17", + "fieldtype": "Column Break", + "hidden": 0, + "idx": 18, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "insert_after": "actual_distance_travelled", + "label": null, + "modified": "2019-06-25 03:13:15.536284", + "modified_by": "Administrator", + "name": "Delivery Trip-column_break_17", + "no_copy": 0, + "options": null, + "owner": "Administrator", + "parent": null, + "parentfield": null, + "parenttype": null, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": null, + "read_only": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "translatable": 0, + "unique": 0, + "width": null + }, + { + "_assign": null, + "_comments": null, + "_liked_by": null, + "_user_tags": null, + "allow_on_submit": 1, + "bold": 0, + "collapsible": 0, + "collapsible_depends_on": null, + "columns": 0, + "creation": "2019-06-25 03:13:15.106705", + "default": null, + "depends_on": null, + "description": null, + "docstatus": 0, + "dt": "Delivery Trip", + "fetch_from": null, + "fetch_if_empty": 0, + "fieldname": "actual_distance_travelled", + "fieldtype": "Int", + "hidden": 0, + "idx": 17, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "insert_after": "odometer_start_time", + "label": "Actual Distance Travelled", + "modified": "2019-06-25 03:13:15.106705", + "modified_by": "Administrator", + "name": "Delivery Trip-actual_distance_travelled", + "no_copy": 0, + "options": null, + "owner": "Administrator", + "parent": null, + "parentfield": null, + "parenttype": null, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": null, + "read_only": 1, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "translatable": 0, + "unique": 0, + "width": null + }, + { + "_assign": null, + "_comments": null, + "_liked_by": null, + "_user_tags": null, + "allow_on_submit": 1, + "bold": 0, + "collapsible": 0, + "collapsible_depends_on": null, + "columns": 0, + "creation": "2019-06-25 03:13:14.786408", + "default": null, + "depends_on": null, + "description": null, + "docstatus": 0, + "dt": "Delivery Trip", + "fetch_from": null, + "fetch_if_empty": 0, + "fieldname": "odometer_start_time", + "fieldtype": "Datetime", + "hidden": 0, + "idx": 16, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "insert_after": "odometer_start_value", + "label": "Odometer Start Time", + "modified": "2019-06-25 03:13:14.786408", + "modified_by": "Administrator", + "name": "Delivery Trip-odometer_start_time", + "no_copy": 0, + "options": null, + "owner": "Administrator", + "parent": null, + "parentfield": null, + "parenttype": null, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": null, + "read_only": 1, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "translatable": 0, + "unique": 0, + "width": null + }, + { + "_assign": null, + "_comments": null, + "_liked_by": null, + "_user_tags": null, + "allow_on_submit": 1, + "bold": 0, + "collapsible": 0, + "collapsible_depends_on": null, + "columns": 0, + "creation": "2019-06-25 03:13:14.448372", + "default": null, + "depends_on": null, + "description": null, + "docstatus": 0, + "dt": "Delivery Trip", + "fetch_from": null, + "fetch_if_empty": 0, + "fieldname": "odometer_start_value", + "fieldtype": "Int", + "hidden": 0, + "idx": 15, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "insert_after": "odometer", + "label": "Odometer Start Value", + "modified": "2019-06-25 03:13:14.448372", + "modified_by": "Administrator", + "name": "Delivery Trip-odometer_start_value", + "no_copy": 0, + "options": null, + "owner": "Administrator", + "parent": null, + "parentfield": null, + "parenttype": null, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": null, + "read_only": 1, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "translatable": 0, + "unique": 0, + "width": null + }, + { + "_assign": null, + "_comments": null, + "_liked_by": null, + "_user_tags": null, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "collapsible_depends_on": null, + "columns": 0, + "creation": "2019-06-25 03:13:14.150139", + "default": null, + "depends_on": null, + "description": null, + "docstatus": 0, + "dt": "Delivery Trip", + "fetch_from": null, + "fetch_if_empty": 0, + "fieldname": "odometer", + "fieldtype": "Section Break", + "hidden": 0, + "idx": 14, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "insert_after": "departure_time", + "label": "Odometer", + "modified": "2019-06-25 03:13:14.150139", + "modified_by": "Administrator", + "name": "Delivery Trip-odometer", + "no_copy": 0, + "options": null, + "owner": "Administrator", + "parent": null, + "parentfield": null, + "parenttype": null, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": null, + "read_only": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "translatable": 0, + "unique": 0, + "width": null + }, + { + "_assign": null, + "_comments": null, + "_liked_by": null, + "_user_tags": null, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "collapsible_depends_on": null, + "columns": 0, + "creation": "2018-09-07 02:42:46.433320", + "default": null, + "depends_on": null, + "description": null, + "docstatus": 0, + "dt": "Delivery Trip", + "fetch_from": null, + "fetch_if_empty": 0, + "fieldname": "map_embed", + "fieldtype": "Long Text", + "hidden": 1, + "idx": 27, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "insert_after": "map_html", + "label": "Map Embed", + "modified": "2018-09-07 02:42:46.433320", + "modified_by": "Administrator", + "name": "Delivery Trip-map_embed", + "no_copy": 0, + "options": null, + "owner": "Administrator", + "parent": null, + "parentfield": null, + "parenttype": null, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": null, + "read_only": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "translatable": 0, + "unique": 0, + "width": null + }, + { + "_assign": null, + "_comments": null, + "_liked_by": null, + "_user_tags": null, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "collapsible_depends_on": null, + "columns": 0, + "creation": "2018-09-07 02:42:04.358976", + "default": null, + "depends_on": null, + "description": null, + "docstatus": 0, + "dt": "Delivery Trip", + "fetch_from": null, + "fetch_if_empty": 0, + "fieldname": "map_html", + "fieldtype": "HTML", + "hidden": 0, + "idx": 26, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "insert_after": "sb_map", + "label": "Map", + "modified": "2018-09-07 02:42:04.358976", + "modified_by": "Administrator", + "name": "Delivery Trip-map_html", + "no_copy": 0, + "options": null, + "owner": "Administrator", + "parent": null, + "parentfield": null, + "parenttype": null, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": null, + "read_only": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "translatable": 0, + "unique": 0, + "width": null + }, + { + "_assign": null, + "_comments": null, + "_liked_by": null, + "_user_tags": null, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "collapsible_depends_on": null, + "columns": 0, + "creation": "2018-09-07 02:41:37.771282", + "default": null, + "depends_on": null, + "description": null, + "docstatus": 0, + "dt": "Delivery Trip", + "fetch_from": null, + "fetch_if_empty": 0, + "fieldname": "sb_map", + "fieldtype": "Section Break", + "hidden": 0, + "idx": 25, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "insert_after": "optimize_route", + "label": "Map", + "modified": "2018-09-07 02:41:37.771282", + "modified_by": "Administrator", + "name": "Delivery Trip-sb_map", + "no_copy": 0, + "options": null, + "owner": "Administrator", + "parent": null, + "parentfield": null, + "parenttype": null, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": null, + "read_only": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "translatable": 0, + "unique": 0, + "width": null + } + ], + "custom_perms": [], + "doctype": "Delivery Trip", + "property_setters": [ + { + "_assign": null, + "_comments": null, + "_liked_by": null, + "_user_tags": null, + "creation": "2019-06-25 05:33:50.964282", + "default_value": null, + "doc_type": "Delivery Trip", + "docstatus": 0, + "doctype_or_field": "DocType", + "field_name": null, + "idx": 0, + "modified": "2019-06-25 05:33:50.964282", + "modified_by": "Administrator", + "name": "Delivery Trip-read_only_onload", + "owner": "Administrator", + "parent": null, + "parentfield": null, + "parenttype": null, + "property": "read_only_onload", + "property_type": "Check", + "value": null + }, + { + "_assign": null, + "_comments": null, + "_liked_by": null, + "_user_tags": null, + "creation": "2018-08-22 02:09:11.677024", + "default_value": null, + "doc_type": "Delivery Trip", + "docstatus": 0, + "doctype_or_field": "DocField", + "field_name": "naming_series", + "idx": 0, + "modified": "2018-09-06 03:22:24.860286", + "modified_by": "Administrator", + "name": "Delivery Trip-naming_series-options", + "owner": "Administrator", + "parent": null, + "parentfield": null, + "parenttype": null, + "property": "options", + "property_type": "Text", + "value": "TOUR-.#####" + } + ], + "sync_on_migrate": 1 +} \ No newline at end of file diff --git a/bloomstack_core/hook_events/delivery_trip.py b/bloomstack_core/hook_events/delivery_trip.py new file mode 100644 index 000000000..dce34c574 --- /dev/null +++ b/bloomstack_core/hook_events/delivery_trip.py @@ -0,0 +1,6 @@ +import frappe + + +def set_vehicle_last_odometer_value(trip, method): + if trip.actual_distance_travelled: + frappe.db.set_value('Vehicle', trip.vehicle, 'last_odometer', trip.odometer_stop_value) diff --git a/bloomstack_core/hooks.py b/bloomstack_core/hooks.py index db0b9eada..bf87fdab4 100755 --- a/bloomstack_core/hooks.py +++ b/bloomstack_core/hooks.py @@ -58,7 +58,8 @@ "Item": "public/js/item.js", "Batch": "public/js/batch.js", "Quotation": "public/js/quotation.js", - "Contract": "public/js/contract.js" + "Contract": "public/js/contract.js", + "Delivery Trip": "public/js/delivery_trip.js" } # doctype_list_js = {"doctype" : "public/js/doctype_list.js"} # doctype_tree_js = {"doctype" : "public/js/doctype_tree.js"} @@ -121,6 +122,9 @@ }, "Stock Entry": { "on_submit": "bloomstack_core.compliance.package.create_package" + }, + "Delivery Trip": { + "on_update_after_submit": "bloomstack_core.hook_events.delivery_trip.set_vehicle_last_odometer_value" } } diff --git a/bloomstack_core/public/js/delivery_trip.js b/bloomstack_core/public/js/delivery_trip.js new file mode 100644 index 000000000..5bff10645 --- /dev/null +++ b/bloomstack_core/public/js/delivery_trip.js @@ -0,0 +1,44 @@ +frappe.ui.form.on('Delivery Trip', { + refresh: (frm) => { + if (frm.doc.docstatus == 1 && frm.doc.status != "Completed") { + if (frm.doc.odometer_start_value == 0) { + frm.add_custom_button(__("Start"), () => { + frappe.prompt({ + "label": "Odometer Start Value", + "fieldtype": "Int", + "fieldname": "odometer_start_value", + "reqd": 1 + }, + (data) => { + frm.set_value('odometer_start_value', data.odometer_start_value); + frm.set_value('odometer_start_time', frappe.datetime.now_datetime()); + frm.dirty(); + frm.save_or_update(); + }, + __("Enter Odometer Value")); + }).addClass("btn-primary"); + } else if (frm.doc.odometer_start_value > 0 && frm.doc.odometer_stop_value == 0) { + frm.add_custom_button(__("Stop"), () => { + frappe.prompt({ + "label": "Odometer Stop Value", + "fieldtype": "Int", + "fieldname": "odometer_stop_value", + "reqd": 1 + }, + (data) => { + if (data.odometer_stop_value > frm.doc.odometer_start_value) { + frm.set_value('odometer_stop_value', data.odometer_stop_value); + frm.set_value('odometer_stop_time', frappe.datetime.now_datetime()); + frm.set_value('actual_distance_travelled', (data.odometer_stop_value - frm.doc.odometer_start_value)); + frm.dirty(); + frm.save_or_update(); + } else { + frappe.throw("The stop value cannot be lower than the start value"); + } + }, + __("Enter Odometer Value")); + }).addClass("btn-primary"); + } + } + } +}); \ No newline at end of file diff --git a/bloomstack_core/utils.py b/bloomstack_core/utils.py index 308d03486..e6b2309d4 100755 --- a/bloomstack_core/utils.py +++ b/bloomstack_core/utils.py @@ -141,7 +141,7 @@ def authorize_document(sign=None, signee=None, docname=None): authorized_doc.is_signed = 1 authorized_doc.authorizer_signature = sign authorized_doc.signee = signee - + authorized_doc.submit() @@ -159,4 +159,4 @@ def create_authorization_request(dt, dn, contact_email, contact_name=None): new_authorization_request.linked_doctype = dt new_authorization_request.linked_docname = dn new_authorization_request.authorizer_email = contact_email - new_authorization_request.save() \ No newline at end of file + new_authorization_request.save()