Cleanup and fixes on delivery trip
This commit is contained in:
parent
46e285efe9
commit
ad2a3e4f38
23
erpnext/hr/doctype/vehicle/test_vehicle.js
Normal file
23
erpnext/hr/doctype/vehicle/test_vehicle.js
Normal file
@ -0,0 +1,23 @@
|
||||
/* eslint-disable */
|
||||
// rename this file from _test_[name] to test_[name] to activate
|
||||
// and remove above this line
|
||||
|
||||
QUnit.test("test: Vehicle", function (assert) {
|
||||
let done = assert.async();
|
||||
|
||||
// number of asserts
|
||||
assert.expect(1);
|
||||
|
||||
frappe.run_serially([
|
||||
// insert a new Vehicle
|
||||
() => frappe.tests.make('Vehicle', [
|
||||
// values to be set
|
||||
{key: 'value'}
|
||||
]),
|
||||
() => {
|
||||
assert.equal(cur_frm.doc.key, 'value');
|
||||
},
|
||||
() => done()
|
||||
]);
|
||||
|
||||
});
|
@ -1,5 +1,6 @@
|
||||
{
|
||||
"allow_copy": 0,
|
||||
"allow_guest_to_view": 0,
|
||||
"allow_import": 0,
|
||||
"allow_rename": 0,
|
||||
"autoname": "field:license_plate",
|
||||
@ -12,6 +13,7 @@
|
||||
"editable_grid": 1,
|
||||
"fields": [
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
@ -21,7 +23,8 @@
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 1,
|
||||
"in_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_standard_filter": 0,
|
||||
"label": "License Plate",
|
||||
@ -40,6 +43,7 @@
|
||||
"unique": 1
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
@ -50,6 +54,7 @@
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_standard_filter": 0,
|
||||
"label": "Make",
|
||||
@ -68,6 +73,7 @@
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
@ -78,6 +84,7 @@
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_standard_filter": 0,
|
||||
"length": 0,
|
||||
@ -95,6 +102,7 @@
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
@ -104,7 +112,8 @@
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 1,
|
||||
"in_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 1,
|
||||
"in_standard_filter": 1,
|
||||
"label": "Model",
|
||||
@ -123,6 +132,7 @@
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
@ -133,6 +143,7 @@
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_standard_filter": 0,
|
||||
"label": "Details",
|
||||
@ -151,6 +162,7 @@
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
@ -160,7 +172,8 @@
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 1,
|
||||
"in_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 1,
|
||||
"in_standard_filter": 0,
|
||||
"label": "Odometer Value (Last)",
|
||||
@ -179,6 +192,7 @@
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
@ -188,7 +202,8 @@
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 1,
|
||||
"in_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_standard_filter": 0,
|
||||
"label": "Acquisition Date",
|
||||
@ -207,6 +222,7 @@
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
@ -217,6 +233,7 @@
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_standard_filter": 0,
|
||||
"label": "Location",
|
||||
@ -235,6 +252,7 @@
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
@ -245,6 +263,7 @@
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_standard_filter": 0,
|
||||
"length": 0,
|
||||
@ -262,6 +281,7 @@
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
@ -272,6 +292,7 @@
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_standard_filter": 0,
|
||||
"label": "Chassis No",
|
||||
@ -290,6 +311,7 @@
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
@ -300,6 +322,7 @@
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 1,
|
||||
"in_standard_filter": 0,
|
||||
"label": "Vehicle Value",
|
||||
@ -319,6 +342,7 @@
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
@ -329,6 +353,7 @@
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_standard_filter": 1,
|
||||
"label": "Employee",
|
||||
@ -348,6 +373,7 @@
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
@ -358,6 +384,7 @@
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_standard_filter": 0,
|
||||
"label": "Insurance Details",
|
||||
@ -376,6 +403,7 @@
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
@ -385,7 +413,8 @@
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 1,
|
||||
"in_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_standard_filter": 0,
|
||||
"label": "Insurance Company",
|
||||
@ -404,6 +433,7 @@
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
@ -413,7 +443,8 @@
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 1,
|
||||
"in_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_standard_filter": 0,
|
||||
"label": "Policy No",
|
||||
@ -432,6 +463,7 @@
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
@ -442,6 +474,7 @@
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_standard_filter": 0,
|
||||
"length": 0,
|
||||
@ -459,6 +492,7 @@
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
@ -469,6 +503,7 @@
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_standard_filter": 0,
|
||||
"label": "Start Date",
|
||||
@ -487,6 +522,7 @@
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
@ -497,6 +533,7 @@
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_standard_filter": 0,
|
||||
"label": "End Date",
|
||||
@ -515,6 +552,7 @@
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
@ -525,6 +563,7 @@
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_standard_filter": 0,
|
||||
"label": "Additional Details",
|
||||
@ -543,6 +582,7 @@
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
@ -553,6 +593,7 @@
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 1,
|
||||
"in_standard_filter": 1,
|
||||
"label": "Fuel Type",
|
||||
@ -572,17 +613,19 @@
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"default": "Litre",
|
||||
"default": "",
|
||||
"fieldname": "uom",
|
||||
"fieldtype": "Link",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 1,
|
||||
"in_standard_filter": 0,
|
||||
"label": "Fuel UOM",
|
||||
@ -602,6 +645,7 @@
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
@ -612,6 +656,7 @@
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_standard_filter": 0,
|
||||
"label": "Last Carbon Check",
|
||||
@ -630,6 +675,7 @@
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
@ -640,6 +686,7 @@
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_standard_filter": 0,
|
||||
"length": 0,
|
||||
@ -657,6 +704,7 @@
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
@ -667,6 +715,7 @@
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_standard_filter": 0,
|
||||
"label": "Color",
|
||||
@ -685,6 +734,7 @@
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
@ -695,6 +745,7 @@
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_standard_filter": 0,
|
||||
"label": "Wheels",
|
||||
@ -713,6 +764,7 @@
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
@ -723,6 +775,7 @@
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_standard_filter": 0,
|
||||
"label": "Doors",
|
||||
@ -741,6 +794,7 @@
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
@ -751,6 +805,7 @@
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_standard_filter": 0,
|
||||
"label": "Amended From",
|
||||
@ -769,17 +824,17 @@
|
||||
"unique": 0
|
||||
}
|
||||
],
|
||||
"has_web_view": 0,
|
||||
"hide_heading": 0,
|
||||
"hide_toolbar": 0,
|
||||
"idx": 0,
|
||||
"image_view": 0,
|
||||
"in_create": 0,
|
||||
"in_dialog": 0,
|
||||
"is_submittable": 0,
|
||||
"issingle": 0,
|
||||
"istable": 0,
|
||||
"max_attachments": 0,
|
||||
"modified": "2017-01-09 11:10:11.678834",
|
||||
"modified": "2017-11-29 14:48:30.813359",
|
||||
"modified_by": "Administrator",
|
||||
"module": "HR",
|
||||
"name": "Vehicle",
|
||||
@ -796,7 +851,6 @@
|
||||
"export": 1,
|
||||
"if_owner": 0,
|
||||
"import": 0,
|
||||
"is_custom": 0,
|
||||
"permlevel": 0,
|
||||
"print": 1,
|
||||
"read": 1,
|
||||
@ -812,6 +866,7 @@
|
||||
"read_only": 0,
|
||||
"read_only_onload": 0,
|
||||
"search_fields": "license_plate,location,model",
|
||||
"show_name_in_global_search": 0,
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"title_field": "",
|
||||
|
@ -2,6 +2,34 @@
|
||||
// For license information, please see license.txt
|
||||
|
||||
frappe.ui.form.on('Delivery Trip', {
|
||||
setup: function(frm) {
|
||||
frm.set_query("address", "delivery_stops", function(doc, cdt, cdn) {
|
||||
var row = locals[cdt][cdn];
|
||||
if (row.customer) {
|
||||
return {
|
||||
query: 'frappe.contacts.doctype.address.address.address_query',
|
||||
filters: {
|
||||
link_doctype: "Customer",
|
||||
link_name: row.customer
|
||||
}
|
||||
};
|
||||
}
|
||||
})
|
||||
|
||||
frm.set_query("contact", "delivery_stops", function(doc, cdt, cdn) {
|
||||
var row = locals[cdt][cdn];
|
||||
if (row.customer) {
|
||||
return {
|
||||
query: 'frappe.contacts.doctype.contact.contact.contact_query',
|
||||
filters: {
|
||||
link_doctype: "Customer",
|
||||
link_name: row.customer
|
||||
}
|
||||
};
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
refresh: function (frm) {
|
||||
if (frm.doc.docstatus == 1 && frm.doc.delivery_stops.length > 0) {
|
||||
frm.add_custom_button(__("Notify Customers via Email"), function () {
|
||||
@ -9,6 +37,7 @@ frappe.ui.form.on('Delivery Trip', {
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
calculate_arrival_time: function (frm) {
|
||||
frappe.call({
|
||||
method: 'erpnext.stock.doctype.delivery_trip.delivery_trip.calculate_time_matrix',
|
||||
@ -19,13 +48,14 @@ frappe.ui.form.on('Delivery Trip', {
|
||||
},
|
||||
callback: function (r) {
|
||||
if (r.message.error) {
|
||||
frappe.throw(__("Malformatted address for " + r.message.error.destination.address + ", please fix to continue."));
|
||||
return;
|
||||
frappe.throw(__("Malformatted address for {0}, please fix to continue.",
|
||||
[r.message.error.destination.address]));
|
||||
}
|
||||
frm.reload_doc();
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
notify_customers: function (frm) {
|
||||
var owner_email = frm.doc.owner == "Administrator"
|
||||
? frappe.user_info("Administrator").email
|
||||
@ -60,74 +90,62 @@ frappe.ui.form.on('Delivery Trip', {
|
||||
}
|
||||
});
|
||||
|
||||
cur_frm.fields_dict['delivery_stops'].grid.get_field("address").get_query = function (doc, cdt, cdn) {
|
||||
var row = locals[cdt][cdn];
|
||||
if (row.customer) {
|
||||
return {
|
||||
query: 'frappe.contacts.doctype.address.address.address_query',
|
||||
filters: {
|
||||
link_doctype: "Customer",
|
||||
link_name: row.customer
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
cur_frm.fields_dict['delivery_stops'].grid.get_field("contact").get_query = function (doc, cdt, cdn) {
|
||||
var row = locals[cdt][cdn];
|
||||
if (row.customer) {
|
||||
return {
|
||||
query: 'frappe.contacts.doctype.contact.contact.contact_query',
|
||||
filters: {
|
||||
link_doctype: "Customer",
|
||||
link_name: row.customer
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
frappe.ui.form.on('Delivery Stop', {
|
||||
customer: function (frm, cdt, cdn) {
|
||||
var row = locals[cdt][cdn];
|
||||
frappe.call({
|
||||
method: "erpnext.stock.doctype.delivery_trip.delivery_trip.get_contact_and_address",
|
||||
args: {"name": row.customer},
|
||||
callback: function (r) {
|
||||
if (r.message) {
|
||||
if (r.message["shipping_address"]) {
|
||||
frappe.model.set_value(cdt, cdn, "address", r.message["shipping_address"].parent);
|
||||
}
|
||||
if (r.message["contact_person"]) {
|
||||
frappe.model.set_value(cdt, cdn, "contact", r.message["contact_person"].parent);
|
||||
if(row.customer) {
|
||||
frappe.call({
|
||||
method: "erpnext.stock.doctype.delivery_trip.delivery_trip.get_contact_and_address",
|
||||
args: {"name": row.customer},
|
||||
callback: function (r) {
|
||||
if (r.message) {
|
||||
if (r.message["shipping_address"]) {
|
||||
frappe.model.set_value(cdt, cdn, "address", r.message["shipping_address"].parent);
|
||||
}
|
||||
if (r.message["contact_person"]) {
|
||||
frappe.model.set_value(cdt, cdn, "contact", r.message["contact_person"].parent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
},
|
||||
address: function (frm, cdt, cdn) {
|
||||
var row = locals[cdt][cdn];
|
||||
frappe.call({
|
||||
method: "frappe.contacts.doctype.address.address.get_address_display",
|
||||
args: {"address_dict": row.address},
|
||||
callback: function (r) {
|
||||
if (r.message) {
|
||||
frappe.model.set_value(cdt, cdn, "customer_address", r.message);
|
||||
if(row.address) {
|
||||
frappe.call({
|
||||
method: "frappe.contacts.doctype.address.address.get_address_display",
|
||||
args: {"address_dict": row.address},
|
||||
callback: function (r) {
|
||||
if (r.message) {
|
||||
frappe.model.set_value(cdt, cdn, "customer_address", r.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
frappe.model.set_value(cdt, cdn, "customer_address", "");
|
||||
}
|
||||
},
|
||||
|
||||
contact: function (frm, cdt, cdn) {
|
||||
var row = locals[cdt][cdn];
|
||||
frappe.call({
|
||||
method: "erpnext.stock.doctype.delivery_trip.delivery_trip.get_contact_display",
|
||||
args: {"contact": row.contact},
|
||||
callback: function (r) {
|
||||
if (r.message) {
|
||||
frappe.model.set_value(cdt, cdn, "customer_contact", r.message);
|
||||
if(row.contact) {
|
||||
frappe.call({
|
||||
method: "erpnext.stock.doctype.delivery_trip.delivery_trip.get_contact_display",
|
||||
args: {"contact": row.contact},
|
||||
callback: function (r) {
|
||||
if (r.message) {
|
||||
frappe.model.set_value(cdt, cdn, "customer_contact", r.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
frappe.model.set_value(cdt, cdn, "customer_contact", "");
|
||||
}
|
||||
},
|
||||
|
||||
select_delivery_notes: function (frm, cdt, cdn) {
|
||||
var row = locals[cdt][cdn];
|
||||
frappe.call({
|
||||
@ -166,7 +184,8 @@ frappe.ui.form.on('Delivery Stop', {
|
||||
var delivery_notes_el = d.fields_dict.delivery_notes_html.$wrapper.html(html);
|
||||
|
||||
d.set_primary_action(__("Select"), function () {
|
||||
var delivery_notes = delivery_notes_el.find('input[type=checkbox]:checked').map((i, el) => $(el).attr('data-delivery-note')).toArray();
|
||||
var delivery_notes = delivery_notes_el.find('input[type=checkbox]:checked')
|
||||
.map((i, el) => $(el).attr('data-delivery-note')).toArray();
|
||||
if (!delivery_notes) return;
|
||||
frappe.model.set_value(cdt, cdn, "delivery_notes", delivery_notes.join(","));
|
||||
d.hide();
|
||||
|
@ -11,7 +11,7 @@ from frappe.model.document import Document
|
||||
from frappe.utils.user import get_user_fullname
|
||||
from frappe.utils import getdate
|
||||
from frappe.integrations.doctype.google_maps.google_maps import round_timedelta
|
||||
from frappe.integrations.doctype.google_maps.google_maps import customer_address_format
|
||||
from frappe.integrations.doctype.google_maps.google_maps import format_address
|
||||
|
||||
class DeliveryTrip(Document):
|
||||
pass
|
||||
@ -42,13 +42,13 @@ def get_default_contact(out, name):
|
||||
def get_default_address(out, name):
|
||||
shipping_addresses = frappe.db.sql(
|
||||
"""
|
||||
select
|
||||
parent, (select is_shipping_address from tabAddress a where a.name=dl.parent) as is_shipping_address
|
||||
select parent,
|
||||
(select is_shipping_address from tabAddress a where a.name=dl.parent) as is_shipping_address
|
||||
from `tabDynamic Link` dl
|
||||
where link_doctype="Customer" and link_name=%s
|
||||
where link_doctype="Customer"
|
||||
and link_name=%s
|
||||
and parenttype = 'Address'
|
||||
"""
|
||||
, (name), as_dict=1)
|
||||
""", (name), as_dict=1)
|
||||
|
||||
if shipping_addresses:
|
||||
for out.shipping_address in shipping_addresses:
|
||||
@ -76,28 +76,35 @@ def get_contact_display(contact):
|
||||
as_dict=1)
|
||||
contact_info.html = """ <b>%(first_name)s %(last_name)s</b> <br> %(phone)s <br> %(mobile_no)s""" % {
|
||||
"first_name": contact_info.first_name,
|
||||
"last_name": contact_info.last_name,
|
||||
"phone": contact_info.phone if contact_info.phone else "",
|
||||
"mobile_no": contact_info.mobile_no if contact_info.mobile_no else "",
|
||||
"last_name": contact_info.last_name or "",
|
||||
"phone": contact_info.phone or "",
|
||||
"mobile_no": contact_info.mobile_no or "",
|
||||
}
|
||||
return contact_info.html
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_delivery_notes(customer):
|
||||
return frappe.db.get_all(
|
||||
"Delivery Note",
|
||||
filters={'customer': customer,
|
||||
'docstatus': 1,
|
||||
'status': ('!=', 'Completed')})
|
||||
return frappe.db.get_all("Delivery Note", filters={
|
||||
'customer': customer,
|
||||
'docstatus': 1,
|
||||
'status': ('!=', 'Completed')
|
||||
})
|
||||
|
||||
@frappe.whitelist()
|
||||
def calculate_time_matrix(name):
|
||||
"""Calucation and round in closest 15 minutes, delivery stops"""
|
||||
|
||||
gmaps_client = frappe.db.get_single_value('Google Maps', 'client_key')
|
||||
gmaps = googlemaps.Client(key=gmaps_client)
|
||||
home = frappe.db.get_single_value('Google Maps', 'home_address')
|
||||
gmaps = frappe.db.get_value('Google Maps', None,
|
||||
['client_key', 'enabled', 'home_address'], as_dict=1)
|
||||
|
||||
if not gmaps.enabled:
|
||||
frappe.throw(_("Google Maps integration is not enabled"))
|
||||
|
||||
try:
|
||||
gmaps_client = googlemaps.Client(key=gmaps.client_key)
|
||||
except Exception as e:
|
||||
frappe.throw(e.message)
|
||||
|
||||
secs_15min = 900
|
||||
doc = frappe.get_doc('Delivery Trip', name)
|
||||
@ -105,38 +112,40 @@ def calculate_time_matrix(name):
|
||||
matrix_duration = []
|
||||
|
||||
for i, stop in enumerate(doc.delivery_stop):
|
||||
|
||||
if i == 0:
|
||||
# The first row is the starting pointing
|
||||
origin = home
|
||||
destination = customer_address_format(doc.delivery_stop[i].address)
|
||||
distance_calc = gmaps.distance_matrix(origin, destination)
|
||||
origin = gmaps.home_address
|
||||
destination = format_address(doc.delivery_stop[i].address)
|
||||
distance_calc = gmaps_client.distance_matrix(origin, destination)
|
||||
matrix_duration.append(distance_calc)
|
||||
|
||||
try:
|
||||
distance_secs = distance_calc['rows'][0]['elements'][0]['duration']['value']
|
||||
except Exception as e:
|
||||
frappe.throw(_("Error '{0}' occured. Arguments {1}.").format(e.message, e.args))
|
||||
stop.estimated_arrival = round_timedelta(departure_time + datetime.timedelta(0, distance_secs + secs_15min),
|
||||
datetime.timedelta(minutes=15))
|
||||
stop.save()
|
||||
frappe.db.commit()
|
||||
|
||||
stop.estimated_arrival = round_timedelta(
|
||||
departure_time + datetime.timedelta(0, distance_secs + secs_15min),
|
||||
datetime.timedelta(minutes=15))
|
||||
else:
|
||||
# Calculation based on previous
|
||||
origin = customer_address_format(doc.delivery_stop[i - 1].address)
|
||||
destination = customer_address_format(doc.delivery_stop[i].address)
|
||||
distance_calc = gmaps.distance_matrix(origin, destination)
|
||||
origin = format_address(doc.delivery_stop[i - 1].address)
|
||||
destination = format_address(doc.delivery_stop[i].address)
|
||||
distance_calc = gmaps_client.distance_matrix(origin, destination)
|
||||
matrix_duration.append(distance_calc)
|
||||
|
||||
try:
|
||||
distance_secs = distance_calc['rows'][0]['elements'][0]['duration']['value']
|
||||
except Exception as e:
|
||||
frappe.throw(_("Error '{0}' occured. Arguments {1}.").format(e.message, e.args))
|
||||
stop.estimated_arrival = round_timedelta(
|
||||
doc.delivery_stop[i - 1].estimated_arrival + datetime.timedelta(0, distance_secs + secs_15min),
|
||||
datetime.timedelta(minutes=15))
|
||||
stop.save()
|
||||
frappe.db.commit()
|
||||
return matrix_duration
|
||||
|
||||
stop.estimated_arrival = round_timedelta(
|
||||
doc.delivery_stop[i - 1].estimated_arrival +
|
||||
datetime.timedelta(0, distance_secs + secs_15min), datetime.timedelta(minutes=15))
|
||||
stop.save()
|
||||
frappe.db.commit()
|
||||
|
||||
return matrix_duration
|
||||
|
||||
@frappe.whitelist()
|
||||
def notify_customers(docname, date, driver, vehicle, sender_email, delivery_notification):
|
||||
@ -146,15 +155,12 @@ def notify_customers(docname, date, driver, vehicle, sender_email, delivery_noti
|
||||
|
||||
for delivery_stop in delivery_stops:
|
||||
delivery_stop_info = frappe.db.get_value(
|
||||
"Delivery Stop",
|
||||
delivery_stop.name,
|
||||
["notified_by_email", "estimated_arrival",
|
||||
"details", "contact", "delivery_notes"],
|
||||
as_dict=1)
|
||||
contact_info = frappe.db.get_value(
|
||||
"Contact", delivery_stop_info.contact,
|
||||
["first_name", "last_name", "email_id", "gender"],
|
||||
"Delivery Stop",
|
||||
delivery_stop.name,
|
||||
["notified_by_email", "estimated_arrival", "details", "contact", "delivery_notes"],
|
||||
as_dict=1)
|
||||
contact_info = frappe.db.get_value("Contact", delivery_stop_info.contact,
|
||||
["first_name", "last_name", "email_id", "gender"], as_dict=1)
|
||||
|
||||
if delivery_stop_info.delivery_notes:
|
||||
delivery_notes = (delivery_stop_info.delivery_notes).split(",")
|
||||
@ -162,31 +168,24 @@ def notify_customers(docname, date, driver, vehicle, sender_email, delivery_noti
|
||||
for delivery_note in delivery_notes:
|
||||
attachments.append(
|
||||
frappe.attach_print('Delivery Note',
|
||||
delivery_note,
|
||||
file_name="Delivery Note",
|
||||
print_format='Delivery Note'))
|
||||
delivery_note,
|
||||
file_name="Delivery Note",
|
||||
print_format='Delivery Note'))
|
||||
|
||||
if not delivery_stop_info.notified_by_email and contact_info.email_id:
|
||||
driver_info = frappe.db.get_value(
|
||||
"Driver",
|
||||
driver,
|
||||
["full_name", "cell_number"],
|
||||
as_dict=1)
|
||||
sender_designation = frappe.db.get_value("Employee",
|
||||
sender_email,
|
||||
["designation"])
|
||||
driver_info = frappe.db.get_value("Driver", driver, ["full_name", "cell_number"], as_dict=1)
|
||||
sender_designation = frappe.db.get_value("Employee", sender_email, ["designation"])
|
||||
|
||||
estimated_arrival = str(delivery_stop_info.estimated_arrival)[:-3]
|
||||
email_template = frappe.get_doc("Standard Reply",
|
||||
delivery_notification)
|
||||
email_template = frappe.get_doc("Standard Reply", delivery_notification)
|
||||
message = frappe.render_template(
|
||||
email_template.response,
|
||||
dict(contact_info=contact_info, sender_name=sender_name,
|
||||
details=delivery_stop_info.details,
|
||||
estimated_arrival=estimated_arrival,
|
||||
date=getdate(date).strftime('%d.%m.%y'), vehicle=vehicle,
|
||||
driver_info=driver_info,
|
||||
sender_designation=sender_designation)
|
||||
email_template.response,
|
||||
dict(contact_info=contact_info, sender_name=sender_name,
|
||||
details=delivery_stop_info.details,
|
||||
estimated_arrival=estimated_arrival,
|
||||
date=getdate(date).strftime('%d.%m.%y'), vehicle=vehicle,
|
||||
driver_info=driver_info,
|
||||
sender_designation=sender_designation)
|
||||
)
|
||||
frappe.sendmail(
|
||||
recipients=contact_info.email_id,
|
||||
@ -194,13 +193,9 @@ def notify_customers(docname, date, driver, vehicle, sender_email, delivery_noti
|
||||
message=message,
|
||||
attachments=attachments,
|
||||
subject=_(email_template.subject).format(getdate(date).strftime('%d.%m.%y'),
|
||||
estimated_arrival))
|
||||
estimated_arrival))
|
||||
|
||||
frappe.db.set_value("Delivery Stop",
|
||||
delivery_stop.name,
|
||||
"notified_by_email", 1)
|
||||
frappe.db.set_value("Delivery Stop",
|
||||
delivery_stop.name,
|
||||
"email_sent_to",
|
||||
contact_info.email_id)
|
||||
frappe.db.set_value("Delivery Stop", delivery_stop.name, "notified_by_email", 1)
|
||||
frappe.db.set_value("Delivery Stop", delivery_stop.name,
|
||||
"email_sent_to", contact_info.email_id)
|
||||
frappe.msgprint(_("Email sent to {0}").format(contact_info.email_id))
|
Loading…
x
Reference in New Issue
Block a user