def test_delivery_note_gl_entry(self): self.clear_stock_account_balance() set_perpetual_inventory() self.assertEqual( cint( frappe.defaults.get_global_default( "auto_accounting_for_stock")), 1) frappe.db.set_value("Item", "_Test Item", "valuation_method", "FIFO") _insert_purchase_receipt() dn = frappe.bean(copy=test_records[0]) dn.doclist[1].expense_account = "Cost of Goods Sold - _TC" dn.doclist[1].cost_center = "Main - _TC" stock_in_hand_account = frappe.db.get_value( "Account", {"master_name": dn.doclist[1].warehouse}) from erpnext.accounts.utils import get_balance_on prev_bal = get_balance_on(stock_in_hand_account, dn.doc.posting_date) dn.insert() dn.submit() gl_entries = get_gl_entries("Delivery Note", dn.doc.name) self.assertTrue(gl_entries) expected_values = { stock_in_hand_account: [0.0, 375.0], "Cost of Goods Sold - _TC": [375.0, 0.0] } for i, gle in enumerate(gl_entries): self.assertEquals([gle.debit, gle.credit], expected_values.get(gle.account)) # check stock in hand balance bal = get_balance_on(stock_in_hand_account, dn.doc.posting_date) self.assertEquals(bal, prev_bal - 375.0) # back dated purchase receipt pr = frappe.bean(copy=pr_test_records[0]) pr.doc.posting_date = "2013-01-01" pr.doclist[1].rate = 100 pr.doclist[1].base_amount = 100 pr.insert() pr.submit() gl_entries = get_gl_entries("Delivery Note", dn.doc.name) self.assertTrue(gl_entries) expected_values = { stock_in_hand_account: [0.0, 666.67], "Cost of Goods Sold - _TC": [666.67, 0.0] } for i, gle in enumerate(gl_entries): self.assertEquals([gle.debit, gle.credit], expected_values.get(gle.account)) dn.cancel() self.assertFalse(get_gl_entries("Delivery Note", dn.doc.name)) set_perpetual_inventory(0)
def test_delivery_note_gl_entry_packing_item(self): company = frappe.db.get_value('Warehouse', 'Stores - TCP1', 'company') make_stock_entry(item_code="_Test Item", target="Stores - TCP1", qty=10, basic_rate=100) make_stock_entry(item_code="_Test Item Home Desktop 100", target="Stores - TCP1", qty=10, basic_rate=100) stock_in_hand_account = get_inventory_account( '_Test Company with perpetual inventory') prev_bal = get_balance_on(stock_in_hand_account) dn = create_delivery_note( item_code="_Test Product Bundle Item", company='_Test Company with perpetual inventory', warehouse='Stores - TCP1', cost_center='Main - TCP1', expense_account="Cost of Goods Sold - TCP1") stock_value_diff_rm1 = abs( frappe.db.get_value( "Stock Ledger Entry", { "voucher_type": "Delivery Note", "voucher_no": dn.name, "item_code": "_Test Item" }, "stock_value_difference")) stock_value_diff_rm2 = abs( frappe.db.get_value( "Stock Ledger Entry", { "voucher_type": "Delivery Note", "voucher_no": dn.name, "item_code": "_Test Item Home Desktop 100" }, "stock_value_difference")) stock_value_diff = stock_value_diff_rm1 + stock_value_diff_rm2 gl_entries = get_gl_entries("Delivery Note", dn.name) self.assertTrue(gl_entries) expected_values = { stock_in_hand_account: [0.0, stock_value_diff], "Cost of Goods Sold - TCP1": [stock_value_diff, 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(flt(bal, 2), flt(prev_bal - stock_value_diff, 2)) dn.cancel() self.assertFalse(get_gl_entries("Delivery Note", dn.name))
def test_delivery_note_gl_entry_packing_item(self): set_perpetual_inventory() make_stock_entry(item_code="_Test Item", target="_Test Warehouse - _TC", qty=10, basic_rate=100) make_stock_entry(item_code="_Test Item Home Desktop 100", target="_Test Warehouse - _TC", qty=10, basic_rate=100) stock_in_hand_account = frappe.db.get_value( "Account", {"warehouse": "_Test Warehouse - _TC"}) prev_bal = get_balance_on(stock_in_hand_account) dn = create_delivery_note(item_code="_Test Product Bundle Item") stock_value_diff_rm1 = abs( frappe.db.get_value( "Stock Ledger Entry", { "voucher_type": "Delivery Note", "voucher_no": dn.name, "item_code": "_Test Item" }, "stock_value_difference")) stock_value_diff_rm2 = abs( frappe.db.get_value( "Stock Ledger Entry", { "voucher_type": "Delivery Note", "voucher_no": dn.name, "item_code": "_Test Item Home Desktop 100" }, "stock_value_difference")) stock_value_diff = stock_value_diff_rm1 + stock_value_diff_rm2 gl_entries = get_gl_entries("Delivery Note", dn.name) self.assertTrue(gl_entries) expected_values = { stock_in_hand_account: [0.0, stock_value_diff], "Cost of Goods Sold - _TC": [stock_value_diff, 0.0] } for i, gle in enumerate(gl_entries): self.assertEquals([gle.debit, gle.credit], expected_values.get(gle.account)) # check stock in hand balance bal = get_balance_on(stock_in_hand_account) self.assertEquals(flt(bal, 2), flt(prev_bal - stock_value_diff, 2)) dn.cancel() self.assertFalse(get_gl_entries("Delivery Note", dn.name)) set_perpetual_inventory(0)
def test_delivery_note_gl_entry(self): self.clear_stock_account_balance() set_perpetual_inventory() self.assertEqual(cint(frappe.defaults.get_global_default("auto_accounting_for_stock")), 1) frappe.db.set_value("Item", "_Test Item", "valuation_method", "FIFO") _insert_purchase_receipt() dn = frappe.copy_doc(test_records[0]) dn.get("delivery_note_details")[0].expense_account = "Cost of Goods Sold - _TC" dn.get("delivery_note_details")[0].cost_center = "Main - _TC" stock_in_hand_account = frappe.db.get_value("Account", {"master_name": dn.get("delivery_note_details")[0].warehouse}) from erpnext.accounts.utils import get_balance_on prev_bal = get_balance_on(stock_in_hand_account, dn.posting_date) dn.insert() dn.submit() gl_entries = get_gl_entries("Delivery Note", dn.name) self.assertTrue(gl_entries) expected_values = { stock_in_hand_account: [0.0, 375.0], "Cost of Goods Sold - _TC": [375.0, 0.0] } for i, gle in enumerate(gl_entries): self.assertEquals([gle.debit, gle.credit], expected_values.get(gle.account)) # check stock in hand balance bal = get_balance_on(stock_in_hand_account, dn.posting_date) self.assertEquals(bal, prev_bal - 375.0) # back dated purchase receipt pr = frappe.copy_doc(pr_test_records[0]) pr.posting_date = "2013-01-01" pr.get("purchase_receipt_details")[0].rate = 100 pr.get("purchase_receipt_details")[0].base_amount = 100 pr.insert() pr.submit() gl_entries = get_gl_entries("Delivery Note", dn.name) self.assertTrue(gl_entries) expected_values = { stock_in_hand_account: [0.0, 666.67], "Cost of Goods Sold - _TC": [666.67, 0.0] } for i, gle in enumerate(gl_entries): self.assertEquals([gle.debit, gle.credit], expected_values.get(gle.account)) dn.cancel() self.assertFalse(get_gl_entries("Delivery Note", dn.name)) set_perpetual_inventory(0)
def test_delivery_note_gl_entry(self): set_perpetual_inventory() self.assertEqual(cint(frappe.defaults.get_global_default("auto_accounting_for_stock")), 1) set_valuation_method("_Test Item", "FIFO") make_stock_entry(target="_Test Warehouse - _TC", qty=5, basic_rate=100) stock_in_hand_account = frappe.db.get_value("Account", {"warehouse": "_Test Warehouse - _TC"}) 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.assertEquals([gle.debit, gle.credit], expected_values.get(gle.account)) # check stock in hand balance bal = get_balance_on(stock_in_hand_account) self.assertEquals(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.assertEquals([gle.debit, gle.credit], expected_values.get(gle.account)) dn.cancel() self.assertFalse(get_gl_entries("Delivery Note", dn.name)) set_perpetual_inventory(0)
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)
def test_delivery_note_gl_entry_packing_item(self): set_perpetual_inventory() make_stock_entry(item_code="_Test Item", target="_Test Warehouse - _TC", qty=10, basic_rate=100) make_stock_entry( item_code="_Test Item Home Desktop 100", target="_Test Warehouse - _TC", qty=10, basic_rate=100 ) stock_in_hand_account = frappe.db.get_value("Account", {"warehouse": "_Test Warehouse - _TC"}) prev_bal = get_balance_on(stock_in_hand_account) dn = create_delivery_note(item_code="_Test Product Bundle Item") stock_value_diff_rm1 = abs( frappe.db.get_value( "Stock Ledger Entry", {"voucher_type": "Delivery Note", "voucher_no": dn.name, "item_code": "_Test Item"}, "stock_value_difference", ) ) stock_value_diff_rm2 = abs( frappe.db.get_value( "Stock Ledger Entry", {"voucher_type": "Delivery Note", "voucher_no": dn.name, "item_code": "_Test Item Home Desktop 100"}, "stock_value_difference", ) ) stock_value_diff = stock_value_diff_rm1 + stock_value_diff_rm2 gl_entries = get_gl_entries("Delivery Note", dn.name) self.assertTrue(gl_entries) expected_values = { stock_in_hand_account: [0.0, stock_value_diff], "Cost of Goods Sold - _TC": [stock_value_diff, 0.0], } for i, gle in enumerate(gl_entries): self.assertEquals([gle.debit, gle.credit], expected_values.get(gle.account)) # check stock in hand balance bal = get_balance_on(stock_in_hand_account) self.assertEquals(flt(bal, 2), flt(prev_bal - stock_value_diff, 2)) dn.cancel() self.assertFalse(get_gl_entries("Delivery Note", dn.name)) 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_delivery_note_with_cost_center(self): from erpnext.accounts.doctype.cost_center.test_cost_center import create_cost_center cost_center = "_Test Cost Center for BS Account - TCP1" create_cost_center(cost_center_name="_Test Cost Center for BS Account", company="_Test Company with perpetual inventory") company = frappe.db.get_value('Warehouse', 'Stores - TCP1', 'company') set_valuation_method("_Test Item", "FIFO") make_stock_entry(target="Stores - TCP1", qty=5, basic_rate=100) stock_in_hand_account = get_inventory_account('_Test Company with perpetual inventory') dn = create_delivery_note(company='_Test Company with perpetual inventory', warehouse='Stores - TCP1', expense_account = "Cost of Goods Sold - TCP1", cost_center=cost_center) gl_entries = get_gl_entries("Delivery Note", dn.name) self.assertTrue(gl_entries) expected_values = { "Cost of Goods Sold - TCP1": { "cost_center": cost_center }, stock_in_hand_account: { "cost_center": cost_center } } for i, gle in enumerate(gl_entries): self.assertEqual(expected_values[gle.account]["cost_center"], gle.cost_center)
def test_delivery_note_no_gl_entry(self): company = frappe.db.get_value('Warehouse', '_Test Warehouse - _TC', 'company') set_perpetual_inventory(0, company) 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, flt(-1 * stock_queue[0][1], 2)) self.assertFalse(get_gl_entries("Delivery Note", dn.name))
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_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_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_delivery_note_cost_center_with_balance_sheet_account(self): cost_center = "Main - TCP1" company = frappe.db.get_value('Warehouse', 'Stores - TCP1', 'company') set_valuation_method("_Test Item", "FIFO") make_stock_entry(target="Stores - TCP1", qty=5, basic_rate=100) stock_in_hand_account = get_inventory_account('_Test Company with perpetual inventory') dn = create_delivery_note(company='_Test Company with perpetual inventory', warehouse='Stores - TCP1', cost_center = 'Main - TCP1', expense_account = "Cost of Goods Sold - TCP1", do_not_submit=1) dn.get('items')[0].cost_center = None dn.submit() gl_entries = get_gl_entries("Delivery Note", dn.name) self.assertTrue(gl_entries) expected_values = { "Cost of Goods Sold - TCP1": { "cost_center": cost_center }, stock_in_hand_account: { "cost_center": cost_center } } for i, gle in enumerate(gl_entries): self.assertEqual(expected_values[gle.account]["cost_center"], gle.cost_center)
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.assertEqual(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.assertEqual(expected_values[gle.account][0], gle.debit) self.assertEqual(expected_values[gle.account][1], 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 = 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)
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_delivery_of_bundled_items_to_target_warehouse(self): company = frappe.db.get_value('Warehouse', 'Stores - TCP1', 'company') set_valuation_method("_Test Item", "FIFO") set_valuation_method("_Test Item Home Desktop 100", "FIFO") target_warehouse=get_warehouse(company=company, abbr="TCP1", warehouse_name="_Test Customer Warehouse").name for warehouse in ("Stores - TCP1", target_warehouse): create_stock_reconciliation(item_code="_Test Item", warehouse=warehouse, company = company, expense_account = "Stock Adjustment - TCP1", qty=500, rate=100) create_stock_reconciliation(item_code="_Test Item Home Desktop 100", company = company, expense_account = "Stock Adjustment - TCP1", warehouse=warehouse, qty=500, rate=100) dn = create_delivery_note(item_code="_Test Product Bundle Item", company='_Test Company with perpetual inventory', cost_center = 'Main - TCP1', expense_account = "Cost of Goods Sold - TCP1", do_not_submit=True, qty=5, rate=500, warehouse="Stores - TCP1", target_warehouse=target_warehouse) dn.submit() # qty after delivery actual_qty_at_source = get_qty_after_transaction(warehouse="Stores - TCP1") self.assertEqual(actual_qty_at_source, 475) actual_qty_at_target = get_qty_after_transaction(warehouse=target_warehouse) self.assertEqual(actual_qty_at_target, 525) # stock value diff for source warehouse for "_Test Item" stock_value_difference = frappe.db.get_value("Stock Ledger Entry", {"voucher_type": "Delivery Note", "voucher_no": dn.name, "item_code": "_Test Item", "warehouse": "Stores - TCP1"}, "stock_value_difference") # stock value diff for target warehouse stock_value_difference1 = frappe.db.get_value("Stock Ledger Entry", {"voucher_type": "Delivery Note", "voucher_no": dn.name, "item_code": "_Test Item", "warehouse": target_warehouse}, "stock_value_difference") self.assertEqual(abs(stock_value_difference), stock_value_difference1) # Check gl entries gl_entries = get_gl_entries("Delivery Note", dn.name) self.assertTrue(gl_entries) stock_value_difference = abs(frappe.db.sql("""select sum(stock_value_difference) from `tabStock Ledger Entry` where voucher_type='Delivery Note' and voucher_no=%s and warehouse='Stores - TCP1'""", dn.name)[0][0]) expected_values = { "Stock In Hand - TCP1": [0.0, stock_value_difference], target_warehouse: [stock_value_difference, 0.0] } for i, gle in enumerate(gl_entries): self.assertEqual([gle.debit, gle.credit], expected_values.get(gle.account))
def test_delivery_note_gl_entry_packing_item(self): self.clear_stock_account_balance() set_perpetual_inventory() _insert_purchase_receipt() _insert_purchase_receipt("_Test Item Home Desktop 100") dn = frappe.copy_doc(test_records[0]) dn.get("delivery_note_details")[0].item_code = "_Test Sales BOM Item" dn.get("delivery_note_details")[0].qty = 1 stock_in_hand_account = frappe.db.get_value( "Account", {"master_name": dn.get("delivery_note_details")[0].warehouse}) from erpnext.accounts.utils import get_balance_on prev_bal = get_balance_on(stock_in_hand_account, dn.posting_date) dn.insert() dn.submit() gl_entries = get_gl_entries("Delivery Note", dn.name) self.assertTrue(gl_entries) expected_values = { stock_in_hand_account: [0.0, 525], "Cost of Goods Sold - _TC": [525.0, 0.0] } for i, gle in enumerate(gl_entries): self.assertEquals([gle.debit, gle.credit], expected_values.get(gle.account)) # check stock in hand balance bal = get_balance_on(stock_in_hand_account, dn.posting_date) self.assertEquals(bal, prev_bal - 525.0) dn.cancel() self.assertFalse(get_gl_entries("Delivery Note", dn.name)) set_perpetual_inventory(0)
def test_reposting_packed_items(self): warehouse = "Stores - TCP1" company = "_Test Company with perpetual inventory" today = nowdate() yesterday = add_to_date(today, days=-1, as_string=True) for item in self.bundle_items: make_stock_entry(item_code=item, to_warehouse=warehouse, qty=10, rate=100, posting_date=today) so = make_sales_order(item_code=self.bundle, qty=1, company=company, warehouse=warehouse) dn = make_delivery_note(so.name) dn.save() dn.submit() gles = get_gl_entries(dn.doctype, dn.name) credit_before_repost = sum(gle.credit for gle in gles) # backdated stock entry for item in self.bundle_items: make_stock_entry(item_code=item, to_warehouse=warehouse, qty=10, rate=200, posting_date=yesterday) # assert correct reposting gles = get_gl_entries(dn.doctype, dn.name) credit_after_reposting = sum(gle.credit for gle in gles) self.assertNotEqual(credit_before_repost, credit_after_reposting) self.assertAlmostEqual(credit_after_reposting, 2 * credit_before_repost)
def test_delivery_of_bundled_items_to_target_warehouse(self): set_perpetual_inventory() frappe.db.set_value("Item", "_Test Item", "valuation_method", "FIFO") for warehouse in ("_Test Warehouse - _TC", "_Test Warehouse 1 - _TC"): create_stock_reconciliation(item_code="_Test Item", target=warehouse, qty=50, rate=100) create_stock_reconciliation(item_code="_Test Item Home Desktop 100", target=warehouse, qty=50, rate=100) opening_qty_test_warehouse_1 = get_qty_after_transaction(warehouse="_Test Warehouse 1 - _TC") dn = create_delivery_note(item_code="_Test Product Bundle Item", qty=5, rate=500, target_warehouse="_Test Warehouse 1 - _TC", do_not_submit=True) dn.submit() # qty after delivery actual_qty = get_qty_after_transaction(warehouse="_Test Warehouse - _TC") self.assertEquals(actual_qty, 25) actual_qty = get_qty_after_transaction(warehouse="_Test Warehouse 1 - _TC") self.assertEquals(actual_qty, opening_qty_test_warehouse_1 + 25) # stock value diff for source warehouse stock_value_difference = frappe.db.get_value("Stock Ledger Entry", {"voucher_type": "Delivery Note", "voucher_no": dn.name, "item_code": "_Test Item Home Desktop 100", "warehouse": "_Test Warehouse - _TC"}, "stock_value_difference") # stock value diff for target warehouse stock_value_difference1 = frappe.db.get_value("Stock Ledger Entry", {"voucher_type": "Delivery Note", "voucher_no": dn.name, "item_code": "_Test Item Home Desktop 100", "warehouse": "_Test Warehouse 1 - _TC"}, "stock_value_difference") self.assertEquals(abs(stock_value_difference), stock_value_difference1) # Check gl entries gl_entries = get_gl_entries("Delivery Note", dn.name) self.assertTrue(gl_entries) stock_value_difference = abs(frappe.db.sql("""select sum(stock_value_difference) from `tabStock Ledger Entry` where voucher_type='Delivery Note' and voucher_no=%s and warehouse='_Test Warehouse - _TC'""", dn.name)[0][0]) expected_values = { "_Test Warehouse - _TC": [0.0, stock_value_difference], "_Test Warehouse 1 - _TC": [stock_value_difference, 0.0] } for i, gle in enumerate(gl_entries): self.assertEquals([gle.debit, gle.credit], expected_values.get(gle.account)) set_perpetual_inventory(0)
def test_delivery_note_gl_entry_packing_item(self): self.clear_stock_account_balance() set_perpetual_inventory() _insert_purchase_receipt() _insert_purchase_receipt("_Test Item Home Desktop 100") dn = frappe.copy_doc(test_records[0]) dn.get("delivery_note_details")[0].item_code = "_Test Sales BOM Item" dn.get("delivery_note_details")[0].qty = 1 stock_in_hand_account = frappe.db.get_value("Account", {"master_name": dn.get("delivery_note_details")[0].warehouse}) from erpnext.accounts.utils import get_balance_on prev_bal = get_balance_on(stock_in_hand_account, dn.posting_date) dn.insert() dn.submit() gl_entries = get_gl_entries("Delivery Note", dn.name) self.assertTrue(gl_entries) expected_values = { stock_in_hand_account: [0.0, 525], "Cost of Goods Sold - _TC": [525.0, 0.0] } for i, gle in enumerate(gl_entries): self.assertEquals([gle.debit, gle.credit], expected_values.get(gle.account)) # check stock in hand balance bal = get_balance_on(stock_in_hand_account, dn.posting_date) self.assertEquals(bal, prev_bal - 525.0) dn.cancel() self.assertFalse(get_gl_entries("Delivery Note", dn.name)) set_perpetual_inventory(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)
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_gl_entries_in_base_currency(self): inv = create_sales_invoice(rate=200) inv_disc = create_invoice_discounting( [inv.name], accounts_receivable_credit=self.ar_credit, accounts_receivable_discounted=self.ar_discounted, accounts_receivable_unpaid=self.ar_unpaid, short_term_loan=self.short_term_loan, bank_charges_account=self.bank_charges_account, bank_account=self.bank_account) gle = get_gl_entries("Invoice Discounting", inv_disc.name) expected_gle = {inv.debit_to: [0.0, 200], self.ar_credit: [200, 0.0]} for i, gle in enumerate(gle): self.assertEqual([gle.debit, gle.credit], expected_gle.get(gle.account))
def test_delivery_note_no_gl_entry(self): self.clear_stock_account_balance() set_perpetual_inventory(0) self.assertEqual(cint(frappe.defaults.get_global_default("auto_accounting_for_stock")), 0) _insert_purchase_receipt() dn = frappe.copy_doc(test_records[0]) dn.insert() dn.submit() stock_value, stock_value_difference = frappe.db.get_value("Stock Ledger Entry", {"voucher_type": "Delivery Note", "voucher_no": dn.name, "item_code": "_Test Item"}, ["stock_value", "stock_value_difference"]) self.assertEqual(stock_value, 0) self.assertEqual(stock_value_difference, -375) self.assertFalse(get_gl_entries("Delivery Note", dn.name))
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)
def assertPurchaseReceiptLCVGLEntries(self, pr): 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 - TCP1": [0.0, 500.0], "Expenses Included In Valuation - TCP1": [0.0, 50.0], "_Test Account Customs Duty - TCP1": [0.0, 150], "_Test Account Shipping Charges - TCP1": [0.0, 100.00], } else: expected_values = { stock_in_hand_account: [400.0, 0.0], fixed_asset_account: [400.0, 0.0], "Stock Received But Not Billed - TCP1": [0.0, 500.0], "Expenses Included In Valuation - TCP1": [0.0, 300.0], } for gle in gl_entries: if not gle.get("is_cancelled"): self.assertEqual(expected_values[gle.account][0], gle.debit, msg=f"incorrect debit for {gle.account}") self.assertEqual(expected_values[gle.account][1], gle.credit, msg=f"incorrect credit for {gle.account}")
def test_delivery_note_no_gl_entry(self): self.clear_stock_account_balance() set_perpetual_inventory(0) self.assertEqual( cint( frappe.defaults.get_global_default( "auto_accounting_for_stock")), 0) _insert_purchase_receipt() dn = frappe.bean(copy=test_records[0]) dn.insert() dn.submit() stock_value, stock_value_difference = frappe.db.get_value( "Stock Ledger Entry", { "voucher_type": "Delivery Note", "voucher_no": dn.doc.name, "item_code": "_Test Item" }, ["stock_value", "stock_value_difference"]) self.assertEqual(stock_value, 0) self.assertEqual(stock_value_difference, -375) self.assertFalse(get_gl_entries("Delivery Note", dn.doc.name))
def test_delivery_of_bundled_items_to_target_warehouse(self): company = frappe.db.get_value('Warehouse', '_Test Warehouse - _TC', 'company') set_perpetual_inventory(1, company) set_valuation_method("_Test Item", "FIFO") set_valuation_method("_Test Item Home Desktop 100", "FIFO") for warehouse in ("_Test Warehouse - _TC", "_Test Warehouse 1 - _TC"): create_stock_reconciliation(item_code="_Test Item", target=warehouse, qty=100, rate=100) create_stock_reconciliation( item_code="_Test Item Home Desktop 100", target=warehouse, qty=100, rate=100) opening_qty_test_warehouse_1 = get_qty_after_transaction( warehouse="_Test Warehouse 1 - _TC") dn = create_delivery_note(item_code="_Test Product Bundle Item", qty=5, rate=500, target_warehouse="_Test Warehouse 1 - _TC", do_not_submit=True) dn.submit() # qty after delivery actual_qty = get_qty_after_transaction( warehouse="_Test Warehouse - _TC") self.assertEquals(actual_qty, 75) actual_qty = get_qty_after_transaction( warehouse="_Test Warehouse 1 - _TC") self.assertEquals(actual_qty, opening_qty_test_warehouse_1 + 25) # stock value diff for source warehouse # for "_Test Item" stock_value_difference = frappe.db.get_value( "Stock Ledger Entry", { "voucher_type": "Delivery Note", "voucher_no": dn.name, "item_code": "_Test Item", "warehouse": "_Test Warehouse - _TC" }, "stock_value_difference") # stock value diff for target warehouse stock_value_difference1 = frappe.db.get_value( "Stock Ledger Entry", { "voucher_type": "Delivery Note", "voucher_no": dn.name, "item_code": "_Test Item", "warehouse": "_Test Warehouse 1 - _TC" }, "stock_value_difference") self.assertEquals(abs(stock_value_difference), stock_value_difference1) # for "_Test Item Home Desktop 100" stock_value_difference = frappe.db.get_value( "Stock Ledger Entry", { "voucher_type": "Delivery Note", "voucher_no": dn.name, "item_code": "_Test Item Home Desktop 100", "warehouse": "_Test Warehouse - _TC" }, "stock_value_difference") # stock value diff for target warehouse stock_value_difference1 = frappe.db.get_value( "Stock Ledger Entry", { "voucher_type": "Delivery Note", "voucher_no": dn.name, "item_code": "_Test Item Home Desktop 100", "warehouse": "_Test Warehouse 1 - _TC" }, "stock_value_difference") self.assertEquals(abs(stock_value_difference), stock_value_difference1) # Check gl entries gl_entries = get_gl_entries("Delivery Note", dn.name) self.assertTrue(gl_entries) stock_value_difference = abs( frappe.db.sql( """select sum(stock_value_difference) from `tabStock Ledger Entry` where voucher_type='Delivery Note' and voucher_no=%s and warehouse='_Test Warehouse - _TC'""", dn.name)[0][0]) expected_values = { "Stock In Hand - _TC": [0.0, stock_value_difference], "_Test Warehouse 1 - _TC": [stock_value_difference, 0.0] } for i, gle in enumerate(gl_entries): self.assertEquals([gle.debit, gle.credit], expected_values.get(gle.account)) set_perpetual_inventory(0, company)
def test_landed_cost_voucher_against_purchase_invoice(self): pi = make_purchase_invoice( update_stock=1, posting_date=frappe.utils.nowdate(), posting_time=frappe.utils.nowtime(), cash_bank_account="Cash - TCP1", company="_Test Company with perpetual inventory", supplier_warehouse="Work In Progress - TCP1", warehouse="Stores - TCP1", cost_center="Main - TCP1", expense_account="_Test Account Cost for Goods Sold - TCP1", ) last_sle = frappe.db.get_value( "Stock Ledger Entry", { "voucher_type": pi.doctype, "voucher_no": pi.name, "item_code": "_Test Item", "warehouse": "Stores - TCP1", }, fieldname=["qty_after_transaction", "stock_value"], as_dict=1, ) create_landed_cost_voucher("Purchase Invoice", pi.name, pi.company) pi_lc_value = frappe.db.get_value("Purchase Invoice Item", {"parent": pi.name}, "landed_cost_voucher_amount") self.assertEqual(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": "Stores - TCP1", }, 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 - TCP1": [0.0, 250.0], "Expenses Included In Valuation - TCP1": [0.0, 50.0], } for gle in gl_entries: if not gle.get("is_cancelled"): self.assertEqual(expected_values[gle.account][0], gle.debit) self.assertEqual(expected_values[gle.account][1], gle.credit)
def test_delivery_of_bundled_items_to_target_warehouse(self): from erpnext.selling.doctype.customer.test_customer import create_internal_customer company = frappe.db.get_value("Warehouse", "Stores - TCP1", "company") customer_name = create_internal_customer( customer_name="_Test Internal Customer 2", represents_company="_Test Company with perpetual inventory", allowed_to_interact_with="_Test Company with perpetual inventory", ) set_valuation_method("_Test Item", "FIFO") set_valuation_method("_Test Item Home Desktop 100", "FIFO") target_warehouse = get_warehouse( company=company, abbr="TCP1", warehouse_name="_Test Customer Warehouse").name for warehouse in ("Stores - TCP1", target_warehouse): create_stock_reconciliation( item_code="_Test Item", warehouse=warehouse, company=company, expense_account="Stock Adjustment - TCP1", qty=500, rate=100, ) create_stock_reconciliation( item_code="_Test Item Home Desktop 100", company=company, expense_account="Stock Adjustment - TCP1", warehouse=warehouse, qty=500, rate=100, ) dn = create_delivery_note( item_code="_Test Product Bundle Item", company="_Test Company with perpetual inventory", customer=customer_name, cost_center="Main - TCP1", expense_account="Cost of Goods Sold - TCP1", qty=5, rate=500, warehouse="Stores - TCP1", target_warehouse=target_warehouse, ) # qty after delivery actual_qty_at_source = get_qty_after_transaction( warehouse="Stores - TCP1") self.assertEqual(actual_qty_at_source, 475) actual_qty_at_target = get_qty_after_transaction( warehouse=target_warehouse) self.assertEqual(actual_qty_at_target, 525) # stock value diff for source warehouse for "_Test Item" stock_value_difference = frappe.db.get_value( "Stock Ledger Entry", { "voucher_type": "Delivery Note", "voucher_no": dn.name, "item_code": "_Test Item", "warehouse": "Stores - TCP1", }, "stock_value_difference", ) # stock value diff for target warehouse stock_value_difference1 = frappe.db.get_value( "Stock Ledger Entry", { "voucher_type": "Delivery Note", "voucher_no": dn.name, "item_code": "_Test Item", "warehouse": target_warehouse, }, "stock_value_difference", ) self.assertEqual(abs(stock_value_difference), stock_value_difference1) # Check gl entries gl_entries = get_gl_entries("Delivery Note", dn.name) self.assertTrue(gl_entries) stock_value_difference = abs( frappe.db.sql( """select sum(stock_value_difference) from `tabStock Ledger Entry` where voucher_type='Delivery Note' and voucher_no=%s and warehouse='Stores - TCP1'""", dn.name, )[0][0]) expected_values = { "Stock In Hand - TCP1": [0.0, stock_value_difference], target_warehouse: [stock_value_difference, 0.0], } for i, gle in enumerate(gl_entries): self.assertEqual([gle.debit, gle.credit], expected_values.get(gle.account)) # tear down frappe.db.rollback()
def test_landed_cost_voucher(self): frappe.db.set_value("Buying Settings", None, "allow_multiple_items", 1) pr = make_purchase_receipt( company="_Test Company with perpetual inventory", warehouse="Stores - TCP1", supplier_warehouse="Work in Progress - TCP1", get_multiple_items=True, get_taxes_and_charges=True) last_sle = frappe.db.get_value( "Stock Ledger Entry", { "voucher_type": pr.doctype, "voucher_no": pr.name, "item_code": "_Test Item", "warehouse": "Stores - TCP1" }, fieldname=["qty_after_transaction", "stock_value"], as_dict=1) create_landed_cost_voucher("Purchase Receipt", pr.name, pr.company) pr_lc_value = frappe.db.get_value("Purchase Receipt Item", {"parent": pr.name}, "landed_cost_voucher_amount") self.assertEqual(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": "Stores - TCP1" }, 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 - TCP1": [0.0, 500.0], "Expenses Included In Valuation - TCP1": [0.0, 50.0], "_Test Account Customs Duty - TCP1": [0.0, 150], "_Test Account Shipping Charges - TCP1": [0.0, 100.00] } else: expected_values = { stock_in_hand_account: [400.0, 0.0], fixed_asset_account: [400.0, 0.0], "Stock Received But Not Billed - TCP1": [0.0, 500.0], "Expenses Included In Valuation - TCP1": [0.0, 300.0] } for gle in gl_entries: if not gle.get('is_cancelled'): self.assertEqual(expected_values[gle.account][0], gle.debit) self.assertEqual(expected_values[gle.account][1], gle.credit)