Skip to content

Commit

Permalink
test: product bundle fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
ankush committed Apr 27, 2022
1 parent 1ac275c commit ee54ece
Showing 1 changed file with 26 additions and 16 deletions.
42 changes: 26 additions & 16 deletions erpnext/stock/doctype/packed_item/test_packed_item.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,50 @@
# Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt

from typing import List, Optional, Tuple

import frappe
from frappe.tests.utils import FrappeTestCase, change_settings
from frappe.utils import add_to_date, nowdate

from erpnext.selling.doctype.product_bundle.test_product_bundle import make_product_bundle
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.stock.doctype.item.test_item import make_item
from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import get_gl_entries
from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry


def create_product_bundle(quantities: Optional[List[int]] = None) -> Tuple[str, List[str]]:
"""Get a new product_bundle for use in tests"""
if not quantities:
quantities = [2, 2]

bundle = make_item(properties={"is_stock_item": 0}).name

bundle_doc = frappe.get_doc({"doctype": "Product Bundle", "new_item_code": bundle})

components = []
for qty in quantities:
compoenent = make_item().name
components.append(compoenent)
bundle_doc.append("items", {"item_code": compoenent, "qty": qty})

bundle_doc.insert()
return bundle, components


class TestPackedItem(FrappeTestCase):
"Test impact on Packed Items table in various scenarios."

@classmethod
def setUpClass(cls) -> None:
super().setUpClass()
cls.warehouse = "_Test Warehouse - _TC"
cls.bundle = "_Test Product Bundle X"
cls.bundle_items = ["_Test Bundle Item 1", "_Test Bundle Item 2"]

cls.bundle2 = "_Test Product Bundle Y"
cls.bundle2_items = ["_Test Bundle Item 3", "_Test Bundle Item 4"]

make_item(cls.bundle, {"is_stock_item": 0})
make_item(cls.bundle2, {"is_stock_item": 0})
for item in cls.bundle_items + cls.bundle2_items:
make_item(item, {"is_stock_item": 1})

make_item("_Test Normal Stock Item", {"is_stock_item": 1})

make_product_bundle(cls.bundle, cls.bundle_items, qty=2)
make_product_bundle(cls.bundle2, cls.bundle2_items, qty=2)
cls.bundle, cls.bundle_items = create_product_bundle()
cls.bundle2, cls.bundle2_items = create_product_bundle()

cls.normal_item = make_item().name
for item in cls.bundle_items + cls.bundle2_items:
make_stock_entry(item_code=item, to_warehouse=cls.warehouse, qty=100, rate=100)

Expand All @@ -58,7 +68,7 @@ def test_updating_bundle_item(self):
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.items[0].item_code = self.normal_item
so.save()

self.assertEqual(len(so.packed_items), 0)
Expand Down

0 comments on commit ee54ece

Please sign in to comment.