From 0f809426d21ccc580a1dcc8480652b37a17cc0ae Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Thu, 17 Dec 2015 12:31:51 +0530 Subject: [PATCH] [fix] Validate transfer qty cannot be greater than qty --- .../purchase_common/purchase_common.js | 3 ++- .../material_request/material_request.js | 19 +++++++++---------- .../material_request/material_request.py | 4 ++++ .../material_request/test_material_request.py | 12 ++++++------ 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/erpnext/buying/doctype/purchase_common/purchase_common.js b/erpnext/buying/doctype/purchase_common/purchase_common.js index 2fb3bc720d..0860bca37c 100644 --- a/erpnext/buying/doctype/purchase_common/purchase_common.js +++ b/erpnext/buying/doctype/purchase_common/purchase_common.js @@ -59,7 +59,8 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({ this.frm.toggle_display("supplier_name", (this.supplier_name && this.frm.doc.supplier_name!==this.frm.doc.supplier)); - if(this.frm.doctype==="Purchase Order" || this.frm.doctype==="Material Request") { + if(this.frm.docstatus==0 && + (this.frm.doctype==="Purchase Order" || this.frm.doctype==="Material Request")) { this.set_from_product_bundle(); } diff --git a/erpnext/stock/doctype/material_request/material_request.js b/erpnext/stock/doctype/material_request/material_request.js index 0efc8bc29c..3ce6707dcf 100644 --- a/erpnext/stock/doctype/material_request/material_request.js +++ b/erpnext/stock/doctype/material_request/material_request.js @@ -39,24 +39,23 @@ erpnext.buying.MaterialRequestController = erpnext.buying.BuyingController.exten this.make_supplier_quotation, frappe.boot.doctype_icons["Supplier Quotation"]); - if(doc.material_request_type === "Material Transfer" && doc.status === "Submitted") - cur_frm.add_custom_button(__("Transfer Material"), this.make_stock_entry, - frappe.boot.doctype_icons["Stock Entry"]); - - if(doc.material_request_type === "Material Issue" && doc.status === "Submitted") - cur_frm.add_custom_button(__("Issue Material"), this.make_stock_entry, - frappe.boot.doctype_icons["Stock Entry"]); - if(flt(doc.per_ordered, 2) < 100) { + if(doc.material_request_type === "Material Transfer" && doc.status === "Submitted") + cur_frm.add_custom_button(__("Transfer Material"), this.make_stock_entry, + frappe.boot.doctype_icons["Stock Entry"]); + + if(doc.material_request_type === "Material Issue" && doc.status === "Submitted") + cur_frm.add_custom_button(__("Issue Material"), this.make_stock_entry, + frappe.boot.doctype_icons["Stock Entry"]); + if(doc.material_request_type === "Purchase") cur_frm.add_custom_button(__('Make Purchase Order'), this.make_purchase_order, frappe.boot.doctype_icons["Purchase Order"]); cur_frm.add_custom_button(__('Stop'), cur_frm.cscript['Stop Material Request'], "icon-exclamation", "btn-default"); + } - - } if (this.frm.doc.docstatus===0) { diff --git a/erpnext/stock/doctype/material_request/material_request.py b/erpnext/stock/doctype/material_request/material_request.py index fd82784cfb..5462228215 100644 --- a/erpnext/stock/doctype/material_request/material_request.py +++ b/erpnext/stock/doctype/material_request/material_request.py @@ -123,6 +123,10 @@ class MaterialRequest(BuyingController): from `tabStock Entry Detail` where material_request = %s and material_request_item = %s and docstatus = 1""", (self.name, d.name))[0][0]) + + if d.ordered_qty and d.ordered_qty > d.qty: + frappe.throw(_("The total Issue / Transfer quantity {0} in Material Request {1} cannot be greater than requested quantity {2} for Item {3}").format(d.ordered_qty, d.parent, d.qty, d.item_code)) + frappe.db.set_value(d.doctype, d.name, "ordered_qty", d.ordered_qty) # note: if qty is 0, its row is still counted in len(self.get("items")) diff --git a/erpnext/stock/doctype/material_request/test_material_request.py b/erpnext/stock/doctype/material_request/test_material_request.py index 5cd7de1fd0..0905b399c6 100644 --- a/erpnext/stock/doctype/material_request/test_material_request.py +++ b/erpnext/stock/doctype/material_request/test_material_request.py @@ -276,8 +276,8 @@ class TestMaterialRequest(unittest.TestCase): "fiscal_year": "_Test Fiscal Year 2013", }) se_doc.get("items")[0].update({ - "qty": 60.0, - "transfer_qty": 60.0, + "qty": 54.0, + "transfer_qty": 54.0, "s_warehouse": "_Test Warehouse 1 - _TC", "basic_rate": 1.0 }) @@ -307,7 +307,7 @@ class TestMaterialRequest(unittest.TestCase): mr.load_from_db() self.assertEquals(mr.per_ordered, 100) - self.assertEquals(mr.get("items")[0].ordered_qty, 60.0) + self.assertEquals(mr.get("items")[0].ordered_qty, 54.0) self.assertEquals(mr.get("items")[1].ordered_qty, 3.0) current_requested_qty_item1 = self._get_requested_qty("_Test Item Home Desktop 100", "_Test Warehouse - _TC") @@ -383,7 +383,7 @@ class TestMaterialRequest(unittest.TestCase): def _get_requested_qty(self, item_code, warehouse): return flt(frappe.db.get_value("Bin", {"item_code": item_code, "warehouse": warehouse}, "indented_qty")) - def test_make_stock_entry_for_Material_Issue(self): + def test_make_stock_entry_for_material_issue(self): from erpnext.stock.doctype.material_request.material_request import make_stock_entry mr = frappe.copy_doc(test_records[0]).insert() @@ -422,13 +422,13 @@ class TestMaterialRequest(unittest.TestCase): se_doc = make_stock_entry(mr.name) se_doc.fiscal_year = "_Test Fiscal Year 2014" - se_doc.get("items")[0].qty = 60.0 + se_doc.get("items")[0].qty = 54.0 se_doc.insert() se_doc.submit() # check if per complete is as expected mr.load_from_db() - self.assertEquals(mr.get("items")[0].ordered_qty, 60.0) + self.assertEquals(mr.get("items")[0].ordered_qty, 54.0) self.assertEquals(mr.get("items")[1].ordered_qty, 3.0) #testing bin requested qty after issuing stock against material request