mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-04 12:49:10 +00:00
[cleanup] [minor] budget code cleaned up with testcases
This commit is contained in:
@@ -6,6 +6,21 @@ test_records = [
|
||||
"doctype": "Budget Distribution",
|
||||
"distribution_id": "_Test Distribution",
|
||||
"fiscal_year": "_Test Fiscal Year 2013",
|
||||
}, {
|
||||
"doctype": "Budget Distribution Detail",
|
||||
"parentfield": "budget_distribution_details",
|
||||
"month": "January",
|
||||
"percentage_allocation": "8"
|
||||
}, {
|
||||
"doctype": "Budget Distribution Detail",
|
||||
"parentfield": "budget_distribution_details",
|
||||
"month": "February",
|
||||
"percentage_allocation": "8"
|
||||
}, {
|
||||
"doctype": "Budget Distribution Detail",
|
||||
"parentfield": "budget_distribution_details",
|
||||
"month": "March",
|
||||
"percentage_allocation": "8"
|
||||
}, {
|
||||
"doctype": "Budget Distribution Detail",
|
||||
"parentfield": "budget_distribution_details",
|
||||
@@ -45,26 +60,11 @@ test_records = [
|
||||
"doctype": "Budget Distribution Detail",
|
||||
"parentfield": "budget_distribution_details",
|
||||
"month": "November",
|
||||
"percentage_allocation": "8"
|
||||
"percentage_allocation": "10"
|
||||
}, {
|
||||
"doctype": "Budget Distribution Detail",
|
||||
"parentfield": "budget_distribution_details",
|
||||
"month": "December",
|
||||
"percentage_allocation": "8"
|
||||
}, {
|
||||
"doctype": "Budget Distribution Detail",
|
||||
"parentfield": "budget_distribution_details",
|
||||
"month": "January",
|
||||
"percentage_allocation": "8"
|
||||
}, {
|
||||
"doctype": "Budget Distribution Detail",
|
||||
"parentfield": "budget_distribution_details",
|
||||
"month": "February",
|
||||
"percentage_allocation": "10"
|
||||
}, {
|
||||
"doctype": "Budget Distribution Detail",
|
||||
"parentfield": "budget_distribution_details",
|
||||
"month": "March",
|
||||
"percentage_allocation": "10"
|
||||
}]
|
||||
]
|
||||
@@ -8,6 +8,7 @@ import webnotes
|
||||
|
||||
class TestJournalVoucher(unittest.TestCase):
|
||||
def test_journal_voucher_with_against_jv(self):
|
||||
self.clear_account_balance()
|
||||
jv_invoice = webnotes.bean(copy=test_records[2])
|
||||
jv_invoice.insert()
|
||||
jv_invoice.submit()
|
||||
@@ -32,20 +33,87 @@ class TestJournalVoucher(unittest.TestCase):
|
||||
self.assertTrue(not webnotes.conn.sql("""select name from `tabJournal Voucher Detail`
|
||||
where against_jv=%s""", jv_invoice.doc.name))
|
||||
|
||||
def test_budget(self):
|
||||
def test_monthly_budget_crossed_ignore(self):
|
||||
webnotes.conn.set_value("Company", "_Test Company", "monthly_bgt_flag", "Ignore")
|
||||
self.clear_account_balance()
|
||||
|
||||
jv = webnotes.bean(copy=test_records[0])
|
||||
jv.doclist[2].account = "_Test Account Cost for Goods Sold - _TC"
|
||||
jv.doclist[2].cost_center = "_Test Cost Center - _TC"
|
||||
jv.doclist[2].debit = 20000.0
|
||||
jv.doclist[1].credit = 20000.0
|
||||
jv.insert()
|
||||
jv.submit()
|
||||
self.assertTrue(webnotes.conn.get_value("GL Entry",
|
||||
{"voucher_type": "Journal Voucher", "voucher_no": jv.doc.name}))
|
||||
|
||||
def test_monthly_budget_crossed_stop(self):
|
||||
from accounts.utils import BudgetError
|
||||
webnotes.conn.set_value("Company", "_Test Company", "monthly_bgt_flag", "Stop")
|
||||
self.clear_account_balance()
|
||||
|
||||
jv = webnotes.bean(copy=test_records[0])
|
||||
jv.doclist[2].account = "_Test Account Cost for Goods Sold - _TC"
|
||||
jv.doclist[2].cost_center = "_Test Cost Center - _TC"
|
||||
jv.doclist[2].debit = 20000.0
|
||||
jv.doclist[1].credit = 20000.0
|
||||
jv.insert()
|
||||
|
||||
self.assertRaises(BudgetError, jv.submit)
|
||||
|
||||
webnotes.conn.set_value("Company", "_Test Company", "monthly_bgt_flag", "Ignore")
|
||||
|
||||
def test_yearly_budget_crossed_stop(self):
|
||||
from accounts.utils import BudgetError
|
||||
self.clear_account_balance()
|
||||
self.test_monthly_budget_crossed_ignore()
|
||||
|
||||
webnotes.conn.set_value("Company", "_Test Company", "yearly_bgt_flag", "Stop")
|
||||
|
||||
jv = webnotes.bean(copy=test_records[0])
|
||||
jv.doc.posting_date = "2013-08-12"
|
||||
jv.doclist[2].account = "_Test Account Cost for Goods Sold - _TC"
|
||||
jv.doclist[2].cost_center = "_Test Cost Center - _TC"
|
||||
jv.doclist[2].debit = 150000.0
|
||||
jv.doclist[1].credit = 150000.0
|
||||
jv.insert()
|
||||
|
||||
self.assertRaises(BudgetError, jv.submit)
|
||||
|
||||
webnotes.conn.set_value("Company", "_Test Company", "yearly_bgt_flag", "Ignore")
|
||||
|
||||
def test_monthly_budget_on_cancellation(self):
|
||||
from accounts.utils import BudgetError
|
||||
webnotes.conn.set_value("Company", "_Test Company", "monthly_bgt_flag", "Stop")
|
||||
self.clear_account_balance()
|
||||
|
||||
jv = webnotes.bean(copy=test_records[0])
|
||||
jv.doclist[1].account = "_Test Account Cost for Goods Sold - _TC"
|
||||
jv.doclist[1].cost_center = "_Test Cost Center - _TC"
|
||||
jv.doclist[1].credit = 30000.0
|
||||
jv.doclist[2].debit = 30000.0
|
||||
jv.submit()
|
||||
|
||||
self.assertTrue(webnotes.conn.get_value("GL Entry",
|
||||
{"voucher_type": "Journal Voucher", "voucher_no": jv.doc.name}))
|
||||
|
||||
jv1 = webnotes.bean(copy=test_records[0])
|
||||
jv1.doc.posting_date = "2013-02-12"
|
||||
jv1.doclist[2].account = "_Test Account Cost for Goods Sold - _TC"
|
||||
jv1.doclist[2].cost_center = "_Test Cost Center - _TC"
|
||||
jv1.doclist[2].debit = 20000.0
|
||||
jv1.doclist[1].credit = 20000.0
|
||||
jv1.insert()
|
||||
jv1.doclist[2].debit = 40000.0
|
||||
jv1.doclist[1].credit = 40000.0
|
||||
jv1.submit()
|
||||
|
||||
self.assertTrue(webnotes.conn.get_value("GL Entry",
|
||||
{"voucher_type": "Journal Voucher", "voucher_no": jv1.doc.name}))
|
||||
|
||||
self.assertRaises(BudgetError, jv.cancel)
|
||||
|
||||
webnotes.conn.set_value("Company", "_Test Company", "monthly_bgt_flag", "Ignore")
|
||||
|
||||
def clear_account_balance(self):
|
||||
webnotes.conn.sql("""delete from `tabGL Entry`""")
|
||||
|
||||
self.assertRaises(BudgetError, jv1.submit)
|
||||
|
||||
|
||||
test_records = [
|
||||
[{
|
||||
|
||||
Reference in New Issue
Block a user