Add Material Request schedule_date field, similar to delivery_date in Sales Order

This commit is contained in:
Sunny 2017-09-25 17:45:47 +08:00
parent c9f9e5235b
commit 23a4b09d43
6 changed files with 97 additions and 8 deletions

View File

@ -448,3 +448,4 @@ erpnext.patches.v8_9.remove_employee_from_salary_structure_parent
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

View File

@ -0,0 +1 @@

View File

@ -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()

View File

@ -17,6 +17,9 @@ frappe.ui.form.on('Material Request', {
// 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 @@ frappe.ui.form.on("Material Request Item", {
},
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 @@ erpnext.buying.MaterialRequestController = erpnext.buying.BuyingController.exten
}
}
});
}
},
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.cscript['Unstop Material Request'] = function(){
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);
}
}

View File

@ -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,

View File

@ -11,14 +11,25 @@ QUnit.test("test material request", function(assert) {
{'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'),