def test_sales_invoice_gl_entry_with_aii_non_stock_item(self): self.clear_stock_account_balance() set_perpetual_inventory() si_copy = webnotes.copy_doclist(test_records[1]) si_copy[1]["item_code"] = "_Test Non Stock Item" si = webnotes.bean(si_copy) si.insert() si.submit() 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""", si.doc.name, as_dict=1) self.assertTrue(gl_entries) expected_values = sorted([ [si.doc.debit_to, 630.0, 0.0], [test_records[1][1]["income_account"], 0.0, 500.0], [test_records[1][2]["account_head"], 0.0, 80.0], [test_records[1][3]["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_time_log_batch(self): tlb = webnotes.bean("Time Log Batch", "_T-Time Log Batch-00001") tlb.submit() si = webnotes.bean(webnotes.copy_doclist(test_records[0])) si.doclist[1].time_log_batch = "_T-Time Log Batch-00001" si.insert() si.submit() self.assertEquals( webnotes.conn.get_value("Time Log Batch", "_T-Time Log Batch-00001", "status"), "Billed") self.assertEquals( webnotes.conn.get_value("Time Log", "_T-Time Log-00001", "status"), "Billed") si.cancel() self.assertEquals( webnotes.conn.get_value("Time Log Batch", "_T-Time Log Batch-00001", "status"), "Submitted") self.assertEquals( webnotes.conn.get_value("Time Log", "_T-Time Log-00001", "status"), "Batched for Billing")
def test_sales_invoice_gl_entry_with_aii_non_stock_item(self): webnotes.defaults.set_global_default("auto_inventory_accounting", 1) si_copy = webnotes.copy_doclist(test_records[1]) si_copy[1]["item_code"] = "_Test Non Stock Item" si = webnotes.bean(si_copy) si.insert() si.submit() 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""", si.doc.name, as_dict=1) self.assertTrue(gl_entries) expected_values = sorted([ [si.doc.debit_to, 630.0, 0.0], [test_records[1][1]["income_account"], 0.0, 500.0], [test_records[1][2]["account_head"], 0.0, 80.0], [test_records[1][3]["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) webnotes.defaults.set_global_default("auto_inventory_accounting", 0)
def test_reserved_qty_for_over_delivery_with_packing_list(self): from selling.doctype.sales_bom.test_sales_bom import test_records as sbom_test_records # change item in test so record test_record = webnotes.copy_doclist(test_records[0]) test_record[1]["item_code"] = "_Test Sales BOM Item" # reset bin self.delete_bin(sbom_test_records[0][1]["item_code"], test_record[1]["reserved_warehouse"]) self.delete_bin(sbom_test_records[0][2]["item_code"], test_record[1]["reserved_warehouse"]) # submit so = self.create_so(test_record) # allow negative stock webnotes.conn.set_default("allow_negative_stock", 1) # set over-delivery tolerance webnotes.conn.set_value('Item', so.doclist[1].item_code, 'tolerance', 50) # submit dn dn = self.create_dn_against_so(so, 15) self.check_reserved_qty(sbom_test_records[0][1]["item_code"], so.doclist[1].reserved_warehouse, 0.0) self.check_reserved_qty(sbom_test_records[0][2]["item_code"], so.doclist[1].reserved_warehouse, 0.0) # cancel dn dn.cancel() self.check_reserved_qty(sbom_test_records[0][1]["item_code"], so.doclist[1].reserved_warehouse, 50.0) self.check_reserved_qty(sbom_test_records[0][2]["item_code"], so.doclist[1].reserved_warehouse, 20.0)
def test_sales_invoice_gl_entry_without_aii(self): webnotes.defaults.set_global_default("auto_inventory_accounting", 0) si = webnotes.bean(webnotes.copy_doclist(test_records[1])) si.insert() si.submit() 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""", si.doc.name, as_dict=1) self.assertTrue(gl_entries) expected_values = sorted([ [si.doc.debit_to, 630.0, 0.0], [test_records[1][1]["income_account"], 0.0, 500.0], [test_records[1][2]["account_head"], 0.0, 80.0], [test_records[1][3]["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_count = webnotes.conn.sql("""select count(name) from `tabGL Entry` where voucher_type='Sales Invoice' and voucher_no=%s and ifnull(is_cancelled, 'No') = 'Yes' order by account asc""", si.doc.name) self.assertEquals(gle_count[0][0], 8)
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)
def test_pos_gl_entry_with_aii(self): webnotes.conn.sql("delete from `tabStock Ledger Entry`") webnotes.defaults.set_global_default("auto_inventory_accounting", 1) 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(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", -5.0]) # check gl entries stock_in_hand_account = webnotes.conn.get_value("Company", "_Test Company", "stock_in_hand_account") 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) expected_gl_entries = sorted([ [si.doc.debit_to, 630.0, 0.0], [test_records[1][1]["income_account"], 0.0, 500.0], [test_records[1][2]["account_head"], 0.0, 80.0], [test_records[1][3]["account_head"], 0.0, 50.0], [stock_in_hand_account, 0.0, 375.0], [test_records[1][1]["expense_account"], 375.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) # cancel si.cancel() gl_count = webnotes.conn.sql("""select count(name) from `tabGL Entry` where voucher_type='Sales Invoice' and voucher_no=%s and ifnull(is_cancelled, 'No') = 'Yes' order by account asc, name asc""", si.doc.name) self.assertEquals(gl_count[0][0], 16) webnotes.defaults.set_global_default("auto_inventory_accounting", 0)
def test_si_gl_entry_with_aii_and_update_stock_with_warehouse_but_no_account(self): self.clear_stock_account_balance() set_perpetual_inventory() webnotes.delete_doc("Account", "_Test Warehouse No Account - _TC") # insert purchase receipt from stock.doctype.purchase_receipt.test_purchase_receipt import test_records \ as pr_test_records pr = webnotes.bean(copy=pr_test_records[0]) pr.doc.naming_series = "_T-Purchase Receipt-" pr.doclist[1].warehouse = "_Test Warehouse No Account - _TC" pr.run_method("calculate_taxes_and_totals") pr.insert() pr.submit() si_doclist = webnotes.copy_doclist(test_records[1]) si_doclist[0]["update_stock"] = 1 si_doclist[0]["posting_time"] = "12:05" si_doclist[1]["warehouse"] = "_Test Warehouse No Account - _TC" si = webnotes.bean(copy=si_doclist) 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 No Account - _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) expected_gl_entries = sorted([ [si.doc.debit_to, 630.0, 0.0], [si_doclist[1]["income_account"], 0.0, 500.0], [si_doclist[2]["account_head"], 0.0, 80.0], [si_doclist[3]["account_head"], 0.0, 50.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) set_perpetual_inventory(0)
def create_dn_against_so(self, so, delivered_qty=0): from stock.doctype.delivery_note.test_delivery_note import test_records as dn_test_records dn = webnotes.bean(webnotes.copy_doclist(dn_test_records[0])) dn.doclist[1].item_code = so.doclist[1].item_code dn.doclist[1].against_sales_order = so.doc.name dn.doclist[1].prevdoc_detail_docname = so.doclist[1].name if delivered_qty: dn.doclist[1].qty = delivered_qty dn.insert() dn.submit() return dn
def create_dn_against_so(self, so, delivered_qty=0): from stock.doctype.delivery_note.test_delivery_note import test_records as dn_test_records dn = webnotes.bean(webnotes.copy_doclist(dn_test_records[0])) dn.doclist[1].item_code = so.doclist[1].item_code dn.doclist[1].prevdoc_doctype = "Sales Order" dn.doclist[1].prevdoc_docname = so.doc.name dn.doclist[1].prevdoc_detail_docname = so.doclist[1].name if delivered_qty: dn.doclist[1].qty = delivered_qty dn.insert() dn.submit() return dn
def test_reserved_qty_for_partial_delivery_with_packing_list(self): from selling.doctype.sales_bom.test_sales_bom import test_records as sbom_test_records # change item in test so record test_record = webnotes.copy_doclist(test_records[0]) test_record[1]["item_code"] = "_Test Sales BOM Item" # reset bin self.delete_bin(sbom_test_records[0][1]["item_code"], test_record[1]["reserved_warehouse"]) self.delete_bin(sbom_test_records[0][2]["item_code"], test_record[1]["reserved_warehouse"]) # submit so = self.create_so(test_record) # allow negative stock webnotes.conn.set_default("allow_negative_stock", 1) # submit dn dn = self.create_dn_against_so(so) self.check_reserved_qty(sbom_test_records[0][1]["item_code"], so.doclist[1].reserved_warehouse, 25.0) self.check_reserved_qty(sbom_test_records[0][2]["item_code"], so.doclist[1].reserved_warehouse, 10.0) # stop so so.load_from_db() so.obj.stop_sales_order() self.check_reserved_qty(sbom_test_records[0][1]["item_code"], so.doclist[1].reserved_warehouse, 0.0) self.check_reserved_qty(sbom_test_records[0][2]["item_code"], so.doclist[1].reserved_warehouse, 0.0) # unstop so so.load_from_db() so.obj.unstop_sales_order() self.check_reserved_qty(sbom_test_records[0][1]["item_code"], so.doclist[1].reserved_warehouse, 25.0) self.check_reserved_qty(sbom_test_records[0][2]["item_code"], so.doclist[1].reserved_warehouse, 10.0) # cancel dn dn.cancel() self.check_reserved_qty(sbom_test_records[0][1]["item_code"], so.doclist[1].reserved_warehouse, 50.0) self.check_reserved_qty(sbom_test_records[0][2]["item_code"], so.doclist[1].reserved_warehouse, 20.0)
def test_payment(self): webnotes.conn.sql("""delete from `tabGL Entry`""") w = self.make() from accounts.doctype.journal_voucher.test_journal_voucher import test_records as jv_test_records jv = webnotes.bean(webnotes.copy_doclist(jv_test_records[0])) jv.doclist[1].against_invoice = w.doc.name jv.insert() jv.submit() self.assertEquals(webnotes.conn.get_value("Sales Invoice", w.doc.name, "outstanding_amount"), 161.8) jv.cancel() self.assertEquals(webnotes.conn.get_value("Sales Invoice", w.doc.name, "outstanding_amount"), 561.8)
def test_time_log_batch(self): tlb = webnotes.bean("Time Log Batch", "_T-Time Log Batch-00001") tlb.submit() si = webnotes.bean(webnotes.copy_doclist(test_records[0])) si.doclist[1].time_log_batch = "_T-Time Log Batch-00001" si.insert() si.submit() self.assertEquals(webnotes.conn.get_value("Time Log Batch", "_T-Time Log Batch-00001", "status"), "Billed") self.assertEquals(webnotes.conn.get_value("Time Log", "_T-Time Log-00001", "status"), "Billed") si.cancel() self.assertEquals(webnotes.conn.get_value("Time Log Batch", "_T-Time Log Batch-00001", "status"), "Submitted") self.assertEquals(webnotes.conn.get_value("Time Log", "_T-Time Log-00001", "status"), "Batched for Billing")
def test_payment(self): w = self.make() from accounts.doctype.journal_voucher.test_journal_voucher \ import test_records as jv_test_records jv = webnotes.bean(webnotes.copy_doclist(jv_test_records[0])) jv.doclist[1].against_invoice = w.doc.name jv.insert() jv.submit() self.assertEquals( webnotes.conn.get_value("Sales Invoice", w.doc.name, "outstanding_amount"), 161.8) jv.cancel() self.assertEquals( webnotes.conn.get_value("Sales Invoice", w.doc.name, "outstanding_amount"), 561.8)
def test_sales_invoice_gl_entry_without_aii(self): webnotes.defaults.set_global_default("auto_inventory_accounting", 0) si = webnotes.bean(webnotes.copy_doclist(test_records[1])) si.insert() si.submit() 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""", si.doc.name, as_dict=1) self.assertTrue(gl_entries) expected_values = sorted([ [si.doc.debit_to, 630.0, 0.0], [test_records[1][1]["income_account"], 0.0, 500.0], [test_records[1][2]["account_head"], 0.0, 80.0], [test_records[1][3]["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_count = webnotes.conn.sql( """select count(name) from `tabGL Entry` where voucher_type='Sales Invoice' and voucher_no=%s and ifnull(is_cancelled, 'No') = 'Yes' order by account asc""", si.doc.name) self.assertEquals(gle_count[0][0], 8)
def make(self): w = webnotes.model_wrapper(webnotes.copy_doclist(test_records[0])) w.insert() w.submit() return w
def test_sales_invoice_gl_entry_with_aii_delivery_note(self): webnotes.conn.sql("delete from `tabStock Ledger Entry`") webnotes.defaults.set_global_default("auto_inventory_accounting", 1) self._insert_purchase_receipt() dn = self._insert_delivery_note() si_against_dn = webnotes.copy_doclist(test_records[1]) si_against_dn[1]["delivery_note"] = dn.doc.name si_against_dn[1]["dn_detail"] = dn.doclist[1].name si = webnotes.bean(si_against_dn) si.insert() si.submit() 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""", si.doc.name, as_dict=1) self.assertTrue(gl_entries) expected_values = sorted([ [si.doc.debit_to, 630.0, 0.0], [test_records[1][1]["income_account"], 0.0, 500.0], [test_records[1][2]["account_head"], 0.0, 80.0], [test_records[1][3]["account_head"], 0.0, 50.0], ["Stock Delivered But Not Billed - _TC", 0.0, 375.0], [test_records[1][1]["expense_account"], 375.0, 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) si.cancel() gl_entries = webnotes.conn.sql("""select account, debit, credit from `tabGL Entry` where voucher_type='Sales Invoice' and voucher_no=%s and ifnull(is_cancelled, 'No') = 'No' order by account asc, name asc""", si.doc.name, as_dict=1) expected_values = sorted([ [si.doc.debit_to, 630.0, 0.0], [si.doc.debit_to, 0.0, 630.0], [test_records[1][1]["income_account"], 0.0, 500.0], [test_records[1][1]["income_account"], 500.0, 0.0], [test_records[1][2]["account_head"], 0.0, 80.0], [test_records[1][2]["account_head"], 80.0, 0.0], [test_records[1][3]["account_head"], 0.0, 50.0], [test_records[1][3]["account_head"], 50.0, 0.0], ["Stock Delivered But Not Billed - _TC", 0.0, 375.0], ["Stock Delivered But Not Billed - _TC", 375.0, 0.0], [test_records[1][1]["expense_account"], 375.0, 0.0], [test_records[1][1]["expense_account"], 0.0, 375.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) webnotes.defaults.set_global_default("auto_inventory_accounting", 0)
def make(self): w = webnotes.bean(webnotes.copy_doclist(test_records[0])) w.insert() w.submit() return w
def test_pos_gl_entry_with_aii(self): webnotes.conn.sql("delete from `tabStock Ledger Entry`") webnotes.defaults.set_global_default("auto_inventory_accounting", 1) old_default_company = webnotes.conn.get_default("company") webnotes.conn.set_default("company", "_Test Company") 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 stock_in_hand_account = webnotes.conn.get_value( "Company", "_Test Company", "stock_in_hand_account") 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) 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_account, 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) # cancel si.cancel() gl_count = webnotes.conn.sql( """select count(name) from `tabGL Entry` where voucher_type='Sales Invoice' and voucher_no=%s and ifnull(is_cancelled, 'No') = 'Yes' order by account asc, name asc""", si.doc.name) self.assertEquals(gl_count[0][0], 16) webnotes.defaults.set_global_default("auto_inventory_accounting", 0) webnotes.conn.set_default("company", old_default_company)
def test_duplication(self): ts = webnotes.bean(webnotes.copy_doclist(test_records[0])) self.assertRaises(OverlapError, ts.insert)