test: Packed Items test file
This commit is contained in:
parent
2f4d266ee1
commit
4e7b4dc9a8
104
erpnext/stock/doctype/packed_item/test_packed_item.py
Normal file
104
erpnext/stock/doctype/packed_item/test_packed_item.py
Normal file
@ -0,0 +1,104 @@
|
||||
# Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and Contributors
|
||||
# License: GNU General Public License v3. See license.txt
|
||||
|
||||
from erpnext.stock.doctype.item.test_item import make_item
|
||||
from erpnext.selling.doctype.product_bundle.test_product_bundle import make_product_bundle
|
||||
from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order
|
||||
from erpnext.tests.utils import ERPNextTestCase, change_settings
|
||||
|
||||
|
||||
class TestPackedItem(ERPNextTestCase):
|
||||
"Test impact on Packed Items table in various scenarios."
|
||||
@classmethod
|
||||
def setUpClass(cls) -> None:
|
||||
make_item("_Test Product Bundle X", {"is_stock_item": 0})
|
||||
make_item("_Test Bundle Item 1", {"is_stock_item": 1})
|
||||
make_item("_Test Bundle Item 2", {"is_stock_item": 1})
|
||||
make_item("_Test Normal Stock Item", {"is_stock_item": 1})
|
||||
|
||||
make_product_bundle(
|
||||
"_Test Product Bundle X",
|
||||
["_Test Bundle Item 1", "_Test Bundle Item 2"],
|
||||
qty=2
|
||||
)
|
||||
|
||||
def test_sales_order_adding_bundle_item(self):
|
||||
"Test impact on packed items if bundle item row is added."
|
||||
so = make_sales_order(item_code = "_Test Product Bundle X", qty=1,
|
||||
do_not_submit=True)
|
||||
|
||||
self.assertEqual(so.items[0].qty, 1)
|
||||
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].qty, 2)
|
||||
|
||||
def test_sales_order_updating_bundle_item(self):
|
||||
"Test impact on packed items if bundle item row is updated."
|
||||
so = make_sales_order(item_code = "_Test Product Bundle X", qty=1,
|
||||
do_not_submit=True)
|
||||
|
||||
so.items[0].qty = 2 # change qty
|
||||
so.save()
|
||||
|
||||
self.assertEqual(so.packed_items[0].qty, 4)
|
||||
self.assertEqual(so.packed_items[1].qty, 4)
|
||||
|
||||
# change item code to non bundle item
|
||||
so.items[0].item_code = "_Test Normal Stock Item"
|
||||
so.save()
|
||||
|
||||
self.assertEqual(len(so.packed_items), 0)
|
||||
|
||||
def test_sales_order_recurring_bundle_item(self):
|
||||
"Test impact on packed items if same bundle item is added and removed."
|
||||
so_items = []
|
||||
for qty in [2, 4, 6, 8]:
|
||||
so_items.append({
|
||||
"item_code": "_Test Product Bundle X",
|
||||
"qty": qty,
|
||||
"rate": 400,
|
||||
"warehouse": "_Test Warehouse - _TC"
|
||||
})
|
||||
|
||||
# create SO with recurring bundle item
|
||||
so = make_sales_order(item_list=so_items, do_not_submit=True)
|
||||
|
||||
# check alternate rows for qty
|
||||
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].qty, 4)
|
||||
self.assertEqual(so.packed_items[3].qty, 8)
|
||||
self.assertEqual(so.packed_items[5].qty, 12)
|
||||
self.assertEqual(so.packed_items[7].qty, 16)
|
||||
|
||||
# delete intermediate row (2nd)
|
||||
del so.items[1]
|
||||
so.save()
|
||||
|
||||
# check alternate rows for qty
|
||||
self.assertEqual(len(so.packed_items), 6)
|
||||
self.assertEqual(so.packed_items[1].qty, 4)
|
||||
self.assertEqual(so.packed_items[3].qty, 12)
|
||||
self.assertEqual(so.packed_items[5].qty, 16)
|
||||
|
||||
# delete last row
|
||||
del so.items[2]
|
||||
so.save()
|
||||
|
||||
# check alternate rows for qty
|
||||
self.assertEqual(len(so.packed_items), 4)
|
||||
self.assertEqual(so.packed_items[1].qty, 4)
|
||||
self.assertEqual(so.packed_items[3].qty, 12)
|
||||
|
||||
@change_settings("Selling Settings", {"editable_bundle_item_rates": 1})
|
||||
def test_sales_order_bundle_item_cumulative_price(self):
|
||||
"Test if Bundle Item rate is cumulative from packed items."
|
||||
so = make_sales_order(item_code = "_Test Product Bundle X", qty=2,
|
||||
do_not_submit=True)
|
||||
|
||||
so.packed_items[0].rate = 150
|
||||
so.packed_items[1].rate = 200
|
||||
so.save()
|
||||
|
||||
self.assertEqual(so.items[0].rate, 350)
|
||||
self.assertEqual(so.items[0].amount, 700)
|
Loading…
x
Reference in New Issue
Block a user