From 2f0dbd9bd898006be30a7c3f93a993c18f4837f6 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Wed, 20 Jul 2016 15:04:44 +0530 Subject: [PATCH] [fix] test --- .../purchase_invoice/test_purchase_invoice.py | 67 ++++++++++--------- 1 file changed, 34 insertions(+), 33 deletions(-) diff --git a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py index bb489e71bc..4ea18aceb8 100644 --- a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py @@ -50,9 +50,9 @@ class TestPurchaseInvoice(unittest.TestCase): pi = frappe.copy_doc(test_records[1]) pi.insert() pi.submit() - + self.check_gle_for_pi(pi.name) - + set_perpetual_inventory(0) def test_gl_entries_with_auto_accounting_for_stock_against_pr(self): @@ -316,59 +316,59 @@ class TestPurchaseInvoice(unittest.TestCase): where voucher_type='Sales Invoice' and voucher_no=%s""", pi.name) self.assertFalse(gle) - + def test_purchase_invoice_update_stock_gl_entry_with_perpetual_inventory(self): set_perpetual_inventory() - - pi = make_purchase_invoice(update_stock=1, posting_date=frappe.utils.nowdate(), + + pi = make_purchase_invoice(update_stock=1, posting_date=frappe.utils.nowdate(), posting_time=frappe.utils.nowtime()) - + 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_gl_entries = dict((d[0], d) for d in [ [pi.credit_to, 0.0, 250.0], [pi.items[0].warehouse, 250.0, 0.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) - + 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(), + 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 + 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) - + def test_update_stock_and_purchase_return(self): actual_qty_0 = get_qty_after_transaction() - + pi = make_purchase_invoice(update_stock=1, posting_date=frappe.utils.nowdate(), posting_time=frappe.utils.nowtime()) - + actual_qty_1 = get_qty_after_transaction() self.assertEquals(actual_qty_0 + 5, actual_qty_1) @@ -377,37 +377,38 @@ class TestPurchaseInvoice(unittest.TestCase): actual_qty_2 = get_qty_after_transaction() self.assertEquals(actual_qty_1 - 2, actual_qty_2) - + pi1.cancel() self.assertEquals(actual_qty_1, get_qty_after_transaction()) - + + pi.reload() pi.cancel() self.assertEquals(actual_qty_0, get_qty_after_transaction()) - + def test_subcontracting_via_purchase_invoice(self): from erpnext.stock.doctype.stock_entry.test_stock_entry import make_stock_entry - + make_stock_entry(item_code="_Test Item", target="_Test Warehouse 1 - _TC", qty=100, basic_rate=100) - make_stock_entry(item_code="_Test Item Home Desktop 100", target="_Test Warehouse 1 - _TC", + make_stock_entry(item_code="_Test Item Home Desktop 100", target="_Test Warehouse 1 - _TC", qty=100, basic_rate=100) - - pi = make_purchase_invoice(item_code="_Test FG Item", qty=10, rate=500, + + pi = make_purchase_invoice(item_code="_Test FG Item", qty=10, rate=500, update_stock=1, is_subcontracted="Yes") - + self.assertEquals(len(pi.get("supplied_items")), 2) - + rm_supp_cost = sum([d.amount for d in pi.get("supplied_items")]) self.assertEquals(pi.get("items")[0].rm_supp_cost, flt(rm_supp_cost, 2)) - + def test_rejected_serial_no(self): pi = make_purchase_invoice(item_code="_Test Serialized Item With Series", received_qty=2, qty=1, rejected_qty=1, rate=500, update_stock=1, rejected_warehouse = "_Test Rejected Warehouse - _TC") - + self.assertEquals(frappe.db.get_value("Serial No", pi.get("items")[0].serial_no, "warehouse"), pi.get("items")[0].warehouse) - - self.assertEquals(frappe.db.get_value("Serial No", pi.get("items")[0].rejected_serial_no, + + self.assertEquals(frappe.db.get_value("Serial No", pi.get("items")[0].rejected_serial_no, "warehouse"), pi.get("items")[0].rejected_warehouse) def make_purchase_invoice(**args): @@ -420,10 +421,10 @@ def make_purchase_invoice(**args): pi.update_stock = 1 if args.is_paid: pi.is_paid = 1 - + if args.cash_bank_account: pi.cash_bank_account=args.cash_bank_account - + pi.company = args.company or "_Test Company" pi.supplier = args.supplier or "_Test Supplier" pi.currency = args.currency or "INR"