def test_reco_moving_average_gl_entries(self): frappe.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"])) frappe.defaults.set_global_default("auto_accounting_for_stock", 0)
def test_reco_moving_average_gl_entries(self): frappe.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"])) frappe.defaults.set_global_default("auto_accounting_for_stock", 0)
def test_reco_fifo_gl_entries(self): frappe.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"])) frappe.defaults.set_global_default("auto_accounting_for_stock", 0)
def make_adjustment_entry(self, expected_gle, voucher_obj): from erpnext.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 erpnext.accounts.general_ledger import make_gl_entries make_gl_entries(gl_entries)
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 test_pos_gl_entry_with_aii(self): 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", {"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, 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 _test_reco_sle_gle(self, valuation_method): set_perpetual_inventory() # [[qty, valuation_rate, posting_date, # posting_time, expected_stock_value, bin_qty, bin_valuation]] 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: repost_stock_as_per_valuation_method(valuation_method) last_sle = get_previous_sle({ "item_code": "_Test Item", "warehouse": "_Test Warehouse - _TC", "posting_date": d[2], "posting_time": d[3] }) # submit stock reconciliation stock_reco = create_stock_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='Stock 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": "Stock 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": "Stock Reconciliation", "voucher_no": stock_reco.name})) self.assertFalse(frappe.db.get_value("GL Entry", {"voucher_type": "Stock Reconciliation", "voucher_no": stock_reco.name})) set_perpetual_inventory(0)