test: move bundle info to class variables
This commit is contained in:
parent
1022db0474
commit
853e658dcc
@ -5,6 +5,7 @@ from erpnext.selling.doctype.product_bundle.test_product_bundle import make_prod
|
|||||||
from erpnext.selling.doctype.sales_order.sales_order import make_delivery_note
|
from erpnext.selling.doctype.sales_order.sales_order import make_delivery_note
|
||||||
from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order
|
from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order
|
||||||
from erpnext.stock.doctype.item.test_item import make_item
|
from erpnext.stock.doctype.item.test_item import make_item
|
||||||
|
from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry
|
||||||
from erpnext.tests.utils import ERPNextTestCase, change_settings
|
from erpnext.tests.utils import ERPNextTestCase, change_settings
|
||||||
|
|
||||||
|
|
||||||
@ -12,31 +13,29 @@ class TestPackedItem(ERPNextTestCase):
|
|||||||
"Test impact on Packed Items table in various scenarios."
|
"Test impact on Packed Items table in various scenarios."
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls) -> None:
|
def setUpClass(cls) -> None:
|
||||||
make_item("_Test Product Bundle X", {"is_stock_item": 0})
|
cls.bundle = "_Test Product Bundle X"
|
||||||
make_item("_Test Bundle Item 1", {"is_stock_item": 1})
|
cls.bundle_items = ["_Test Bundle Item 1", "_Test Bundle Item 2"]
|
||||||
make_item("_Test Bundle Item 2", {"is_stock_item": 1})
|
make_item(cls.bundle, {"is_stock_item": 0})
|
||||||
|
for item in cls.bundle_items:
|
||||||
|
make_item(item, {"is_stock_item": 1})
|
||||||
|
|
||||||
make_item("_Test Normal Stock Item", {"is_stock_item": 1})
|
make_item("_Test Normal Stock Item", {"is_stock_item": 1})
|
||||||
|
|
||||||
make_product_bundle(
|
make_product_bundle(cls.bundle, cls.bundle_items, qty=2)
|
||||||
"_Test Product Bundle X",
|
|
||||||
["_Test Bundle Item 1", "_Test Bundle Item 2"],
|
|
||||||
qty=2
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_adding_bundle_item(self):
|
def test_adding_bundle_item(self):
|
||||||
"Test impact on packed items if bundle item row is added."
|
"Test impact on packed items if bundle item row is added."
|
||||||
so = make_sales_order(item_code = "_Test Product Bundle X", qty=1,
|
so = make_sales_order(item_code = self.bundle, qty=1,
|
||||||
do_not_submit=True)
|
do_not_submit=True)
|
||||||
|
|
||||||
self.assertEqual(so.items[0].qty, 1)
|
self.assertEqual(so.items[0].qty, 1)
|
||||||
self.assertEqual(len(so.packed_items), 2)
|
self.assertEqual(len(so.packed_items), 2)
|
||||||
self.assertEqual(so.packed_items[0].item_code, "_Test Bundle Item 1")
|
self.assertEqual(so.packed_items[0].item_code, self.bundle_items[0])
|
||||||
self.assertEqual(so.packed_items[0].qty, 2)
|
self.assertEqual(so.packed_items[0].qty, 2)
|
||||||
|
|
||||||
def test_updating_bundle_item(self):
|
def test_updating_bundle_item(self):
|
||||||
"Test impact on packed items if bundle item row is updated."
|
"Test impact on packed items if bundle item row is updated."
|
||||||
so = make_sales_order(item_code = "_Test Product Bundle X", qty=1,
|
so = make_sales_order(item_code=self.bundle, qty=1, do_not_submit=True)
|
||||||
do_not_submit=True)
|
|
||||||
|
|
||||||
so.items[0].qty = 2 # change qty
|
so.items[0].qty = 2 # change qty
|
||||||
so.save()
|
so.save()
|
||||||
@ -55,7 +54,7 @@ class TestPackedItem(ERPNextTestCase):
|
|||||||
so_items = []
|
so_items = []
|
||||||
for qty in [2, 4, 6, 8]:
|
for qty in [2, 4, 6, 8]:
|
||||||
so_items.append({
|
so_items.append({
|
||||||
"item_code": "_Test Product Bundle X",
|
"item_code": self.bundle,
|
||||||
"qty": qty,
|
"qty": qty,
|
||||||
"rate": 400,
|
"rate": 400,
|
||||||
"warehouse": "_Test Warehouse - _TC"
|
"warehouse": "_Test Warehouse - _TC"
|
||||||
@ -66,7 +65,7 @@ class TestPackedItem(ERPNextTestCase):
|
|||||||
|
|
||||||
# check alternate rows for qty
|
# check alternate rows for qty
|
||||||
self.assertEqual(len(so.packed_items), 8)
|
self.assertEqual(len(so.packed_items), 8)
|
||||||
self.assertEqual(so.packed_items[1].item_code, "_Test Bundle Item 2")
|
self.assertEqual(so.packed_items[1].item_code, self.bundle_items[1])
|
||||||
self.assertEqual(so.packed_items[1].qty, 4)
|
self.assertEqual(so.packed_items[1].qty, 4)
|
||||||
self.assertEqual(so.packed_items[3].qty, 8)
|
self.assertEqual(so.packed_items[3].qty, 8)
|
||||||
self.assertEqual(so.packed_items[5].qty, 12)
|
self.assertEqual(so.packed_items[5].qty, 12)
|
||||||
@ -94,8 +93,7 @@ class TestPackedItem(ERPNextTestCase):
|
|||||||
@change_settings("Selling Settings", {"editable_bundle_item_rates": 1})
|
@change_settings("Selling Settings", {"editable_bundle_item_rates": 1})
|
||||||
def test_bundle_item_cumulative_price(self):
|
def test_bundle_item_cumulative_price(self):
|
||||||
"Test if Bundle Item rate is cumulative from packed items."
|
"Test if Bundle Item rate is cumulative from packed items."
|
||||||
so = make_sales_order(item_code = "_Test Product Bundle X", qty=2,
|
so = make_sales_order(item_code=self.bundle, qty=2, do_not_submit=True)
|
||||||
do_not_submit=True)
|
|
||||||
|
|
||||||
so.packed_items[0].rate = 150
|
so.packed_items[0].rate = 150
|
||||||
so.packed_items[1].rate = 200
|
so.packed_items[1].rate = 200
|
||||||
@ -109,7 +107,7 @@ class TestPackedItem(ERPNextTestCase):
|
|||||||
so_items = []
|
so_items = []
|
||||||
for qty in [2, 4]:
|
for qty in [2, 4]:
|
||||||
so_items.append({
|
so_items.append({
|
||||||
"item_code": "_Test Product Bundle X",
|
"item_code": self.bundle,
|
||||||
"qty": qty,
|
"qty": qty,
|
||||||
"rate": 400,
|
"rate": 400,
|
||||||
"warehouse": "_Test Warehouse - _TC"
|
"warehouse": "_Test Warehouse - _TC"
|
||||||
|
Loading…
Reference in New Issue
Block a user