test case fixed
This commit is contained in:
parent
d9117cb726
commit
832988e2fd
@ -58,7 +58,7 @@ def validate_expense_against_budget(args):
|
|||||||
b.action_if_annual_budget_exceeded, b.action_if_accumulated_monthly_budget_exceeded
|
b.action_if_annual_budget_exceeded, b.action_if_accumulated_monthly_budget_exceeded
|
||||||
from `tabBudget` b, `tabBudget Account` ba
|
from `tabBudget` b, `tabBudget Account` ba
|
||||||
where
|
where
|
||||||
b.name=ba.parent and b.fiscal_year=%s and ba.account=%s
|
b.name=ba.parent and b.fiscal_year=%s and ba.account=%s and b.docstatus=1
|
||||||
and exists(select name from `tabCost Center` where lft<=%s and rgt>=%s and name=b.cost_center)
|
and exists(select name from `tabCost Center` where lft<=%s and rgt>=%s and name=b.cost_center)
|
||||||
""", (args.fiscal_year, args.account, cc_lft, cc_rgt), as_dict=True)
|
""", (args.fiscal_year, args.account, cc_lft, cc_rgt), as_dict=True)
|
||||||
|
|
||||||
|
@ -10,44 +10,50 @@ from erpnext.accounts.doctype.journal_entry.test_journal_entry import make_journ
|
|||||||
|
|
||||||
class TestBudget(unittest.TestCase):
|
class TestBudget(unittest.TestCase):
|
||||||
def test_monthly_budget_crossed_ignore(self):
|
def test_monthly_budget_crossed_ignore(self):
|
||||||
budget = make_budget()
|
|
||||||
frappe.db.set_value("Budget", budget, "action_if_accumulated_monthly_budget_exceeded", "Ignore")
|
|
||||||
|
|
||||||
set_total_expense_zero("2013-02-28")
|
set_total_expense_zero("2013-02-28")
|
||||||
|
|
||||||
|
budget = make_budget()
|
||||||
|
|
||||||
jv = make_journal_entry("_Test Account Cost for Goods Sold - _TC",
|
jv = make_journal_entry("_Test Account Cost for Goods Sold - _TC",
|
||||||
"_Test Bank - _TC", 40000, "_Test Cost Center - _TC", submit=True)
|
"_Test Bank - _TC", 40000, "_Test Cost Center - _TC", submit=True)
|
||||||
|
|
||||||
self.assertTrue(frappe.db.get_value("GL Entry",
|
self.assertTrue(frappe.db.get_value("GL Entry",
|
||||||
{"voucher_type": "Journal Entry", "voucher_no": jv.name}))
|
{"voucher_type": "Journal Entry", "voucher_no": jv.name}))
|
||||||
|
|
||||||
def test_monthly_budget_crossed_stop(self):
|
budget.cancel()
|
||||||
budget = make_budget()
|
|
||||||
frappe.db.set_value("Budget", budget, "action_if_accumulated_monthly_budget_exceeded", "Stop")
|
|
||||||
|
|
||||||
|
def test_monthly_budget_crossed_stop(self):
|
||||||
set_total_expense_zero("2013-02-28")
|
set_total_expense_zero("2013-02-28")
|
||||||
|
|
||||||
|
budget = make_budget()
|
||||||
|
|
||||||
|
frappe.db.set_value("Budget", budget.name, "action_if_accumulated_monthly_budget_exceeded", "Stop")
|
||||||
|
|
||||||
jv = make_journal_entry("_Test Account Cost for Goods Sold - _TC",
|
jv = make_journal_entry("_Test Account Cost for Goods Sold - _TC",
|
||||||
"_Test Bank - _TC", 40000, "_Test Cost Center - _TC")
|
"_Test Bank - _TC", 40000, "_Test Cost Center - _TC")
|
||||||
|
|
||||||
self.assertRaises(BudgetError, jv.submit)
|
self.assertRaises(BudgetError, jv.submit)
|
||||||
|
|
||||||
def test_yearly_budget_crossed_stop(self):
|
budget.load_from_db()
|
||||||
self.test_monthly_budget_crossed_ignore()
|
budget.cancel()
|
||||||
|
|
||||||
|
def test_yearly_budget_crossed_stop(self):
|
||||||
set_total_expense_zero("2013-02-28")
|
set_total_expense_zero("2013-02-28")
|
||||||
|
|
||||||
|
budget = make_budget()
|
||||||
|
|
||||||
jv = make_journal_entry("_Test Account Cost for Goods Sold - _TC",
|
jv = make_journal_entry("_Test Account Cost for Goods Sold - _TC",
|
||||||
"_Test Bank - _TC", 150000, "_Test Cost Center - _TC")
|
"_Test Bank - _TC", 150000, "_Test Cost Center - _TC")
|
||||||
|
|
||||||
self.assertRaises(BudgetError, jv.submit)
|
self.assertRaises(BudgetError, jv.submit)
|
||||||
|
|
||||||
def test_monthly_budget_on_cancellation(self):
|
budget.cancel()
|
||||||
budget = make_budget()
|
|
||||||
frappe.db.set_value("Budget", budget, "action_if_accumulated_monthly_budget_exceeded", "Ignore")
|
|
||||||
|
|
||||||
|
def test_monthly_budget_on_cancellation(self):
|
||||||
set_total_expense_zero("2013-02-28")
|
set_total_expense_zero("2013-02-28")
|
||||||
|
|
||||||
|
budget = make_budget()
|
||||||
|
|
||||||
jv1 = make_journal_entry("_Test Account Cost for Goods Sold - _TC",
|
jv1 = make_journal_entry("_Test Account Cost for Goods Sold - _TC",
|
||||||
"_Test Bank - _TC", 20000, "_Test Cost Center - _TC", submit=True)
|
"_Test Bank - _TC", 20000, "_Test Cost Center - _TC", submit=True)
|
||||||
|
|
||||||
@ -60,22 +66,28 @@ class TestBudget(unittest.TestCase):
|
|||||||
self.assertTrue(frappe.db.get_value("GL Entry",
|
self.assertTrue(frappe.db.get_value("GL Entry",
|
||||||
{"voucher_type": "Journal Entry", "voucher_no": jv2.name}))
|
{"voucher_type": "Journal Entry", "voucher_no": jv2.name}))
|
||||||
|
|
||||||
frappe.db.set_value("Budget", budget, "action_if_accumulated_monthly_budget_exceeded", "Stop")
|
frappe.db.set_value("Budget", budget.name, "action_if_accumulated_monthly_budget_exceeded", "Stop")
|
||||||
|
|
||||||
self.assertRaises(BudgetError, jv1.cancel)
|
self.assertRaises(BudgetError, jv1.cancel)
|
||||||
|
|
||||||
def test_monthly_budget_against_group_cost_center(self):
|
budget.load_from_db()
|
||||||
budget = make_budget("_Test Company - _TC")
|
budget.cancel()
|
||||||
frappe.db.set_value("Budget", budget, "action_if_accumulated_monthly_budget_exceeded", "Stop")
|
|
||||||
|
|
||||||
|
def test_monthly_budget_against_group_cost_center(self):
|
||||||
set_total_expense_zero("2013-02-28")
|
set_total_expense_zero("2013-02-28")
|
||||||
set_total_expense_zero("2013-02-28", "_Test Cost Center 2 - _TC")
|
set_total_expense_zero("2013-02-28", "_Test Cost Center 2 - _TC")
|
||||||
|
|
||||||
|
budget = make_budget("_Test Company - _TC")
|
||||||
|
frappe.db.set_value("Budget", budget.name, "action_if_accumulated_monthly_budget_exceeded", "Stop")
|
||||||
|
|
||||||
jv = make_journal_entry("_Test Account Cost for Goods Sold - _TC",
|
jv = make_journal_entry("_Test Account Cost for Goods Sold - _TC",
|
||||||
"_Test Bank - _TC", 40000, "_Test Cost Center 2 - _TC")
|
"_Test Bank - _TC", 40000, "_Test Cost Center 2 - _TC")
|
||||||
|
|
||||||
self.assertRaises(BudgetError, jv.submit)
|
self.assertRaises(BudgetError, jv.submit)
|
||||||
|
|
||||||
|
budget.load_from_db()
|
||||||
|
budget.cancel()
|
||||||
|
|
||||||
def set_total_expense_zero(posting_date, cost_center=None):
|
def set_total_expense_zero(posting_date, cost_center=None):
|
||||||
existing_expense = get_actual_expense({
|
existing_expense = get_actual_expense({
|
||||||
"account": "_Test Account Cost for Goods Sold - _TC",
|
"account": "_Test Account Cost for Goods Sold - _TC",
|
||||||
@ -89,27 +101,20 @@ def set_total_expense_zero(posting_date, cost_center=None):
|
|||||||
"_Test Bank - _TC", -existing_expense, "_Test Cost Center - _TC", submit=True)
|
"_Test Bank - _TC", -existing_expense, "_Test Cost Center - _TC", submit=True)
|
||||||
|
|
||||||
def make_budget(cost_center=None):
|
def make_budget(cost_center=None):
|
||||||
existing_budget = frappe.db.get_value("Budget",
|
budget = frappe.new_doc("Budget")
|
||||||
{"cost_center": cost_center or "_Test Cost Center - _TC",
|
budget.cost_center = cost_center or "_Test Cost Center - _TC"
|
||||||
"fiscal_year": "_Test Fiscal Year 2013", "company": "_Test Company"})
|
budget.fiscal_year = "_Test Fiscal Year 2013"
|
||||||
|
budget.monthly_distribution = "_Test Distribution"
|
||||||
|
budget.company = "_Test Company"
|
||||||
|
budget.action_if_annual_budget_exceeded = "Stop"
|
||||||
|
budget.action_if_accumulated_monthly_budget_exceeded = "Ignore"
|
||||||
|
|
||||||
if not existing_budget:
|
budget.append("accounts", {
|
||||||
budget = frappe.new_doc("Budget")
|
"account": "_Test Account Cost for Goods Sold - _TC",
|
||||||
budget.cost_center = cost_center or "_Test Cost Center - _TC"
|
"budget_amount": 100000
|
||||||
budget.fiscal_year = "_Test Fiscal Year 2013"
|
})
|
||||||
budget.monthly_distribution = "_Test Distribution"
|
|
||||||
budget.company = "_Test Company"
|
|
||||||
budget.action_if_annual_budget_exceeded = "Stop"
|
|
||||||
budget.action_if_accumulated_monthly_budget_exceeded = "Stop"
|
|
||||||
|
|
||||||
budget.append("accounts", {
|
budget.insert()
|
||||||
"account": "_Test Account Cost for Goods Sold - _TC",
|
budget.submit()
|
||||||
"budget_amount": 100000
|
|
||||||
})
|
|
||||||
|
|
||||||
budget.insert()
|
return budget
|
||||||
budget.submit()
|
|
||||||
|
|
||||||
return budget.name
|
|
||||||
else:
|
|
||||||
return existing_budget
|
|
@ -70,7 +70,8 @@ def make_stock_entry(**args):
|
|||||||
"basic_rate": args.rate or args.basic_rate,
|
"basic_rate": args.rate or args.basic_rate,
|
||||||
"conversion_factor": 1.0,
|
"conversion_factor": 1.0,
|
||||||
"serial_no": args.serial_no,
|
"serial_no": args.serial_no,
|
||||||
'cost_center': args.cost_center
|
'cost_center': args.cost_center,
|
||||||
|
'expense_account': args.expense_account
|
||||||
})
|
})
|
||||||
|
|
||||||
if not args.do_not_save:
|
if not args.do_not_save:
|
||||||
|
@ -122,7 +122,7 @@ class TestStockEntry(unittest.TestCase):
|
|||||||
set_perpetual_inventory()
|
set_perpetual_inventory()
|
||||||
|
|
||||||
mr = make_stock_entry(item_code="_Test Item", target="_Test Warehouse - _TC",
|
mr = make_stock_entry(item_code="_Test Item", target="_Test Warehouse - _TC",
|
||||||
qty=50, basic_rate=100)
|
qty=50, basic_rate=100, expense_account="Stock Adjustment - _TC")
|
||||||
|
|
||||||
stock_in_hand_account = frappe.db.get_value("Account", {"account_type": "Warehouse",
|
stock_in_hand_account = frappe.db.get_value("Account", {"account_type": "Warehouse",
|
||||||
"warehouse": mr.get("items")[0].t_warehouse})
|
"warehouse": mr.get("items")[0].t_warehouse})
|
||||||
@ -149,9 +149,10 @@ class TestStockEntry(unittest.TestCase):
|
|||||||
set_perpetual_inventory()
|
set_perpetual_inventory()
|
||||||
|
|
||||||
make_stock_entry(item_code="_Test Item", target="_Test Warehouse - _TC",
|
make_stock_entry(item_code="_Test Item", target="_Test Warehouse - _TC",
|
||||||
qty=50, basic_rate=100)
|
qty=50, basic_rate=100, expense_account="Stock Adjustment - _TC")
|
||||||
|
|
||||||
mi = make_stock_entry(item_code="_Test Item", source="_Test Warehouse - _TC", qty=40)
|
mi = make_stock_entry(item_code="_Test Item", source="_Test Warehouse - _TC",
|
||||||
|
qty=40, expense_account="Stock Adjustment - _TC")
|
||||||
|
|
||||||
self.check_stock_ledger_entries("Stock Entry", mi.name,
|
self.check_stock_ledger_entries("Stock Entry", mi.name,
|
||||||
[["_Test Item", "_Test Warehouse - _TC", -40.0]])
|
[["_Test Item", "_Test Warehouse - _TC", -40.0]])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user