From 18bed504dc4a4d2a9a458adae2a455ad160b60cc Mon Sep 17 00:00:00 2001 From: Shreya Date: Wed, 27 Jun 2018 15:14:43 +0530 Subject: [PATCH] Set target qty 0 If the ordered qty exceeds the quantity in blanket order items, on routing to a new Purchase order or Sales order, set target qty as 0 to avoid negative qty. --- .../doctype/blanket_order/blanket_order.py | 7 ++++-- .../blanket_order/test_blanket_order.js | 23 +++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 erpnext/manufacturing/doctype/blanket_order/test_blanket_order.js diff --git a/erpnext/manufacturing/doctype/blanket_order/blanket_order.py b/erpnext/manufacturing/doctype/blanket_order/blanket_order.py index 5381abfe0a..822c7fcc1a 100644 --- a/erpnext/manufacturing/doctype/blanket_order/blanket_order.py +++ b/erpnext/manufacturing/doctype/blanket_order/blanket_order.py @@ -4,6 +4,7 @@ from __future__ import unicode_literals import frappe +from frappe.utils import flt from frappe.model.document import Document from frappe.model.mapper import get_mapped_doc from erpnext.stock.doctype.item.item import get_item_defaults @@ -28,7 +29,8 @@ class BlanketOrder(Document): @frappe.whitelist() def make_sales_order(source_name): def update_item(source, target, source_parent): - target.qty = source.get("qty") - source.get("ordered_qty") + target_qty = source.get("qty") - source.get("ordered_qty") + target.qty = target_qty if not flt(target_qty) < 0 else 0 item = get_item_defaults(target.item_code, source_parent.company) if item: target.item_name = item.get("item_name") @@ -53,7 +55,8 @@ def make_sales_order(source_name): @frappe.whitelist() def make_purchase_order(source_name): def update_item(source, target, source_parent): - target.qty = source.get("qty") - source.get("ordered_qty") + target_qty = source.get("qty") - source.get("ordered_qty") + target.qty = target_qty if not flt(target_qty) < 0 else 0 item = get_item_defaults(target.item_code, source_parent.company) if item: target.item_name = item.get("item_name") diff --git a/erpnext/manufacturing/doctype/blanket_order/test_blanket_order.js b/erpnext/manufacturing/doctype/blanket_order/test_blanket_order.js new file mode 100644 index 0000000000..51a0d94841 --- /dev/null +++ b/erpnext/manufacturing/doctype/blanket_order/test_blanket_order.js @@ -0,0 +1,23 @@ +/* eslint-disable */ +// rename this file from _test_[name] to test_[name] to activate +// and remove above this line + +QUnit.test("test: Blanket Order", function (assert) { + let done = assert.async(); + + // number of asserts + assert.expect(1); + + frappe.run_serially([ + // insert a new Blanket Order + () => frappe.tests.make('Blanket Order', [ + // values to be set + {key: 'value'} + ]), + () => { + assert.equal(cur_frm.doc.key, 'value'); + }, + () => done() + ]); + +});