From 23a4b09d4328fe1386d24f16a5f6408931527f41 Mon Sep 17 00:00:00 2001 From: Sunny Date: Mon, 25 Sep 2017 17:45:47 +0800 Subject: [PATCH 01/14] Add Material Request schedule_date field, similar to delivery_date in Sales Order --- erpnext/patches.txt | 1 + erpnext/patches/v8_11/__init__.py | 1 + .../set_schedule_date_for_material_request.py | 20 ++++++++++ .../material_request/material_request.js | 40 +++++++++++++++---- .../material_request/material_request.json | 32 ++++++++++++++- .../tests/test_material_request.js | 11 +++++ 6 files changed, 97 insertions(+), 8 deletions(-) create mode 100644 erpnext/patches/v8_11/__init__.py create mode 100644 erpnext/patches/v8_11/set_schedule_date_for_material_request.py diff --git a/erpnext/patches.txt b/erpnext/patches.txt index e75c490a36..48447f0e43 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -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 \ 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 0000000000..8b13789179 --- /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 0000000000..bef43bd0d4 --- /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 7043fb7ba8..17a3914796 100644 --- a/erpnext/stock/doctype/material_request/material_request.js +++ b/erpnext/stock/doctype/material_request/material_request.js @@ -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); + } +} \ 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 87cde0d3e2..9d38248fbd 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 22d1088cfe..1ae41f5898 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 @@ 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'), From 12cb07ce3c1d5d297800ee101a18728101b5d9a5 Mon Sep 17 00:00:00 2001 From: Sunny Date: Mon, 25 Sep 2017 20:52:46 +0800 Subject: [PATCH 02/14] [fix] test records --- .../doctype/material_request/test_records.json | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/erpnext/stock/doctype/material_request/test_records.json b/erpnext/stock/doctype/material_request/test_records.json index 09d1912ed7..f30958a85b 100644 --- a/erpnext/stock/doctype/material_request/test_records.json +++ b/erpnext/stock/doctype/material_request/test_records.json @@ -2,7 +2,7 @@ { "company": "_Test Company", "doctype": "Material Request", - "fiscal_year": "_Test Fiscal Year 2013", + "fiscal_year": "_Test Fiscal Year 2013", "items": [ { "description": "_Test Item Home Desktop 100", @@ -11,7 +11,7 @@ "item_name": "_Test Item Home Desktop 100", "parentfield": "items", "qty": 54.0, - "schedule_date": "2013-02-18", + "schedule_date": "2013-02-26", "uom": "_Test UOM 1", "warehouse": "_Test Warehouse - _TC" }, @@ -22,19 +22,20 @@ "item_name": "_Test Item Home Desktop 200", "parentfield": "items", "qty": 3.0, - "schedule_date": "2013-02-19", + "schedule_date": "2013-02-25", "uom": "_Test UOM 1", "warehouse": "_Test Warehouse - _TC" } ], "material_request_type": "Purchase", "naming_series": "_T-Material Request-", - "transaction_date": "2013-02-18" + "transaction_date": "2013-02-18", + "schedule_date": "2013-02-25" }, { "company": "_Test Company", "doctype": "Material Request", - "fiscal_year": "_Test Fiscal Year 2013", + "fiscal_year": "_Test Fiscal Year 2013", "items": [ { "description": "_Test FG Item", @@ -43,13 +44,14 @@ "item_name": "_Test FG Item", "parentfield": "items", "qty": 5, - "schedule_date": "2013-02-18", + "schedule_date": "2013-02-25", "uom": "_Test UOM 1", "warehouse": "_Test Warehouse - _TC" } ], "material_request_type": "Manufacture", "naming_series": "_T-Material Request-", - "transaction_date": "2013-02-18" + "transaction_date": "2013-02-18", + "schedule_date": "2013-02-25" } ] \ No newline at end of file From f7a8277d122cd75773ccc407e76b015403cbc603 Mon Sep 17 00:00:00 2001 From: Sunny Date: Mon, 25 Sep 2017 01:03:12 +0800 Subject: [PATCH 03/14] Add Purchase Order schedule_date field, similar to delivery_date in Sales Order --- .../doctype/purchase_order/purchase_order.js | 30 ++++++++++++----- .../purchase_order/purchase_order.json | 33 ++++++++++++++++++- .../tests/test_purchase_order.js | 18 +++++++++- .../purchase_order_item.json | 2 +- 4 files changed, 71 insertions(+), 12 deletions(-) diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.js b/erpnext/buying/doctype/purchase_order/purchase_order.js index a51246bcb8..bbec98174f 100644 --- a/erpnext/buying/doctype/purchase_order/purchase_order.js +++ b/erpnext/buying/doctype/purchase_order/purchase_order.js @@ -15,6 +15,8 @@ frappe.ui.form.on("Purchase Order", { }, onload: function(frm) { + set_schedule_date(frm); + erpnext.queries.setup_queries(frm, "Warehouse", function() { return erpnext.queries.warehouse(frm.doc); }); @@ -107,12 +109,7 @@ erpnext.buying.PurchaseOrderController = erpnext.buying.BuyingController.extend( }, 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 @@ erpnext.buying.PurchaseOrderController = erpnext.buying.BuyingController.extend( 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 @@ erpnext.buying.PurchaseOrderController = erpnext.buying.BuyingController.extend( cur_frm.cscript.calculate_taxes_and_totals(); } }) - } + }, + + items_on_form_rendered: set_schedule_date(cur_frm), }); @@ -268,8 +270,18 @@ cur_frm.cscript.on_submit = function(doc, cdt, cdn) { } } +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 919707c08d..c6e33d5386 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 e6529e60db..a818992db3 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 @@ QUnit.test("test: purchase order", function(assert) { {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 @@ QUnit.test("test: purchase order", function(assert) { () => { // 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 2dd7b6c0ed..5ba57b6390 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, From 65c7a6947a974c21645e0200148997e0097ff77a Mon Sep 17 00:00:00 2001 From: Sunny Date: Mon, 25 Sep 2017 10:54:45 +0800 Subject: [PATCH 04/14] [fix] Codacy errors --- .../buying/doctype/purchase_order/tests/test_purchase_order.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 a818992db3..6605a65170 100644 --- a/erpnext/buying/doctype/purchase_order/tests/test_purchase_order.js +++ b/erpnext/buying/doctype/purchase_order/tests/test_purchase_order.js @@ -20,7 +20,7 @@ QUnit.test("test: purchase order", function(assert) { {"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)}, From 284ceb7abe8c6ce58a1891927b77db7350c5658d Mon Sep 17 00:00:00 2001 From: Sunny Date: Mon, 25 Sep 2017 11:05:36 +0800 Subject: [PATCH 05/14] Set PO Reqd By Date default in code, to next date --- erpnext/buying/doctype/purchase_order/purchase_order.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.json b/erpnext/buying/doctype/purchase_order/purchase_order.json index c6e33d5386..3c606a2a5a 100644 --- a/erpnext/buying/doctype/purchase_order/purchase_order.json +++ b/erpnext/buying/doctype/purchase_order/purchase_order.json @@ -298,7 +298,7 @@ "bold": 0, "collapsible": 0, "columns": 0, - "default": "Today", + "default": "", "fieldname": "schedule_date", "fieldtype": "Date", "hidden": 0, From 71866e06f3950c52b9656e45a18e666bc75b0fd7 Mon Sep 17 00:00:00 2001 From: Sunny Date: Mon, 25 Sep 2017 01:03:12 +0800 Subject: [PATCH 06/14] Add Purchase Order schedule_date field, similar to delivery_date in Sales Order --- erpnext/buying/doctype/purchase_order/purchase_order.json | 2 +- .../doctype/purchase_order/tests/test_purchase_order.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.json b/erpnext/buying/doctype/purchase_order/purchase_order.json index 3c606a2a5a..3a64f202ba 100644 --- a/erpnext/buying/doctype/purchase_order/purchase_order.json +++ b/erpnext/buying/doctype/purchase_order/purchase_order.json @@ -324,7 +324,7 @@ "unique": 0 }, { - "allow_bulk_edit": 0, + "allow_bulk_edit": 0, "allow_on_submit": 0, "bold": 0, "collapsible": 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 6605a65170..966238cb87 100644 --- a/erpnext/buying/doctype/purchase_order/tests/test_purchase_order.js +++ b/erpnext/buying/doctype/purchase_order/tests/test_purchase_order.js @@ -13,14 +13,14 @@ QUnit.test("test: purchase order", function(assert) { {items: [ [ {"item_code": 'Test Product 4'}, - {"schedule_date": frappe.datetime.add_days(frappe.datetime.now_date(), 2)}, + {"schedule_date": frappe.datetime.add_days(frappe.datetime.now_date(), 1)}, {"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)}, From 799d69babab4b0501e2d526a9776a3cc8c9d2414 Mon Sep 17 00:00:00 2001 From: Sunny Date: Mon, 25 Sep 2017 10:54:45 +0800 Subject: [PATCH 07/14] [fix] Codacy errors --- .../buying/doctype/purchase_order/tests/test_purchase_order.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 966238cb87..ffc6874de3 100644 --- a/erpnext/buying/doctype/purchase_order/tests/test_purchase_order.js +++ b/erpnext/buying/doctype/purchase_order/tests/test_purchase_order.js @@ -20,7 +20,7 @@ QUnit.test("test: purchase order", function(assert) { {"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)}, From 65cd9f228432a22e54b07f456d5c619f24a487be Mon Sep 17 00:00:00 2001 From: Sunny Date: Mon, 25 Sep 2017 14:28:42 +0800 Subject: [PATCH 08/14] Add patch to update schedule date of submitted Purchase Orders --- .../set_schedule_date_for_purchase_order.py | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 erpnext/patches/v8_11/set_schedule_date_for_purchase_order.py diff --git a/erpnext/patches/v8_11/set_schedule_date_for_purchase_order.py b/erpnext/patches/v8_11/set_schedule_date_for_purchase_order.py new file mode 100644 index 0000000000..3c733b1a16 --- /dev/null +++ b/erpnext/patches/v8_11/set_schedule_date_for_purchase_order.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("Purchase Order") + frappe.reload_doctype("Purchase Order Item") + + if not frappe.db.has_column("Purchase Order", "schedule_date"): + return + + #Update only submitted PO + for po in frappe.get_all("Purchase Order", filters= [["docstatus", "=", 1]], fields=["name"]): + purchase_order = frappe.get_doc("Purchase Order", po) + if purchase_order.items: + if not purchase_order.schedule_date: + purchase_order.schedule_date = purchase_order.items[0].schedule_date + purchase_order.save() \ No newline at end of file From 892ec599d47b587ebab6d2d7d8955bae19750021 Mon Sep 17 00:00:00 2001 From: Sunny Date: Mon, 25 Sep 2017 14:54:50 +0800 Subject: [PATCH 09/14] [fix] tests --- .../buying/doctype/purchase_order/tests/test_purchase_order.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 ffc6874de3..6605a65170 100644 --- a/erpnext/buying/doctype/purchase_order/tests/test_purchase_order.js +++ b/erpnext/buying/doctype/purchase_order/tests/test_purchase_order.js @@ -13,7 +13,7 @@ QUnit.test("test: purchase order", function(assert) { {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'}, From 0d91d3f572df0e0b9b51e39842281e3b19ad9952 Mon Sep 17 00:00:00 2001 From: Sunny Date: Tue, 26 Sep 2017 10:56:31 +0800 Subject: [PATCH 10/14] add schedule_date while creating Material Request --- erpnext/demo/user/purchase.py | 1 + .../production_planning_tool.py | 2 +- erpnext/setup/setup_wizard/sample_data.py | 1 + .../doctype/material_request/test_records.json | 14 +++++++------- erpnext/stock/reorder_item.py | 3 ++- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/erpnext/demo/user/purchase.py b/erpnext/demo/user/purchase.py index 960a3169cf..82983f0a71 100644 --- a/erpnext/demo/user/purchase.py +++ b/erpnext/demo/user/purchase.py @@ -103,6 +103,7 @@ def make_material_request(item_code, qty): mr.material_request_type = "Purchase" mr.transaction_date = frappe.flags.current_date + mr.schedule_date = frappe.utils.add_days(mr.transaction_date, 7) mr.append("items", { "doctype": "Material Request Item", diff --git a/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py b/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py index 815e504447..99cf6b3560 100644 --- a/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py +++ b/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py @@ -516,7 +516,7 @@ class ProductionPlanningTool(Document): "transaction_date": nowdate(), "status": "Draft", "company": self.company, - "requested_by": frappe.session.user + "schedule_date": add_days(nowdate(), cint(item_wrapper.lead_time_days)), }) material_request.update({"material_request_type": item_wrapper.default_material_request_type}) diff --git a/erpnext/setup/setup_wizard/sample_data.py b/erpnext/setup/setup_wizard/sample_data.py index bc26e09677..43911f06c1 100644 --- a/erpnext/setup/setup_wizard/sample_data.py +++ b/erpnext/setup/setup_wizard/sample_data.py @@ -73,6 +73,7 @@ def make_material_request(items): mr = frappe.get_doc({ "doctype": "Material Request", "material_request_type": "Purchase", + "schedule_date": frappe.utils.add_days(frappe.utils.nowdate(), 7), "items": [{ "schedule_date": frappe.utils.add_days(frappe.utils.nowdate(), 7), "item_code": i.name, diff --git a/erpnext/stock/doctype/material_request/test_records.json b/erpnext/stock/doctype/material_request/test_records.json index f30958a85b..1c714969eb 100644 --- a/erpnext/stock/doctype/material_request/test_records.json +++ b/erpnext/stock/doctype/material_request/test_records.json @@ -2,7 +2,7 @@ { "company": "_Test Company", "doctype": "Material Request", - "fiscal_year": "_Test Fiscal Year 2013", + "fiscal_year": "_Test Fiscal Year 2013", "items": [ { "description": "_Test Item Home Desktop 100", @@ -11,7 +11,7 @@ "item_name": "_Test Item Home Desktop 100", "parentfield": "items", "qty": 54.0, - "schedule_date": "2013-02-26", + "schedule_date": "2013-02-18", "uom": "_Test UOM 1", "warehouse": "_Test Warehouse - _TC" }, @@ -22,7 +22,7 @@ "item_name": "_Test Item Home Desktop 200", "parentfield": "items", "qty": 3.0, - "schedule_date": "2013-02-25", + "schedule_date": "2013-02-19", "uom": "_Test UOM 1", "warehouse": "_Test Warehouse - _TC" } @@ -30,12 +30,12 @@ "material_request_type": "Purchase", "naming_series": "_T-Material Request-", "transaction_date": "2013-02-18", - "schedule_date": "2013-02-25" + "schedule_date": "2013-02-19" }, { "company": "_Test Company", "doctype": "Material Request", - "fiscal_year": "_Test Fiscal Year 2013", + "fiscal_year": "_Test Fiscal Year 2013", "items": [ { "description": "_Test FG Item", @@ -44,7 +44,7 @@ "item_name": "_Test FG Item", "parentfield": "items", "qty": 5, - "schedule_date": "2013-02-25", + "schedule_date": "2013-02-19", "uom": "_Test UOM 1", "warehouse": "_Test Warehouse - _TC" } @@ -52,6 +52,6 @@ "material_request_type": "Manufacture", "naming_series": "_T-Material Request-", "transaction_date": "2013-02-18", - "schedule_date": "2013-02-25" + "schedule_date": "2013-02-19" } ] \ No newline at end of file diff --git a/erpnext/stock/reorder_item.py b/erpnext/stock/reorder_item.py index 01a6a6d547..ade6121700 100644 --- a/erpnext/stock/reorder_item.py +++ b/erpnext/stock/reorder_item.py @@ -121,7 +121,8 @@ def create_material_request(material_requests): mr.update({ "company": company, "transaction_date": nowdate(), - "material_request_type": "Material Transfer" if request_type=="Transfer" else request_type + "material_request_type": "Material Transfer" if request_type=="Transfer" else request_type, + "schedule_date": add_days(nowdate(),cint(item.lead_time_days)) }) for d in items: From bf68611567a14fc9e17b98fb2703eb91b53d5dd4 Mon Sep 17 00:00:00 2001 From: Sunny Date: Tue, 26 Sep 2017 11:03:58 +0800 Subject: [PATCH 11/14] clean code --- .../doctype/purchase_order/purchase_order.js | 30 ++++++------------ .../purchase_order/purchase_order.json | 31 ------------------- .../tests/test_purchase_order.js | 18 +---------- .../purchase_order_item.json | 2 +- .../set_schedule_date_for_purchase_order.py | 20 ------------ 5 files changed, 11 insertions(+), 90 deletions(-) delete mode 100644 erpnext/patches/v8_11/set_schedule_date_for_purchase_order.py diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.js b/erpnext/buying/doctype/purchase_order/purchase_order.js index bbec98174f..a51246bcb8 100644 --- a/erpnext/buying/doctype/purchase_order/purchase_order.js +++ b/erpnext/buying/doctype/purchase_order/purchase_order.js @@ -15,8 +15,6 @@ frappe.ui.form.on("Purchase Order", { }, onload: function(frm) { - set_schedule_date(frm); - erpnext.queries.setup_queries(frm, "Warehouse", function() { return erpnext.queries.warehouse(frm.doc); }); @@ -109,7 +107,12 @@ erpnext.buying.PurchaseOrderController = erpnext.buying.BuyingController.extend( }, validate: function() { - set_schedule_date(cur_frm); + // 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(); + } + }) }, make_stock_entry: function() { @@ -198,10 +201,7 @@ erpnext.buying.PurchaseOrderController = erpnext.buying.BuyingController.extend( 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"); - } + this.frm.script_manager.copy_from_first_row("items", row, ["schedule_date"]); }, unclose_purchase_order: function(){ @@ -225,9 +225,7 @@ erpnext.buying.PurchaseOrderController = erpnext.buying.BuyingController.extend( cur_frm.cscript.calculate_taxes_and_totals(); } }) - }, - - items_on_form_rendered: set_schedule_date(cur_frm), + } }); @@ -270,18 +268,8 @@ cur_frm.cscript.on_submit = function(doc, cdt, cdn) { } } -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) { - var row = frappe.get_doc(cdt, cdn); - if(row.schedule_date){ - set_schedule_date(cur_frm); - } + erpnext.utils.copy_value_in_all_row(doc, cdt, cdn, "items", "schedule_date"); } 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 3a64f202ba..b9a5f81cdb 100644 --- a/erpnext/buying/doctype/purchase_order/purchase_order.json +++ b/erpnext/buying/doctype/purchase_order/purchase_order.json @@ -292,37 +292,6 @@ "set_only_once": 0, "unique": 0 }, - { - "allow_bulk_edit": 0, - "allow_on_submit": 1, - "bold": 0, - "collapsible": 0, - "columns": 0, - "default": "", - "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 6605a65170..e6529e60db 100644 --- a/erpnext/buying/doctype/purchase_order/tests/test_purchase_order.js +++ b/erpnext/buying/doctype/purchase_order/tests/test_purchase_order.js @@ -13,18 +13,9 @@ QUnit.test("test: purchase order", function(assert) { {items: [ [ {"item_code": 'Test Product 4'}, - {"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}, + {"qty": 5}, {"uom": 'Unit'}, {"rate": 100}, {"warehouse": 'Stores - '+frappe.get_abbr(frappe.defaults.get_default("Company"))} @@ -39,19 +30,12 @@ QUnit.test("test: purchase order", function(assert) { () => { // 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 5ba57b6390..c4d86a3aba 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": 1, + "in_list_view": 0, "in_standard_filter": 0, "label": "Reqd By Date", "length": 0, diff --git a/erpnext/patches/v8_11/set_schedule_date_for_purchase_order.py b/erpnext/patches/v8_11/set_schedule_date_for_purchase_order.py deleted file mode 100644 index 3c733b1a16..0000000000 --- a/erpnext/patches/v8_11/set_schedule_date_for_purchase_order.py +++ /dev/null @@ -1,20 +0,0 @@ -# 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("Purchase Order") - frappe.reload_doctype("Purchase Order Item") - - if not frappe.db.has_column("Purchase Order", "schedule_date"): - return - - #Update only submitted PO - for po in frappe.get_all("Purchase Order", filters= [["docstatus", "=", 1]], fields=["name"]): - purchase_order = frappe.get_doc("Purchase Order", po) - if purchase_order.items: - if not purchase_order.schedule_date: - purchase_order.schedule_date = purchase_order.items[0].schedule_date - purchase_order.save() \ No newline at end of file From 73f1c93cd25e1f6465a67ea41e6755bb367a2e9f Mon Sep 17 00:00:00 2001 From: Sunny Date: Tue, 26 Sep 2017 11:44:10 +0800 Subject: [PATCH 12/14] fix ppt code --- .../doctype/production_planning_tool/production_planning_tool.py | 1 + 1 file changed, 1 insertion(+) diff --git a/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py b/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py index 99cf6b3560..73b73b90d8 100644 --- a/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py +++ b/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py @@ -516,6 +516,7 @@ class ProductionPlanningTool(Document): "transaction_date": nowdate(), "status": "Draft", "company": self.company, + "requested_by": frappe.session.user, "schedule_date": add_days(nowdate(), cint(item_wrapper.lead_time_days)), }) material_request.update({"material_request_type": item_wrapper.default_material_request_type}) From 33670bba47db31b58efda21558e17b647449f742 Mon Sep 17 00:00:00 2001 From: Sunny Date: Tue, 26 Sep 2017 12:17:15 +0800 Subject: [PATCH 13/14] fix reorder_item --- erpnext/stock/reorder_item.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/stock/reorder_item.py b/erpnext/stock/reorder_item.py index ade6121700..8da9f110f0 100644 --- a/erpnext/stock/reorder_item.py +++ b/erpnext/stock/reorder_item.py @@ -122,7 +122,7 @@ def create_material_request(material_requests): "company": company, "transaction_date": nowdate(), "material_request_type": "Material Transfer" if request_type=="Transfer" else request_type, - "schedule_date": add_days(nowdate(),cint(item.lead_time_days)) + "schedule_date": add_days(nowdate(), cint(items[0].lead_time_days)) }) for d in items: From 3ec69604780760c769bce2cbdbf79f4b0e0101e7 Mon Sep 17 00:00:00 2001 From: Sunny Date: Thu, 28 Sep 2017 15:26:20 +0800 Subject: [PATCH 14/14] move Material Request patch to v9 --- erpnext/patches/v8_11/__init__.py | 1 - .../{v8_11 => v9_0}/set_schedule_date_for_material_request.py | 0 2 files changed, 1 deletion(-) delete mode 100644 erpnext/patches/v8_11/__init__.py rename erpnext/patches/{v8_11 => v9_0}/set_schedule_date_for_material_request.py (100%) diff --git a/erpnext/patches/v8_11/__init__.py b/erpnext/patches/v8_11/__init__.py deleted file mode 100644 index 8b13789179..0000000000 --- a/erpnext/patches/v8_11/__init__.py +++ /dev/null @@ -1 +0,0 @@ - diff --git a/erpnext/patches/v8_11/set_schedule_date_for_material_request.py b/erpnext/patches/v9_0/set_schedule_date_for_material_request.py similarity index 100% rename from erpnext/patches/v8_11/set_schedule_date_for_material_request.py rename to erpnext/patches/v9_0/set_schedule_date_for_material_request.py