def make_items():
	items = ['Test Finished Goods - A', 'Test FG A RW 1', 'Test FG A RW 2', 'Alternate Item For A RW 1']
	for item_code in items:
		if not frappe.db.exists('Item', item_code):
			create_item(item_code)

	create_stock_reconciliation(item_code="Test FG A RW 1",
		warehouse='_Test Warehouse - _TC', qty=10, rate=2000)

	if frappe.db.exists('Item', 'Test FG A RW 1'):
		doc = frappe.get_doc('Item', 'Test FG A RW 1')
		doc.allow_alternative_item = 1
		doc.save()

	if frappe.db.exists('Item', 'Test Finished Goods - A'):
		doc = frappe.get_doc('Item', 'Test Finished Goods - A')
		doc.is_sub_contracted_item = 1
		doc.save()

	if not frappe.db.get_value('BOM',
		{'item': 'Test Finished Goods - A', 'docstatus': 1}):
		make_bom(item = 'Test Finished Goods - A', raw_materials = ['Test FG A RW 1', 'Test FG A RW 2'])

	if not frappe.db.get_value('Warehouse', {'warehouse_name': 'Test Supplier Warehouse'}):
		frappe.get_doc({
			'doctype': 'Warehouse',
			'warehouse_name': 'Test Supplier Warehouse',
			'company': '_Test Company'
		}).insert(ignore_permissions=True)
Beispiel #2
0
	def test_work_order_with_non_stock_item(self):
		items = {'Finished Good Test Item For non stock': 1, '_Test FG Item': 1, '_Test FG Non Stock Item': 0}
		for item, is_stock_item in items.items():
			make_item(item, {
				'is_stock_item': is_stock_item
			})

		if not frappe.db.get_value('Item Price', {'item_code': '_Test FG Non Stock Item'}):
			frappe.get_doc({
				'doctype': 'Item Price',
				'item_code': '_Test FG Non Stock Item',
				'price_list_rate': 1000,
				'price_list': 'Standard Buying'
			}).insert(ignore_permissions=True)

		fg_item = 'Finished Good Test Item For non stock'
		test_stock_entry.make_stock_entry(item_code="_Test FG Item",
			target="_Test Warehouse - _TC", qty=1, basic_rate=100)

		if not frappe.db.get_value('BOM', {'item': fg_item}):
			make_bom(item=fg_item, rate=1000, raw_materials = ['_Test FG Item', '_Test FG Non Stock Item'])

		wo = make_wo_order_test_record(production_item = fg_item)

		se = frappe.get_doc(make_stock_entry(wo.name, "Material Transfer for Manufacture", 1))
		se.insert()
		se.submit()

		ste = frappe.get_doc(make_stock_entry(wo.name, "Manufacture", 1))
		ste.insert()
		self.assertEqual(len(ste.additional_costs), 1)
		self.assertEqual(ste.total_additional_costs, 1000)
Beispiel #3
0
    def test_request_for_raw_materials(self):
        item = make_item(
            "_Test Finished Item", {
                "is_stock_item":
                1,
                "maintain_stock":
                1,
                "valuation_rate":
                500,
                "item_defaults": [{
                    "default_warehouse": "_Test Warehouse - _TC",
                    "company": "_Test Company"
                }]
            })
        make_item(
            "_Test Raw Item A", {
                "maintain_stock":
                1,
                "valuation_rate":
                100,
                "item_defaults": [{
                    "default_warehouse": "_Test Warehouse - _TC",
                    "company": "_Test Company"
                }]
            })
        make_item(
            "_Test Raw Item B", {
                "maintain_stock":
                1,
                "valuation_rate":
                200,
                "item_defaults": [{
                    "default_warehouse": "_Test Warehouse - _TC",
                    "company": "_Test Company"
                }]
            })
        from erpnext.manufacturing.doctype.production_plan.test_production_plan import make_bom
        make_bom(item=item.item_code,
                 rate=1000,
                 raw_materials=['_Test Raw Item A', '_Test Raw Item B'])

        so = make_sales_order(**{
            "item_list": [{
                "item_code": item.item_code,
                "qty": 1,
                "rate": 1000
            }]
        })
        so.submit()
        mr_dict = frappe._dict()
        items = so.get_work_order_items(1)
        mr_dict['items'] = items
        mr_dict['include_exploded_items'] = 0
        mr_dict['ignore_existing_ordered_qty'] = 1
        make_raw_material_request(mr_dict, so.company, so.name)
        mr = frappe.db.sql(
            """select name from `tabMaterial Request` ORDER BY creation DESC LIMIT 1""",
            as_dict=1)[0]
        mr_doc = frappe.get_doc('Material Request', mr.get('name'))
        self.assertEqual(mr_doc.items[0].sales_order, so.name)
Beispiel #4
0
	def test_work_order_with_non_stock_item(self):
		items = {'Finished Good Test Item For non stock': 1, '_Test FG Item': 1, '_Test FG Non Stock Item': 0}
		for item, is_stock_item in items.items():
			make_item(item, {
				'is_stock_item': is_stock_item
			})

		if not frappe.db.get_value('Item Price', {'item_code': '_Test FG Non Stock Item'}):
			frappe.get_doc({
				'doctype': 'Item Price',
				'item_code': '_Test FG Non Stock Item',
				'price_list_rate': 1000,
				'price_list': 'Standard Buying'
			}).insert(ignore_permissions=True)

		fg_item = 'Finished Good Test Item For non stock'
		test_stock_entry.make_stock_entry(item_code="_Test FG Item",
			target="_Test Warehouse - _TC", qty=1, basic_rate=100)

		if not frappe.db.get_value('BOM', {'item': fg_item}):
			make_bom(item=fg_item, rate=1000, raw_materials = ['_Test FG Item', '_Test FG Non Stock Item'])

		wo = make_wo_order_test_record(production_item = fg_item)

		se = frappe.get_doc(make_stock_entry(wo.name, "Material Transfer for Manufacture", 1))
		se.insert()
		se.submit()

		ste = frappe.get_doc(make_stock_entry(wo.name, "Manufacture", 1))
		ste.insert()
		self.assertEqual(len(ste.additional_costs), 1)
		self.assertEqual(ste.total_additional_costs, 1000)
def make_subcontracted_item(**args):
    from erpnext.manufacturing.doctype.production_plan.test_production_plan import make_bom

    args = frappe._dict(args)

    if not frappe.db.exists('Item', args.item_code):
        make_item(
            args.item_code, {
                'is_stock_item': 1,
                'is_sub_contracted_item': 1,
                'has_batch_no': args.get("has_batch_no") or 0
            })

    if not args.raw_materials:
        if not frappe.db.exists('Item', "Test Extra Item 1"):
            make_item("Test Extra Item 1", {
                'is_stock_item': 1,
            })

        if not frappe.db.exists('Item', "Test Extra Item 2"):
            make_item("Test Extra Item 2", {
                'is_stock_item': 1,
            })

        args.raw_materials = ['_Test FG Item', 'Test Extra Item 1']

    if not frappe.db.get_value('BOM', {'item': args.item_code}, 'name'):
        make_bom(item=args.item_code, raw_materials=args.get("raw_materials"))
def make_items():
	items = ['Test Finished Goods - A', 'Test FG A RW 1', 'Test FG A RW 2', 'Alternate Item For A RW 1']
	for item_code in items:
		if not frappe.db.exists('Item', item_code):
			create_item(item_code)

	create_stock_reconciliation(item_code="Test FG A RW 1",
		warehouse='_Test Warehouse - _TC', qty=10, rate=2000)

	if frappe.db.exists('Item', 'Test FG A RW 1'):
		doc = frappe.get_doc('Item', 'Test FG A RW 1')
		doc.allow_alternative_item = 1
		doc.save()

	if frappe.db.exists('Item', 'Test Finished Goods - A'):
		doc = frappe.get_doc('Item', 'Test Finished Goods - A')
		doc.is_sub_contracted_item = 1
		doc.save()

	if not frappe.db.get_value('BOM',
		{'item': 'Test Finished Goods - A', 'docstatus': 1}):
		make_bom(item = 'Test Finished Goods - A', raw_materials = ['Test FG A RW 1', 'Test FG A RW 2'])

	if not frappe.db.get_value('Warehouse', {'warehouse_name': 'Test Supplier Warehouse'}):
		frappe.get_doc({
			'doctype': 'Warehouse',
			'warehouse_name': 'Test Supplier Warehouse',
			'company': '_Test Company'
		}).insert(ignore_permissions=True)
Beispiel #7
0
    def test_work_order_with_non_transfer_item(self):
        items = {
            'Finished Good Transfer Item': 1,
            '_Test FG Item': 1,
            '_Test FG Item 1': 0
        }
        for item, allow_transfer in items.items():
            make_item(item, {'include_item_in_manufacturing': allow_transfer})

        fg_item = 'Finished Good Transfer Item'
        test_stock_entry.make_stock_entry(item_code="_Test FG Item",
                                          target="_Test Warehouse - _TC",
                                          qty=1,
                                          basic_rate=100)
        test_stock_entry.make_stock_entry(item_code="_Test FG Item 1",
                                          target="_Test Warehouse - _TC",
                                          qty=1,
                                          basic_rate=100)

        if not frappe.db.get_value('BOM', {'item': fg_item}):
            make_bom(item=fg_item,
                     raw_materials=['_Test FG Item', '_Test FG Item 1'])

        wo = make_wo_order_test_record(production_item=fg_item)
        ste = frappe.get_doc(
            make_stock_entry(wo.name, "Material Transfer for Manufacture", 1))
        ste.insert()
        ste.submit()
        self.assertEqual(len(ste.items), 1)
        ste1 = frappe.get_doc(make_stock_entry(wo.name, "Manufacture", 1))
        self.assertEqual(len(ste1.items), 3)
Beispiel #8
0
    def test_valuation_rate_missing_on_make_stock_entry(self):
        item_name = 'Test Valuation Rate Missing'
        rm_item = '_Test raw material item'
        make_item(item_name, {
            "is_stock_item": 1,
            "include_item_in_manufacturing": 1,
        })
        make_item('_Test raw material item', {
            "is_stock_item": 1,
            "include_item_in_manufacturing": 1,
        })

        if not frappe.db.get_value('BOM', {'item': item_name}):
            make_bom(item=item_name, raw_materials=[rm_item], rm_qty=1)

        company = "_Test Company with perpetual inventory"
        source_warehouse = create_warehouse(
            "Test Valuation Rate Missing Warehouse", company=company)
        wo = make_wo_order_test_record(item=item_name,
                                       qty=1,
                                       source_warehouse=source_warehouse,
                                       company=company)

        self.assertRaises(frappe.ValidationError, make_stock_entry, wo.name,
                          'Material Transfer for Manufacture')
Beispiel #9
0
    def test_sub_contracted_item_costing(self):
        from erpnext.manufacturing.doctype.production_plan.test_production_plan import make_bom

        company = "_Test Company"
        rm_item_code = "_Test Item for Reposting"
        subcontracted_item = "_Test Subcontracted Item for Reposting"

        frappe.db.set_value("Buying Settings", None,
                            "backflush_raw_materials_of_subcontract_based_on",
                            "BOM")
        make_bom(item=subcontracted_item,
                 raw_materials=[rm_item_code],
                 currency="INR")

        # Purchase raw materials on supplier warehouse: Qty = 50, Rate = 100
        pr = make_purchase_receipt(company=company,
                                   posting_date='2020-04-10',
                                   warehouse="Stores - _TC",
                                   item_code=rm_item_code,
                                   qty=10,
                                   rate=100)

        # Purchase Receipt for subcontracted item
        pr1 = make_purchase_receipt(company=company,
                                    posting_date='2020-04-20',
                                    warehouse="Finished Goods - _TC",
                                    supplier_warehouse="Stores - _TC",
                                    item_code=subcontracted_item,
                                    qty=10,
                                    rate=20,
                                    is_subcontracted="Yes")

        self.assertEqual(pr1.items[0].valuation_rate, 120)

        # Update raw material's valuation via LCV, Additional cost = 50
        lcv = create_landed_cost_voucher("Purchase Receipt", pr.name,
                                         pr.company)

        pr1.reload()
        self.assertEqual(pr1.items[0].valuation_rate, 125)

        # check outgoing_rate for DN after reposting
        incoming_rate = frappe.db.get_value(
            "Stock Ledger Entry", {
                "voucher_type": "Purchase Receipt",
                "voucher_no": pr1.name,
                "item_code": subcontracted_item
            }, "incoming_rate")
        self.assertEqual(incoming_rate, 125)

        # cleanup data
        pr1.cancel()
        lcv.cancel()
        pr.cancel()
Beispiel #10
0
	def test_request_for_raw_materials(self):
		from erpnext.stock.doctype.item.test_item import make_item
		item = make_item("_Test Finished Item", {"is_stock_item": 1,
			"maintain_stock": 1,
			"valuation_rate": 500,
			"item_defaults": [
				{
					"default_warehouse": "_Test Warehouse - _TC",
					"company": "_Test Company"
				}]
			})
		make_item("_Test Raw Item A", {"maintain_stock": 1,
					"valuation_rate": 100,
					"item_defaults": [
						{
							"default_warehouse": "_Test Warehouse - _TC",
							"company": "_Test Company"
						}]
					})
		make_item("_Test Raw Item B", {"maintain_stock": 1,
					"valuation_rate": 200,
					"item_defaults": [
						{
							"default_warehouse": "_Test Warehouse - _TC",
							"company": "_Test Company"
						}]
					})
		from erpnext.manufacturing.doctype.production_plan.test_production_plan import make_bom
		make_bom(item=item.item_code, rate=1000,
			raw_materials = ['_Test Raw Item A', '_Test Raw Item B'])

		so = make_sales_order(**{
			"item_list": [{
				"item_code": item.item_code,
				"qty": 1,
				"rate":1000
			}]
		})
		so.submit()
		mr_dict = frappe._dict()
		items = so.get_work_order_items(1)
		mr_dict['items'] = items
		mr_dict['include_exploded_items'] = 0
		mr_dict['ignore_existing_ordered_qty'] = 1
		make_raw_material_request(mr_dict, so.company, so.name)
		mr = frappe.db.sql("""select name from `tabMaterial Request` ORDER BY creation DESC LIMIT 1""", as_dict=1)[0]
		mr_doc = frappe.get_doc('Material Request',mr.get('name'))
		self.assertEqual(mr_doc.items[0].sales_order, so.name)
Beispiel #11
0
def setup_bom(**args):
	from erpnext.manufacturing.doctype.production_plan.test_production_plan import make_bom

	args = frappe._dict(args)

	if not frappe.db.exists('Item', args.item_code):
		make_item(args.item_code, {
			'is_stock_item': 1
		})

	if not args.raw_materials:
		if not frappe.db.exists('Item', "Test Extra Item N-1"):
			make_item("Test Extra Item N-1", {
				'is_stock_item': 1,
			})

		args.raw_materials = ['Test Extra Item N-1']

	name = frappe.db.get_value('BOM', {'item': args.item_code}, 'name')
	if not name:
		bom_doc = make_bom(item = args.item_code, raw_materials = args.get("raw_materials"),
			routing = args.routing, with_operations=1, currency = args.currency)
	else:
		bom_doc = frappe.get_doc("BOM", name)

	return bom_doc
Beispiel #12
0
    def test_bom_cost(self):
        for item in ["BOM Cost Test Item 1", "BOM Cost Test Item 2", "BOM Cost Test Item 3"]:
            item_doc = create_item(item, valuation_rate=100)
            if item_doc.valuation_rate != 100.00:
                frappe.db.set_value("Item", item_doc.name,
                                    "valuation_rate", 100)

        bom_no = frappe.db.get_value(
            'BOM', {'item': 'BOM Cost Test Item 1'}, "name")
        if not bom_no:
            doc = make_bom(item='BOM Cost Test Item 1',
                           raw_materials=['BOM Cost Test Item 2', 'BOM Cost Test Item 3'], currency="INR")
        else:
            doc = frappe.get_doc("BOM", bom_no)

        self.assertEquals(doc.total_cost, 200)

        frappe.db.set_value("Item", "BOM Cost Test Item 2",
                            "valuation_rate", 200)
        update_cost()

        doc.load_from_db()
        self.assertEquals(doc.total_cost, 300)

        frappe.db.set_value("Item", "BOM Cost Test Item 2",
                            "valuation_rate", 100)
        update_cost()

        doc.load_from_db()
        self.assertEquals(doc.total_cost, 200)
Beispiel #13
0
    def test_close_work_order(self):
        items = [
            'Test FG Item for Closed WO', 'Test RM Item 1 for Closed WO',
            'Test RM Item 2 for Closed WO'
        ]

        company = '_Test Company with perpetual inventory'
        for item_code in items:
            create_item(item_code=item_code,
                        is_stock_item=1,
                        is_purchase_item=1,
                        opening_stock=100,
                        valuation_rate=10,
                        company=company,
                        warehouse='Stores - TCP1')

        item = 'Test FG Item for Closed WO'
        raw_materials = [
            'Test RM Item 1 for Closed WO', 'Test RM Item 2 for Closed WO'
        ]
        if not frappe.db.get_value('BOM', {'item': item}):
            bom = make_bom(item=item,
                           source_warehouse='Stores - TCP1',
                           raw_materials=raw_materials,
                           do_not_save=True)
            bom.with_operations = 1
            bom.append(
                'operations', {
                    'operation': '_Test Operation 1',
                    'workstation': '_Test Workstation 1',
                    'hour_rate': 20,
                    'time_in_mins': 60
                })

            bom.submit()

        wo_order = make_wo_order_test_record(item=item,
                                             company=company,
                                             planned_start_date=now(),
                                             qty=20,
                                             skip_transfer=1)
        job_cards = frappe.db.get_value('Job Card',
                                        {'work_order': wo_order.name}, 'name')

        if len(job_cards) == len(bom.operations):
            for jc in job_cards:
                job_card_doc = frappe.get_doc('Job Card', jc)
                job_card_doc.append(
                    'time_logs', {
                        'from_time': now(),
                        'time_in_mins': 60,
                        'completed_qty': job_card_doc.for_quantity
                    })

                job_card_doc.submit()

            close_work_order(wo_order, "Closed")
            self.assertEqual(wo_order.get('status'), "Closed")
Beispiel #14
0
    def test_operation_time_with_batch_size(self):
        fg_item = "Test Batch Size Item For BOM"
        rm1 = "Test Batch Size Item RM 1 For BOM"

        for item in [
                "Test Batch Size Item For BOM",
                "Test Batch Size Item RM 1 For BOM"
        ]:
            make_item(item, {
                "include_item_in_manufacturing": 1,
                "is_stock_item": 1
            })

        bom_name = frappe.db.get_value("BOM", {
            "item": fg_item,
            "is_active": 1,
            "with_operations": 1
        }, "name")

        if not bom_name:
            bom = make_bom(item=fg_item,
                           rate=1000,
                           raw_materials=[rm1],
                           do_not_save=True)
            bom.with_operations = 1
            bom.append(
                "operations", {
                    "operation": "_Test Operation 1",
                    "workstation": "_Test Workstation 1",
                    "description": "Test Data",
                    "operating_cost": 100,
                    "time_in_mins": 40,
                    "batch_size": 5
                })

            bom.save()
            bom.submit()
            bom_name = bom.name

        work_order = make_wo_order_test_record(item=fg_item,
                                               planned_start_date=now(),
                                               qty=1,
                                               do_not_save=True)

        work_order.set_work_order_operations()
        work_order.save()
        self.assertEqual(work_order.operations[0].time_in_mins, 8.0)

        work_order1 = make_wo_order_test_record(item=fg_item,
                                                planned_start_date=now(),
                                                qty=5,
                                                do_not_save=True)

        work_order1.set_work_order_operations()
        work_order1.save()
        self.assertEqual(work_order1.operations[0].time_in_mins, 40.0)
Beispiel #15
0
def make_bom_for_subcontracted_items():
    boms = {
        'Subcontracted Item SA1': [
            'Subcontracted SRM Item 1', 'Subcontracted SRM Item 2',
            'Subcontracted SRM Item 3'
        ],
        'Subcontracted Item SA2': ['Subcontracted SRM Item 2'],
        'Subcontracted Item SA3': ['Subcontracted SRM Item 2'],
        'Subcontracted Item SA4': [
            'Subcontracted SRM Item 1', 'Subcontracted SRM Item 2',
            'Subcontracted SRM Item 3'
        ],
        'Subcontracted Item SA5': ['Subcontracted SRM Item 5'],
        'Subcontracted Item SA6': ['Subcontracted SRM Item 3']
    }

    for item_code, raw_materials in boms.items():
        if not frappe.db.exists('BOM', {'item': item_code}):
            make_bom(item=item_code, raw_materials=raw_materials, rate=100)
def make_items():
    items = [
        "Test Finished Goods - A",
        "Test FG A RW 1",
        "Test FG A RW 2",
        "Alternate Item For A RW 1",
    ]
    for item_code in items:
        if not frappe.db.exists("Item", item_code):
            create_item(item_code)

    try:
        create_stock_reconciliation(item_code="Test FG A RW 1",
                                    warehouse="_Test Warehouse - _TC",
                                    qty=10,
                                    rate=2000)
    except EmptyStockReconciliationItemsError:
        pass

    if frappe.db.exists("Item", "Test FG A RW 1"):
        doc = frappe.get_doc("Item", "Test FG A RW 1")
        doc.allow_alternative_item = 1
        doc.save()

    if frappe.db.exists("Item", "Test Finished Goods - A"):
        doc = frappe.get_doc("Item", "Test Finished Goods - A")
        doc.is_sub_contracted_item = 1
        doc.save()

    if not frappe.db.get_value("BOM", {
            "item": "Test Finished Goods - A",
            "docstatus": 1
    }):
        make_bom(item="Test Finished Goods - A",
                 raw_materials=["Test FG A RW 1", "Test FG A RW 2"])

    if not frappe.db.get_value("Warehouse",
                               {"warehouse_name": "Test Supplier Warehouse"}):
        frappe.get_doc({
            "doctype": "Warehouse",
            "warehouse_name": "Test Supplier Warehouse",
            "company": "_Test Company",
        }).insert(ignore_permissions=True)
Beispiel #17
0
def make_subcontracted_item(item_code):
    from erpnext.manufacturing.doctype.production_plan.test_production_plan import make_bom

    if not frappe.db.exists('Item', item_code):
        make_item(item_code, {'is_stock_item': 1, 'is_sub_contracted_item': 1})

    if not frappe.db.exists('Item', "Test Extra Item 1"):
        make_item("Test Extra Item 1", {
            'is_stock_item': 1,
        })

    if not frappe.db.exists('Item', "Test Extra Item 2"):
        make_item("Test Extra Item 2", {
            'is_stock_item': 1,
        })

    if not frappe.db.get_value('BOM', {'item': item_code}, 'name'):
        make_bom(item=item_code,
                 raw_materials=['_Test FG Item', 'Test Extra Item 1'])
Beispiel #18
0
def make_subcontracted_item(item_code):
	from erpnext.manufacturing.doctype.production_plan.test_production_plan import make_bom

	if not frappe.db.exists('Item', item_code):
		make_item(item_code, {
			'is_stock_item': 1,
			'is_sub_contracted_item': 1
		})

	if not frappe.db.exists('Item', "Test Extra Item 1"):
		make_item("Test Extra Item 1", {
			'is_stock_item': 1,
		})

	if not frappe.db.exists('Item', "Test Extra Item 2"):
		make_item("Test Extra Item 2", {
			'is_stock_item': 1,
		})

	if not frappe.db.get_value('BOM', {'item': item_code}, 'name'):
		make_bom(item = item_code, raw_materials = ['_Test FG Item', 'Test Extra Item 1'])
Beispiel #19
0
def make_bom_for_subcontracted_items():
    boms = {
        "Subcontracted Item SA1": [
            "Subcontracted SRM Item 1",
            "Subcontracted SRM Item 2",
            "Subcontracted SRM Item 3",
        ],
        "Subcontracted Item SA2": ["Subcontracted SRM Item 2"],
        "Subcontracted Item SA3": ["Subcontracted SRM Item 2"],
        "Subcontracted Item SA4": [
            "Subcontracted SRM Item 1",
            "Subcontracted SRM Item 2",
            "Subcontracted SRM Item 3",
        ],
        "Subcontracted Item SA5": ["Subcontracted SRM Item 5"],
        "Subcontracted Item SA6": ["Subcontracted SRM Item 3"],
    }

    for item_code, raw_materials in boms.items():
        if not frappe.db.exists("BOM", {"item": item_code}):
            make_bom(item=item_code, raw_materials=raw_materials, rate=100)
Beispiel #20
0
    def test_job_card_scrap_item(self):
        items = [
            'Test FG Item for Scrap Item Test',
            'Test RM Item 1 for Scrap Item Test',
            'Test RM Item 2 for Scrap Item Test'
        ]

        company = '_Test Company with perpetual inventory'
        for item_code in items:
            create_item(item_code=item_code,
                        is_stock_item=1,
                        is_purchase_item=1,
                        opening_stock=100,
                        valuation_rate=10,
                        company=company,
                        warehouse='Stores - TCP1')

        item = 'Test FG Item for Scrap Item Test'
        raw_materials = [
            'Test RM Item 1 for Scrap Item Test',
            'Test RM Item 2 for Scrap Item Test'
        ]
        if not frappe.db.get_value('BOM', {'item': item}):
            bom = make_bom(item=item,
                           source_warehouse='Stores - TCP1',
                           raw_materials=raw_materials,
                           do_not_save=True)
            bom.with_operations = 1
            bom.append(
                'operations', {
                    'operation': '_Test Operation 1',
                    'workstation': '_Test Workstation 1',
                    'hour_rate': 20,
                    'time_in_mins': 60
                })

            bom.submit()

        wo_order = make_wo_order_test_record(item=item,
                                             company=company,
                                             planned_start_date=now(),
                                             qty=20,
                                             skip_transfer=1)
        job_card = frappe.db.get_value('Job Card',
                                       {'work_order': wo_order.name}, 'name')
        update_job_card(job_card)

        stock_entry = frappe.get_doc(
            make_stock_entry(wo_order.name, "Manufacture", 10))
        for row in stock_entry.items:
            if row.is_scrap_item:
                self.assertEqual(row.qty, 1)
Beispiel #21
0
    def test_make_stock_entry_for_customer_provided_item(self):
        finished_item = 'Test Item for Make Stock Entry 1'
        make_item(finished_item, {
            "include_item_in_manufacturing": 1,
            "is_stock_item": 1
        })

        customer_provided_item = 'CUST-0987'
        make_item(
            customer_provided_item, {
                'is_purchase_item': 0,
                'is_customer_provided_item': 1,
                "is_stock_item": 1,
                "include_item_in_manufacturing": 1,
                'customer': '_Test Customer'
            })

        if not frappe.db.exists('BOM', {'item': finished_item}):
            make_bom(item=finished_item,
                     raw_materials=[customer_provided_item],
                     rm_qty=1)

        company = "_Test Company with perpetual inventory"
        customer_warehouse = create_warehouse(
            "Test Customer Provided Warehouse", company=company)
        wo = make_wo_order_test_record(item=finished_item,
                                       qty=1,
                                       source_warehouse=customer_warehouse,
                                       company=company)

        ste = frappe.get_doc(
            make_stock_entry(wo.name,
                             purpose='Material Transfer for Manufacture'))
        ste.insert()

        self.assertEqual(len(ste.items), 1)
        for item in ste.items:
            self.assertEqual(item.allow_zero_valuation_rate, 1)
            self.assertEqual(item.valuation_rate, 0)
Beispiel #22
0
	def test_work_order_with_non_transfer_item(self):
		items = {'Finished Good Transfer Item': 1, '_Test FG Item': 1, '_Test FG Item 1': 0}
		for item, allow_transfer in items.items():
			make_item(item, {
				'include_item_in_manufacturing': allow_transfer
			})

		fg_item = 'Finished Good Transfer Item'
		test_stock_entry.make_stock_entry(item_code="_Test FG Item",
			target="_Test Warehouse - _TC", qty=1, basic_rate=100)
		test_stock_entry.make_stock_entry(item_code="_Test FG Item 1",
			target="_Test Warehouse - _TC", qty=1, basic_rate=100)

		if not frappe.db.get_value('BOM', {'item': fg_item}):
			make_bom(item=fg_item, raw_materials = ['_Test FG Item', '_Test FG Item 1'])

		wo = make_wo_order_test_record(production_item = fg_item)
		ste = frappe.get_doc(make_stock_entry(wo.name, "Material Transfer for Manufacture", 1))
		ste.insert()
		ste.submit()
		self.assertEqual(len(ste.items), 1)
		ste1 = frappe.get_doc(make_stock_entry(wo.name, "Manufacture", 1))
		self.assertEqual(len(ste1.items), 3)
Beispiel #23
0
def make_subcontracted_item(**args):
    from erpnext.manufacturing.doctype.production_plan.test_production_plan import make_bom

    args = frappe._dict(args)

    if not frappe.db.exists("Item", args.item_code):
        make_item(
            args.item_code,
            {
                "is_stock_item": 1,
                "is_sub_contracted_item": 1,
                "has_batch_no": args.get("has_batch_no") or 0,
            },
        )

    if not args.raw_materials:
        if not frappe.db.exists("Item", "Test Extra Item 1"):
            make_item(
                "Test Extra Item 1",
                {
                    "is_stock_item": 1,
                },
            )

        if not frappe.db.exists("Item", "Test Extra Item 2"):
            make_item(
                "Test Extra Item 2",
                {
                    "is_stock_item": 1,
                },
            )

        args.raw_materials = ["_Test FG Item", "Test Extra Item 1"]

    if not frappe.db.get_value("BOM", {"item": args.item_code}, "name"):
        make_bom(item=args.item_code, raw_materials=args.get("raw_materials"))
Beispiel #24
0
	def test_serial_no_based_delivery(self):
		frappe.set_value("Stock Settings", None, "automatically_set_serial_nos_based_on_fifo", 1)
		from erpnext.stock.doctype.item.test_item import make_item
		item = make_item("_Reserved_Serialized_Item", {"is_stock_item": 1,
					"maintain_stock": 1,
					"has_serial_no": 1,
					"serial_no_series": "SI.####",
					"valuation_rate": 500,
					"item_defaults": [
						{
							"default_warehouse": "_Test Warehouse - _TC",
							"company": "_Test Company"
						}]
					})
		frappe.db.sql("""delete from `tabSerial No` where item_code=%s""", (item.item_code))
		make_item("_Test Item A", {"maintain_stock": 1,
					"valuation_rate": 100,
					"item_defaults": [
						{
							"default_warehouse": "_Test Warehouse - _TC",
							"company": "_Test Company"
						}]
					})
		make_item("_Test Item B", {"maintain_stock": 1,
					"valuation_rate": 200,
					"item_defaults": [
						{
							"default_warehouse": "_Test Warehouse - _TC",
							"company": "_Test Company"
						}]
					})
		from erpnext.manufacturing.doctype.production_plan.test_production_plan import make_bom
		make_bom(item=item.item_code, rate=1000,
			raw_materials = ['_Test Item A', '_Test Item B'])

		so = make_sales_order(**{
			"item_list": [{
				"item_code": item.item_code,
				"ensure_delivery_based_on_produced_serial_no": 1,
				"qty": 1,
				"rate":1000
			}]
		})
		so.submit()
		from erpnext.manufacturing.doctype.work_order.test_work_order import \
			make_wo_order_test_record
		work_order = make_wo_order_test_record(item=item.item_code,
			qty=1, do_not_save=True)
		work_order.fg_warehouse = "_Test Warehouse - _TC"
		work_order.sales_order = so.name
		work_order.submit()
		make_stock_entry(item_code=item.item_code, target="_Test Warehouse - _TC", qty=1)
		item_serial_no = frappe.get_doc("Serial No", {"item_code": item.item_code})
		from erpnext.manufacturing.doctype.work_order.work_order import \
			make_stock_entry as make_production_stock_entry
		se = frappe.get_doc(make_production_stock_entry(work_order.name, "Manufacture", 1))
		se.submit()
		reserved_serial_no = se.get("items")[2].serial_no
		serial_no_so = frappe.get_value("Serial No", reserved_serial_no, "sales_order")
		self.assertEqual(serial_no_so, so.name)
		dn = make_delivery_note(so.name)
		dn.save()
		self.assertEqual(reserved_serial_no, dn.get("items")[0].serial_no)
		item_line = dn.get("items")[0]
		item_line.serial_no = item_serial_no.name
		self.assertRaises(frappe.ValidationError, dn.submit)
		item_line = dn.get("items")[0]
		item_line.serial_no =  reserved_serial_no
		self.assertTrue(dn.submit)
		dn.load_from_db()
		dn.cancel()
		si = make_sales_invoice(so.name)
		si.update_stock = 1
		si.save()
		self.assertEqual(si.get("items")[0].serial_no, reserved_serial_no)
		item_line = si.get("items")[0]
		item_line.serial_no = item_serial_no.name
		self.assertRaises(frappe.ValidationError, dn.submit)
		item_line = si.get("items")[0]
		item_line.serial_no = reserved_serial_no
		self.assertTrue(si.submit)
		si.submit()
		si.load_from_db()
		si.cancel()
		si = make_sales_invoice(so.name)
		si.update_stock = 0
		si.submit()
		from erpnext.accounts.doctype.sales_invoice.sales_invoice import \
			make_delivery_note as make_delivery_note_from_invoice
		dn = make_delivery_note_from_invoice(si.name)
		dn.save()
		dn.submit()
		self.assertEqual(dn.get("items")[0].serial_no, reserved_serial_no)
		dn.load_from_db()
		dn.cancel()
		si.load_from_db()
		si.cancel()
		se.load_from_db()
		se.cancel()
		self.assertFalse(frappe.db.exists("Serial No", {"sales_order": so.name}))
Beispiel #25
0
	def test_serial_no_based_delivery(self):
		frappe.set_value("Stock Settings", None, "automatically_set_serial_nos_based_on_fifo", 1)
		item = make_item("_Reserved_Serialized_Item", {"is_stock_item": 1,
					"maintain_stock": 1,
					"has_serial_no": 1,
					"serial_no_series": "SI.####",
					"valuation_rate": 500,
					"item_defaults": [
						{
							"default_warehouse": "_Test Warehouse - _TC",
							"company": "_Test Company"
						}]
					})
		frappe.db.sql("""delete from `tabSerial No` where item_code=%s""", (item.item_code))
		make_item("_Test Item A", {"maintain_stock": 1,
					"valuation_rate": 100,
					"item_defaults": [
						{
							"default_warehouse": "_Test Warehouse - _TC",
							"company": "_Test Company"
						}]
					})
		make_item("_Test Item B", {"maintain_stock": 1,
					"valuation_rate": 200,
					"item_defaults": [
						{
							"default_warehouse": "_Test Warehouse - _TC",
							"company": "_Test Company"
						}]
					})
		from erpnext.manufacturing.doctype.production_plan.test_production_plan import make_bom
		make_bom(item=item.item_code, rate=1000,
			raw_materials = ['_Test Item A', '_Test Item B'])

		so = make_sales_order(**{
			"item_list": [{
				"item_code": item.item_code,
				"ensure_delivery_based_on_produced_serial_no": 1,
				"qty": 1,
				"rate":1000
			}]
		})
		so.submit()
		from erpnext.manufacturing.doctype.work_order.test_work_order import \
			make_wo_order_test_record
		work_order = make_wo_order_test_record(item=item.item_code,
			qty=1, do_not_save=True)
		work_order.fg_warehouse = "_Test Warehouse - _TC"
		work_order.sales_order = so.name
		work_order.submit()
		make_stock_entry(item_code=item.item_code, target="_Test Warehouse - _TC", qty=1)
		item_serial_no = frappe.get_doc("Serial No", {"item_code": item.item_code})
		from erpnext.manufacturing.doctype.work_order.work_order import \
			make_stock_entry as make_production_stock_entry
		se = frappe.get_doc(make_production_stock_entry(work_order.name, "Manufacture", 1))
		se.submit()
		reserved_serial_no = se.get("items")[2].serial_no
		serial_no_so = frappe.get_value("Serial No", reserved_serial_no, "sales_order")
		self.assertEqual(serial_no_so, so.name)
		dn = make_delivery_note(so.name)
		dn.save()
		self.assertEqual(reserved_serial_no, dn.get("items")[0].serial_no)
		item_line = dn.get("items")[0]
		item_line.serial_no = item_serial_no.name
		item_line = dn.get("items")[0]
		item_line.serial_no =  reserved_serial_no
		dn.submit()
		dn.load_from_db()
		dn.cancel()
		si = make_sales_invoice(so.name)
		si.update_stock = 1
		si.save()
		self.assertEqual(si.get("items")[0].serial_no, reserved_serial_no)
		item_line = si.get("items")[0]
		item_line.serial_no = item_serial_no.name
		self.assertRaises(frappe.ValidationError, dn.submit)
		item_line = si.get("items")[0]
		item_line.serial_no = reserved_serial_no
		self.assertTrue(si.submit)
		si.submit()
		si.load_from_db()
		si.cancel()
		si = make_sales_invoice(so.name)
		si.update_stock = 0
		si.submit()
		from erpnext.accounts.doctype.sales_invoice.sales_invoice import \
			make_delivery_note as make_delivery_note_from_invoice
		dn = make_delivery_note_from_invoice(si.name)
		dn.save()
		dn.submit()
		self.assertEqual(dn.get("items")[0].serial_no, reserved_serial_no)
		dn.load_from_db()
		dn.cancel()
		si.load_from_db()
		si.cancel()
		se.load_from_db()
		se.cancel()
		self.assertFalse(frappe.db.exists("Serial No", {"sales_order": so.name}))
Beispiel #26
0
    def test_batch_size_for_fg_item(self):
        fg_item = "Test Batch Size Item For BOM 3"
        rm1 = "Test Batch Size Item RM 1 For BOM 3"

        frappe.db.set_value('Manufacturing Settings', None,
                            'make_serial_no_batch_from_work_order', 0)
        for item in [
                "Test Batch Size Item For BOM 3",
                "Test Batch Size Item RM 1 For BOM 3"
        ]:
            item_args = {
                "include_item_in_manufacturing": 1,
                "is_stock_item": 1
            }

            if item == fg_item:
                item_args['has_batch_no'] = 1
                item_args['create_new_batch'] = 1
                item_args['batch_number_series'] = 'TBSI3.#####'

            make_item(item, item_args)

        bom_name = frappe.db.get_value("BOM", {
            "item": fg_item,
            "is_active": 1,
            "with_operations": 1
        }, "name")

        if not bom_name:
            bom = make_bom(item=fg_item,
                           rate=1000,
                           raw_materials=[rm1],
                           do_not_save=True)
            bom.save()
            bom.submit()
            bom_name = bom.name

        work_order = make_wo_order_test_record(item=fg_item,
                                               skip_transfer=True,
                                               planned_start_date=now(),
                                               qty=1)
        ste1 = frappe.get_doc(
            make_stock_entry(work_order.name, "Manufacture", 1))
        for row in ste1.get('items'):
            if row.is_finished_item:
                self.assertEqual(row.item_code, fg_item)

        work_order = make_wo_order_test_record(item=fg_item,
                                               skip_transfer=True,
                                               planned_start_date=now(),
                                               qty=1)
        frappe.db.set_value('Manufacturing Settings', None,
                            'make_serial_no_batch_from_work_order', 1)
        ste1 = frappe.get_doc(
            make_stock_entry(work_order.name, "Manufacture", 1))
        for row in ste1.get('items'):
            if row.is_finished_item:
                self.assertEqual(row.item_code, fg_item)

        work_order = make_wo_order_test_record(item=fg_item,
                                               skip_transfer=True,
                                               planned_start_date=now(),
                                               qty=30,
                                               do_not_save=True)
        work_order.batch_size = 10
        work_order.insert()
        work_order.submit()
        self.assertEqual(work_order.has_batch_no, 1)
        ste1 = frappe.get_doc(
            make_stock_entry(work_order.name, "Manufacture", 30))
        for row in ste1.get('items'):
            if row.is_finished_item:
                self.assertEqual(row.item_code, fg_item)
                self.assertEqual(row.qty, 10)

        frappe.db.set_value('Manufacturing Settings', None,
                            'make_serial_no_batch_from_work_order', 0)