Test Cases - Journal Voucher, Purchase Invoice, Period Closing Voucher frappe/frappe#478
This commit is contained in:
		
							parent
							
								
									2ce39cf770
								
							
						
					
					
						commit
						cd71e1d8ab
					
				| @ -9,10 +9,14 @@ import frappe | |||||||
| class TestJournalVoucher(unittest.TestCase): | class TestJournalVoucher(unittest.TestCase): | ||||||
| 	def test_journal_voucher_with_against_jv(self): | 	def test_journal_voucher_with_against_jv(self): | ||||||
| 		self.clear_account_balance() | 		self.clear_account_balance() | ||||||
| 		jv_invoice = frappe.copy_doc(test_records[1]) | 		jv_invoice = frappe.copy_doc(test_records[2]) | ||||||
| 		jv_invoice.insert() | 		jv_invoice.insert() | ||||||
| 		jv_invoice.submit() | 		jv_invoice.submit() | ||||||
| 
 | 
 | ||||||
|  | 		self.assertTrue(frappe.db.sql("""select name from `tabJournal Voucher Detail` | ||||||
|  | 			where account = %s and docstatus = 1 and parent = %s""", | ||||||
|  | 			("_Test Customer - _TC", jv_invoice.name))) | ||||||
|  | 
 | ||||||
| 		self.assertTrue(not frappe.db.sql("""select name from `tabJournal Voucher Detail` | 		self.assertTrue(not frappe.db.sql("""select name from `tabJournal Voucher Detail` | ||||||
| 			where against_jv=%s""", jv_invoice.name)) | 			where against_jv=%s""", jv_invoice.name)) | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -5,25 +5,25 @@ | |||||||
| from __future__ import unicode_literals | from __future__ import unicode_literals | ||||||
| import unittest | import unittest | ||||||
| import frappe | import frappe | ||||||
|  | from erpnext.accounts.doctype.journal_voucher.test_journal_voucher import test_records as jv_records | ||||||
| 
 | 
 | ||||||
| class TestPeriodClosingVoucher(unittest.TestCase): | class TestPeriodClosingVoucher(unittest.TestCase): | ||||||
| 	def test_closing_entry(self): | 	def test_closing_entry(self): | ||||||
| 		# clear GL Entries | 		# clear GL Entries | ||||||
| 		frappe.db.sql("""delete from `tabGL Entry`""") | 		frappe.db.sql("""delete from `tabGL Entry`""") | ||||||
| 		 |  | ||||||
| 		from erpnext.accounts.doctype.journal_voucher.test_journal_voucher import test_records as jv_records |  | ||||||
| 		jv = frappe.copy_doc(jv_records[2]) | 		jv = frappe.copy_doc(jv_records[2]) | ||||||
| 		jv.insert() | 		jv.insert() | ||||||
| 		jv.submit() | 		jv.submit() | ||||||
| 
 | 
 | ||||||
| 		jv1 = frappe.copy_doc(jv_records[0]) | 		jv1 = frappe.copy_doc(jv_records[0]) | ||||||
| 		jv1.get("entries")[1].account = "_Test Account Cost for Goods Sold - _TC" | 		jv1.get("entries")[1].account = "_Test Account Cost for Goods Sold - _TC" | ||||||
|  | 		jv1.get("entries")[1].cost_center = "_Test Cost Center - _TC" | ||||||
| 		jv1.get("entries")[1].debit = 600.0 | 		jv1.get("entries")[1].debit = 600.0 | ||||||
| 		jv1.get("entries")[0].credit = 600.0 | 		jv1.get("entries")[0].credit = 600.0 | ||||||
| 		jv1.insert() | 		jv1.insert() | ||||||
| 		jv1.submit() | 		jv1.submit() | ||||||
| 
 | 
 | ||||||
| 		pcv = frappe.copy_doc(test_record) | 		pcv = frappe.copy_doc(test_records[0]) | ||||||
| 		pcv.insert() | 		pcv.insert() | ||||||
| 		pcv.submit() | 		pcv.submit() | ||||||
| 
 | 
 | ||||||
| @ -45,12 +45,4 @@ class TestPeriodClosingVoucher(unittest.TestCase): | |||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| test_dependencies = ["Customer", "Cost Center"] | test_dependencies = ["Customer", "Cost Center"] | ||||||
| 	 | test_records = frappe.get_test_records("Period Closing Voucher") | ||||||
| test_record = [{ |  | ||||||
| 	"doctype": "Period Closing Voucher",  |  | ||||||
| 	"closing_account_head": "_Test Account Reserves and Surplus - _TC", |  | ||||||
| 	"company": "_Test Company",  |  | ||||||
| 	"fiscal_year": "_Test Fiscal Year 2013",  |  | ||||||
| 	"posting_date": "2013-03-31",  |  | ||||||
| 	"remarks": "test" |  | ||||||
| }] |  | ||||||
|  | |||||||
| @ -0,0 +1,8 @@ | |||||||
|  | [{ | ||||||
|  | 	"doctype": "Period Closing Voucher", | ||||||
|  | 	"closing_account_head": "_Test Account Reserves and Surplus - _TC", | ||||||
|  | 	"company": "_Test Company", | ||||||
|  | 	"fiscal_year": "_Test Fiscal Year 2013", | ||||||
|  | 	"posting_date": "2013-03-31", | ||||||
|  | 	"remarks": "test" | ||||||
|  | }] | ||||||
| @ -11,15 +11,15 @@ class TestPricingRule(unittest.TestCase): | |||||||
| 		from erpnext.stock.get_item_details import get_item_details | 		from erpnext.stock.get_item_details import get_item_details | ||||||
| 		from frappe import MandatoryError | 		from frappe import MandatoryError | ||||||
| 
 | 
 | ||||||
| 		test_record = [{ | 		test_record = { | ||||||
| 			"doctype": "Pricing Rule", | 			"doctype": "Pricing Rule", | ||||||
| 			"apply_on": "Item Code", | 			"apply_on": "Item Code", | ||||||
| 			"item_code": "_Test Item", | 			"item_code": "_Test Item", | ||||||
| 			"price_or_discount": "Discount Percentage", | 			"price_or_discount": "Discount Percentage", | ||||||
| 			"price": 0, | 			"price": 0, | ||||||
| 			"discount_percentage": 10, | 			"discount_percentage": 10, | ||||||
| 		}] | 		} | ||||||
| 		frappe.copy_doc(test_record).insert() | 		frappe.get_doc(test_record.copy()).insert() | ||||||
| 
 | 
 | ||||||
| 		args = frappe._dict({ | 		args = frappe._dict({ | ||||||
| 			"item_code": "_Test Item", | 			"item_code": "_Test Item", | ||||||
| @ -38,7 +38,7 @@ class TestPricingRule(unittest.TestCase): | |||||||
| 		details = get_item_details(args) | 		details = get_item_details(args) | ||||||
| 		self.assertEquals(details.get("discount_percentage"), 10) | 		self.assertEquals(details.get("discount_percentage"), 10) | ||||||
| 
 | 
 | ||||||
| 		prule = frappe.copy_doc(test_record) | 		prule = frappe.get_doc(test_record.copy()) | ||||||
| 		prule.applicable_for = "Customer" | 		prule.applicable_for = "Customer" | ||||||
| 		self.assertRaises(MandatoryError, prule.insert) | 		self.assertRaises(MandatoryError, prule.insert) | ||||||
| 		prule.customer = "_Test Customer" | 		prule.customer = "_Test Customer" | ||||||
| @ -47,7 +47,7 @@ class TestPricingRule(unittest.TestCase): | |||||||
| 		details = get_item_details(args) | 		details = get_item_details(args) | ||||||
| 		self.assertEquals(details.get("discount_percentage"), 20) | 		self.assertEquals(details.get("discount_percentage"), 20) | ||||||
| 
 | 
 | ||||||
| 		prule = frappe.copy_doc(test_record) | 		prule = frappe.get_doc(test_record.copy()) | ||||||
| 		prule.apply_on = "Item Group" | 		prule.apply_on = "Item Group" | ||||||
| 		prule.item_group = "All Item Groups" | 		prule.item_group = "All Item Groups" | ||||||
| 		prule.discount_percentage = 15 | 		prule.discount_percentage = 15 | ||||||
| @ -57,7 +57,7 @@ class TestPricingRule(unittest.TestCase): | |||||||
| 		details = get_item_details(args) | 		details = get_item_details(args) | ||||||
| 		self.assertEquals(details.get("discount_percentage"), 10) | 		self.assertEquals(details.get("discount_percentage"), 10) | ||||||
| 
 | 
 | ||||||
| 		prule = frappe.copy_doc(test_record) | 		prule = frappe.get_doc(test_record.copy()) | ||||||
| 		prule.applicable_for = "Campaign" | 		prule.applicable_for = "Campaign" | ||||||
| 		prule.campaign = "_Test Campaign" | 		prule.campaign = "_Test Campaign" | ||||||
| 		prule.discount_percentage = 5 | 		prule.discount_percentage = 5 | ||||||
|  | |||||||
| @ -76,8 +76,8 @@ class TestPurchaseInvoice(unittest.TestCase): | |||||||
| 		pi = frappe.copy_doc(test_records[1]) | 		pi = frappe.copy_doc(test_records[1]) | ||||||
| 		pi.get("entries")[0].item_code = "_Test Non Stock Item" | 		pi.get("entries")[0].item_code = "_Test Non Stock Item" | ||||||
| 		pi.get("entries")[0].expense_account = "_Test Account Cost for Goods Sold - _TC" | 		pi.get("entries")[0].expense_account = "_Test Account Cost for Goods Sold - _TC" | ||||||
| 		pi.get("entries").pop(2) | 		pi.get("other_charges").pop(0) | ||||||
| 		pi.get("entries").pop(1) | 		pi.get("other_charges").pop(1) | ||||||
| 		pi.insert() | 		pi.insert() | ||||||
| 		pi.submit() | 		pi.submit() | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -139,6 +139,7 @@ def reconcile_against_document(args): | |||||||
| 
 | 
 | ||||||
| 		# cancel JV | 		# cancel JV | ||||||
| 		jv_obj = frappe.get_doc('Journal Voucher', d['voucher_no']) | 		jv_obj = frappe.get_doc('Journal Voucher', d['voucher_no']) | ||||||
|  | 
 | ||||||
| 		jv_obj.make_gl_entries(cancel=1, adv_adj=1) | 		jv_obj.make_gl_entries(cancel=1, adv_adj=1) | ||||||
| 
 | 
 | ||||||
| 		# update ref in JV Detail | 		# update ref in JV Detail | ||||||
| @ -170,12 +171,9 @@ def update_against_doc(d, jv_obj): | |||||||
| 	""" | 	""" | ||||||
| 		Updates against document, if partial amount splits into rows | 		Updates against document, if partial amount splits into rows | ||||||
| 	""" | 	""" | ||||||
| 
 | 	jv_detail = jv_obj.get("entries", {"name": d["voucher_detail_no"]})[0] | ||||||
| 	frappe.db.sql(""" | 	jv_detail.set(d["dr_or_cr"], d["allocated_amt"]) | ||||||
| 		update `tabJournal Voucher Detail` t1, `tabJournal Voucher` t2	 | 	jv_detail.set(d["against_fld"], d["against_voucher"]) | ||||||
| 		set t1.%(dr_or_cr)s = '%(allocated_amt)s',  |  | ||||||
| 		t1.%(against_fld)s = '%(against_voucher)s', t2.modified = now()  |  | ||||||
| 		where t1.name = '%(voucher_detail_no)s' and t1.parent = t2.name""" % d) |  | ||||||
| 
 | 
 | ||||||
| 	if d['allocated_amt'] < d['unadjusted_amt']: | 	if d['allocated_amt'] < d['unadjusted_amt']: | ||||||
| 		jvd = frappe.db.sql("""select cost_center, balance, against_account, is_advance | 		jvd = frappe.db.sql("""select cost_center, balance, against_account, is_advance | ||||||
| @ -190,7 +188,10 @@ def update_against_doc(d, jv_obj): | |||||||
| 		ch.against_account = cstr(jvd[0][2]) | 		ch.against_account = cstr(jvd[0][2]) | ||||||
| 		ch.is_advance = cstr(jvd[0][3]) | 		ch.is_advance = cstr(jvd[0][3]) | ||||||
| 		ch.docstatus = 1 | 		ch.docstatus = 1 | ||||||
| 		ch.save(1) | 
 | ||||||
|  | 	# will work as update after submit | ||||||
|  | 	jv_obj.ignore_validate_update_after_submit = True | ||||||
|  | 	jv_obj.save() | ||||||
| 
 | 
 | ||||||
| def get_account_list(doctype, txt, searchfield, start, page_len, filters): | def get_account_list(doctype, txt, searchfield, start, page_len, filters): | ||||||
| 	if not filters.get("group_or_ledger"): | 	if not filters.get("group_or_ledger"): | ||||||
|  | |||||||
| @ -10,7 +10,6 @@ test_records = frappe.get_test_records('Lead') | |||||||
| 
 | 
 | ||||||
| class TestLead(unittest.TestCase): | class TestLead(unittest.TestCase): | ||||||
| 	def test_make_customer(self): | 	def test_make_customer(self): | ||||||
| 		print "test_make_customer" |  | ||||||
| 		from erpnext.selling.doctype.lead.lead import make_customer | 		from erpnext.selling.doctype.lead.lead import make_customer | ||||||
| 
 | 
 | ||||||
| 		customer = make_customer("_T-Lead-00001") | 		customer = make_customer("_T-Lead-00001") | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user