def test_reco_moving_average_gl_entries(self):
		webnotes.defaults.set_global_default("auto_accounting_for_stock", 1)
		
		# [[qty, valuation_rate, posting_date, 
		#		posting_time, stock_in_hand_debit]]
		input_data = [
			[50, 1000, "2012-12-26", "12:00", 36500], 
			[5, 1000, "2012-12-26", "12:00", -8500], 
			[15, 1000, "2012-12-26", "12:00", 1500], 
			[25, 900, "2012-12-26", "12:00", 9000], 
			[20, 500, "2012-12-26", "12:00", -3500], 
			["", 1000, "2012-12-26", "12:05", 1500],
			[20, "", "2012-12-26", "12:05", 4500],
			[10, 2000, "2012-12-26", "12:10", 6500],
			[0, "", "2012-12-26", "12:10", -13500],
			[50, 1000, "2013-01-01", "12:00", 50000], 
			[5, 1000, "2013-01-01", "12:00", 5000],
			[1, 1000, "2012-12-01", "00:00", 1000],
			
		]
			
		for d in input_data:
			self.cleanup_data()
			self.insert_existing_sle("Moving Average")
			stock_reco = self.submit_stock_reconciliation(d[0], d[1], d[2], d[3])
			self.assertFalse(get_stock_and_account_difference(["_Test Warehouse - _TC"]))
			
			# cancel
			stock_reco.cancel()
			self.assertFalse(get_stock_and_account_difference(["_Test Warehouse - _TC"]))
		
		webnotes.defaults.set_global_default("auto_accounting_for_stock", 0)
	def test_reco_fifo_gl_entries(self):
		webnotes.defaults.set_global_default("auto_accounting_for_stock", 1)
		
		# [[qty, valuation_rate, posting_date, posting_time, stock_in_hand_debit]]
		input_data = [
			[50, 1000, "2012-12-26", "12:00"], 
			[5, 1000, "2012-12-26", "12:00"], 
			[15, 1000, "2012-12-26", "12:00"], 
			[25, 900, "2012-12-26", "12:00"], 
			[20, 500, "2012-12-26", "12:00"], 
			["", 1000, "2012-12-26", "12:05"],
			[20, "", "2012-12-26", "12:05"],
			[10, 2000, "2012-12-26", "12:10"],
			[0, "", "2012-12-26", "12:10"],
			[50, 1000, "2013-01-01", "12:00"], 
			[5, 1000, "2013-01-01", "12:00"],
			[1, 1000, "2012-12-01", "00:00"],
		]
			
		for d in input_data:
			self.cleanup_data()
			self.insert_existing_sle("FIFO")
			self.assertFalse(get_stock_and_account_difference(["_Test Account Stock In Hand - _TC"]))
			stock_reco = self.submit_stock_reconciliation(d[0], d[1], d[2], d[3])
			
			
			self.assertFalse(get_stock_and_account_difference(["_Test Account Stock In Hand - _TC"]))

			stock_reco.cancel()
			self.assertFalse(get_stock_and_account_difference(["_Test Account Stock In Hand - _TC"]))
		
		webnotes.defaults.set_global_default("auto_accounting_for_stock", 0)
Exemple #3
0
	def make_adjustment_entry(self, expected_gle, voucher_obj):
		from accounts.utils import get_stock_and_account_difference
		account_list = [d.account for d in expected_gle]
		acc_diff = get_stock_and_account_difference(account_list, expected_gle[0].posting_date)
		
		cost_center = self.get_company_default("cost_center")
		stock_adjustment_account = self.get_company_default("stock_adjustment_account")

		gl_entries = []
		for account, diff in acc_diff.items():
			if diff:
				gl_entries.append([
					# stock in hand account
					voucher_obj.get_gl_dict({
						"account": account,
						"against": stock_adjustment_account,
						"debit": diff,
						"remarks": "Adjustment Accounting Entry for Stock",
					}),
				
					# account against stock in hand
					voucher_obj.get_gl_dict({
						"account": stock_adjustment_account,
						"against": account,
						"credit": diff,
						"cost_center": cost_center or None,
						"remarks": "Adjustment Accounting Entry for Stock",
					}),
				])
				
		if gl_entries:
			from accounts.general_ledger import make_gl_entries
			make_gl_entries(gl_entries)
Exemple #4
0
	def test_pos_gl_entry_with_aii(self):
		self.clear_stock_account_balance()
		set_perpetual_inventory()
		
		self._insert_purchase_receipt()
		self._insert_pos_settings()
		
		pos = webnotes.copy_doclist(test_records[1])
		pos[0]["is_pos"] = 1
		pos[0]["update_stock"] = 1
		pos[0]["posting_time"] = "12:05"
		pos[0]["cash_bank_account"] = "_Test Account Bank Account - _TC"
		pos[0]["paid_amount"] = 600.0

		si = webnotes.bean(copy=pos)
		si.insert()
		si.submit()
		
		# check stock ledger entries
		sle = webnotes.conn.sql("""select * from `tabStock Ledger Entry` 
			where voucher_type = 'Sales Invoice' and voucher_no = %s""", 
			si.doc.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 = webnotes.conn.sql("""select account, debit, credit
			from `tabGL Entry` where voucher_type='Sales Invoice' and voucher_no=%s
			order by account asc, debit asc""", si.doc.name, as_dict=1)
		self.assertTrue(gl_entries)
		# print gl_entries
		
		stock_in_hand = webnotes.conn.get_value("Account", {"master_name": "_Test Warehouse - _TC"})
				
		expected_gl_entries = sorted([
			[si.doc.debit_to, 630.0, 0.0],
			[pos[1]["income_account"], 0.0, 500.0],
			[pos[2]["account_head"], 0.0, 80.0],
			[pos[3]["account_head"], 0.0, 50.0],
			[stock_in_hand, 0.0, 75.0],
			[pos[1]["expense_account"], 75.0, 0.0],
			[si.doc.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 = webnotes.conn.sql("""select * from `tabGL Entry` 
			where voucher_type='Sales Invoice' and voucher_no=%s""", si.doc.name)
		
		self.assertFalse(gle)
		
		self.assertFalse(get_stock_and_account_difference([stock_in_hand]))
		
		set_perpetual_inventory(0)
Exemple #5
0
	def test_pos_gl_entry_with_aii(self):
		self.clear_stock_account_balance()
		set_perpetual_inventory()
		
		self._insert_purchase_receipt()
		self._insert_pos_settings()
		
		pos = webnotes.copy_doclist(test_records[1])
		pos[0]["is_pos"] = 1
		pos[0]["update_stock"] = 1
		pos[0]["posting_time"] = "12:05"
		pos[0]["cash_bank_account"] = "_Test Account Bank Account - _TC"
		pos[0]["paid_amount"] = 600.0

		si = webnotes.bean(copy=pos)
		si.insert()
		si.submit()
		
		# check stock ledger entries
		sle = webnotes.conn.sql("""select * from `tabStock Ledger Entry` 
			where voucher_type = 'Sales Invoice' and voucher_no = %s""", 
			si.doc.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 = webnotes.conn.sql("""select account, debit, credit
			from `tabGL Entry` where voucher_type='Sales Invoice' and voucher_no=%s
			order by account asc, debit asc""", si.doc.name, as_dict=1)
		self.assertTrue(gl_entries)
		# print gl_entries
		
		stock_in_hand = webnotes.conn.get_value("Account", {"master_name": "_Test Warehouse - _TC"})
				
		expected_gl_entries = sorted([
			[si.doc.debit_to, 630.0, 0.0],
			[pos[1]["income_account"], 0.0, 500.0],
			[pos[2]["account_head"], 0.0, 80.0],
			[pos[3]["account_head"], 0.0, 50.0],
			[stock_in_hand, 0.0, 75.0],
			[pos[1]["expense_account"], 75.0, 0.0],
			[si.doc.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 = webnotes.conn.sql("""select * from `tabGL Entry` 
			where voucher_type='Sales Invoice' and voucher_no=%s""", si.doc.name)
		
		self.assertFalse(gle)
		
		self.assertFalse(get_stock_and_account_difference([stock_in_hand]))
		
		set_perpetual_inventory(0)