示例#1
0
	def test_product_bundle_mapping_on_creating_so(self):
		from erpnext.selling.doctype.product_bundle.test_product_bundle import make_product_bundle
		from erpnext.selling.doctype.quotation.quotation import make_sales_order
		from erpnext.stock.doctype.item.test_item import make_item

		make_item("_Test Product Bundle", {"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_product_bundle("_Test Product Bundle",
			["_Test Bundle Item 1", "_Test Bundle Item 2"])

		quotation = make_quotation(item_code="_Test Product Bundle", qty=1, rate=100)
		sales_order = make_sales_order(quotation.name)

		quotation_item = [quotation.items[0].item_code, quotation.items[0].rate, quotation.items[0].qty, quotation.items[0].amount]
		so_item = [sales_order.items[0].item_code, sales_order.items[0].rate, sales_order.items[0].qty, sales_order.items[0].amount]

		self.assertEqual(quotation_item, so_item)

		quotation_packed_items = [
			[quotation.packed_items[0].parent_item, quotation.packed_items[0].item_code, quotation.packed_items[0].qty],
			[quotation.packed_items[1].parent_item, quotation.packed_items[1].item_code, quotation.packed_items[1].qty]
		]
		so_packed_items = [
			[sales_order.packed_items[0].parent_item, sales_order.packed_items[0].item_code, sales_order.packed_items[0].qty],
			[sales_order.packed_items[1].parent_item, sales_order.packed_items[1].item_code, sales_order.packed_items[1].qty]
		]

		self.assertEqual(quotation_packed_items, so_packed_items)
示例#2
0
	def test_update_child_product_bundle(self):
		# test Update Items with product bundle
		if not frappe.db.exists("Item", "_Product Bundle Item"):
			bundle_item = make_item("_Product Bundle Item", {"is_stock_item": 0})
			bundle_item.append("item_defaults", {
					"company": "_Test Company",
					"default_warehouse": "_Test Warehouse - _TC"})
			bundle_item.save(ignore_permissions=True)

		make_item("_Packed Item", {"is_stock_item": 1})
		make_product_bundle("_Product Bundle Item", ["_Packed Item"], 2)

		so = make_sales_order(item_code = "_Test Item", warehouse=None)

		added_item = json.dumps([{"item_code" : "_Product Bundle Item", "rate" : 200, 'qty' : 2}])
		update_child_qty_rate('Sales Order', added_item, so.name)

		so.reload()
		self.assertEqual(so.packed_items[0].qty, 4)

		# test uom and conversion factor change
		update_uom_conv_factor = json.dumps([{
			'item_code': so.get("items")[0].item_code,
			'rate': so.get("items")[0].rate,
			'qty': so.get("items")[0].qty,
			'uom': "_Test UOM 1",
			'conversion_factor': 2,
			'docname': so.get("items")[0].name
		}])
		update_child_qty_rate('Sales Order', update_uom_conv_factor, so.name)

		so.reload()
		self.assertEqual(so.packed_items[0].qty, 8)
示例#3
0
    def test_delivery_note_bundle_with_batched_item(self):
        batched_bundle = make_item("_Test Batched bundle",
                                   {"is_stock_item": 0})
        batched_item = make_item(
            "_Test Batched Item",
            {
                "is_stock_item": 1,
                "has_batch_no": 1,
                "create_new_batch": 1,
                "batch_number_series": "TESTBATCH.#####",
            },
        )
        make_product_bundle(parent=batched_bundle.name,
                            items=[batched_item.name])
        make_stock_entry(item_code=batched_item.name,
                         target="_Test Warehouse - _TC",
                         qty=10,
                         basic_rate=42)

        try:
            dn = create_delivery_note(item_code=batched_bundle.name, qty=1)
        except frappe.ValidationError as e:
            if "batch" in str(e).lower():
                self.fail(
                    "Batch numbers not getting added to bundled items in DN.")
            raise e

        self.assertTrue("TESTBATCH" in dn.packed_items[0].batch_no,
                        "Batch number not added in packed item")
示例#4
0
    def test_item_merging_with_product_bundle(self):
        from erpnext.selling.doctype.product_bundle.test_product_bundle import make_product_bundle

        create_item("Test Item Bundle Item 1", is_stock_item=False)
        create_item("Test Item Bundle Item 2", is_stock_item=False)
        create_item("Test Item inside Bundle")
        bundle_items = ["Test Item inside Bundle"]

        # make bundles for both items
        bundle1 = make_product_bundle("Test Item Bundle Item 1",
                                      bundle_items,
                                      qty=2)
        make_product_bundle("Test Item Bundle Item 2", bundle_items, qty=2)

        with self.assertRaises(DataValidationError):
            frappe.rename_doc("Item",
                              "Test Item Bundle Item 1",
                              "Test Item Bundle Item 2",
                              merge=True)

        bundle1.delete()
        frappe.rename_doc("Item",
                          "Test Item Bundle Item 1",
                          "Test Item Bundle Item 2",
                          merge=True)

        self.assertFalse(frappe.db.exists("Item", "Test Item Bundle Item 1"))
示例#5
0
    def test_mix_type_product_bundle(self):
        from erpnext.stock.doctype.item.test_item import make_item
        from erpnext.selling.doctype.product_bundle.test_product_bundle import make_product_bundle

        make_item("_Test Mix Product Bundle", {
            "is_stock_item": 0,
            "is_pro_applicable": 0,
            "is_sales_item": 1
        })
        make_item("_Test Mix Product Bundle Item 1", {
            "is_stock_item": 1,
            "is_sales_item": 1
        })
        make_item("_Test Mix Product Bundle Item 2", {
            "is_stock_item": 0,
            "is_pro_applicable": 0,
            "is_sales_item": 1
        })

        make_product_bundle("_Test Mix Product Bundle", [
            "_Test Mix Product Bundle Item 1",
            "_Test Mix Product Bundle Item 2"
        ])

        self.assertRaises(WarehouseRequired,
                          make_sales_order,
                          item_code="_Test Mix Product Bundle",
                          warehouse="")
示例#6
0
    def test_service_type_product_bundle(self):
        from erpnext.stock.doctype.item.test_item import make_item
        from erpnext.selling.doctype.product_bundle.test_product_bundle import make_product_bundle

        make_item("_Test Service Product Bundle", {
            "is_stock_item": 0,
            "is_pro_applicable": 0,
            "is_sales_item": 1
        })
        make_item("_Test Service Product Bundle Item 1", {
            "is_stock_item": 0,
            "is_pro_applicable": 0,
            "is_sales_item": 1
        })
        make_item("_Test Service Product Bundle Item 2", {
            "is_stock_item": 0,
            "is_pro_applicable": 0,
            "is_sales_item": 1
        })

        make_product_bundle("_Test Service Product Bundle", [
            "_Test Service Product Bundle Item 1",
            "_Test Service Product Bundle Item 2"
        ])

        so = make_sales_order(item_code="_Test Service Product Bundle",
                              warehouse=None)

        self.assertTrue("_Test Service Product Bundle Item 1" in
                        [d.item_code for d in so.packed_items])
        self.assertTrue("_Test Service Product Bundle Item 2" in
                        [d.item_code for d in so.packed_items])
示例#7
0
    def test_update_child_qty_rate_product_bundle(self):
        # test Update Items with product bundle
        if not frappe.db.exists("Item", "_Product Bundle Item"):
            bundle_item = make_item("_Product Bundle Item",
                                    {"is_stock_item": 0})
            bundle_item.append(
                "item_defaults", {
                    "company": "_Test Company",
                    "default_warehouse": "_Test Warehouse - _TC"
                })
            bundle_item.save(ignore_permissions=True)

        make_item("_Packed Item", {"is_stock_item": 1})
        make_product_bundle("_Product Bundle Item", ["_Packed Item"], 2)

        so = make_sales_order(item_code="_Test Item", warehouse=None)

        added_item = json.dumps([{
            "item_code": "_Product Bundle Item",
            "rate": 200,
            'qty': 2
        }])
        update_child_qty_rate('Sales Order', added_item, so.name)

        so.reload()
        self.assertEqual(so.packed_items[0].qty, 4)
示例#8
0
	def test_mix_type_product_bundle(self):
		make_item("_Test Mix Product Bundle", {"is_stock_item": 0})
		make_item("_Test Mix Product Bundle Item 1", {"is_stock_item": 1})
		make_item("_Test Mix Product Bundle Item 2", {"is_stock_item": 0})

		make_product_bundle("_Test Mix Product Bundle",
			["_Test Mix Product Bundle Item 1", "_Test Mix Product Bundle Item 2"])

		self.assertRaises(WarehouseRequired, make_sales_order, item_code = "_Test Mix Product Bundle", warehouse="")
示例#9
0
	def test_mix_type_product_bundle(self):
		from erpnext.selling.doctype.product_bundle.test_product_bundle import make_product_bundle
		from erpnext.stock.doctype.item.test_item import make_item
		make_item("_Test Mix Product Bundle", {"is_stock_item": 0})
		make_item("_Test Mix Product Bundle Item 1", {"is_stock_item": 1})
		make_item("_Test Mix Product Bundle Item 2", {"is_stock_item": 0})

		make_product_bundle("_Test Mix Product Bundle",
			["_Test Mix Product Bundle Item 1", "_Test Mix Product Bundle Item 2"])

		self.assertRaises(WarehouseRequired, make_sales_order, item_code = "_Test Mix Product Bundle", warehouse="")
示例#10
0
	def test_service_type_product_bundle(self):
		make_item("_Test Service Product Bundle", {"is_stock_item": 0})
		make_item("_Test Service Product Bundle Item 1", {"is_stock_item": 0})
		make_item("_Test Service Product Bundle Item 2", {"is_stock_item": 0})

		make_product_bundle("_Test Service Product Bundle",
			["_Test Service Product Bundle Item 1", "_Test Service Product Bundle Item 2"])

		so = make_sales_order(item_code = "_Test Service Product Bundle", warehouse=None)

		self.assertTrue("_Test Service Product Bundle Item 1" in [d.item_code for d in so.packed_items])
		self.assertTrue("_Test Service Product Bundle Item 2" in [d.item_code for d in so.packed_items])
示例#11
0
	def test_service_type_product_bundle(self):
		from erpnext.selling.doctype.product_bundle.test_product_bundle import make_product_bundle
		from erpnext.stock.doctype.item.test_item import make_item
		make_item("_Test Service Product Bundle", {"is_stock_item": 0})
		make_item("_Test Service Product Bundle Item 1", {"is_stock_item": 0})
		make_item("_Test Service Product Bundle Item 2", {"is_stock_item": 0})

		make_product_bundle("_Test Service Product Bundle",
			["_Test Service Product Bundle Item 1", "_Test Service Product Bundle Item 2"])

		so = make_sales_order(item_code = "_Test Service Product Bundle", warehouse=None)

		self.assertTrue("_Test Service Product Bundle Item 1" in [d.item_code for d in so.packed_items])
		self.assertTrue("_Test Service Product Bundle Item 2" in [d.item_code for d in so.packed_items])
示例#12
0
	def test_product_bundle_price_calculation_for_multiple_product_bundles_when_calculate_bundle_price_is_checked(
		self,
	):
		from erpnext.selling.doctype.product_bundle.test_product_bundle import make_product_bundle
		from erpnext.stock.doctype.item.test_item import make_item

		make_item("_Test Product Bundle 1", {"is_stock_item": 0})
		make_item("_Test Product Bundle 2", {"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 Bundle Item 3", {"is_stock_item": 1})

		make_product_bundle("_Test Product Bundle 1", ["_Test Bundle Item 1", "_Test Bundle Item 2"])
		make_product_bundle("_Test Product Bundle 2", ["_Test Bundle Item 2", "_Test Bundle Item 3"])

		enable_calculate_bundle_price()

		item_list = [
			{
				"item_code": "_Test Product Bundle 1",
				"warehouse": "",
				"qty": 1,
				"rate": 400,
				"delivered_by_supplier": 1,
				"supplier": "_Test Supplier",
			},
			{
				"item_code": "_Test Product Bundle 2",
				"warehouse": "",
				"qty": 1,
				"rate": 400,
				"delivered_by_supplier": 1,
				"supplier": "_Test Supplier",
			},
		]

		quotation = make_quotation(item_list=item_list, do_not_submit=1)
		quotation.packed_items[0].rate = 100
		quotation.packed_items[1].rate = 200
		quotation.packed_items[2].rate = 200
		quotation.packed_items[3].rate = 300
		quotation.save()

		expected_values = [300, 500]

		for item in quotation.items:
			self.assertEqual(item.amount, expected_values[item.idx - 1])

		enable_calculate_bundle_price(enable=0)
示例#13
0
	def test_product_bundle_price_calculation_when_calculate_bundle_price_is_unchecked(self):
		from erpnext.selling.doctype.product_bundle.test_product_bundle import make_product_bundle
		from erpnext.stock.doctype.item.test_item import make_item

		make_item("_Test Product Bundle", {"is_stock_item": 0})
		bundle_item1 = make_item("_Test Bundle Item 1", {"is_stock_item": 1})
		bundle_item2 = make_item("_Test Bundle Item 2", {"is_stock_item": 1})

		make_product_bundle("_Test Product Bundle", ["_Test Bundle Item 1", "_Test Bundle Item 2"])

		bundle_item1.valuation_rate = 100
		bundle_item1.save()

		bundle_item2.valuation_rate = 200
		bundle_item2.save()

		quotation = make_quotation(item_code="_Test Product Bundle", qty=2, rate=100)
		self.assertEqual(quotation.items[0].amount, 200)
示例#14
0
	def test_product_bundle_price_calculation_when_calculate_bundle_price_is_checked(self):
		from erpnext.selling.doctype.product_bundle.test_product_bundle import make_product_bundle
		from erpnext.stock.doctype.item.test_item import make_item

		make_item("_Test Product Bundle", {"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_product_bundle("_Test Product Bundle", ["_Test Bundle Item 1", "_Test Bundle Item 2"])

		enable_calculate_bundle_price()

		quotation = make_quotation(item_code="_Test Product Bundle", qty=2, rate=100, do_not_submit=1)
		quotation.packed_items[0].rate = 100
		quotation.packed_items[1].rate = 200
		quotation.save()

		self.assertEqual(quotation.items[0].amount, 600)
		self.assertEqual(quotation.items[0].rate, 300)

		enable_calculate_bundle_price(enable=0)
示例#15
0
	def test_packed_items_indices_are_reset_when_product_bundle_is_deleted_from_items_table(self):
		from erpnext.selling.doctype.product_bundle.test_product_bundle import make_product_bundle
		from erpnext.stock.doctype.item.test_item import make_item

		make_item("_Test Product Bundle 1", {"is_stock_item": 0})
		make_item("_Test Product Bundle 2", {"is_stock_item": 0})
		make_item("_Test Product Bundle 3", {"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 Bundle Item 3", {"is_stock_item": 1})

		make_product_bundle("_Test Product Bundle 1", ["_Test Bundle Item 1", "_Test Bundle Item 2"])
		make_product_bundle("_Test Product Bundle 2", ["_Test Bundle Item 2", "_Test Bundle Item 3"])
		make_product_bundle("_Test Product Bundle 3", ["_Test Bundle Item 3", "_Test Bundle Item 1"])

		item_list = [
			{
				"item_code": "_Test Product Bundle 1",
				"warehouse": "",
				"qty": 1,
				"rate": 400,
				"delivered_by_supplier": 1,
				"supplier": "_Test Supplier",
			},
			{
				"item_code": "_Test Product Bundle 2",
				"warehouse": "",
				"qty": 1,
				"rate": 400,
				"delivered_by_supplier": 1,
				"supplier": "_Test Supplier",
			},
			{
				"item_code": "_Test Product Bundle 3",
				"warehouse": "",
				"qty": 1,
				"rate": 400,
				"delivered_by_supplier": 1,
				"supplier": "_Test Supplier",
			},
		]

		quotation = make_quotation(item_list=item_list, do_not_submit=1)
		del quotation.items[1]
		quotation.save()

		for id, item in enumerate(quotation.packed_items):
			expected_index = id + 1
			self.assertEqual(item.idx, expected_index)