Add Purchase Order schedule_date field, similar to delivery_date in Sales Order
diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.js b/erpnext/buying/doctype/purchase_order/purchase_order.js
index a51246b..bbec981 100644
--- a/erpnext/buying/doctype/purchase_order/purchase_order.js
+++ b/erpnext/buying/doctype/purchase_order/purchase_order.js
@@ -15,6 +15,8 @@
},
onload: function(frm) {
+ set_schedule_date(frm);
+
erpnext.queries.setup_queries(frm, "Warehouse", function() {
return erpnext.queries.warehouse(frm.doc);
});
@@ -107,12 +109,7 @@
},
validate: function() {
- // set default schedule date as today if missing.
- (this.frm.doc.items || []).forEach(function(d) {
- if(!d.schedule_date) {
- d.schedule_date = frappe.datetime.nowdate();
- }
- })
+ set_schedule_date(cur_frm);
},
make_stock_entry: function() {
@@ -201,7 +198,10 @@
items_add: function(doc, cdt, cdn) {
var row = frappe.get_doc(cdt, cdn);
- this.frm.script_manager.copy_from_first_row("items", row, ["schedule_date"]);
+ if(doc.schedule_date) {
+ row.schedule_date = doc.schedule_date;
+ refresh_field("schedule_date", cdn, "items");
+ }
},
unclose_purchase_order: function(){
@@ -225,7 +225,9 @@
cur_frm.cscript.calculate_taxes_and_totals();
}
})
- }
+ },
+
+ items_on_form_rendered: set_schedule_date(cur_frm),
});
@@ -268,8 +270,18 @@
}
}
+function set_schedule_date(frm) {
+ if(!frm.doc.schedule_date){
+ frm.doc.schedule_date = frappe.datetime.add_days(frappe.datetime.now_date(), 1);
+ }
+ 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) {
- erpnext.utils.copy_value_in_all_row(doc, cdt, cdn, "items", "schedule_date");
+ var row = frappe.get_doc(cdt, cdn);
+ if(row.schedule_date){
+ set_schedule_date(cur_frm);
+ }
}
frappe.provide("erpnext.buying");
diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.json b/erpnext/buying/doctype/purchase_order/purchase_order.json
index 919707c..c6e33d5 100644
--- a/erpnext/buying/doctype/purchase_order/purchase_order.json
+++ b/erpnext/buying/doctype/purchase_order/purchase_order.json
@@ -291,7 +291,38 @@
"search_index": 1,
"set_only_once": 0,
"unique": 0
- },
+ },
+ {
+ "allow_bulk_edit": 0,
+ "allow_on_submit": 1,
+ "bold": 0,
+ "collapsible": 0,
+ "columns": 0,
+ "default": "Today",
+ "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": "Reqd By 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,
diff --git a/erpnext/buying/doctype/purchase_order/tests/test_purchase_order.js b/erpnext/buying/doctype/purchase_order/tests/test_purchase_order.js
index e6529e6..a818992 100644
--- a/erpnext/buying/doctype/purchase_order/tests/test_purchase_order.js
+++ b/erpnext/buying/doctype/purchase_order/tests/test_purchase_order.js
@@ -13,12 +13,21 @@
{items: [
[
{"item_code": 'Test Product 4'},
- {"schedule_date": frappe.datetime.add_days(frappe.datetime.now_date(), 1)},
+ {"schedule_date": frappe.datetime.add_days(frappe.datetime.now_date(), 2)},
{"expected_delivery_date": frappe.datetime.add_days(frappe.datetime.now_date(), 5)},
{"qty": 5},
{"uom": 'Unit'},
{"rate": 100},
{"warehouse": 'Stores - '+frappe.get_abbr(frappe.defaults.get_default("Company"))}
+ ],
+ [
+ {"item_code": 'Test Product 1'},
+ {"schedule_date": frappe.datetime.add_days(frappe.datetime.now_date(), 1)},
+ {"expected_delivery_date": frappe.datetime.add_days(frappe.datetime.now_date(), 5)},
+ {"qty": 2},
+ {"uom": 'Unit'},
+ {"rate": 100},
+ {"warehouse": 'Stores - '+frappe.get_abbr(frappe.defaults.get_default("Company"))}
]
]},
@@ -30,12 +39,19 @@
() => {
// Get supplier details
assert.ok(cur_frm.doc.supplier_name == 'Test Supplier', "Supplier name correct");
+ assert.ok(cur_frm.doc.schedule_date == frappe.datetime.add_days(frappe.datetime.now_date(), 1), "Schedule Date correct");
assert.ok($('div.control-value.like-disabled-input.for-description').text().includes('Contact 3'), "Contact display correct");
assert.ok(cur_frm.doc.contact_email == 'test@supplier.com', "Contact email correct");
// Get item details
assert.ok(cur_frm.doc.items[0].item_name == 'Test Product 4', "Item name correct");
assert.ok(cur_frm.doc.items[0].description == 'Test Product 4', "Description correct");
assert.ok(cur_frm.doc.items[0].qty == 5, "Quantity correct");
+ assert.ok(cur_frm.doc.items[0].schedule_date == frappe.datetime.add_days(frappe.datetime.now_date(), 2), "Schedule Date correct");
+
+ assert.ok(cur_frm.doc.items[1].item_name == 'Test Product 1', "Item name correct");
+ assert.ok(cur_frm.doc.items[1].description == 'Test Product 1', "Description correct");
+ assert.ok(cur_frm.doc.items[1].qty == 2, "Quantity correct");
+ assert.ok(cur_frm.doc.items[1].schedule_date == cur_frm.doc.schedule_date, "Schedule Date correct");
// Calculate total
assert.ok(cur_frm.doc.total == 500, "Total correct");
// Get terms
diff --git a/erpnext/buying/doctype/purchase_order_item/purchase_order_item.json b/erpnext/buying/doctype/purchase_order_item/purchase_order_item.json
index 2dd7b6c..5ba57b6 100755
--- a/erpnext/buying/doctype/purchase_order_item/purchase_order_item.json
+++ b/erpnext/buying/doctype/purchase_order_item/purchase_order_item.json
@@ -148,7 +148,7 @@
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
- "in_list_view": 0,
+ "in_list_view": 1,
"in_standard_filter": 0,
"label": "Reqd By Date",
"length": 0,