From a113861b0c7725a922d733e0b362419c222753f3 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Tue, 15 Oct 2019 12:43:27 +0530 Subject: [PATCH 1/3] fix: Always set required date based on min date on item table --- erpnext/controllers/buying_controller.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/controllers/buying_controller.py b/erpnext/controllers/buying_controller.py index 9d37df0406..db1c44ed97 100644 --- a/erpnext/controllers/buying_controller.py +++ b/erpnext/controllers/buying_controller.py @@ -695,8 +695,8 @@ class BuyingController(StockController): def validate_schedule_date(self): if not self.get("items"): return - if not self.schedule_date: - self.schedule_date = min([d.schedule_date for d in self.get("items")]) + + self.schedule_date = min([d.schedule_date for d in self.get("items")]) if self.schedule_date: for d in self.get('items'): From 19070621af1848edc4cf6bf922c73297ab4a08de Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Tue, 15 Oct 2019 14:11:40 +0530 Subject: [PATCH 2/3] tests: added tests for PO scheduled date --- .../purchase_order/test_purchase_order.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/erpnext/buying/doctype/purchase_order/test_purchase_order.py b/erpnext/buying/doctype/purchase_order/test_purchase_order.py index ff0b65b7be..4506db6405 100644 --- a/erpnext/buying/doctype/purchase_order/test_purchase_order.py +++ b/erpnext/buying/doctype/purchase_order/test_purchase_order.py @@ -589,6 +589,23 @@ class TestPurchaseOrder(unittest.TestCase): frappe.db.set_value("Accounts Settings", "Accounts Settings", "unlink_advance_payment_on_cancelation_of_order", 0) + def test_schedule_date(self): + po = create_purchase_order(do_not_submit=True) + po.schedule_date = None + po.append("items", { + "item_code": "_Test Item", + "qty": 1, + "rate": 100, + "schedule_date": add_days(nowdate(), 5) + }) + po.save() + self.assertEqual(po.schedule_date, add_days(nowdate(), 1)) + + po.items[0].schedule_date = add_days(nowdate(), 2) + po.save() + self.assertEqual(po.schedule_date, add_days(nowdate(), 2)) + + def make_pr_against_po(po, received_qty=0): pr = make_purchase_receipt(po) pr.get("items")[0].qty = received_qty or 5 From dd893254bec268d437a584674d119a57177a8931 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 21 Oct 2019 13:40:00 +0530 Subject: [PATCH 3/3] Update buying_controller.py --- erpnext/controllers/buying_controller.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/erpnext/controllers/buying_controller.py b/erpnext/controllers/buying_controller.py index db1c44ed97..0dde898005 100644 --- a/erpnext/controllers/buying_controller.py +++ b/erpnext/controllers/buying_controller.py @@ -696,7 +696,9 @@ class BuyingController(StockController): if not self.get("items"): return - self.schedule_date = min([d.schedule_date for d in self.get("items")]) + earliest_schedule_date = min([d.schedule_date for d in self.get("items")]) + if earliest_schedule_date: + self.schedule_date = earliest_schedule_date if self.schedule_date: for d in self.get('items'):