diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py index 84bf6aa3c15..f674b69e1ab 100644 --- a/erpnext/controllers/stock_controller.py +++ b/erpnext/controllers/stock_controller.py @@ -1361,7 +1361,7 @@ def repost_required_for_queue(doc: StockController) -> bool: @frappe.whitelist() -def make_quality_inspections(doctype, docname, items): +def make_quality_inspections(doctype, docname, items, inspection_type): if isinstance(items, str): items = json.loads(items) @@ -1381,7 +1381,7 @@ def make_quality_inspections(doctype, docname, items): quality_inspection = frappe.get_doc( { "doctype": "Quality Inspection", - "inspection_type": "Incoming", + "inspection_type": inspection_type, "inspected_by": frappe.session.user, "reference_type": doctype, "reference_name": docname, diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index 261d557dc81..ce7dfc71a41 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -2203,6 +2203,8 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe ]; const me = this; + const inspection_type = ["Purchase Receipt", "Purchase Invoice", "Subcontracting Receipt"].includes(this.frm.doc.doctype) + ? "Incoming" : "Outgoing"; const dialog = new frappe.ui.Dialog({ title: __("Select Items for Quality Inspection"), size: "extra-large", @@ -2214,7 +2216,8 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe args: { doctype: me.frm.doc.doctype, docname: me.frm.doc.name, - items: data.items + items: data.items, + inspection_type: inspection_type }, freeze: true, callback: function (r) { diff --git a/erpnext/stock/doctype/quality_inspection/test_quality_inspection.py b/erpnext/stock/doctype/quality_inspection/test_quality_inspection.py index f59d7c3216b..9656a6252e7 100644 --- a/erpnext/stock/doctype/quality_inspection/test_quality_inspection.py +++ b/erpnext/stock/doctype/quality_inspection/test_quality_inspection.py @@ -138,9 +138,13 @@ class TestQualityInspection(FrappeTestCase): def test_make_quality_inspections_from_linked_document(self): dn = create_delivery_note(item_code="_Test Item with QA", do_not_submit=True) + if dn.doctype in ["Purchase Receipt", "Purchase Invoice", "Subcontracting Receipt"]: + inspection_type = "Incoming" + else: + inspection_type = "Outgoing" for item in dn.items: item.sample_size = item.qty - quality_inspections = make_quality_inspections(dn.doctype, dn.name, dn.items) + quality_inspections = make_quality_inspections(dn.doctype, dn.name, dn.items, inspection_type) self.assertEqual(len(dn.items), len(quality_inspections)) # cleanup