From f9ced8f28fc8d8a29305ab6db4e80e4f4cb4a122 Mon Sep 17 00:00:00 2001 From: Neil Trini Lasrado Date: Fri, 31 Oct 2014 17:22:47 +0530 Subject: [PATCH] test-cases added --- .../material_request/material_request.py | 12 ++++------- .../material_request/test_material_request.py | 21 ++++++++++++++----- .../stock/doctype/stock_entry/stock_entry.py | 3 ++- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/erpnext/stock/doctype/material_request/material_request.py b/erpnext/stock/doctype/material_request/material_request.py index efb3edd73f..80c61ab842 100644 --- a/erpnext/stock/doctype/material_request/material_request.py +++ b/erpnext/stock/doctype/material_request/material_request.py @@ -293,22 +293,19 @@ def make_supplier_quotation(source_name, target_doc=None): @frappe.whitelist() def make_stock_entry(source_name, target_doc=None): - - obj = frappe.get_doc("Material Request", source_name) - def update_item(obj, target, source_parent): target.conversion_factor = 1 target.qty = flt(obj.qty) - flt(obj.ordered_qty) target.transfer_qty = flt(obj.qty) - flt(obj.ordered_qty) + if source_parent.material_request_type == "Material Transfer": + target.t_warehouse = obj.warehouse + else: + target.s_warehouse = obj.warehouse def set_missing_values(source, target): target.purpose = source.material_request_type target.run_method("get_stock_and_rate") - if obj.material_request_type=="Material Issue": - warehouse = "s_warehouse" - else: - warehouse = "t_warehouse" doclist = get_mapped_doc("Material Request", source_name, { "Material Request": { "doctype": "Stock Entry", @@ -323,7 +320,6 @@ def make_stock_entry(source_name, target_doc=None): "name": "material_request_item", "parent": "material_request", "uom": "stock_uom", - "warehouse": warehouse }, "postprocess": update_item } diff --git a/erpnext/stock/doctype/material_request/test_material_request.py b/erpnext/stock/doctype/material_request/test_material_request.py index ab1d3ccd95..753c5b19a9 100644 --- a/erpnext/stock/doctype/material_request/test_material_request.py +++ b/erpnext/stock/doctype/material_request/test_material_request.py @@ -51,7 +51,7 @@ class TestMaterialRequest(unittest.TestCase): mr.name) mr = frappe.get_doc("Material Request", mr.name) - mr.material_request_type = "Transfer" + mr.material_request_type = "Material Transfer" mr.submit() se = make_stock_entry(mr.name) @@ -168,7 +168,7 @@ class TestMaterialRequest(unittest.TestCase): # submit material request of type Purchase mr = frappe.copy_doc(test_records[0]) - mr.material_request_type = "Transfer" + mr.material_request_type = "Material Transfer" mr.insert() mr.submit() @@ -257,7 +257,7 @@ class TestMaterialRequest(unittest.TestCase): # submit material request of type Purchase mr = frappe.copy_doc(test_records[0]) - mr.material_request_type = "Transfer" + mr.material_request_type = "Material Transfer" mr.insert() mr.submit() @@ -330,9 +330,9 @@ class TestMaterialRequest(unittest.TestCase): self.assertEquals(current_requested_qty_item2, existing_requested_qty_item2 + 3.0) def test_incorrect_mapping_of_stock_entry(self): - # submit material request of type Purchase + # submit material request of type Transfer mr = frappe.copy_doc(test_records[0]) - mr.material_request_type = "Transfer" + mr.material_request_type = "Material Transfer" mr.insert() mr.submit() @@ -363,6 +363,17 @@ class TestMaterialRequest(unittest.TestCase): se = frappe.copy_doc(se_doc) self.assertRaises(frappe.MappingMismatchError, se.insert) + # submit material request of type Transfer + mr = frappe.copy_doc(test_records[0]) + mr.material_request_type = "Material Issue" + mr.insert() + mr.submit() + + # map a stock entry + from erpnext.stock.doctype.material_request.material_request import make_stock_entry + se_doc = make_stock_entry(mr.name) + self.assertEquals(se_doc.get("mtn_details")[0].s_warehouse, "_Test Warehouse - _TC") + def test_warehouse_company_validation(self): from erpnext.stock.utils import InvalidWarehouseCompany mr = frappe.copy_doc(test_records[0]) diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py index d06a761075..839554a7f6 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/stock_entry.py @@ -625,7 +625,8 @@ class StockEntry(StockController): mreq_item = frappe.db.get_value("Material Request Item", {"name": item.material_request_item, "parent": item.material_request}, ["item_code", "warehouse", "idx"], as_dict=True) - if mreq_item.item_code != item.item_code or mreq_item.warehouse != item.t_warehouse: + if mreq_item.item_code != item.item_code or \ + mreq_item.warehouse != (item.s_warehouse if self.purpose== "Material Issue" else item.t_warehouse): frappe.throw(_("Item or Warehouse for row {0} does not match Material Request").format(item.idx), frappe.MappingMismatchError)