Пример #1
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 dataent.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 = dataent.get_doc(
            make_stock_entry(wo.name, "Material Transfer for Manufacture", 1))
        ste.insert()
        ste.submit()
        self.assertEqual(len(ste.items), 1)
        ste1 = dataent.get_doc(make_stock_entry(wo.name, "Manufacture", 1))
        self.assertEqual(len(ste1.items), 3)
Пример #2
0
    def test_create_two_quotations(self):
        from epaas.stock.doctype.item.test_item import make_item

        first_item = make_item("_Test Laptop", {"is_stock_item": 1})

        second_item = make_item("_Test CPU", {"is_stock_item": 1})

        qo_item1 = [{
            "item_code": first_item.item_code,
            "warehouse": "",
            "qty": 2,
            "rate": 400,
            "delivered_by_supplier": 1,
            "supplier": '_Test Supplier'
        }]

        qo_item2 = [{
            "item_code": second_item.item_code,
            "warehouse": "_Test Warehouse - _TC",
            "qty": 2,
            "rate": 300,
            "conversion_factor": 1.0
        }]

        first_qo = make_quotation(item_list=qo_item1, do_not_submit=True)
        first_qo.submit()
        sec_qo = make_quotation(item_list=qo_item2, do_not_submit=True)
        sec_qo.submit()
Пример #3
0
def make_serialized_item():
	asset_item = "Test Serialized Asset Item"

	if not dataent.db.exists('Item', asset_item):
		asset_category = dataent.get_all('Asset Category')

		if asset_category:
			asset_category = asset_category[0].name

		if not asset_category:
			doc = dataent.get_doc({
				'doctype': 'Asset Category',
				'asset_category_name': 'Test Asset Category',
				'depreciation_method': 'Straight Line',
				'total_number_of_depreciations': 12,
				'frequency_of_depreciation': 1,
				'accounts': [{
					'company_name': '_Test Company',
					'fixed_asset_account': '_Test Fixed Asset - _TC',
					'accumulated_depreciation_account': 'Depreciation - _TC',
					'depreciation_expense_account': 'Depreciation - _TC'
				}]
			}).insert()

			asset_category = doc.name

		make_item(asset_item, {'is_stock_item':0,
			'stock_uom': 'Box', 'is_fixed_asset': 1, 'has_serial_no': 1,
			'asset_category': asset_category, 'serial_no_series': 'ABC.###'})
Пример #4
0
    def test_auto_insert_price(self):
        from epaas.stock.doctype.item.test_item import make_item
        make_item("_Test Item for Auto Price List", {"is_stock_item": 0})
        dataent.db.set_value("Stock Settings", None,
                             "auto_insert_price_list_rate_if_missing", 1)

        item_price = dataent.db.get_value(
            "Item Price", {
                "price_list": "_Test Price List",
                "item_code": "_Test Item for Auto Price List"
            })
        if item_price:
            dataent.delete_doc("Item Price", item_price)

        make_sales_order(item_code="_Test Item for Auto Price List",
                         selling_price_list="_Test Price List",
                         rate=100)

        self.assertEqual(
            dataent.db.get_value(
                "Item Price", {
                    "price_list": "_Test Price List",
                    "item_code": "_Test Item for Auto Price List"
                }, "price_list_rate"), 100)

        # do not update price list
        dataent.db.set_value("Stock Settings", None,
                             "auto_insert_price_list_rate_if_missing", 0)

        item_price = dataent.db.get_value(
            "Item Price", {
                "price_list": "_Test Price List",
                "item_code": "_Test Item for Auto Price List"
            })
        if item_price:
            dataent.delete_doc("Item Price", item_price)

        make_sales_order(item_code="_Test Item for Auto Price List",
                         selling_price_list="_Test Price List",
                         rate=100)

        self.assertEqual(
            dataent.db.get_value(
                "Item Price", {
                    "price_list": "_Test Price List",
                    "item_code": "_Test Item for Auto Price List"
                }, "price_list_rate"), None)

        dataent.db.set_value("Stock Settings", None,
                             "auto_insert_price_list_rate_if_missing", 1)
Пример #5
0
    def test_not_accept_duplicate_serial_no(self):
        from epaas.stock.doctype.stock_entry.test_stock_entry import make_stock_entry
        from epaas.stock.doctype.delivery_note.test_delivery_note import create_delivery_note

        item_code = dataent.db.get_value('Item', {
            'has_serial_no': 1,
            'is_fixed_asset': 0
        })
        if not item_code:
            item = make_item("Test Serial Item 1", dict(has_serial_no=1))
            item_code = item.name

        serial_no = random_string(5)
        make_purchase_receipt(item_code=item_code, qty=1, serial_no=serial_no)
        create_delivery_note(item_code=item_code, qty=1, serial_no=serial_no)

        pr = make_purchase_receipt(item_code=item_code,
                                   qty=1,
                                   serial_no=serial_no,
                                   do_not_submit=True)
        self.assertRaises(SerialNoDuplicateError, pr.submit)

        se = make_stock_entry(item_code=item_code,
                              target="_Test Warehouse - _TC",
                              qty=1,
                              serial_no=serial_no,
                              basic_rate=100,
                              do_not_submit=True)
        self.assertRaises(SerialNoDuplicateError, se.submit)
Пример #6
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 dataent.db.get_value('Item Price',
                                    {'item_code': '_Test FG Non Stock Item'}):
            dataent.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 dataent.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 = dataent.get_doc(
            make_stock_entry(wo.name, "Material Transfer for Manufacture", 1))
        se.insert()
        se.submit()

        ste = dataent.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)
Пример #7
0
    def test_mix_type_product_bundle(self):
        from epaas.selling.doctype.product_bundle.test_product_bundle import make_product_bundle
        from epaas.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="")
Пример #8
0
    def test_purchase_return_for_multi_uom(self):
        item_code = "_Test Purchase Return For Multi-UOM"
        if not dataent.db.exists('Item', item_code):
            item = make_item(item_code, {'stock_uom': 'Box'})
            row = item.append('uoms', {
                'uom': 'Unit',
                'conversion_factor': 0.1
            })
            row.db_update()

        pr = make_purchase_receipt(item_code=item_code,
                                   qty=1,
                                   uom="Box",
                                   conversion_factor=1.0)
        return_pr = make_purchase_receipt(item_code=item_code,
                                          qty=-10,
                                          uom="Unit",
                                          stock_uom="Box",
                                          conversion_factor=0.1,
                                          is_return=1,
                                          return_against=pr.name)

        self.assertEqual(abs(return_pr.items[0].stock_qty), 1.0)
Пример #9
0
def make_subcontracted_item(item_code):
    from epaas.manufacturing.doctype.production_plan.test_production_plan import make_bom

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

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

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

    if not dataent.db.get_value('BOM', {'item': item_code}, 'name'):
        make_bom(item=item_code,
                 raw_materials=['_Test FG Item', 'Test Extra Item 1'])
Пример #10
0
    def test_service_type_product_bundle(self):
        from epaas.selling.doctype.product_bundle.test_product_bundle import make_product_bundle
        from epaas.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])
Пример #11
0
    def test_serialized_asset_item(self):
        asset_item = "Test Serialized Asset Item"

        if not dataent.db.exists('Item', asset_item):
            asset_category = dataent.get_all('Asset Category')

            if asset_category:
                asset_category = asset_category[0].name

            if not asset_category:
                doc = dataent.get_doc({
                    'doctype':
                    'Asset Category',
                    'asset_category_name':
                    'Test Asset Category',
                    'depreciation_method':
                    'Straight Line',
                    'total_number_of_depreciations':
                    12,
                    'frequency_of_depreciation':
                    1,
                    'accounts': [{
                        'company_name':
                        '_Test Company',
                        'fixed_asset_account':
                        '_Test Fixed Asset - _TC',
                        'accumulated_depreciation_account':
                        'Depreciation - _TC',
                        'depreciation_expense_account':
                        'Depreciation - _TC'
                    }]
                }).insert()

                asset_category = doc.name

            item_data = make_item(
                asset_item, {
                    'is_stock_item': 0,
                    'stock_uom': 'Box',
                    'is_fixed_asset': 1,
                    'has_serial_no': 1,
                    'asset_category': asset_category,
                    'serial_no_series': 'ABC.###'
                })
            asset_item = item_data.item_code

        pr = make_purchase_receipt(item_code=asset_item, qty=3)
        asset = dataent.db.get_value('Asset', {'purchase_receipt': pr.name},
                                     'name')
        asset_movement = dataent.db.get_value('Asset Movement',
                                              {'reference_name': pr.name},
                                              'name')
        serial_nos = dataent.get_all('Serial No', {'asset': asset}, 'name')

        self.assertEquals(len(serial_nos), 3)

        location = dataent.db.get_value('Serial No', serial_nos[0].name,
                                        'location')
        self.assertEquals(location, "Test Location")

        pr.cancel()
        serial_nos = dataent.get_all('Serial No', {'asset': asset},
                                     'name') or []
        self.assertEquals(len(serial_nos), 0)
        #dataent.db.sql("delete from `tabLocation")
        dataent.db.sql("delete from `tabAsset`")
Пример #12
0
    def test_request_for_raw_materials(self):
        from epaas.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 epaas.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 = dataent._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 = dataent.db.sql(
            """select name from `tabMaterial Request` ORDER BY creation DESC LIMIT 1""",
            as_dict=1)[0]
        mr_doc = dataent.get_doc('Material Request', mr.get('name'))
        self.assertEqual(mr_doc.items[0].sales_order, so.name)
Пример #13
0
    def test_serial_no_based_delivery(self):
        dataent.set_value("Stock Settings", None,
                          "automatically_set_serial_nos_based_on_fifo", 1)
        from epaas.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"
                }]
            })
        dataent.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 epaas.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 epaas.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 = dataent.get_doc("Serial No",
                                         {"item_code": item.item_code})
        from epaas.manufacturing.doctype.work_order.work_order import \
         make_stock_entry as make_production_stock_entry
        se = dataent.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 = dataent.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(dataent.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(dataent.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 epaas.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(
            dataent.db.exists("Serial No", {"sales_order": so.name}))
Пример #14
0
    def test_drop_shipping(self):
        from epaas.selling.doctype.sales_order.sales_order import make_purchase_order_for_drop_shipment
        from epaas.buying.doctype.purchase_order.purchase_order import update_status

        make_stock_entry(target="_Test Warehouse - _TC", qty=10, rate=100)
        from epaas.stock.doctype.item.test_item import make_item
        po_item = make_item("_Test Item for Drop Shipping", {
            "is_stock_item": 1,
            "delivered_by_supplier": 1
        })

        dn_item = make_item("_Test Regular Item", {"is_stock_item": 1})

        so_items = [{
            "item_code": po_item.item_code,
            "warehouse": "",
            "qty": 2,
            "rate": 400,
            "delivered_by_supplier": 1,
            "supplier": '_Test Supplier'
        }, {
            "item_code": dn_item.item_code,
            "warehouse": "_Test Warehouse - _TC",
            "qty": 2,
            "rate": 300,
            "conversion_factor": 1.0
        }]

        if dataent.db.get_value("Item", "_Test Regular Item",
                                "is_stock_item") == 1:
            make_stock_entry(item="_Test Regular Item",
                             target="_Test Warehouse - _TC",
                             qty=10,
                             rate=100)

        #setuo existing qty from bin
        bin = dataent.get_all("Bin",
                              filters={
                                  "item_code": po_item.item_code,
                                  "warehouse": "_Test Warehouse - _TC"
                              },
                              fields=["ordered_qty", "reserved_qty"])

        existing_ordered_qty = bin[0].ordered_qty if bin else 0.0
        existing_reserved_qty = bin[0].reserved_qty if bin else 0.0

        bin = dataent.get_all("Bin",
                              filters={
                                  "item_code": dn_item.item_code,
                                  "warehouse": "_Test Warehouse - _TC"
                              },
                              fields=["reserved_qty"])

        existing_reserved_qty_for_dn_item = bin[0].reserved_qty if bin else 0.0

        #create so, po and partial dn
        so = make_sales_order(item_list=so_items, do_not_submit=True)
        so.submit()

        po = make_purchase_order_for_drop_shipment(so.name, '_Test Supplier')
        po.submit()

        dn = create_dn_against_so(so.name, delivered_qty=1)

        self.assertEqual(so.customer, po.customer)
        self.assertEqual(po.items[0].sales_order, so.name)
        self.assertEqual(po.items[0].item_code, po_item.item_code)
        self.assertEqual(dn.items[0].item_code, dn_item.item_code)

        #test ordered_qty and reserved_qty
        bin = dataent.get_all("Bin",
                              filters={
                                  "item_code": po_item.item_code,
                                  "warehouse": "_Test Warehouse - _TC"
                              },
                              fields=["ordered_qty", "reserved_qty"])

        ordered_qty = bin[0].ordered_qty if bin else 0.0
        reserved_qty = bin[0].reserved_qty if bin else 0.0

        self.assertEqual(abs(flt(ordered_qty)), existing_ordered_qty)
        self.assertEqual(abs(flt(reserved_qty)), existing_reserved_qty)

        reserved_qty = dataent.db.get_value(
            "Bin", {
                "item_code": dn_item.item_code,
                "warehouse": "_Test Warehouse - _TC"
            }, "reserved_qty")

        self.assertEqual(abs(flt(reserved_qty)),
                         existing_reserved_qty_for_dn_item + 1)

        #test po_item length
        self.assertEqual(len(po.items), 1)

        #test per_delivered status
        update_status("Delivered", po.name)
        self.assertEqual(
            flt(dataent.db.get_value("Sales Order", so.name, "per_delivered"),
                2), 75.00)

        #test reserved qty after complete delivery
        dn = create_dn_against_so(so.name, delivered_qty=1)
        reserved_qty = dataent.db.get_value(
            "Bin", {
                "item_code": dn_item.item_code,
                "warehouse": "_Test Warehouse - _TC"
            }, "reserved_qty")

        self.assertEqual(abs(flt(reserved_qty)),
                         existing_reserved_qty_for_dn_item)

        #test after closing so
        so.db_set('status', "Closed")
        so.update_reserved_qty()

        bin = dataent.get_all("Bin",
                              filters={
                                  "item_code": po_item.item_code,
                                  "warehouse": "_Test Warehouse - _TC"
                              },
                              fields=["ordered_qty", "reserved_qty"])

        ordered_qty = bin[0].ordered_qty if bin else 0.0
        reserved_qty = bin[0].reserved_qty if bin else 0.0

        self.assertEqual(abs(flt(ordered_qty)), existing_ordered_qty)
        self.assertEqual(abs(flt(reserved_qty)), existing_reserved_qty)

        reserved_qty = dataent.db.get_value(
            "Bin", {
                "item_code": dn_item.item_code,
                "warehouse": "_Test Warehouse - _TC"
            }, "reserved_qty")

        self.assertEqual(abs(flt(reserved_qty)),
                         existing_reserved_qty_for_dn_item)
Пример #15
0
 def make_batch_item(cls, item_name):
     from epaas.stock.doctype.item.test_item import make_item
     if not dataent.db.exists(item_name):
         return make_item(
             item_name,
             dict(has_batch_no=1, create_new_batch=1, is_stock_item=1))