示例#1
0
def make_subcontracted_item(**args):
    from erpbee.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"))
示例#2
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)
示例#3
0
    def test_sub_contracted_item_costing(self):
        from erpbee.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()
示例#4
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)
示例#5
0
def setup_bom(**args):
    from erpbee.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 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)
    else:
        bom_doc = frappe.get_doc("BOM", name)

    return bom_doc
示例#6
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)
示例#7
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)
示例#8
0
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)