mirror of
https://github.com/frappe/erpnext.git
synced 2026-02-17 08:35:00 +00:00
test: Zero Qty in RFQ and Supplier Quotation
(cherry picked from commit 8f96c0b546)
# Conflicts:
# erpnext/buying/doctype/request_for_quotation/test_request_for_quotation.py
# erpnext/buying/doctype/supplier_quotation/test_supplier_quotation.py
This commit is contained in:
@@ -5,7 +5,11 @@
|
||||
from urllib.parse import urlparse
|
||||
|
||||
import frappe
|
||||
<<<<<<< HEAD
|
||||
from frappe.tests.utils import FrappeTestCase
|
||||
=======
|
||||
from frappe.tests import IntegrationTestCase, UnitTestCase, change_settings
|
||||
>>>>>>> 8f96c0b546 (test: Zero Qty in RFQ and Supplier Quotation)
|
||||
from frappe.utils import nowdate
|
||||
|
||||
from erpnext.buying.doctype.request_for_quotation.request_for_quotation import (
|
||||
@@ -20,7 +24,39 @@ from erpnext.stock.doctype.item.test_item import make_item
|
||||
from erpnext.templates.pages.rfq import check_supplier_has_docname_access
|
||||
|
||||
|
||||
<<<<<<< HEAD
|
||||
class TestRequestforQuotation(FrappeTestCase):
|
||||
=======
|
||||
class UnitTestRequestForQuotation(UnitTestCase):
|
||||
"""
|
||||
Unit tests for RequestForQuotation.
|
||||
Use this class for testing individual functions and methods.
|
||||
"""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class TestRequestforQuotation(IntegrationTestCase):
|
||||
def test_rfq_qty(self):
|
||||
rfq = make_request_for_quotation(qty=0, do_not_save=True)
|
||||
with self.assertRaises(InvalidQtyError):
|
||||
rfq.save()
|
||||
|
||||
# No error with qty=1
|
||||
rfq.items[0].qty = 1
|
||||
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()
|
||||
|
||||
>>>>>>> 8f96c0b546 (test: Zero Qty in RFQ and Supplier Quotation)
|
||||
def test_quote_status(self):
|
||||
rfq = make_request_for_quotation()
|
||||
|
||||
@@ -161,6 +197,15 @@ class TestRequestforQuotation(FrappeTestCase):
|
||||
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":
|
||||
"""
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
|
||||
import frappe
|
||||
<<<<<<< HEAD
|
||||
from frappe.tests.utils import FrappeTestCase
|
||||
from frappe.utils import add_days, today
|
||||
|
||||
@@ -12,6 +13,47 @@ class TestPurchaseOrder(FrappeTestCase):
|
||||
from erpnext.buying.doctype.supplier_quotation.supplier_quotation import make_purchase_order
|
||||
|
||||
sq = frappe.copy_doc(test_records[0]).insert()
|
||||
=======
|
||||
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
|
||||
|
||||
|
||||
class UnitTestSupplierQuotation(UnitTestCase):
|
||||
"""
|
||||
Unit tests for SupplierQuotation.
|
||||
Use this class for testing individual functions and methods.
|
||||
"""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class TestPurchaseOrder(IntegrationTestCase):
|
||||
def test_supplier_quotation_qty(self):
|
||||
sq = frappe.copy_doc(self.globalTestRecords["Supplier Quotation"][0])
|
||||
sq.items[0].qty = 0
|
||||
with self.assertRaises(InvalidQtyError):
|
||||
sq.save()
|
||||
|
||||
# No error with qty=1
|
||||
sq.items[0].qty = 1
|
||||
sq.save()
|
||||
self.assertEqual(sq.items[0].qty, 1)
|
||||
|
||||
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()
|
||||
>>>>>>> 8f96c0b546 (test: Zero Qty in RFQ and Supplier Quotation)
|
||||
|
||||
self.assertRaises(frappe.ValidationError, make_purchase_order, sq.name)
|
||||
|
||||
@@ -30,5 +72,18 @@ class TestPurchaseOrder(FrappeTestCase):
|
||||
|
||||
po.insert()
|
||||
|
||||
<<<<<<< HEAD
|
||||
|
||||
test_records = frappe.get_test_records("Supplier Quotation")
|
||||
=======
|
||||
@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)
|
||||
>>>>>>> 8f96c0b546 (test: Zero Qty in RFQ and Supplier Quotation)
|
||||
|
||||
Reference in New Issue
Block a user