From 0c8411d085b9f0f6e3db645d24ae90503631d313 Mon Sep 17 00:00:00 2001 From: Anurag Mishra Date: Fri, 28 Dec 2018 16:53:00 +0530 Subject: [PATCH 1/2] test cases sucess --- erpnext/controllers/stock_controller.py | 20 +++++++++++-------- .../setup/doctype/item_group/item_group.py | 2 +- .../test_quality_inspection.py | 13 +++++++++--- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py index 63e89ab6e3..5ea3dee216 100644 --- a/erpnext/controllers/stock_controller.py +++ b/erpnext/controllers/stock_controller.py @@ -14,6 +14,7 @@ from erpnext.stock import get_warehouse_account_map class QualityInspectionRequiredError(frappe.ValidationError): pass class QualityInspectionRejectedError(frappe.ValidationError): pass +class QualityInspectionNotSubmittedError(frappe.ValidationError): pass class StockController(AccountsController): def validate(self): @@ -338,18 +339,21 @@ class StockController(AccountsController): qa_required = True elif self.doctype == "Stock Entry" and not d.quality_inspection and d.t_warehouse: qa_required = True + if self.docstatus == 1 and d.quality_inspection: + qa_doc = frappe.get_doc("Quality Inspection", d.quality_inspection) + if qa_doc.docstatus == 0: + link = frappe.utils.get_link_to_form('Quality Inspection', d.quality_inspection) + frappe.msgprint(_("Quality Inspection: {0} is not submitted for the item: {1} in row {2}").format(link, d.item_code, d.idx)) + raise QualityInspectionNotSubmittedError - if qa_required: + qa_failed = any([r.status=="Rejected" for r in qa_doc.readings]) + if qa_failed: + frappe.throw(_("Row {0}: Quality Inspection rejected for item {1}") + .format(d.idx, d.item_code), QualityInspectionRejectedError) + elif qa_required : frappe.msgprint(_("Quality Inspection required for Item {0}").format(d.item_code)) if self.docstatus==1: raise QualityInspectionRequiredError - elif self.docstatus == 1: - if d.quality_inspection: - qa_doc = frappe.get_doc("Quality Inspection", d.quality_inspection) - qa_failed = any([r.status=="Rejected" for r in qa_doc.readings]) - if qa_failed: - frappe.throw(_("Row {0}: Quality Inspection rejected for item {1}") - .format(d.idx, d.item_code), QualityInspectionRejectedError) def update_blanket_order(self): diff --git a/erpnext/setup/doctype/item_group/item_group.py b/erpnext/setup/doctype/item_group/item_group.py index 6bc9036195..2c185019eb 100644 --- a/erpnext/setup/doctype/item_group/item_group.py +++ b/erpnext/setup/doctype/item_group/item_group.py @@ -147,7 +147,7 @@ def adjust_qty_for_expired_items(data): if item.get('has_batch_no') and item.get('website_warehouse'): stock_qty_dict = get_qty_in_stock( item.get('name'), 'website_warehouse', item.get('website_warehouse')) - qty = stock_qty_dict.stock_qty[0][0] + qty = stock_qty_dict.stock_qty[0][0] if stock_qty_dict.stock_qty else 0 item['in_stock'] = 1 if qty else 0 adjusted_data.append(item) diff --git a/erpnext/stock/doctype/quality_inspection/test_quality_inspection.py b/erpnext/stock/doctype/quality_inspection/test_quality_inspection.py index 60cc9a0972..0f0b4016e2 100644 --- a/erpnext/stock/doctype/quality_inspection/test_quality_inspection.py +++ b/erpnext/stock/doctype/quality_inspection/test_quality_inspection.py @@ -6,7 +6,7 @@ import unittest from frappe.utils import nowdate from erpnext.stock.doctype.item.test_item import create_item from erpnext.stock.doctype.delivery_note.test_delivery_note import create_delivery_note -from erpnext.controllers.stock_controller import QualityInspectionRejectedError, QualityInspectionRequiredError +from erpnext.controllers.stock_controller import QualityInspectionRejectedError, QualityInspectionRequiredError, QualityInspectionNotSubmittedError # test_records = frappe.get_test_records('Quality Inspection') @@ -19,7 +19,7 @@ class TestQualityInspection(unittest.TestCase): dn = create_delivery_note(item_code="_Test Item with QA", do_not_submit=True) self.assertRaises(QualityInspectionRequiredError, dn.submit) - qa = create_quality_inspection(reference_type="Delivery Note", reference_name=dn.name, status="Rejected") + qa = create_quality_inspection(reference_type="Delivery Note", reference_name=dn.name, status="Rejected", submit=True) dn.reload() self.assertRaises(QualityInspectionRejectedError, dn.submit) @@ -27,6 +27,12 @@ class TestQualityInspection(unittest.TestCase): dn.reload() dn.submit() + def test_qa_not_submit(self): + dn = create_delivery_note(item_code="_Test Item with QA", do_not_submit=True) + qa = create_quality_inspection(reference_type="Delivery Note", reference_name=dn.name, submit = False) + dn.items[0].quality_inspection = qa.name + self.assertRaises(QualityInspectionNotSubmittedError, dn.submit) + def create_quality_inspection(**args): args = frappe._dict(args) qa = frappe.new_doc("Quality Inspection") @@ -42,6 +48,7 @@ def create_quality_inspection(**args): "status": args.status }) qa.save() - qa.submit() + if args.submit: + qa.submit() return qa From 0885485a61d760f096bf25692722d6d4555de59f Mon Sep 17 00:00:00 2001 From: Anurag Mishra <32095923+Anurag810@users.noreply.github.com> Date: Tue, 1 Jan 2019 15:00:16 +0530 Subject: [PATCH 2/2] changes --- erpnext/controllers/stock_controller.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py index 5ea3dee216..0b19b7aaf9 100644 --- a/erpnext/controllers/stock_controller.py +++ b/erpnext/controllers/stock_controller.py @@ -343,8 +343,7 @@ class StockController(AccountsController): qa_doc = frappe.get_doc("Quality Inspection", d.quality_inspection) if qa_doc.docstatus == 0: link = frappe.utils.get_link_to_form('Quality Inspection', d.quality_inspection) - frappe.msgprint(_("Quality Inspection: {0} is not submitted for the item: {1} in row {2}").format(link, d.item_code, d.idx)) - raise QualityInspectionNotSubmittedError + frappe.throw(_("Quality Inspection: {0} is not submitted for the item: {1} in row {2}").format(link, d.item_code, d.idx), QualityInspectionNotSubmittedError) qa_failed = any([r.status=="Rejected" for r in qa_doc.readings]) if qa_failed: @@ -432,4 +431,4 @@ def get_voucherwise_gl_entries(future_stock_vouchers, posting_date): tuple([posting_date] + [d[1] for d in future_stock_vouchers]), as_dict=1): gl_entries.setdefault((d.voucher_type, d.voucher_no), []).append(d) - return gl_entries \ No newline at end of file + return gl_entries