示例#1
0
	def test_material_receipt_gl_entry(self):
		self._clear_stock_account_balance()
		set_perpetual_inventory()

		mr = frappe.copy_doc(test_records[0])
		mr.insert()
		mr.submit()

		stock_in_hand_account = frappe.db.get_value("Account", {"account_type": "Warehouse",
			"master_name": mr.get("mtn_details")[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_sales_invoice_gl_entry_without_aii(self):
		set_perpetual_inventory(0)
		si = frappe.copy_doc(test_records[1])
		si.insert()
		si.submit()

		gl_entries = frappe.db.sql("""select account, debit, credit
			from `tabGL Entry` where voucher_type='Sales Invoice' and voucher_no=%s
			order by account asc""", si.name, as_dict=1)

		self.assertTrue(gl_entries)

		expected_values = sorted([
			[si.debit_to, 630.0, 0.0],
			[test_records[1]["items"][0]["income_account"], 0.0, 500.0],
			[test_records[1]["taxes"][0]["account_head"], 0.0, 80.0],
			[test_records[1]["taxes"][1]["account_head"], 0.0, 50.0],
		])

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

		# cancel
		si.cancel()

		gle = frappe.db.sql("""select * from `tabGL Entry`
			where voucher_type='Sales Invoice' and voucher_no=%s""", si.name)

		self.assertFalse(gle)
	def test_return_purchase_invoice(self):
		set_perpetual_inventory()

		pi = make_purchase_invoice()

		return_pi = make_purchase_invoice(is_return=1, return_against=pi.name, qty=-2)


		# check gl entries for return
		gl_entries = frappe.db.sql("""select account, debit, credit
			from `tabGL Entry` where voucher_type=%s and voucher_no=%s
			order by account desc""", ("Purchase Invoice", return_pi.name), as_dict=1)

		self.assertTrue(gl_entries)

		expected_values = {
			"Creditors - _TC": [100.0, 0.0],
			"Stock Received But Not Billed - _TC": [0.0, 100.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)
	def test_pos_gl_entry_with_aii(self):
		self.clear_stock_account_balance()
		set_perpetual_inventory()
		self.make_pos_setting()

		self._insert_purchase_receipt()

		pos = copy.deepcopy(test_records[1])
		pos["is_pos"] = 1
		pos["update_stock"] = 1
		pos["posting_time"] = "12:05"
		pos["cash_bank_account"] = "_Test Account Bank Account - _TC"
		pos["paid_amount"] = 600.0

		si = frappe.copy_doc(pos)
		si.insert()
		si.submit()

		# check stock ledger entries
		sle = frappe.db.sql("""select * from `tabStock Ledger Entry`
			where voucher_type = 'Sales Invoice' and voucher_no = %s""",
			si.name, as_dict=1)[0]
		self.assertTrue(sle)
		self.assertEquals([sle.item_code, sle.warehouse, sle.actual_qty],
			["_Test Item", "_Test Warehouse - _TC", -1.0])

		# check gl entries
		gl_entries = frappe.db.sql("""select account, debit, credit
			from `tabGL Entry` where voucher_type='Sales Invoice' and voucher_no=%s
			order by account asc, debit asc""", si.name, as_dict=1)
		self.assertTrue(gl_entries)

		stock_in_hand = frappe.db.get_value("Account", {"master_name": "_Test Warehouse - _TC"})

		expected_gl_entries = sorted([
			[si.debit_to, 630.0, 0.0],
			[pos["entries"][0]["income_account"], 0.0, 500.0],
			[pos["other_charges"][0]["account_head"], 0.0, 80.0],
			[pos["other_charges"][1]["account_head"], 0.0, 50.0],
			[stock_in_hand, 0.0, 75.0],
			[pos["entries"][0]["expense_account"], 75.0, 0.0],
			[si.debit_to, 0.0, 600.0],
			["_Test Account Bank Account - _TC", 600.0, 0.0]
		])
		for i, gle in enumerate(gl_entries):
			self.assertEquals(expected_gl_entries[i][0], gle.account)
			self.assertEquals(expected_gl_entries[i][1], gle.debit)
			self.assertEquals(expected_gl_entries[i][2], gle.credit)

		si.cancel()
		gle = frappe.db.sql("""select * from `tabGL Entry`
			where voucher_type='Sales Invoice' and voucher_no=%s""", si.name)

		self.assertFalse(gle)

		self.assertFalse(get_stock_and_account_difference([stock_in_hand]))

		set_perpetual_inventory(0)

		frappe.db.sql("delete from `tabPOS Setting`")
	def check_planned_qty(self):
		set_perpetual_inventory(0)

		planned0 = frappe.db.get_value("Bin", {"item_code": "_Test FG Item", "warehouse": "_Test Warehouse 1 - _TC"}, "planned_qty") or 0

		pro_doc = frappe.copy_doc(test_records[0])
		pro_doc.insert()
		pro_doc.submit()

		# add raw materials to stores
		test_stock_entry.make_stock_entry("_Test Item", None, "Stores - _TC", 100, 100)
		test_stock_entry.make_stock_entry("_Test Item Home Desktop 100", None, "Stores - _TC", 100, 100)

		# from stores to wip
		s = frappe.get_doc(make_stock_entry(pro_doc.name, "Material Transfer", 4))
		for d in s.get("mtn_details"):
			d.s_warehouse = "Stores - _TC"
		s.fiscal_year = "_Test Fiscal Year 2013"
		s.posting_date = "2013-01-02"
		s.insert()
		s.submit()

		# from wip to fg
		s = frappe.get_doc(make_stock_entry(pro_doc.name, "Manufacture", 4))
		s.fiscal_year = "_Test Fiscal Year 2013"
		s.posting_date = "2013-01-03"
		s.insert()
		s.submit()

		self.assertEqual(frappe.db.get_value("Production Order", pro_doc.name,
			"produced_qty"), 4)
		planned1 = frappe.db.get_value("Bin", {"item_code": "_Test FG Item", "warehouse": "_Test Warehouse 1 - _TC"}, "planned_qty")
		self.assertEqual(planned1 - planned0, 6)

		return pro_doc
	def test_material_receipt_gl_entry(self):
		set_perpetual_inventory()

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

		stock_in_hand_account = frappe.db.get_value("Account", {"account_type": "Warehouse",
			"warehouse": 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))
示例#7
0
    def test_repack_no_change_in_valuation(self):
        self._clear_stock_account_balance()
        set_perpetual_inventory()

        self._insert_material_receipt()

        repack = frappe.copy_doc(test_records[3])
        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)
	def test_material_issue_gl_entry(self):
		set_perpetual_inventory()

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

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

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

		stock_in_hand_account = frappe.db.get_value("Account", {"account_type": "Warehouse",
			"warehouse": "_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))
	def test_gl_entries_with_auto_accounting_for_stock_against_pr(self):
		set_perpetual_inventory(1)
		self.assertEqual(cint(frappe.defaults.get_global_default("auto_accounting_for_stock")), 1)

		pr = frappe.copy_doc(pr_test_records[0])
		pr.submit()

		pi = frappe.copy_doc(test_records[1])
		for d in pi.get("entries"):
			d.purchase_receipt = pr.name
		pi.insert()
		pi.submit()

		gl_entries = frappe.db.sql("""select account, debit, credit
			from `tabGL Entry` where voucher_type='Purchase Invoice' and voucher_no=%s
			order by account asc""", pi.name, as_dict=1)
		self.assertTrue(gl_entries)

		expected_values = sorted([
			["_Test Supplier - _TC", 0, 720],
			["Stock Received But Not Billed - _TC", 500.0, 0],
			["_Test Account Shipping Charges - _TC", 100.0, 0],
			["_Test Account VAT - _TC", 120.0, 0],
		])

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

		set_perpetual_inventory(0)
示例#10
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"}))
			
		# 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"}))
			
		set_perpetual_inventory(0)
示例#11
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"}))
			
		set_perpetual_inventory(0)
示例#12
0
	def test_material_transfer_gl_entry(self):
		set_perpetual_inventory()

		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 = frappe.db.get_value("Account", {"account_type": "Warehouse",
			"warehouse": mtn.get("items")[0].s_warehouse})

		fixed_asset_account = frappe.db.get_value("Account", {"account_type": "Warehouse",
			"warehouse": mtn.get("items")[0].t_warehouse})

		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))
示例#13
0
	def tearDown(self):
		frappe.set_user("Administrator")
		set_perpetual_inventory(0)

		for role in ("Stock User", "Sales User"):
			set_user_permission_doctypes(doctype="Stock Entry", role=role,
				apply_user_permissions=0, user_permission_doctypes=None)
示例#14
0
	def test_warehouse_user(self):
		set_perpetual_inventory(0)

		for role in ("Stock User", "Sales User"):
			set_user_permission_doctypes(doctype="Stock Entry", role=role,
				apply_user_permissions=1, user_permission_doctypes=["Warehouse"])

		frappe.defaults.add_default("Warehouse", "_Test Warehouse 1 - _TC", "*****@*****.**", "User Permission")
		frappe.defaults.add_default("Warehouse", "_Test Warehouse 2 - _TC1", "*****@*****.**", "User Permission")
		test_user = frappe.get_doc("User", "*****@*****.**")
		test_user.add_roles("Sales User", "Sales Manager", "Stock User")
		test_user.remove_roles("Stock Manager")

		frappe.get_doc("User", "*****@*****.**")\
			.add_roles("Sales User", "Sales Manager", "Stock User", "Stock 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"
		self.assertRaises(frappe.PermissionError, st1.insert)

		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.insert()
		st1.submit()

		frappe.defaults.clear_default("Warehouse", "_Test Warehouse 1 - _TC",
			"*****@*****.**", parenttype="User Permission")
		frappe.defaults.clear_default("Warehouse", "_Test Warehouse 2 - _TC1",
			"*****@*****.**", parenttype="User Permission")
示例#15
0
    def test_repack_no_change_in_valuation(self):
        set_perpetual_inventory(0)

        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.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)
示例#16
0
	def test_delivery_note_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()
		cost_center = "_Test Cost Center - _TC"

		company = frappe.db.get_value('Warehouse', '_Test Warehouse - _TC', 'company')
		set_perpetual_inventory(1, company)

		set_valuation_method("_Test Item", "FIFO")

		make_stock_entry(target="_Test Warehouse - _TC", qty=5, basic_rate=100)

		stock_in_hand_account = get_inventory_account('_Test Company')
		dn = create_delivery_note()

		gl_entries = get_gl_entries("Delivery Note", dn.name)

		self.assertTrue(gl_entries)
		expected_values = {
			"Cost of Goods Sold - _TC": {
				"cost_center": cost_center
			},
			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, company)
	def test_sales_return_for_non_bundled_items(self):
		set_perpetual_inventory()

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

		actual_qty_0 = get_qty_after_transaction()

		dn = create_delivery_note(qty=5, rate=500)

		actual_qty_1 = get_qty_after_transaction()
		self.assertEquals(actual_qty_0 - 5, actual_qty_1)

		# outgoing_rate
		outgoing_rate = frappe.db.get_value("Stock Ledger Entry", {"voucher_type": "Delivery Note",
			"voucher_no": dn.name}, "stock_value_difference") / 5

		# return entry
		dn1 = create_delivery_note(is_return=1, return_against=dn.name, qty=-2, rate=500)

		actual_qty_2 = get_qty_after_transaction()

		self.assertEquals(actual_qty_1 + 2, actual_qty_2)

		incoming_rate, stock_value_difference = frappe.db.get_value("Stock Ledger Entry",
			{"voucher_type": "Delivery Note", "voucher_no": dn1.name},
			["incoming_rate", "stock_value_difference"])

		self.assertEquals(flt(incoming_rate, 3), abs(flt(outgoing_rate, 3)))

		gle_warehouse_amount = frappe.db.get_value("GL Entry", {"voucher_type": "Delivery Note",
			"voucher_no": dn1.name, "account": "_Test Warehouse - _TC"}, "debit")

		self.assertEquals(gle_warehouse_amount, stock_value_difference)

		set_perpetual_inventory(0)
示例#18
0
	def test_material_issue_gl_entry(self):
		self._clear_stock_account_balance()
		set_perpetual_inventory()

		self._insert_material_receipt()

		mi = frappe.copy_doc(test_records[1])
		mi.insert()
		mi.submit()

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

		stock_in_hand_account = frappe.db.get_value("Account", {"account_type": "Warehouse",
			"master_name": mi.get("mtn_details")[0].s_warehouse})

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

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

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

		self.assertEquals(frappe.db.get_value("Bin", {"warehouse": mi.get("mtn_details")[0].s_warehouse,
			"item_code": mi.get("mtn_details")[0].item_code}, "actual_qty"), 50)

		self.assertEquals(frappe.db.get_value("Bin", {"warehouse": mi.get("mtn_details")[0].s_warehouse,
			"item_code": mi.get("mtn_details")[0].item_code}, "stock_value"), 5000)
	def test_sales_invoice_gl_entry_with_perpetual_inventory_no_item_code(self):
		set_perpetual_inventory()

		si = frappe.get_doc(test_records[1])
		si.get("items")[0].item_code = None
		si.insert()
		si.submit()

		gl_entries = frappe.db.sql("""select account, debit, credit
			from `tabGL Entry` where voucher_type='Sales Invoice' and voucher_no=%s
			order by account asc""", si.name, as_dict=1)
		self.assertTrue(gl_entries)

		expected_values = dict((d[0], d) for d in [
			[si.debit_to, 630.0, 0.0],
			[test_records[1]["items"][0]["income_account"], 0.0, 500.0],
			[test_records[1]["taxes"][0]["account_head"], 0.0, 80.0],
			[test_records[1]["taxes"][1]["account_head"], 0.0, 50.0],
		])
		for i, gle in enumerate(gl_entries):
			self.assertEquals(expected_values[gle.account][0], gle.account)
			self.assertEquals(expected_values[gle.account][1], gle.debit)
			self.assertEquals(expected_values[gle.account][2], gle.credit)

		set_perpetual_inventory(0)
    def test_delivery_note_no_gl_entry(self):
        set_perpetual_inventory(0)
        self.assertEqual(cint(frappe.defaults.get_global_default("auto_accounting_for_stock")), 0)

        make_stock_entry(target="_Test Warehouse - _TC", qty=5, basic_rate=100)

        stock_queue = json.loads(
            get_previous_sle(
                {
                    "item_code": "_Test Item",
                    "warehouse": "_Test Warehouse - _TC",
                    "posting_date": nowdate(),
                    "posting_time": nowtime(),
                }
            ).stock_queue
            or "[]"
        )

        dn = create_delivery_note()

        sle = frappe.get_doc("Stock Ledger Entry", {"voucher_type": "Delivery Note", "voucher_no": dn.name})

        self.assertEqual(sle.stock_value_difference, -1 * stock_queue[0][1])

        self.assertFalse(get_gl_entries("Delivery Note", dn.name))
	def test_gl_entries_without_perpetual_inventory(self):
		frappe.db.set_value("Company", "_Test Company", "round_off_account", "Round Off - _TC")
		wrapper = frappe.copy_doc(test_records[0])
		set_perpetual_inventory(0, wrapper.company)
		self.assertTrue(not cint(erpnext.is_perpetual_inventory_enabled(wrapper.company)))
		wrapper.insert()
		wrapper.submit()
		wrapper.load_from_db()
		dl = wrapper

		expected_gl_entries = {
			"_Test Payable - _TC": [0, 1512.0],
			"_Test Account Cost for Goods Sold - _TC": [1250, 0],
			"_Test Account Shipping Charges - _TC": [100, 0],
			"_Test Account Excise Duty - _TC": [140, 0],
			"_Test Account Education Cess - _TC": [2.8, 0],
			"_Test Account S&H Education Cess - _TC": [1.4, 0],
			"_Test Account CST - _TC": [29.88, 0],
			"_Test Account VAT - _TC": [156.25, 0],
			"_Test Account Discount - _TC": [0, 168.03],
			"Round Off - _TC": [0, 0.3]
		}
		gl_entries = frappe.db.sql("""select account, debit, credit from `tabGL Entry`
			where voucher_type = 'Purchase Invoice' and voucher_no = %s""", dl.name, as_dict=1)
		for d in gl_entries:
			self.assertEqual([d.debit, d.credit], expected_gl_entries.get(d.account))
	def test_sales_invoice_gl_entry_with_aii_non_stock_item(self):
		self.clear_stock_account_balance()
		set_perpetual_inventory()
		si = frappe.get_doc(test_records[1])
		si.get("entries")[0].item_code = "_Test Non Stock Item"
		si.insert()
		si.submit()

		gl_entries = frappe.db.sql("""select account, debit, credit
			from `tabGL Entry` where voucher_type='Sales Invoice' and voucher_no=%s
			order by account asc""", si.name, as_dict=1)
		self.assertTrue(gl_entries)

		expected_values = sorted([
			[si.debit_to, 630.0, 0.0],
			[test_records[1]["entries"][0]["income_account"], 0.0, 500.0],
			[test_records[1]["other_charges"][0]["account_head"], 0.0, 80.0],
			[test_records[1]["other_charges"][1]["account_head"], 0.0, 50.0],
		])
		for i, gle in enumerate(gl_entries):
			self.assertEquals(expected_values[i][0], gle.account)
			self.assertEquals(expected_values[i][1], gle.debit)
			self.assertEquals(expected_values[i][2], gle.credit)

		set_perpetual_inventory(0)
    def test_purchase_invoice_for_is_paid_and_update_stock_gl_entry_with_perpetual_inventory(self):
        set_perpetual_inventory()
        pi = make_purchase_invoice(
            update_stock=1,
            posting_date=frappe.utils.nowdate(),
            posting_time=frappe.utils.nowtime(),
            cash_bank_account="Cash - _TC",
            is_paid=1,
        )

        gl_entries = frappe.db.sql(
            """select account, account_currency, sum(debit) as debit,
				sum(credit) as credit, debit_in_account_currency, credit_in_account_currency
			from `tabGL Entry` where voucher_type='Purchase Invoice' and voucher_no=%s
			group by account, voucher_no order by account asc;""",
            pi.name,
            as_dict=1,
        )

        self.assertTrue(gl_entries)

        expected_gl_entries = dict(
            (d[0], d)
            for d in [[pi.credit_to, 250.0, 250.0], [pi.items[0].warehouse, 250.0, 0.0], ["Cash - _TC", 0.0, 250.0]]
        )

        for i, gle in enumerate(gl_entries):
            self.assertEquals(expected_gl_entries[gle.account][0], gle.account)
            self.assertEquals(expected_gl_entries[gle.account][1], gle.debit)
            self.assertEquals(expected_gl_entries[gle.account][2], gle.credit)
示例#24
0
	def test_repack_with_change_in_valuation(self):
		set_perpetual_inventory()

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

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

		stock_in_hand_account = frappe.db.get_value("Account", {"account_type": "Warehouse",
			"warehouse": 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.check_gl_entries("Stock Entry", repack.name,
			sorted([
				[stock_in_hand_account, stock_value_diff, 0.0],
				["Stock Adjustment - _TC", 0.0, stock_value_diff],
			])
		)
		set_perpetual_inventory(0)
示例#25
0
	def test_gl_entries_with_aia_for_non_stock_items(self):
		set_perpetual_inventory()
		self.assertEqual(cint(frappe.defaults.get_global_default("auto_accounting_for_stock")), 1)

		pi = frappe.copy_doc(test_records[1])
		pi.get("items")[0].item_code = "_Test Non Stock Item"
		pi.get("items")[0].expense_account = "_Test Account Cost for Goods Sold - _TC"
		pi.get("taxes").pop(0)
		pi.get("taxes").pop(1)
		pi.insert()
		pi.submit()

		gl_entries = frappe.db.sql("""select account, debit, credit
			from `tabGL Entry` where voucher_type='Purchase Invoice' and voucher_no=%s
			order by account asc""", pi.name, as_dict=1)
		self.assertTrue(gl_entries)

		expected_values = sorted([
			["_Test Payable - _TC", 0, 620],
			["_Test Account Cost for Goods Sold - _TC", 500.0, 0],
			["_Test Account VAT - _TC", 120.0, 0],
		])

		for i, gle in enumerate(gl_entries):
			self.assertEquals(expected_values[i][0], gle.account)
			self.assertEquals(expected_values[i][1], gle.debit)
			self.assertEquals(expected_values[i][2], gle.credit)
		set_perpetual_inventory(0)
示例#26
0
	def test_gl_entries_without_auto_accounting_for_stock(self):
		set_perpetual_inventory(0)
		self.assertTrue(not cint(frappe.defaults.get_global_default("auto_accounting_for_stock")))

		wrapper = frappe.copy_doc(test_records[0])
		wrapper.insert()
		wrapper.submit()
		wrapper.load_from_db()
		dl = wrapper

		expected_gl_entries = {
			"_Test Payable - _TC": [0, 1512.30],
			"_Test Account Cost for Goods Sold - _TC": [1250, 0],
			"_Test Account Shipping Charges - _TC": [100, 0],
			"_Test Account Excise Duty - _TC": [140, 0],
			"_Test Account Education Cess - _TC": [2.8, 0],
			"_Test Account S&H Education Cess - _TC": [1.4, 0],
			"_Test Account CST - _TC": [29.88, 0],
			"_Test Account VAT - _TC": [156.25, 0],
			"_Test Account Discount - _TC": [0, 168.03],
		}
		gl_entries = frappe.db.sql("""select account, debit, credit from `tabGL Entry`
			where voucher_type = 'Purchase Invoice' and voucher_no = %s""", dl.name, as_dict=1)
		for d in gl_entries:
			self.assertEqual([d.debit, d.credit], expected_gl_entries.get(d.account))
	def test_return_entire_bundled_items(self):
		set_perpetual_inventory()

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

		dn = create_delivery_note(item_code="_Test Product Bundle Item", qty=5, rate=500)

		#  return bundled item
		dn1 = create_delivery_note(item_code='_Test Product Bundle Item', is_return=1,
			return_against=dn.name, qty=-2, rate=500)

		# qty after return
		actual_qty = get_qty_after_transaction()
		self.assertEquals(actual_qty, 35)

		# Check incoming rate for return entry
		incoming_rate, stock_value_difference = frappe.db.get_value("Stock Ledger Entry",
			{"voucher_type": "Delivery Note", "voucher_no": dn1.name},
			["incoming_rate", "stock_value_difference"])

		self.assertEquals(incoming_rate, 100)

		# Check gl entry for warehouse
		gle_warehouse_amount = frappe.db.get_value("GL Entry", {"voucher_type": "Delivery Note",
			"voucher_no": dn1.name, "account": "_Test Warehouse - _TC"}, "debit")

		self.assertEquals(gle_warehouse_amount, 1400)

		set_perpetual_inventory(0)
示例#28
0
	def test_warehouse_user(self):
		set_perpetual_inventory(0)

		frappe.defaults.add_default("Warehouse", "_Test Warehouse 1 - _TC", "*****@*****.**", "User Permission")
		frappe.defaults.add_default("Warehouse", "_Test Warehouse 2 - _TC1", "*****@*****.**", "User Permission")
		test_user = frappe.get_doc("User", "*****@*****.**")
		test_user.add_roles("Sales User", "Sales Manager", "Material User")
		test_user.remove_roles("Material Manager")

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

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

		frappe.set_user("*****@*****.**")
		st1 = frappe.copy_doc(test_records[0])
		st1.company = "_Test Company 1"
		st1.get("mtn_details")[0].t_warehouse="_Test Warehouse 2 - _TC1"
		st1.insert()
		st1.submit()

		frappe.defaults.clear_default("Warehouse", "_Test Warehouse 1 - _TC",
			"*****@*****.**", parenttype="User Permission")
		frappe.defaults.clear_default("Warehouse", "_Test Warehouse 2 - _TC1",
			"*****@*****.**", parenttype="User Permission")
示例#29
0
    def test_gl_entries_with_auto_accounting_for_stock(self):
        set_perpetual_inventory(1)
        self.assertEqual(cint(frappe.defaults.get_global_default("auto_accounting_for_stock")), 1)

        pi = frappe.copy_doc(test_records[1])
        pi.insert()
        pi.submit()

        gl_entries = frappe.db.sql(
            """select account, debit, credit
			from `tabGL Entry` where voucher_type='Purchase Invoice' and voucher_no=%s
			order by account asc""",
            pi.name,
            as_dict=1,
        )
        self.assertTrue(gl_entries)

        expected_values = dict(
            (d[0], d)
            for d in [
                ["_Test Payable - _TC", 0, 720],
                ["Stock Received But Not Billed - _TC", 750.0, 0],
                ["Expenses Included In Valuation - _TC", 0.0, 250.0],
                ["_Test Account Shipping Charges - _TC", 100.0, 0],
                ["_Test Account VAT - _TC", 120.0, 0],
            ]
        )

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

        set_perpetual_inventory(0)
	def test_landed_cost_voucher(self):
		frappe.db.set_value("Buying Settings", None, "allow_multiple_items", 1)
		set_perpetual_inventory(1)
		pr = frappe.copy_doc(pr_test_records[0])
		pr.submit()

		last_sle = frappe.db.get_value("Stock Ledger Entry", {
				"voucher_type": pr.doctype,
				"voucher_no": pr.name,
				"item_code": "_Test Item",
				"warehouse": "_Test Warehouse - _TC"
			},
			fieldname=["qty_after_transaction", "stock_value"], as_dict=1)

		submit_landed_cost_voucher("Purchase Receipt", pr.name)

		pr_lc_value = frappe.db.get_value("Purchase Receipt Item", {"parent": pr.name}, "landed_cost_voucher_amount")
		self.assertEquals(pr_lc_value, 25.0)

		last_sle_after_landed_cost = frappe.db.get_value("Stock Ledger Entry", {
				"voucher_type": pr.doctype,
				"voucher_no": pr.name,
				"item_code": "_Test Item",
				"warehouse": "_Test Warehouse - _TC"
			},
			fieldname=["qty_after_transaction", "stock_value"], as_dict=1)

		self.assertEqual(last_sle.qty_after_transaction, last_sle_after_landed_cost.qty_after_transaction)

		self.assertEqual(last_sle_after_landed_cost.stock_value - last_sle.stock_value, 25.0)

		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: [800.0, 0.0],
				"Stock Received But Not Billed - _TC": [0.0, 500.0],
				"Expenses Included In Valuation - _TC": [0.0, 300.0]
			}
			
		else:
			expected_values = {
				stock_in_hand_account: [400.0, 0.0],
				fixed_asset_account: [400.0, 0.0],
				"Stock Received But Not Billed - _TC": [0.0, 500.0],
				"Expenses Included In Valuation - _TC": [0.0, 300.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)
    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.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)
    def check_planned_qty(self):
        set_perpetual_inventory(0)

        planned0 = frappe.db.get_value("Bin", {
            "item_code": "_Test FG Item",
            "warehouse": "_Test Warehouse 1 - _TC"
        }, "planned_qty") or 0

        pro_order = make_prod_order_test_record()

        planned1 = frappe.db.get_value("Bin", {
            "item_code": "_Test FG Item",
            "warehouse": "_Test Warehouse 1 - _TC"
        }, "planned_qty")

        self.assertEqual(planned1, planned0 + 10)

        # add raw materials to stores
        test_stock_entry.make_stock_entry(item_code="_Test Item",
                                          target="Stores - _TC",
                                          qty=100,
                                          basic_rate=100)
        test_stock_entry.make_stock_entry(
            item_code="_Test Item Home Desktop 100",
            target="Stores - _TC",
            qty=100,
            basic_rate=100)

        # from stores to wip
        s = frappe.get_doc(
            make_stock_entry(pro_order.name,
                             "Material Transfer for Manufacture", 4))
        for d in s.get("items"):
            d.s_warehouse = "Stores - _TC"
        s.insert()
        s.submit()

        # from wip to fg
        s = frappe.get_doc(make_stock_entry(pro_order.name, "Manufacture", 4))
        s.insert()
        s.submit()

        self.assertEqual(
            frappe.db.get_value("Production Order", pro_order.name,
                                "produced_qty"), 4)

        planned2 = frappe.db.get_value("Bin", {
            "item_code": "_Test FG Item",
            "warehouse": "_Test Warehouse 1 - _TC"
        }, "planned_qty")

        self.assertEqual(planned2, planned0 + 6)

        return pro_order
示例#33
0
    def test_gl_entries_with_perpetual_inventory(self):
        pi = frappe.copy_doc(test_records[1])
        set_perpetual_inventory(1, pi.company)
        self.assertTrue(
            cint(erpnext.is_perpetual_inventory_enabled(pi.company)), 1)
        pi.insert()
        pi.submit()

        self.check_gle_for_pi(pi.name)

        set_perpetual_inventory(0, pi.company)
示例#34
0
    def test_warehouse_company_validation(self):
        set_perpetual_inventory(0)
        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.insert()
        self.assertRaises(InvalidWarehouseCompany, st1.submit)
	def test_gl_entries_with_auto_accounting_for_stock(self):
		set_perpetual_inventory(1)
		self.assertEqual(cint(frappe.defaults.get_global_default("auto_accounting_for_stock")), 1)

		pi = frappe.copy_doc(test_records[1])
		pi.insert()
		pi.submit()

		self.check_gle_for_pi(pi.name)

		set_perpetual_inventory(0)
示例#36
0
	def test_si_gl_entry_with_aii_and_update_stock_with_warehouse_but_no_account(self):
		set_perpetual_inventory()
		frappe.delete_doc("Account", "_Test Warehouse No Account - _TC")

		# insert purchase receipt
		from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import test_records \
			as pr_test_records
		pr = frappe.copy_doc(pr_test_records[0])
		pr.naming_series = "_T-Purchase Receipt-"
		pr.get("items")[0].warehouse = "_Test Warehouse No Account - _TC"
		pr.insert()
		pr.submit()

		si_doc = copy.deepcopy(test_records[1])
		si_doc["update_stock"] = 1
		# si_doc["posting_time"] = "12:05"
		si_doc.get("items")[0]["warehouse"] = "_Test Warehouse No Account - _TC"

		si = frappe.copy_doc(si_doc)
		si.insert()
		si.submit()

		# check stock ledger entries
		sle = frappe.db.sql("""select * from `tabStock Ledger Entry`
			where voucher_type = 'Sales Invoice' and voucher_no = %s""",
			si.name, as_dict=1)[0]
		self.assertTrue(sle)
		self.assertEquals([sle.item_code, sle.warehouse, sle.actual_qty],
			["_Test Item", "_Test Warehouse No Account - _TC", -1.0])

		# check gl entries
		gl_entries = frappe.db.sql("""select account, debit, credit
			from `tabGL Entry` where voucher_type='Sales Invoice' and voucher_no=%s
			order by account asc, debit asc""", si.name, as_dict=1)
		self.assertTrue(gl_entries)

		expected_gl_entries = dict((d[0], d) for d in [
			[si.debit_to, 630.0, 0.0],
			[si_doc.get("items")[0]["income_account"], 0.0, 500.0],
			[si_doc.get("taxes")[0]["account_head"], 0.0, 80.0],
			[si_doc.get("taxes")[1]["account_head"], 0.0, 50.0],
		])
		for i, gle in enumerate(gl_entries):
			self.assertEquals(expected_gl_entries[gle.account][0], gle.account)
			self.assertEquals(expected_gl_entries[gle.account][1], gle.debit)
			self.assertEquals(expected_gl_entries[gle.account][2], gle.credit)

		si.cancel()
		gle = frappe.db.sql("""select * from `tabGL Entry`
			where voucher_type='Sales Invoice' and voucher_no=%s""", si.name)

		self.assertFalse(gle)
		set_perpetual_inventory(0)
示例#37
0
    def test_warehouse_company_validation(self):
        set_perpetual_inventory(0)
        self._clear_stock_account_balance()
        frappe.bean("Profile", "*****@*****.**").get_controller()\
         .add_roles("Sales User", "Sales Manager", "Material User", "Material Manager")
        frappe.set_user("*****@*****.**")

        from erpnext.stock.utils import InvalidWarehouseCompany
        st1 = frappe.bean(copy=test_records[0])
        st1.doclist[1].t_warehouse = "_Test Warehouse 2 - _TC1"
        st1.insert()
        self.assertRaises(InvalidWarehouseCompany, st1.submit)
示例#38
0
    def test_sales_return_for_non_bundled_items(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)

        actual_qty_0 = get_qty_after_transaction()

        dn = create_delivery_note(qty=5, rate=500)

        actual_qty_1 = get_qty_after_transaction()
        self.assertEquals(actual_qty_0 - 5, actual_qty_1)

        # outgoing_rate
        outgoing_rate = frappe.db.get_value("Stock Ledger Entry", {
            "voucher_type": "Delivery Note",
            "voucher_no": dn.name
        }, "stock_value_difference") / 5

        # return entry
        dn1 = create_delivery_note(is_return=1,
                                   return_against=dn.name,
                                   qty=-2,
                                   rate=500)

        actual_qty_2 = get_qty_after_transaction()

        self.assertEquals(actual_qty_1 + 2, actual_qty_2)

        incoming_rate, stock_value_difference = frappe.db.get_value(
            "Stock Ledger Entry", {
                "voucher_type": "Delivery Note",
                "voucher_no": dn1.name
            }, ["incoming_rate", "stock_value_difference"])

        self.assertEquals(flt(incoming_rate, 3), abs(flt(outgoing_rate, 3)))
        stock_in_hand_account = get_inventory_account('_Test Company',
                                                      dn1.items[0].warehouse)

        gle_warehouse_amount = frappe.db.get_value(
            "GL Entry", {
                "voucher_type": "Delivery Note",
                "voucher_no": dn1.name,
                "account": stock_in_hand_account
            }, "debit")

        self.assertEquals(gle_warehouse_amount, stock_value_difference)

        set_perpetual_inventory(0, company)
示例#39
0
    def test_jv_against_stock_account(self):
        from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import set_perpetual_inventory
        set_perpetual_inventory()

        jv = frappe.copy_doc(test_records[0])
        jv.get("entries")[0].account = "_Test Warehouse - _TC"
        jv.insert()

        from erpnext.accounts.general_ledger import StockAccountInvalidTransaction
        self.assertRaises(StockAccountInvalidTransaction, jv.submit)

        set_perpetual_inventory(0)
    def test_stock_reco_for_batch_item(self):
        set_perpetual_inventory()

        to_delete_records = []
        to_delete_serial_nos = []

        # Add new serial nos
        item_code = "Stock-Reco-batch-Item-1"
        warehouse = "_Test Warehouse for Stock Reco2 - _TC"

        sr = create_stock_reconciliation(item_code=item_code,
                                         warehouse=warehouse,
                                         qty=5,
                                         rate=200,
                                         do_not_save=1,
                                         do_not_submit=1)
        sr.save(ignore_permissions=True)
        sr.submit()

        self.assertTrue(sr.items[0].batch_no)
        to_delete_records.append(sr.name)

        sr1 = create_stock_reconciliation(item_code=item_code,
                                          warehouse=warehouse,
                                          qty=6,
                                          rate=300,
                                          batch_no=sr.items[0].batch_no)

        args = {
            "item_code": item_code,
            "warehouse": warehouse,
            "posting_date": nowdate(),
            "posting_time": nowtime(),
        }

        valuation_rate = get_incoming_rate(args)
        self.assertEqual(valuation_rate, 300)
        to_delete_records.append(sr1.name)

        sr2 = create_stock_reconciliation(item_code=item_code,
                                          warehouse=warehouse,
                                          qty=0,
                                          rate=0,
                                          batch_no=sr.items[0].batch_no)

        stock_value = get_stock_value_on(warehouse, nowdate(), item_code)
        self.assertEqual(stock_value, 0)
        to_delete_records.append(sr2.name)

        to_delete_records.reverse()
        for d in to_delete_records:
            stock_doc = frappe.get_doc("Stock Reconciliation", d)
            stock_doc.cancel()
	def test_stock_reco_for_same_item_with_multiple_batches(self):
		from erpnext.stock.doctype.stock_entry.test_stock_entry import make_stock_entry

		set_perpetual_inventory()

		item_code = "Stock-Reco-batch-Item-2"
		warehouse = "_Test Warehouse for Stock Reco3 - _TC"

		create_warehouse("_Test Warehouse for Stock Reco3", {"is_group": 0,
			"parent_warehouse": "_Test Warehouse Group - _TC", "company": "_Test Company"})

		batch_item_doc = create_item(item_code, is_stock_item=1)
		if not batch_item_doc.has_batch_no:
			frappe.db.set_value("Item", item_code, {
				"has_batch_no": 1,
				"create_new_batch": 1,
				"batch_number_series": "Test-C.####"
			})

		# inward entries with different batch and valuation rate
		ste1=make_stock_entry(posting_date="2012-12-15", posting_time="02:00", item_code=item_code,
			target=warehouse, qty=6, basic_rate=700)
		ste2=make_stock_entry(posting_date="2012-12-16", posting_time="02:00", item_code=item_code,
			target=warehouse, qty=3, basic_rate=200)
		ste3=make_stock_entry(posting_date="2012-12-17", posting_time="02:00", item_code=item_code,
			target=warehouse, qty=2, basic_rate=500)
		ste4=make_stock_entry(posting_date="2012-12-17", posting_time="02:00", item_code=item_code,
			target=warehouse, qty=4, basic_rate=100)

		batchwise_item_details = {}
		for stock_doc in [ste1, ste2, ste3, ste4]:
			self.assertEqual(item_code, stock_doc.items[0].item_code)
			batchwise_item_details[stock_doc.items[0].batch_no] = [stock_doc.items[0].qty, 0.01]

		stock_balance = frappe.get_all("Stock Ledger Entry",
			filters = {"item_code": item_code, "warehouse": warehouse},
			fields=["sum(stock_value_difference)"], as_list=1)

		self.assertEqual(flt(stock_balance[0][0]), 6200.00)

		sr = create_stock_reconciliation(item_code=item_code,
			warehouse = warehouse, batch_details = batchwise_item_details)

		stock_balance = frappe.get_all("Stock Ledger Entry",
			filters = {"item_code": item_code, "warehouse": warehouse},
			fields=["sum(stock_value_difference)"], as_list=1)

		self.assertEqual(flt(stock_balance[0][0]), 0.15)

		for doc in [sr, ste1, ste2, ste3, ste4]:
			doc.cancel()
			frappe.delete_doc(doc.doctype, doc.name)
示例#42
0
    def test_material_transfer_gl_entry(self):
        set_perpetual_inventory()

        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 = frappe.db.get_value(
            "Account", {
                "account_type": "Warehouse",
                "warehouse": mtn.get("items")[0].s_warehouse
            })

        fixed_asset_account = frappe.db.get_value(
            "Account", {
                "account_type": "Warehouse",
                "warehouse": mtn.get("items")[0].t_warehouse
            })

        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))
示例#43
0
    def check_planned_qty(self):
        set_perpetual_inventory(0)

        planned0 = frappe.db.get_value("Bin", {
            "item_code": "_Test FG Item",
            "warehouse": "_Test Warehouse 1 - _TC"
        }, "planned_qty") or 0

        pro_doc = frappe.copy_doc(test_records[0])
        pro_doc.insert()
        pro_doc.submit()

        # add raw materials to stores
        test_stock_entry.make_stock_entry(item_code="_Test Item",
                                          target="Stores - _TC",
                                          qty=100,
                                          incoming_rate=100)
        test_stock_entry.make_stock_entry(
            item_code="_Test Item Home Desktop 100",
            target="Stores - _TC",
            qty=100,
            incoming_rate=100)

        # from stores to wip
        s = frappe.get_doc(
            make_stock_entry(pro_doc.name, "Material Transfer for Manufacture",
                             4))
        for d in s.get("items"):
            d.s_warehouse = "Stores - _TC"
        s.fiscal_year = "_Test Fiscal Year 2013"
        s.posting_date = "2013-01-02"
        s.insert()
        s.submit()

        # from wip to fg
        s = frappe.get_doc(make_stock_entry(pro_doc.name, "Manufacture", 4))
        s.fiscal_year = "_Test Fiscal Year 2013"
        s.posting_date = "2013-01-03"
        s.insert()
        s.submit()

        self.assertEqual(
            frappe.db.get_value("Production Order", pro_doc.name,
                                "produced_qty"), 4)
        planned1 = frappe.db.get_value("Bin", {
            "item_code": "_Test FG Item",
            "warehouse": "_Test Warehouse 1 - _TC"
        }, "planned_qty")

        self.assertEqual(planned1 - planned0, 6)

        return pro_doc
示例#44
0
	def test_stock_reco_for_serialized_item(self):
		set_perpetual_inventory()

		to_delete_records = []
		to_delete_serial_nos = []

		# Add new serial nos
		serial_item_code = "Stock-Reco-Serial-Item-1"
		serial_warehouse = "_Test Warehouse for Stock Reco1 - _TC"

		sr = create_stock_reconciliation(item_code=serial_item_code,
			warehouse = serial_warehouse, qty=5, rate=200)

		serial_nos = get_serial_nos(sr.items[0].serial_no)
		self.assertEqual(len(serial_nos), 5)

		args = {
			"item_code": serial_item_code,
			"warehouse": serial_warehouse,
			"posting_date": nowdate(),
			"posting_time": nowtime(),
			"serial_no": sr.items[0].serial_no
		}

		valuation_rate = get_incoming_rate(args)
		self.assertEqual(valuation_rate, 200)

		to_delete_records.append(sr.name)

		sr = create_stock_reconciliation(item_code=serial_item_code,
			warehouse = serial_warehouse, qty=5, rate=300, serial_no = '\n'.join(serial_nos))

		serial_nos1 = get_serial_nos(sr.items[0].serial_no)
		self.assertEqual(len(serial_nos1), 5)

		args = {
			"item_code": serial_item_code,
			"warehouse": serial_warehouse,
			"posting_date": nowdate(),
			"posting_time": nowtime(),
			"serial_no": sr.items[0].serial_no
		}

		valuation_rate = get_incoming_rate(args)
		self.assertEqual(valuation_rate, 300)

		to_delete_records.append(sr.name)
		to_delete_records.reverse()

		for d in to_delete_records:
			stock_doc = frappe.get_doc("Stock Reconciliation", d)
			stock_doc.cancel()
	def test_landed_cost_voucher(self):
		frappe.db.set_value("Buying Settings", None, "allow_multiple_items", 1)
		set_perpetual_inventory(1)
		pr = frappe.copy_doc(pr_test_records[0])
		pr.submit()

		last_sle = frappe.db.get_value("Stock Ledger Entry", {
				"voucher_type": pr.doctype,
				"voucher_no": pr.name,
				"item_code": "_Test Item",
				"warehouse": "_Test Warehouse - _TC"
			},
			fieldname=["qty_after_transaction", "stock_value"], as_dict=1)

		submit_landed_cost_voucher("Purchase Receipt", pr.name)

		pr_lc_value = frappe.db.get_value("Purchase Receipt Item", {"parent": pr.name}, "landed_cost_voucher_amount")
		self.assertEquals(pr_lc_value, 25.0)

		last_sle_after_landed_cost = frappe.db.get_value("Stock Ledger Entry", {
				"voucher_type": pr.doctype,
				"voucher_no": pr.name,
				"item_code": "_Test Item",
				"warehouse": "_Test Warehouse - _TC"
			},
			fieldname=["qty_after_transaction", "stock_value"], as_dict=1)

		self.assertEqual(last_sle.qty_after_transaction, last_sle_after_landed_cost.qty_after_transaction)

		self.assertEqual(last_sle_after_landed_cost.stock_value - last_sle.stock_value, 25.0)

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

		self.assertTrue(gl_entries)

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


		expected_values = {
			stock_in_hand_account: [400.0, 0.0],
			fixed_asset_account: [400.0, 0.0],
			"Stock Received But Not Billed - _TC": [0.0, 500.0],
			"Expenses Included In Valuation - _TC": [0.0, 300.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)
示例#46
0
    def pos_gl_entry(self, si, pos, cash_amount):
        # check stock ledger entries
        sle = frappe.db.sql("""select * from `tabStock Ledger Entry`
			where voucher_type = 'Sales Invoice' and voucher_no = %s""",
                            si.name,
                            as_dict=1)[0]
        self.assertTrue(sle)
        self.assertEquals([sle.item_code, sle.warehouse, sle.actual_qty],
                          ["_Test Item", "_Test Warehouse - _TC", -1.0])

        # check gl entries
        gl_entries = frappe.db.sql("""select account, debit, credit
			from `tabGL Entry` where voucher_type='Sales Invoice' and voucher_no=%s
			order by account asc, debit asc""",
                                   si.name,
                                   as_dict=1)
        self.assertTrue(gl_entries)

        stock_in_hand = frappe.db.get_value(
            "Account", {"warehouse": "_Test Warehouse - _TC"})

        expected_gl_entries = sorted(
            [[si.debit_to, 630.0, 0.0],
             [pos["items"][0]["income_account"], 0.0, 500.0],
             [pos["taxes"][0]["account_head"], 0.0, 80.0],
             [pos["taxes"][1]["account_head"], 0.0, 50.0],
             [stock_in_hand, 0.0,
              abs(sle.stock_value_difference)],
             [
                 pos["items"][0]["expense_account"],
                 abs(sle.stock_value_difference), 0.0
             ], [si.debit_to, 0.0, 300.0], [si.debit_to, 0.0, cash_amount],
             ["_Test Bank - _TC", 300.0, 0.0],
             ["Cash - _TC", cash_amount, 0.0]])

        for i, gle in enumerate(sorted(gl_entries,
                                       key=lambda gle: gle.account)):
            self.assertEquals(expected_gl_entries[i][0], gle.account)
            self.assertEquals(expected_gl_entries[i][1], gle.debit)
            self.assertEquals(expected_gl_entries[i][2], gle.credit)

        si.cancel()
        gle = frappe.db.sql(
            """select * from `tabGL Entry`
			where voucher_type='Sales Invoice' and voucher_no=%s""", si.name)

        self.assertFalse(gle)

        set_perpetual_inventory(0)

        frappe.db.sql("delete from `tabPOS Profile`")
	def test_delivery_note_gl_entry(self):
		company = frappe.db.get_value('Warehouse', '_Test Warehouse - _TC', 'company')
		set_perpetual_inventory(1, company)

		set_valuation_method("_Test Item", "FIFO")

		make_stock_entry(target="_Test Warehouse - _TC", qty=5, basic_rate=100)

		stock_in_hand_account = get_inventory_account('_Test Company')
		prev_bal = get_balance_on(stock_in_hand_account)

		dn = create_delivery_note()

		gl_entries = get_gl_entries("Delivery Note", dn.name)
		self.assertTrue(gl_entries)

		stock_value_difference = abs(frappe.db.get_value("Stock Ledger Entry",
			{"voucher_type": "Delivery Note", "voucher_no": dn.name}, "stock_value_difference"))

		expected_values = {
			stock_in_hand_account: [0.0, stock_value_difference],
			"Cost of Goods Sold - _TC": [stock_value_difference, 0.0]
		}
		for i, gle in enumerate(gl_entries):
			self.assertEqual([gle.debit, gle.credit], expected_values.get(gle.account))

		# check stock in hand balance
		bal = get_balance_on(stock_in_hand_account)
		self.assertEqual(bal, prev_bal - stock_value_difference)

		# back dated incoming entry
		make_stock_entry(posting_date=add_days(nowdate(), -2), target="_Test Warehouse - _TC",
			qty=5, basic_rate=100)

		gl_entries = get_gl_entries("Delivery Note", dn.name)
		self.assertTrue(gl_entries)

		stock_value_difference = abs(frappe.db.get_value("Stock Ledger Entry",
			{"voucher_type": "Delivery Note", "voucher_no": dn.name}, "stock_value_difference"))

		expected_values = {
			stock_in_hand_account: [0.0, stock_value_difference],
			"Cost of Goods Sold - _TC": [stock_value_difference, 0.0]
		}
		for i, gle in enumerate(gl_entries):
			self.assertEqual([gle.debit, gle.credit], expected_values.get(gle.account))

		dn.cancel()
		self.assertFalse(get_gl_entries("Delivery Note", dn.name))
		set_perpetual_inventory(0, company)
示例#48
0
	def test_landed_cost_voucher_against_purchase_invoice(self):
		set_perpetual_inventory(1)
		
		pi = make_purchase_invoice(update_stock=1, posting_date=frappe.utils.nowdate(),
			posting_time=frappe.utils.nowtime())

		last_sle = frappe.db.get_value("Stock Ledger Entry", {
				"voucher_type": pi.doctype,
				"voucher_no": pi.name,
				"item_code": "_Test Item",
				"warehouse": "_Test Warehouse - _TC"
			},
			fieldname=["qty_after_transaction", "stock_value"], as_dict=1)

		submit_landed_cost_voucher("Purchase Invoice", pi.name)
		
		pi_lc_value = frappe.db.get_value("Purchase Invoice Item", {"parent": pi.name}, 
			"landed_cost_voucher_amount")
			
		self.assertEquals(pi_lc_value, 50.0)

		last_sle_after_landed_cost = frappe.db.get_value("Stock Ledger Entry", {
				"voucher_type": pi.doctype,
				"voucher_no": pi.name,
				"item_code": "_Test Item",
				"warehouse": "_Test Warehouse - _TC"
			},
			fieldname=["qty_after_transaction", "stock_value"], as_dict=1)

		self.assertEqual(last_sle.qty_after_transaction, last_sle_after_landed_cost.qty_after_transaction)

		self.assertEqual(last_sle_after_landed_cost.stock_value - last_sle.stock_value, 50.0)

		gl_entries = get_gl_entries("Purchase Invoice", pi.name)

		self.assertTrue(gl_entries)
		stock_in_hand_account = get_inventory_account(pi.company, pi.get("items")[0].warehouse)

		expected_values = {
			stock_in_hand_account: [300.0, 0.0],
			"Creditors - _TC": [0.0, 250.0],
			"Expenses Included In Valuation - _TC": [0.0, 50.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)
    def test_material_issue_gl_entry(self):
        self._clear_stock_account_balance()
        set_perpetual_inventory()

        self._insert_material_receipt()

        mi = frappe.copy_doc(test_records[1])
        mi.insert()
        mi.submit()

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

        stock_in_hand_account = frappe.db.get_value(
            "Account", {
                "account_type": "Warehouse",
                "master_name": mi.get("mtn_details")[0].s_warehouse
            })

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

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

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

        self.assertEquals(
            frappe.db.get_value(
                "Bin", {
                    "warehouse": mi.get("mtn_details")[0].s_warehouse,
                    "item_code": mi.get("mtn_details")[0].item_code
                }, "actual_qty"), 50)

        self.assertEquals(
            frappe.db.get_value(
                "Bin", {
                    "warehouse": mi.get("mtn_details")[0].s_warehouse,
                    "item_code": mi.get("mtn_details")[0].item_code
                }, "stock_value"), 5000)
示例#50
0
    def test_landed_cost_voucher(self):
        set_perpetual_inventory(1)
        pr = frappe.copy_doc(pr_test_records[0])
        pr.submit()

        bin_details = frappe.db.get_value("Bin", {
            "warehouse": "_Test Warehouse - _TC",
            "item_code": "_Test Item"
        }, ["actual_qty", "stock_value"],
                                          as_dict=1)

        self.submit_landed_cost_voucher(pr)

        pr_lc_value = frappe.db.get_value("Purchase Receipt Item",
                                          {"parent": pr.name},
                                          "landed_cost_voucher_amount")
        self.assertEquals(pr_lc_value, 25.0)

        bin_details_after_lcv = frappe.db.get_value("Bin", {
            "warehouse": "_Test Warehouse - _TC",
            "item_code": "_Test Item"
        }, ["actual_qty", "stock_value"],
                                                    as_dict=1)

        self.assertEqual(bin_details.actual_qty,
                         bin_details_after_lcv.actual_qty)

        self.assertEqual(
            bin_details_after_lcv.stock_value - bin_details.stock_value, 25.0)

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

        self.assertTrue(gl_entries)

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

        expected_values = {
            stock_in_hand_account: [400.0, 0.0],
            fixed_asset_account: [400.0, 0.0],
            "Stock Received But Not Billed - _TC": [0.0, 500.0],
            "Expenses Included In Valuation - _TC": [0.0, 300.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)
示例#51
0
	def test_gl_entries_with_perpetual_inventory_against_pr(self):
		pr = frappe.copy_doc(pr_test_records[0])
		set_perpetual_inventory(1, pr.company)
		self.assertTrue(cint(erpnext.is_perpetual_inventory_enabled(pr.company)), 1)
		pr.submit()

		pi = frappe.copy_doc(test_records[1])
		for d in pi.get("items"):
			d.purchase_receipt = pr.name
		pi.insert()
		pi.submit()

		self.check_gle_for_pi(pi.name)

		set_perpetual_inventory(0, pr.company)
示例#52
0
    def test_multi_currency_gle(self):
        set_perpetual_inventory(0)
        si = create_sales_invoice(customer="_Test Customer USD",
                                  debit_to="_Test Receivable USD - _TC",
                                  currency="USD",
                                  conversion_rate=50)

        gl_entries = frappe.db.sql(
            """select account, account_currency, debit, credit,
			debit_in_account_currency, credit_in_account_currency
			from `tabGL Entry` where voucher_type='Sales Invoice' and voucher_no=%s
			order by account asc""",
            si.name,
            as_dict=1)

        self.assertTrue(gl_entries)

        expected_values = {
            "_Test Receivable USD - _TC": {
                "account_currency": "USD",
                "debit": 5000,
                "debit_in_account_currency": 100,
                "credit": 0,
                "credit_in_account_currency": 0
            },
            "Sales - _TC": {
                "account_currency": "INR",
                "debit": 0,
                "debit_in_account_currency": 0,
                "credit": 5000,
                "credit_in_account_currency": 5000
            }
        }

        for field in ("account_currency", "debit", "debit_in_account_currency",
                      "credit", "credit_in_account_currency"):
            for i, gle in enumerate(gl_entries):
                self.assertEquals(expected_values[gle.account][field],
                                  gle[field])

        # cancel
        si.cancel()

        gle = frappe.db.sql(
            """select name from `tabGL Entry`
			where voucher_type='Sales Invoice' and voucher_no=%s""", si.name)

        self.assertFalse(gle)
示例#53
0
	def test_multi_currency_gle(self):
		set_perpetual_inventory(0)

		pi = make_purchase_invoice(supplier="_Test Supplier USD", credit_to="_Test Payable USD - _TC",
			currency="USD", conversion_rate=50)

		gl_entries = frappe.db.sql("""select account, account_currency, debit, credit,
			debit_in_account_currency, credit_in_account_currency
			from `tabGL Entry` where voucher_type='Purchase Invoice' and voucher_no=%s
			order by account asc""", pi.name, as_dict=1)

		self.assertTrue(gl_entries)

		expected_values = {
			"_Test Payable USD - _TC": {
				"account_currency": "USD",
				"debit": 0,
				"debit_in_account_currency": 0,
				"credit": 12500,
				"credit_in_account_currency": 250
			},
			"_Test Account Cost for Goods Sold - _TC": {
				"account_currency": "INR",
				"debit": 12500,
				"debit_in_account_currency": 12500,
				"credit": 0,
				"credit_in_account_currency": 0
			}
		}

		for field in ("account_currency", "debit", "debit_in_account_currency", "credit", "credit_in_account_currency"):
			for i, gle in enumerate(gl_entries):
				self.assertEquals(expected_values[gle.account][field], gle[field])


		# Check for valid currency
		pi1 = make_purchase_invoice(supplier="_Test Supplier USD", credit_to="_Test Payable USD - _TC",
			do_not_save=True)

		self.assertRaises(InvalidCurrency, pi1.save)

		# cancel
		pi.cancel()

		gle = frappe.db.sql("""select name from `tabGL Entry`
			where voucher_type='Sales Invoice' and voucher_no=%s""", pi.name)

		self.assertFalse(gle)
示例#54
0
	def test_gl_entries_with_auto_accounting_for_stock_against_pr(self):
		set_perpetual_inventory(1)
		self.assertEqual(cint(frappe.defaults.get_global_default("auto_accounting_for_stock")), 1)

		pr = frappe.copy_doc(pr_test_records[0])
		pr.submit()

		pi = frappe.copy_doc(test_records[1])
		for d in pi.get("items"):
			d.purchase_receipt = pr.name
		pi.insert()
		pi.submit()

		self.check_gle_for_pi(pi.name)

		set_perpetual_inventory(0)
示例#55
0
	def test_inter_company_transfer(self):
		set_perpetual_inventory(0, "_Test Company 1")
		set_perpetual_inventory(0)
		se = make_serialized_item(target_warehouse="_Test Warehouse - _TC")
		serial_nos = get_serial_nos(se.get("items")[0].serial_no)

		create_delivery_note(item_code="_Test Serialized Item With Series", qty=1, serial_no=serial_nos[0])

		wh = create_warehouse("_Test Warehouse", company="_Test Company 1")
		make_purchase_receipt(item_code="_Test Serialized Item With Series", qty=1, serial_no=serial_nos[0],
			company="_Test Company 1", warehouse=wh)

		serial_no = frappe.db.get_value("Serial No", serial_nos[0], ["warehouse", "company"], as_dict=1)

		self.assertEqual(serial_no.warehouse, wh)
		self.assertEqual(serial_no.company, "_Test Company 1")
示例#56
0
    def test_return_entire_bundled_items(self):
        set_perpetual_inventory()

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

        dn = create_delivery_note(item_code="_Test Product Bundle Item",
                                  qty=5,
                                  rate=500)

        #  return bundled item
        dn1 = create_delivery_note(item_code='_Test Product Bundle Item',
                                   is_return=1,
                                   return_against=dn.name,
                                   qty=-2,
                                   rate=500)

        # qty after return
        actual_qty = get_qty_after_transaction()
        self.assertEquals(actual_qty, 35)

        # Check incoming rate for return entry
        incoming_rate, stock_value_difference = frappe.db.get_value(
            "Stock Ledger Entry", {
                "voucher_type": "Delivery Note",
                "voucher_no": dn1.name
            }, ["incoming_rate", "stock_value_difference"])

        self.assertEquals(incoming_rate, 100)

        # Check gl entry for warehouse
        gle_warehouse_amount = frappe.db.get_value(
            "GL Entry", {
                "voucher_type": "Delivery Note",
                "voucher_no": dn1.name,
                "account": "_Test Warehouse - _TC"
            }, "debit")

        self.assertEquals(gle_warehouse_amount, 1400)

        set_perpetual_inventory(0)
    def test_material_issue_gl_entry(self):
        set_perpetual_inventory()

        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 = frappe.db.get_value(
            "Account", {
                "account_type": "Stock",
                "warehouse": "_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))
示例#58
0
	def test_return_sales_invoice(self):
		set_perpetual_inventory()
		
		make_stock_entry(item_code="_Test Item", target="_Test Warehouse - _TC", qty=50, incoming_rate=100)
		
		actual_qty_0 = get_qty_after_transaction()
		
		si = create_sales_invoice(qty=5, rate=500, update_stock=1)

		actual_qty_1 = get_qty_after_transaction()
		self.assertEquals(actual_qty_0 - 5, actual_qty_1)
		
		# outgoing_rate
		outgoing_rate = frappe.db.get_value("Stock Ledger Entry", {"voucher_type": "Sales Invoice", 
			"voucher_no": si.name}, "stock_value_difference") / 5
		
		# return entry
		si1 = create_sales_invoice(is_return=1, return_against=si.name, qty=-2, rate=500, update_stock=1)

		actual_qty_2 = get_qty_after_transaction()
			
		self.assertEquals(actual_qty_1 + 2, actual_qty_2)
		
		incoming_rate, stock_value_difference = frappe.db.get_value("Stock Ledger Entry", 
			{"voucher_type": "Sales Invoice", "voucher_no": si1.name}, 
			["incoming_rate", "stock_value_difference"])
			
		self.assertEquals(flt(incoming_rate, 3), abs(flt(outgoing_rate, 3)))
		
		
		# Check gl entry
		gle_warehouse_amount = frappe.db.get_value("GL Entry", {"voucher_type": "Sales Invoice", 
			"voucher_no": si1.name, "account": "_Test Warehouse - _TC"}, "debit")
			
		self.assertEquals(gle_warehouse_amount, stock_value_difference)
		
		party_credited = frappe.db.get_value("GL Entry", {"voucher_type": "Sales Invoice", 
			"voucher_no": si1.name, "account": "Debtors - _TC", "party": "_Test Customer"}, "credit")
			
		self.assertEqual(party_credited, 1000)
		
		# Check outstanding amount
		self.assertFalse(si1.outstanding_amount)
		self.assertEqual(frappe.db.get_value("Sales Invoice", si.name, "outstanding_amount"), 1500)
		
		set_perpetual_inventory(0)
    def test_repack_with_change_in_valuation(self):
        set_perpetual_inventory()

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

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

        stock_in_hand_account = frappe.db.get_value(
            "Account", {
                "account_type": "Warehouse",
                "warehouse": 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.check_gl_entries(
            "Stock Entry", repack.name,
            sorted([
                [stock_in_hand_account, stock_value_diff, 0.0],
                ["Stock Adjustment - _TC", 0.0, stock_value_diff],
            ]))
        set_perpetual_inventory(0)
示例#60
0
	def test_jv_against_stock_account(self):
		from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import set_perpetual_inventory
		set_perpetual_inventory()

		jv = frappe.copy_doc({
			"cheque_date": nowdate(),
			"cheque_no": "33",
			"company": "_Test Company with perpetual inventory",
			"doctype": "Journal Entry",
			"accounts": [
			{
				"account": "Debtors - TCP1",
				"party_type": "Customer",
				"party": "_Test Customer",
				"credit_in_account_currency": 400.0,
				"debit_in_account_currency": 0.0,
				"doctype": "Journal Entry Account",
				"parentfield": "accounts",
				"cost_center": "Main - TCP1"
			},
			{
				"account": "_Test Bank - TCP1",
				"credit_in_account_currency": 0.0,
				"debit_in_account_currency": 400.0,
				"doctype": "Journal Entry Account",
				"parentfield": "accounts",
				"cost_center": "Main - TCP1"
			}
			],
			"naming_series": "_T-Journal Entry-",
			"posting_date": nowdate(),
			"user_remark": "test",
			"voucher_type": "Bank Entry"
			})

		jv.get("accounts")[0].update({
			"account": get_inventory_account('_Test Company with perpetual inventory'),
			"company": "_Test Company with perpetual inventory",
			"party_type": None,
			"party": None
		})

		self.assertRaises(StockAccountInvalidTransaction, jv.submit)
		jv.cancel()
		set_perpetual_inventory(0)