Add Material Request schedule_date field, similar to delivery_date in Sales Order
diff --git a/erpnext/patches.txt b/erpnext/patches.txt
index e75c490..48447f0 100644
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -448,3 +448,4 @@
erpnext.patches.v8_9.delete_gst_doctypes_for_outside_india_accounts
erpnext.patches.v8_9.set_default_fields_in_variant_settings
erpnext.patches.v8_9.update_billing_gstin_for_indian_account
+erpnext.patches.v9_0.set_schedule_date_for_material_request
\ No newline at end of file
diff --git a/erpnext/patches/v8_11/__init__.py b/erpnext/patches/v8_11/__init__.py
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/erpnext/patches/v8_11/__init__.py
@@ -0,0 +1 @@
+
diff --git a/erpnext/patches/v8_11/set_schedule_date_for_material_request.py b/erpnext/patches/v8_11/set_schedule_date_for_material_request.py
new file mode 100644
index 0000000..bef43bd
--- /dev/null
+++ b/erpnext/patches/v8_11/set_schedule_date_for_material_request.py
@@ -0,0 +1,20 @@
+# Copyright (c) 2017, Frappe and Contributors
+# License: GNU General Public License v3. See license.txt
+
+from __future__ import unicode_literals
+import frappe
+
+def execute():
+ frappe.reload_doctype("Material Request")
+ frappe.reload_doctype("Material Request Item")
+
+ if not frappe.db.has_column("Material Request", "schedule_date"):
+ return
+
+ #Update only submitted MR
+ for mr in frappe.get_all("Material Request", filters= [["docstatus", "=", 1]], fields=["name"]):
+ material_request = frappe.get_doc("Material Request", mr)
+ if material_request.items:
+ if not material_request.schedule_date:
+ material_request.schedule_date = material_request.items[0].schedule_date
+ material_request.save()
\ No newline at end of file
diff --git a/erpnext/stock/doctype/material_request/material_request.js b/erpnext/stock/doctype/material_request/material_request.js
index 7043fb7..17a3914 100644
--- a/erpnext/stock/doctype/material_request/material_request.js
+++ b/erpnext/stock/doctype/material_request/material_request.js
@@ -17,6 +17,9 @@
// add item, if previous view was item
erpnext.utils.add_item(frm);
+ //set schedule_date
+ set_schedule_date(frm);
+
// formatter for material request item
frm.set_indicator_formatter('item_code',
function(doc) { return (doc.qty<=doc.ordered_qty) ? "green" : "orange" }),
@@ -38,12 +41,7 @@
},
item_code: function(frm, doctype, name) {
- frm.script_manager.copy_from_first_row('items', frm.selected_doc,
- 'schedule_date');
- },
-
- schedule_date: function(frm, cdt, cdn) {
- erpnext.utils.copy_value_in_all_row(frm.doc, cdt, cdn, "items", "schedule_date");
+ set_schedule_date(frm);
}
});
@@ -227,7 +225,21 @@
}
}
});
- }
+ },
+
+ validate: function() {
+ set_schedule_date(cur_frm);
+ },
+
+ items_add: function(doc, cdt, cdn) {
+ var row = frappe.get_doc(cdt, cdn);
+ if(doc.schedule_date) {
+ row.schedule_date = doc.schedule_date;
+ refresh_field("schedule_date", cdn, "items");
+ }
+ },
+
+ items_on_form_rendered: set_schedule_date(cur_frm),
});
// for backward compatibility: combine new and previous states
@@ -246,3 +258,17 @@
cur_frm.refresh();
});
};
+
+function set_schedule_date(frm) {
+ if(!frm.doc.schedule_date){
+ frm.doc.schedule_date = frappe.datetime.add_days(frappe.datetime.now_date(), 5);
+ }
+ erpnext.utils.copy_value_in_all_row(frm.doc, frm.doc.doctype, frm.doc.name, "items", "schedule_date");
+}
+
+cur_frm.cscript.schedule_date = function(doc, cdt, cdn) {
+ var row = frappe.get_doc(cdt, cdn);
+ if(row.schedule_date){
+ set_schedule_date(cur_frm);
+ }
+}
\ No newline at end of file
diff --git a/erpnext/stock/doctype/material_request/material_request.json b/erpnext/stock/doctype/material_request/material_request.json
index 87cde0d..9d38248 100644
--- a/erpnext/stock/doctype/material_request/material_request.json
+++ b/erpnext/stock/doctype/material_request/material_request.json
@@ -132,7 +132,37 @@
"unique": 0
},
{
- "allow_bulk_edit": 0,
+ "allow_bulk_edit": 0,
+ "allow_on_submit": 1,
+ "bold": 0,
+ "collapsible": 0,
+ "columns": 0,
+ "fieldname": "schedule_date",
+ "fieldtype": "Date",
+ "hidden": 0,
+ "ignore_user_permissions": 0,
+ "ignore_xss_filter": 0,
+ "in_filter": 0,
+ "in_global_search": 0,
+ "in_list_view": 0,
+ "in_standard_filter": 0,
+ "label": "Required Date",
+ "length": 0,
+ "no_copy": 0,
+ "permlevel": 0,
+ "precision": "",
+ "print_hide": 0,
+ "print_hide_if_no_value": 0,
+ "read_only": 0,
+ "remember_last_selected_value": 0,
+ "report_hide": 0,
+ "reqd": 1,
+ "search_index": 0,
+ "set_only_once": 0,
+ "unique": 0
+ },
+ {
+ "allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
diff --git a/erpnext/stock/doctype/material_request/tests/test_material_request.js b/erpnext/stock/doctype/material_request/tests/test_material_request.js
index 22d1088..1ae41f5 100644
--- a/erpnext/stock/doctype/material_request/tests/test_material_request.js
+++ b/erpnext/stock/doctype/material_request/tests/test_material_request.js
@@ -11,14 +11,25 @@
{'schedule_date': frappe.datetime.add_days(frappe.datetime.nowdate(), 5)},
{'qty': 5},
{'item_code': 'Test Product 1'},
+ ],
+ [
+ {'schedule_date': frappe.datetime.add_days(frappe.datetime.nowdate(), 6)},
+ {'qty': 2},
+ {'item_code': 'Test Product 2'},
]
]},
]);
},
() => cur_frm.save(),
() => {
+ assert.ok(cur_frm.doc.schedule_date == frappe.datetime.add_days(frappe.datetime.now_date(), 5), "Schedule Date correct");
+
// get_item_details
assert.ok(cur_frm.doc.items[0].item_name=='Test Product 1', "Item name correct");
+ assert.ok(cur_frm.doc.items[0].schedule_date == frappe.datetime.add_days(frappe.datetime.now_date(), 5), "Schedule Date correct");
+
+ assert.ok(cur_frm.doc.items[1].item_name=='Test Product 2', "Item name correct");
+ assert.ok(cur_frm.doc.items[1].schedule_date == frappe.datetime.add_days(frappe.datetime.now_date(), 6), "Schedule Date correct");
},
() => frappe.tests.click_button('Submit'),
() => frappe.tests.click_button('Yes'),