[fix] Validate transfer qty cannot be greater than qty

This commit is contained in:
Anand Doshi 2015-12-17 12:31:51 +05:30
parent 824122c42a
commit 0f809426d2
4 changed files with 21 additions and 17 deletions

View File

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

View File

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

View File

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

View File

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