def test_purchase_receipt_gl_entry(self):
		set_perpetual_inventory()
		self.assertEqual(cint(frappe.defaults.get_global_default("auto_accounting_for_stock")), 1)
		pr = frappe.copy_doc(test_records[0])
		pr.insert()
		pr.submit()

		gl_entries = get_gl_entries("Purchase Receipt", pr.name)

		self.assertTrue(gl_entries)

		stock_in_hand_account = frappe.db.get_value("Account",
			{"warehouse": pr.get("items")[0].warehouse})
		fixed_asset_account = frappe.db.get_value("Account",
			{"warehouse": pr.get("items")[1].warehouse})

		expected_values = {
			stock_in_hand_account: [375.0, 0.0],
			fixed_asset_account: [375.0, 0.0],
			"Stock Received But Not Billed - _TC": [0.0, 500.0],
			"Expenses Included In Valuation - _TC": [0.0, 250.0]
		}

		for gle in gl_entries:
			self.assertEquals(expected_values[gle.account][0], gle.debit)
			self.assertEquals(expected_values[gle.account][1], gle.credit)

		pr.cancel()
		self.assertFalse(get_gl_entries("Purchase Receipt", pr.name))

		set_perpetual_inventory(0)
Пример #2
0
	def test_purchase_receipt_for_disable_allow_cost_center_in_entry_of_bs_account(self):
		accounts_settings = frappe.get_doc('Accounts Settings', 'Accounts Settings')
		accounts_settings.allow_cost_center_in_entry_of_bs_account = 0
		accounts_settings.save()

		if not frappe.db.exists('Location', 'Test Location'):
			frappe.get_doc({
				'doctype': 'Location',
				'location_name': 'Test Location'
			}).insert()

		set_perpetual_inventory(1, "_Test Company")
		pr = make_purchase_receipt()

		stock_in_hand_account = get_inventory_account(pr.company, pr.get("items")[0].warehouse)
		gl_entries = get_gl_entries("Purchase Receipt", pr.name)

		self.assertTrue(gl_entries)

		expected_values = {
			"Stock Received But Not Billed - _TC": {
				"cost_center": None
			},
			stock_in_hand_account: {
				"cost_center": None
			}
		}
		for i, gle in enumerate(gl_entries):
			self.assertEqual(expected_values[gle.account]["cost_center"], gle.cost_center)

		set_perpetual_inventory(0, pr.company)
Пример #3
0
	def test_warehouse_merging(self):
		set_perpetual_inventory(1)

		create_warehouse("Test Warehouse for Merging 1")
		create_warehouse("Test Warehouse for Merging 2")

		make_stock_entry(item_code="_Test Item", target="Test Warehouse for Merging 1 - _TC",
			qty=1, rate=100)
		make_stock_entry(item_code="_Test Item", target="Test Warehouse for Merging 2 - _TC",
			qty=1, rate=100)

		existing_bin_qty = (
			cint(frappe.db.get_value("Bin",
				{"item_code": "_Test Item", "warehouse": "Test Warehouse for Merging 1 - _TC"}, "actual_qty"))
			+ cint(frappe.db.get_value("Bin",
				{"item_code": "_Test Item", "warehouse": "Test Warehouse for Merging 2 - _TC"}, "actual_qty"))
		)

		rename_doc("Warehouse", "Test Warehouse for Merging 1 - _TC",
			"Test Warehouse for Merging 2 - _TC", merge=True)

		self.assertFalse(frappe.db.exists("Warehouse", "Test Warehouse for Merging 1 - _TC"))

		bin_qty = frappe.db.get_value("Bin",
			{"item_code": "_Test Item", "warehouse": "Test Warehouse for Merging 2 - _TC"}, "actual_qty")

		self.assertEqual(bin_qty, existing_bin_qty)

		self.assertTrue(frappe.db.get_value("Warehouse",
			filters={"account": "Test Warehouse for Merging 2 - _TC"}))
Пример #4
0
	def test_warehouse_renaming(self):
		set_perpetual_inventory(1)
		create_warehouse("Test Warehouse for Renaming 1")
		account = get_inventory_account("_Test Company", "Test Warehouse for Renaming 1 - _TC")
		self.assertTrue(frappe.db.get_value("Warehouse", filters={"account": account}))

		# Rename with abbr
		if frappe.db.exists("Warehouse", "Test Warehouse for Renaming 2 - _TC"):
			frappe.delete_doc("Warehouse", "Test Warehouse for Renaming 2 - _TC")
		rename_doc("Warehouse", "Test Warehouse for Renaming 1 - _TC", "Test Warehouse for Renaming 2 - _TC")

		self.assertTrue(frappe.db.get_value("Warehouse",
			filters={"account": "Test Warehouse for Renaming 1 - _TC"}))

		# Rename without abbr
		if frappe.db.exists("Warehouse", "Test Warehouse for Renaming 3 - _TC"):
			frappe.delete_doc("Warehouse", "Test Warehouse for Renaming 3 - _TC")

		rename_doc("Warehouse", "Test Warehouse for Renaming 2 - _TC", "Test Warehouse for Renaming 3")

		self.assertTrue(frappe.db.get_value("Warehouse",
			filters={"account": "Test Warehouse for Renaming 1 - _TC"}))

		# Another rename with multiple dashes
		if frappe.db.exists("Warehouse", "Test - Warehouse - Company - _TC"):
			frappe.delete_doc("Warehouse", "Test - Warehouse - Company - _TC")
		rename_doc("Warehouse", "Test Warehouse for Renaming 3 - _TC", "Test - Warehouse - Company")
Пример #5
0
	def test_warehouse_renaming(self):
		set_perpetual_inventory(1)
		create_warehouse("Test Warehouse for Renaming 1")
		account = get_inventory_account("_Test Company", "Test Warehouse for Renaming 1 - _TC")
		self.assertTrue(frappe.db.get_value("Warehouse", filters={"account": account}))

		# Rename with abbr
		if frappe.db.exists("Warehouse", "Test Warehouse for Renaming 2 - _TC"):
			frappe.delete_doc("Warehouse", "Test Warehouse for Renaming 2 - _TC")
		rename_doc("Warehouse", "Test Warehouse for Renaming 1 - _TC", "Test Warehouse for Renaming 2 - _TC")

		self.assertTrue(frappe.db.get_value("Warehouse",
			filters={"account": "Test Warehouse for Renaming 1 - _TC"}))

		# Rename without abbr
		if frappe.db.exists("Warehouse", "Test Warehouse for Renaming 3 - _TC"):
			frappe.delete_doc("Warehouse", "Test Warehouse for Renaming 3 - _TC")

		rename_doc("Warehouse", "Test Warehouse for Renaming 2 - _TC", "Test Warehouse for Renaming 3")

		self.assertTrue(frappe.db.get_value("Warehouse",
			filters={"account": "Test Warehouse for Renaming 1 - _TC"}))

		# Another rename with multiple dashes
		if frappe.db.exists("Warehouse", "Test - Warehouse - Company - _TC"):
			frappe.delete_doc("Warehouse", "Test - Warehouse - Company - _TC")
		rename_doc("Warehouse", "Test Warehouse for Renaming 3 - _TC", "Test - Warehouse - Company")
Пример #6
0
	def test_warehouse_merging(self):
		set_perpetual_inventory(1)

		create_warehouse("Test Warehouse for Merging 1")
		create_warehouse("Test Warehouse for Merging 2")

		make_stock_entry(item_code="_Test Item", target="Test Warehouse for Merging 1 - _TC",
			qty=1, rate=100)
		make_stock_entry(item_code="_Test Item", target="Test Warehouse for Merging 2 - _TC",
			qty=1, rate=100)

		existing_bin_qty = (
			cint(frappe.db.get_value("Bin",
				{"item_code": "_Test Item", "warehouse": "Test Warehouse for Merging 1 - _TC"}, "actual_qty"))
			+ cint(frappe.db.get_value("Bin",
				{"item_code": "_Test Item", "warehouse": "Test Warehouse for Merging 2 - _TC"}, "actual_qty"))
		)

		rename_doc("Warehouse", "Test Warehouse for Merging 1 - _TC",
			"Test Warehouse for Merging 2 - _TC", merge=True)

		self.assertFalse(frappe.db.exists("Warehouse", "Test Warehouse for Merging 1 - _TC"))

		bin_qty = frappe.db.get_value("Bin",
			{"item_code": "_Test Item", "warehouse": "Test Warehouse for Merging 2 - _TC"}, "actual_qty")

		self.assertEqual(bin_qty, existing_bin_qty)

		self.assertFalse(frappe.db.exists("Account", "Test Warehouse for Merging 1 - _TC"))
		self.assertTrue(frappe.db.exists("Account", "Test Warehouse for Merging 2 - _TC"))
		self.assertTrue(frappe.db.get_value("Account",
			filters={"warehouse": "Test Warehouse for Merging 2 - _TC"}))
Пример #7
0
	def test_purchase_receipt_for_disable_allow_cost_center_in_entry_of_bs_account(self):
		accounts_settings = frappe.get_doc('Accounts Settings', 'Accounts Settings')
		accounts_settings.allow_cost_center_in_entry_of_bs_account = 0
		accounts_settings.save()

		if not frappe.db.exists('Location', 'Test Location'):
			frappe.get_doc({
				'doctype': 'Location',
				'location_name': 'Test Location'
			}).insert()

		set_perpetual_inventory(1, "_Test Company")
		pr = make_purchase_receipt()

		stock_in_hand_account = get_inventory_account(pr.company, pr.get("items")[0].warehouse)
		gl_entries = get_gl_entries("Purchase Receipt", pr.name)

		self.assertTrue(gl_entries)

		expected_values = {
			"Stock Received But Not Billed - _TC": {
				"cost_center": None
			},
			stock_in_hand_account: {
				"cost_center": None
			}
		}
		for i, gle in enumerate(gl_entries):
			self.assertEqual(expected_values[gle.account]["cost_center"], gle.cost_center)

		set_perpetual_inventory(0, pr.company)
Пример #8
0
    def test_repack_no_change_in_valuation(self):
        company = frappe.db.get_value('Warehouse', '_Test Warehouse - _TC',
                                      'company')
        set_perpetual_inventory(0, company)

        make_stock_entry(item_code="_Test Item",
                         target="_Test Warehouse - _TC",
                         qty=50,
                         basic_rate=100)
        make_stock_entry(item_code="_Test Item Home Desktop 100",
                         target="_Test Warehouse - _TC",
                         qty=50,
                         basic_rate=100)

        repack = frappe.copy_doc(test_records[3])
        repack.posting_date = nowdate()
        repack.posting_time = nowtime()
        repack.set_stock_entry_type()
        repack.insert()
        repack.submit()

        self.check_stock_ledger_entries(
            "Stock Entry", repack.name,
            [["_Test Item", "_Test Warehouse - _TC", -50.0],
             ["_Test Item Home Desktop 100", "_Test Warehouse - _TC", 1]])

        gl_entries = frappe.db.sql("""select account, debit, credit
			from `tabGL Entry` where voucher_type='Stock Entry' and voucher_no=%s
			order by account desc""",
                                   repack.name,
                                   as_dict=1)
        self.assertFalse(gl_entries)

        set_perpetual_inventory(0, repack.company)
    def test_purchase_receipt_no_gl_entry(self):
        company = frappe.db.get_value('Warehouse', '_Test Warehouse - _TC',
                                      'company')
        set_perpetual_inventory(0, company)

        existing_bin_stock_value = frappe.db.get_value(
            "Bin", {
                "item_code": "_Test Item",
                "warehouse": "_Test Warehouse - _TC"
            }, "stock_value")

        pr = make_purchase_receipt()

        stock_value_difference = frappe.db.get_value(
            "Stock Ledger Entry", {
                "voucher_type": "Purchase Receipt",
                "voucher_no": pr.name,
                "item_code": "_Test Item",
                "warehouse": "_Test Warehouse - _TC"
            }, "stock_value_difference")

        self.assertEqual(stock_value_difference, 250)

        current_bin_stock_value = frappe.db.get_value(
            "Bin", {
                "item_code": "_Test Item",
                "warehouse": "_Test Warehouse - _TC"
            }, "stock_value")
        self.assertEqual(current_bin_stock_value,
                         existing_bin_stock_value + 250)

        self.assertFalse(get_gl_entries("Purchase Receipt", pr.name))
Пример #10
0
	def test_warehouse_user(self):
		add_user_permission("Warehouse", "_Test Warehouse 1 - _TC", "*****@*****.**")
		add_user_permission("Warehouse", "_Test Warehouse 2 - _TC1", "*****@*****.**")
		add_user_permission("Company", "_Test Company 1", "*****@*****.**")
		test_user = frappe.get_doc("User", "*****@*****.**")
		test_user.add_roles("Sales User", "Sales Manager", "Stock User")
		test_user.remove_roles("Stock Manager", "System Manager")

		frappe.get_doc("User", "*****@*****.**")\
			.add_roles("Sales User", "Sales Manager", "Stock User", "Stock Manager")

		st1 = frappe.copy_doc(test_records[0])
		st1.company = "_Test Company 1"
		set_perpetual_inventory(0, st1.company)
		frappe.set_user("*****@*****.**")
		st1.get("items")[0].t_warehouse="_Test Warehouse 2 - _TC1"
		self.assertRaises(frappe.PermissionError, st1.insert)

		test_user.add_roles("System Manager")

		frappe.set_user("*****@*****.**")
		st1 = frappe.copy_doc(test_records[0])
		st1.company = "_Test Company 1"
		st1.get("items")[0].t_warehouse="_Test Warehouse 2 - _TC1"
		st1.get("items")[0].expense_account = "Stock Adjustment - _TC1"
		st1.get("items")[0].cost_center = "Main - _TC1"
		st1.set_stock_entry_type()
		st1.insert()
		st1.submit()

		frappe.set_user("Administrator")
		remove_user_permission("Warehouse", "_Test Warehouse 1 - _TC", "*****@*****.**")
		remove_user_permission("Warehouse", "_Test Warehouse 2 - _TC1", "*****@*****.**")
		remove_user_permission("Company", "_Test Company 1", "*****@*****.**")
Пример #11
0
	def test_purchase_return(self):
		set_perpetual_inventory()

		pr = make_purchase_receipt()

		return_pr = make_purchase_receipt(is_return=1, return_against=pr.name, qty=-2)

		# check sle
		outgoing_rate = frappe.db.get_value("Stock Ledger Entry", {"voucher_type": "Purchase Receipt",
			"voucher_no": return_pr.name}, "outgoing_rate")

		self.assertEqual(outgoing_rate, 50)


		# check gl entries for return
		gl_entries = get_gl_entries("Purchase Receipt", return_pr.name)

		self.assertTrue(gl_entries)
		stock_in_hand_account = get_inventory_account(return_pr.company)

		expected_values = {
			stock_in_hand_account: [0.0, 100.0],
			"Stock Received But Not Billed - _TC": [100.0, 0.0],
		}

		for gle in gl_entries:
			self.assertEquals(expected_values[gle.account][0], gle.debit)
			self.assertEquals(expected_values[gle.account][1], gle.credit)

		set_perpetual_inventory(0)
Пример #12
0
    def test_material_receipt_gl_entry(self):
        company = frappe.db.get_value('Warehouse', '_Test Warehouse - _TC',
                                      'company')
        set_perpetual_inventory(1, company)

        mr = make_stock_entry(item_code="_Test Item",
                              target="_Test Warehouse - _TC",
                              qty=50,
                              basic_rate=100,
                              expense_account="Stock Adjustment - _TC")

        stock_in_hand_account = get_inventory_account(
            mr.company,
            mr.get("items")[0].t_warehouse)
        self.check_stock_ledger_entries(
            "Stock Entry", mr.name,
            [["_Test Item", "_Test Warehouse - _TC", 50.0]])

        self.check_gl_entries(
            "Stock Entry", mr.name,
            sorted([[stock_in_hand_account, 5000.0, 0.0],
                    ["Stock Adjustment - _TC", 0.0, 5000.0]]))

        mr.cancel()

        self.assertFalse(
            frappe.db.sql(
                """select * from `tabStock Ledger Entry`
			where voucher_type='Stock Entry' and voucher_no=%s""", mr.name))

        self.assertFalse(
            frappe.db.sql(
                """select * from `tabGL Entry`
			where voucher_type='Stock Entry' and voucher_no=%s""", mr.name))
    def test_subcontracting_gle_fg_item_rate_zero(self):
        from erpnext.stock.doctype.stock_entry.test_stock_entry import make_stock_entry
        set_perpetual_inventory()
        frappe.db.set_value("Buying Settings", None,
                            "backflush_raw_materials_of_subcontract_based_on",
                            "BOM")
        make_stock_entry(item_code="_Test Item",
                         target="Work In Progress - TCP1",
                         qty=100,
                         basic_rate=100,
                         company="_Test Company with perpetual inventory")
        make_stock_entry(item_code="_Test Item Home Desktop 100",
                         target="Work In Progress - TCP1",
                         qty=100,
                         basic_rate=100,
                         company="_Test Company with perpetual inventory")
        pr = make_purchase_receipt(
            item_code="_Test FG Item",
            qty=10,
            rate=0,
            is_subcontracted="Yes",
            company="_Test Company with perpetual inventory",
            warehouse='Stores - TCP1',
            supplier_warehouse='Work In Progress - TCP1')

        gl_entries = get_gl_entries("Purchase Receipt", pr.name)

        self.assertFalse(gl_entries)

        set_perpetual_inventory(0)
    def test_purchase_receipt_gl_entry(self):
        set_perpetual_inventory()
        self.assertEqual(
            cint(
                frappe.defaults.get_global_default(
                    "auto_accounting_for_stock")), 1)
        pr = frappe.copy_doc(test_records[0])
        pr.insert()
        pr.submit()

        gl_entries = get_gl_entries("Purchase Receipt", pr.name)

        self.assertTrue(gl_entries)

        stock_in_hand_account = frappe.db.get_value(
            "Account", {"warehouse": pr.get("items")[0].warehouse})
        fixed_asset_account = frappe.db.get_value(
            "Account", {"warehouse": pr.get("items")[1].warehouse})

        expected_values = {
            stock_in_hand_account: [375.0, 0.0],
            fixed_asset_account: [375.0, 0.0],
            "Stock Received But Not Billed - _TC": [0.0, 500.0],
            "Expenses Included In Valuation - _TC": [0.0, 250.0]
        }

        for gle in gl_entries:
            self.assertEquals(expected_values[gle.account][0], gle.debit)
            self.assertEquals(expected_values[gle.account][1], gle.credit)

        pr.cancel()
        self.assertFalse(get_gl_entries("Purchase Receipt", pr.name))

        set_perpetual_inventory(0)
Пример #15
0
	def test_warehouse_renaming(self):
		set_perpetual_inventory(1)
		create_warehouse("Test Warehouse for Renaming 1")

		self.assertTrue(frappe.db.exists("Account", "Test Warehouse for Renaming 1 - _TC"))
		self.assertTrue(frappe.db.get_value("Account",
			filters={"warehouse": "Test Warehouse for Renaming 1 - _TC"}))

		# Rename with abbr
		if frappe.db.exists("Warehouse", "Test Warehouse for Renaming 2 - _TC"):
			frappe.delete_doc("Warehouse", "Test Warehouse for Renaming 2 - _TC")
		rename_doc("Warehouse", "Test Warehouse for Renaming 1 - _TC", "Test Warehouse for Renaming 2 - _TC")

		self.assertTrue(frappe.db.exists("Account", "Test Warehouse for Renaming 2 - _TC"))
		self.assertTrue(frappe.db.get_value("Account",
			filters={"warehouse": "Test Warehouse for Renaming 2 - _TC"}))
		self.assertFalse(frappe.db.get_value("Account",
			filters={"warehouse": "Test Warehouse for Renaming 1 - _TC"}))

		# Rename without abbr
		if frappe.db.exists("Warehouse", "Test Warehouse for Renaming 3 - _TC"):
			frappe.delete_doc("Warehouse", "Test Warehouse for Renaming 3 - _TC")

		rename_doc("Warehouse", "Test Warehouse for Renaming 2 - _TC", "Test Warehouse for Renaming 3")

		self.assertTrue(frappe.db.exists("Account", "Test Warehouse for Renaming 3 - _TC"))
		self.assertTrue(frappe.db.get_value("Account",
			filters={"warehouse": "Test Warehouse for Renaming 3 - _TC"}))
Пример #16
0
    def test_material_transfer_gl_entry(self):
        company = frappe.db.get_value('Warehouse', '_Test Warehouse - _TC',
                                      'company')
        set_perpetual_inventory(1, company)

        create_stock_reconciliation(qty=100, rate=100)

        mtn = make_stock_entry(item_code="_Test Item",
                               source="_Test Warehouse - _TC",
                               target="_Test Warehouse 1 - _TC",
                               qty=45)

        self.check_stock_ledger_entries(
            "Stock Entry", mtn.name,
            [["_Test Item", "_Test Warehouse - _TC", -45.0],
             ["_Test Item", "_Test Warehouse 1 - _TC", 45.0]])

        stock_in_hand_account = get_inventory_account(
            mtn.company,
            mtn.get("items")[0].s_warehouse)

        fixed_asset_account = get_inventory_account(
            mtn.company,
            mtn.get("items")[0].t_warehouse)

        if stock_in_hand_account == fixed_asset_account:
            # no gl entry as both source and target warehouse has linked to same account.
            self.assertFalse(
                frappe.db.sql(
                    """select * from `tabGL Entry`
				where voucher_type='Stock Entry' and voucher_no=%s""", mtn.name))

        else:
            stock_value_diff = abs(
                frappe.db.get_value(
                    "Stock Ledger Entry", {
                        "voucher_type": "Stock Entry",
                        "voucher_no": mtn.name,
                        "warehouse": "_Test Warehouse - _TC"
                    }, "stock_value_difference"))

            self.check_gl_entries(
                "Stock Entry", mtn.name,
                sorted([
                    [stock_in_hand_account, 0.0, stock_value_diff],
                    [fixed_asset_account, stock_value_diff, 0.0],
                ]))

        mtn.cancel()
        self.assertFalse(
            frappe.db.sql(
                """select * from `tabStock Ledger Entry`
			where voucher_type='Stock Entry' and voucher_no=%s""", mtn.name))

        self.assertFalse(
            frappe.db.sql(
                """select * from `tabGL Entry`
			where voucher_type='Stock Entry' and voucher_no=%s""", mtn.name))
Пример #17
0
    def test_repack_with_additional_costs(self):
        company = frappe.db.get_value('Warehouse', '_Test Warehouse - _TC',
                                      'company')
        set_perpetual_inventory(1, company)

        make_stock_entry(item_code="_Test Item",
                         target="_Test Warehouse - _TC",
                         qty=50,
                         basic_rate=100)
        repack = frappe.copy_doc(test_records[3])
        repack.posting_date = nowdate()
        repack.posting_time = nowtime()

        repack.set("additional_costs", [
            {
                "description": "Actual Oerating Cost",
                "amount": 1000
            },
            {
                "description": "additional operating costs",
                "amount": 200
            },
        ])

        repack.set_stock_entry_type()
        repack.insert()
        repack.submit()

        stock_in_hand_account = get_inventory_account(
            repack.company,
            repack.get("items")[1].t_warehouse)
        rm_stock_value_diff = abs(
            frappe.db.get_value(
                "Stock Ledger Entry", {
                    "voucher_type": "Stock Entry",
                    "voucher_no": repack.name,
                    "item_code": "_Test Item"
                }, "stock_value_difference"))

        fg_stock_value_diff = abs(
            frappe.db.get_value(
                "Stock Ledger Entry", {
                    "voucher_type": "Stock Entry",
                    "voucher_no": repack.name,
                    "item_code": "_Test Item Home Desktop 100"
                }, "stock_value_difference"))

        stock_value_diff = flt(fg_stock_value_diff - rm_stock_value_diff, 2)

        self.assertEqual(stock_value_diff, 1200)

        self.check_gl_entries(
            "Stock Entry", repack.name,
            sorted([[stock_in_hand_account, 1200, 0.0],
                    ["Expenses Included In Valuation - _TC", 0.0, 1200.0]]))
        set_perpetual_inventory(0, repack.company)
Пример #18
0
	def test_warehouse_company_validation(self):
		company = frappe.db.get_value('Warehouse', '_Test Warehouse 2 - _TC1', 'company')
		set_perpetual_inventory(0, company)
		frappe.get_doc("User", "*****@*****.**")\
			.add_roles("Sales User", "Sales Manager", "Stock User", "Stock Manager")
		frappe.set_user("*****@*****.**")

		from erpnext.stock.utils import InvalidWarehouseCompany
		st1 = frappe.copy_doc(test_records[0])
		st1.get("items")[0].t_warehouse="_Test Warehouse 2 - _TC1"
		st1.set_stock_entry_type()
		st1.insert()
		self.assertRaises(InvalidWarehouseCompany, st1.submit)
Пример #19
0
	def test_purchase_return_for_rejected_qty(self):
		set_perpetual_inventory()

		pr = make_purchase_receipt(received_qty=4, qty=2)

		return_pr = make_purchase_receipt(is_return=1, return_against=pr.name, received_qty = -4, qty=-2)

		actual_qty = frappe.db.get_value("Stock Ledger Entry", {"voucher_type": "Purchase Receipt",
			"voucher_no": return_pr.name, 'warehouse': return_pr.items[0].rejected_warehouse}, "actual_qty")

		self.assertEqual(actual_qty, -2)

		set_perpetual_inventory(0)
Пример #20
0
	def test_stock_transfer_from_purchase_receipt_with_valuation(self):
		set_perpetual_inventory(1)
		warehouse = frappe.get_doc('Warehouse', '_Test Warehouse 2 - _TC')
		warehouse.account = '_Test Account Stock In Hand - _TC'
		warehouse.save()

		pr = make_purchase_receipt(do_not_save=1)
		pr.items[0].from_warehouse = '_Test Warehouse 2 - _TC'
		pr.supplier_warehouse = ''


		pr.append('taxes', {
			'charge_type': 'On Net Total',
			'account_head': '_Test Account Shipping Charges - _TC',
			'category': 'Valuation and Total',
			'cost_center': 'Main - _TC',
			'description': 'Test',
			'rate': 9
		})

		pr.submit()

		gl_entries = get_gl_entries('Purchase Receipt', pr.name)
		sl_entries = get_sl_entries('Purchase Receipt', pr.name)

		expected_gle = [
			['Stock In Hand - _TC', 272.5, 0.0],
			['_Test Account Stock In Hand - _TC', 0.0, 250.0],
			['_Test Account Shipping Charges - _TC', 0.0, 22.5]
		]

		expected_sle = {
			'_Test Warehouse 2 - _TC': -5,
			'_Test Warehouse - _TC': 5
		}

		for sle in sl_entries:
			self.assertEqual(expected_sle[sle.warehouse], sle.actual_qty)

		for i, gle in enumerate(gl_entries):
			self.assertEqual(gle.account, expected_gle[i][0])
			self.assertEqual(gle.debit, expected_gle[i][1])
			self.assertEqual(gle.credit, expected_gle[i][2])

		warehouse.account = ''
		warehouse.save()
		set_perpetual_inventory(0)
Пример #21
0
    def test_material_issue_gl_entry(self):
        company = frappe.db.get_value('Warehouse', '_Test Warehouse - _TC',
                                      'company')
        set_perpetual_inventory(1, company)

        make_stock_entry(item_code="_Test Item",
                         target="_Test Warehouse - _TC",
                         qty=50,
                         basic_rate=100,
                         expense_account="Stock Adjustment - _TC")

        mi = make_stock_entry(item_code="_Test Item",
                              source="_Test Warehouse - _TC",
                              qty=40,
                              expense_account="Stock Adjustment - _TC")

        self.check_stock_ledger_entries(
            "Stock Entry", mi.name,
            [["_Test Item", "_Test Warehouse - _TC", -40.0]])

        stock_in_hand_account = get_inventory_account(mi.company,
                                                      "_Test Warehouse - _TC")
        stock_value_diff = abs(
            frappe.db.get_value("Stock Ledger Entry", {
                "voucher_type": "Stock Entry",
                "voucher_no": mi.name
            }, "stock_value_difference"))

        self.check_gl_entries(
            "Stock Entry", mi.name,
            sorted([[stock_in_hand_account, 0.0, stock_value_diff],
                    ["Stock Adjustment - _TC", stock_value_diff, 0.0]]))

        mi.cancel()

        self.assertFalse(
            frappe.db.sql(
                """select name from `tabStock Ledger Entry`
			where voucher_type='Stock Entry' and voucher_no=%s""", mi.name))

        self.assertFalse(
            frappe.db.sql(
                """select name from `tabGL Entry`
			where voucher_type='Stock Entry' and voucher_no=%s""", mi.name))
Пример #22
0
	def test_purchase_receipt_no_gl_entry(self):
		set_perpetual_inventory(0)

		existing_bin_stock_value = frappe.db.get_value("Bin", {"item_code": "_Test Item",
			"warehouse": "_Test Warehouse - _TC"}, "stock_value")

		pr = make_purchase_receipt()

		stock_value_difference = frappe.db.get_value("Stock Ledger Entry",
			{"voucher_type": "Purchase Receipt", "voucher_no": pr.name,
				"item_code": "_Test Item", "warehouse": "_Test Warehouse - _TC"}, "stock_value_difference")

		self.assertEqual(stock_value_difference, 250)

		current_bin_stock_value = frappe.db.get_value("Bin", {"item_code": "_Test Item",
			"warehouse": "_Test Warehouse - _TC"}, "stock_value")
		self.assertEqual(current_bin_stock_value, existing_bin_stock_value + 250)

		self.assertFalse(get_gl_entries("Purchase Receipt", pr.name))
    def test_purchase_receipt_gl_entry(self):
        pr = frappe.copy_doc(test_records[0])
        set_perpetual_inventory(1, pr.company)
        self.assertEqual(
            cint(erpnext.is_perpetual_inventory_enabled(pr.company)), 1)
        pr.insert()
        pr.submit()

        gl_entries = get_gl_entries("Purchase Receipt", pr.name)

        self.assertTrue(gl_entries)

        stock_in_hand_account = get_inventory_account(
            pr.company,
            pr.get("items")[0].warehouse)
        fixed_asset_account = get_inventory_account(
            pr.company,
            pr.get("items")[1].warehouse)

        if stock_in_hand_account == fixed_asset_account:
            expected_values = {
                stock_in_hand_account: [750.0, 0.0],
                "Stock Received But Not Billed - _TC": [0.0, 500.0],
                "Expenses Included In Valuation - _TC": [0.0, 250.0]
            }
        else:
            expected_values = {
                stock_in_hand_account: [375.0, 0.0],
                fixed_asset_account: [375.0, 0.0],
                "Stock Received But Not Billed - _TC": [0.0, 500.0],
                "Expenses Included In Valuation - _TC": [0.0, 250.0]
            }

        for gle in gl_entries:
            self.assertEqual(expected_values[gle.account][0], gle.debit)
            self.assertEqual(expected_values[gle.account][1], gle.credit)

        pr.cancel()
        self.assertFalse(get_gl_entries("Purchase Receipt", pr.name))

        set_perpetual_inventory(0, pr.company)
Пример #24
0
    def test_stock_transfer_from_purchase_receipt(self):
        set_perpetual_inventory(1)
        pr = make_purchase_receipt(do_not_save=1)
        pr.supplier_warehouse = ''
        pr.items[0].from_warehouse = '_Test Warehouse 2 - _TC'

        pr.submit()

        gl_entries = get_gl_entries('Purchase Receipt', pr.name)
        sl_entries = get_sl_entries('Purchase Receipt', pr.name)

        self.assertFalse(gl_entries)

        expected_sle = {
            '_Test Warehouse 2 - _TC': -5,
            '_Test Warehouse - _TC': 5
        }

        for sle in sl_entries:
            self.assertEqual(expected_sle[sle.warehouse], sle.actual_qty)

        set_perpetual_inventory(0)
Пример #25
0
	def test_purchase_receipt_gl_entry(self):
		pr = frappe.copy_doc(test_records[0])
		set_perpetual_inventory(1, pr.company)
		self.assertEqual(cint(erpnext.is_perpetual_inventory_enabled(pr.company)), 1)
		pr.insert()
		pr.submit()

		gl_entries = get_gl_entries("Purchase Receipt", pr.name)

		self.assertTrue(gl_entries)

		stock_in_hand_account = get_inventory_account(pr.company, pr.get("items")[0].warehouse)
		fixed_asset_account = get_inventory_account(pr.company, pr.get("items")[1].warehouse)

		if stock_in_hand_account == fixed_asset_account:
			expected_values = {
				stock_in_hand_account: [750.0, 0.0],
				"Stock Received But Not Billed - _TC": [0.0, 500.0],
				"Expenses Included In Valuation - _TC": [0.0, 250.0]
			}
		else:
			expected_values = {
				stock_in_hand_account: [375.0, 0.0],
				fixed_asset_account: [375.0, 0.0],
				"Stock Received But Not Billed - _TC": [0.0, 500.0],
				"Expenses Included In Valuation - _TC": [0.0, 250.0]
			}

		for gle in gl_entries:
			self.assertEquals(expected_values[gle.account][0], gle.debit)
			self.assertEquals(expected_values[gle.account][1], gle.credit)

		pr.cancel()
		self.assertFalse(get_gl_entries("Purchase Receipt", pr.name))

		set_perpetual_inventory(0, pr.company)
Пример #26
0
    def test_gle_for_opening_stock_entry(self):
        set_perpetual_inventory(1)

        mr = make_stock_entry(item_code="_Test Item",
                              target="_Test Warehouse - _TC",
                              qty=50,
                              basic_rate=100,
                              expense_account="Stock Adjustment - _TC",
                              is_opening="Yes",
                              do_not_save=True)

        self.assertRaises(OpeningEntryAccountError, mr.save)

        mr.items[0].expense_account = "Temporary Opening - _TC"
        mr.save()
        mr.submit()

        is_opening = frappe.db.get_value("GL Entry",
                                         filters={
                                             "voucher_type": "Stock Entry",
                                             "voucher_no": mr.name
                                         },
                                         fieldname="is_opening")
        self.assertEqual(is_opening, "Yes")
Пример #27
0
	def setUp(self):
		erpnext.set_perpetual_inventory(0)
Пример #28
0
	def setUp(self):
		set_perpetual_inventory(0)
		frappe.db.set_value("Buying Settings", None, "allow_multiple_items", 1)
Пример #29
0
    def _test_reco_sle_gle(self, valuation_method):
        set_perpetual_inventory()
        input_data = [[50, 1000, "2012-12-26", "12:00"],
                      [25, 900, "2012-12-26", "12:00"],
                      ["", 1000, "2012-12-20", "12:05"],
                      [20, "", "2012-12-26", "12:05"],
                      [0, "", "2012-12-31", "12:10"]]

        for d in input_data:
            set_valuation_method("_Test Item", valuation_method)

            last_sle = get_previous_sle({
                "item_code": "_Test Item",
                "warehouse": "_Test Warehouse - _TC",
                "posting_date": d[2],
                "posting_time": d[3]
            })

            # submit Inventory Reconciliation
            stock_reco = create_inventory_reconciliation(qty=d[0],
                                                         rate=d[1],
                                                         posting_date=d[2],
                                                         posting_time=d[3])

            # check stock value
            sle = frappe.db.sql("""select * from `tabStock Ledger Entry`
				where voucher_type='Inventory Reconciliation' and voucher_no=%s""",
                                stock_reco.name,
                                as_dict=1)

            qty_after_transaction = flt(d[0]) if d[0] != "" else flt(
                last_sle.get("qty_after_transaction"))

            valuation_rate = flt(d[1]) if d[1] != "" else flt(
                last_sle.get("valuation_rate"))

            if qty_after_transaction == last_sle.get("qty_after_transaction") \
              and valuation_rate == last_sle.get("valuation_rate"):
                self.assertFalse(sle)
            else:
                self.assertEqual(sle[0].qty_after_transaction,
                                 qty_after_transaction)
                self.assertEqual(sle[0].stock_value,
                                 qty_after_transaction * valuation_rate)

                # no gl entries
                self.assertTrue(
                    frappe.db.get_value(
                        "Stock Ledger Entry", {
                            "voucher_type": "Inventory Reconciliation",
                            "voucher_no": stock_reco.name
                        }))
                self.assertFalse(
                    get_stock_and_account_difference(
                        ["_Test Account Stock In Hand - _TC"]))

            stock_reco.cancel()

            self.assertFalse(
                frappe.db.get_value(
                    "Stock Ledger Entry", {
                        "voucher_type": "Inventory Reconciliation",
                        "voucher_no": stock_reco.name
                    }))

            self.assertFalse(
                frappe.db.get_value(
                    "GL Entry", {
                        "voucher_type": "Inventory Reconciliation",
                        "voucher_no": stock_reco.name
                    }))

            set_perpetual_inventory(0)
Пример #30
0
 def tearDown(self):
     frappe.set_user("Administrator")
     set_perpetual_inventory(0)