From 8f96c0b5461488dbe2739d5d8e65d42a44b3b301 Mon Sep 17 00:00:00 2001 From: marination <25857446+marination@users.noreply.github.com> Date: Wed, 12 Mar 2025 18:32:59 +0100 Subject: [PATCH] test: Zero Qty in RFQ and Supplier Quotation --- .../test_request_for_quotation.py | 20 +++++++++++++- .../test_supplier_quotation.py | 26 ++++++++++++++++--- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/erpnext/buying/doctype/request_for_quotation/test_request_for_quotation.py b/erpnext/buying/doctype/request_for_quotation/test_request_for_quotation.py index 63d995f562b..038a7640059 100644 --- a/erpnext/buying/doctype/request_for_quotation/test_request_for_quotation.py +++ b/erpnext/buying/doctype/request_for_quotation/test_request_for_quotation.py @@ -5,7 +5,7 @@ from urllib.parse import urlparse import frappe -from frappe.tests import IntegrationTestCase, UnitTestCase +from frappe.tests import IntegrationTestCase, UnitTestCase, change_settings from frappe.utils import nowdate from erpnext.buying.doctype.request_for_quotation.request_for_quotation import ( @@ -41,6 +41,15 @@ class TestRequestforQuotation(IntegrationTestCase): rfq.save() self.assertEqual(rfq.items[0].qty, 1) + def test_rfq_zero_qty(self): + """ + Test if RFQ with zero qty (Unit Price Item) is conditionally allowed. + """ + rfq = make_request_for_quotation(qty=0, do_not_save=True) + + with change_settings("Buying Settings", {"allow_zero_qty_in_request_for_quotation": 1}): + rfq.save() + def test_quote_status(self): rfq = make_request_for_quotation() @@ -181,6 +190,15 @@ class TestRequestforQuotation(IntegrationTestCase): supplier_doc.reload() self.assertTrue(supplier_doc.portal_users[0].user) + @change_settings("Buying Settings", {"allow_zero_qty_in_request_for_quotation": 1}) + def test_map_supplier_quotation_from_zero_qty_rfq(self): + rfq = make_request_for_quotation(qty=0) + sq = make_supplier_quotation_from_rfq(rfq.name, for_supplier=rfq.get("suppliers")[0].supplier) + + self.assertEqual(len(sq.items), 1) + self.assertEqual(sq.items[0].qty, 0) + self.assertEqual(sq.items[0].item_code, rfq.items[0].item_code) + def make_request_for_quotation(**args) -> "RequestforQuotation": """ diff --git a/erpnext/buying/doctype/supplier_quotation/test_supplier_quotation.py b/erpnext/buying/doctype/supplier_quotation/test_supplier_quotation.py index dad2cba4877..d1f03586a36 100644 --- a/erpnext/buying/doctype/supplier_quotation/test_supplier_quotation.py +++ b/erpnext/buying/doctype/supplier_quotation/test_supplier_quotation.py @@ -3,8 +3,9 @@ import frappe -from frappe.tests import IntegrationTestCase, UnitTestCase +from frappe.tests import IntegrationTestCase, UnitTestCase, change_settings +from erpnext.buying.doctype.supplier_quotation.supplier_quotation import make_purchase_order from erpnext.controllers.accounts_controller import InvalidQtyError @@ -29,9 +30,17 @@ class TestPurchaseOrder(IntegrationTestCase): sq.save() self.assertEqual(sq.items[0].qty, 1) - def test_make_purchase_order(self): - from erpnext.buying.doctype.supplier_quotation.supplier_quotation import make_purchase_order + def test_supplier_quotation_zero_qty(self): + """ + Test if RFQ with zero qty (Unit Price Item) is conditionally allowed. + """ + sq = frappe.copy_doc(self.globalTestRecords["Supplier Quotation"][0]) + sq.items[0].qty = 0 + with change_settings("Buying Settings", {"allow_zero_qty_in_supplier_quotation": 1}): + sq.save() + + def test_make_purchase_order(self): sq = frappe.copy_doc(self.globalTestRecords["Supplier Quotation"][0]).insert() self.assertRaises(frappe.ValidationError, make_purchase_order, sq.name) @@ -50,3 +59,14 @@ class TestPurchaseOrder(IntegrationTestCase): doc.set("schedule_date", "2013-04-12") po.insert() + + @change_settings("Buying Settings", {"allow_zero_qty_in_supplier_quotation": 1}) + def test_map_purchase_order_from_zero_qty_supplier_quotation(self): + sq = frappe.copy_doc(self.globalTestRecords["Supplier Quotation"][0]) + sq.items[0].qty = 0 + sq.submit() + + po = make_purchase_order(sq.name) + self.assertEqual(len(po.get("items")), 1) + self.assertEqual(po.get("items")[0].qty, 0) + self.assertEqual(po.get("items")[0].item_code, sq.get("items")[0].item_code)