test case fixed
This commit is contained in:
parent
d9117cb726
commit
832988e2fd
@ -58,15 +58,15 @@ def validate_expense_against_budget(args):
|
||||
b.action_if_annual_budget_exceeded, b.action_if_accumulated_monthly_budget_exceeded
|
||||
from `tabBudget` b, `tabBudget Account` ba
|
||||
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)
|
||||
""", (args.fiscal_year, args.account, cc_lft, cc_rgt), as_dict=True)
|
||||
|
||||
|
||||
for budget in budget_records:
|
||||
if budget.budget_amount:
|
||||
yearly_action = budget.action_if_annual_budget_exceeded
|
||||
monthly_action = budget.action_if_accumulated_monthly_budget_exceeded
|
||||
|
||||
|
||||
if monthly_action in ["Stop", "Warn"]:
|
||||
budget_amount = get_accumulated_monthly_budget(budget.monthly_distribution,
|
||||
args.posting_date, args.fiscal_year, budget.budget_amount)
|
||||
|
@ -10,44 +10,50 @@ from erpnext.accounts.doctype.journal_entry.test_journal_entry import make_journ
|
||||
|
||||
class TestBudget(unittest.TestCase):
|
||||
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")
|
||||
|
||||
budget = make_budget()
|
||||
|
||||
jv = make_journal_entry("_Test Account Cost for Goods Sold - _TC",
|
||||
"_Test Bank - _TC", 40000, "_Test Cost Center - _TC", submit=True)
|
||||
|
||||
self.assertTrue(frappe.db.get_value("GL Entry",
|
||||
{"voucher_type": "Journal Entry", "voucher_no": jv.name}))
|
||||
|
||||
budget.cancel()
|
||||
|
||||
def test_monthly_budget_crossed_stop(self):
|
||||
budget = make_budget()
|
||||
frappe.db.set_value("Budget", budget, "action_if_accumulated_monthly_budget_exceeded", "Stop")
|
||||
|
||||
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",
|
||||
"_Test Bank - _TC", 40000, "_Test Cost Center - _TC")
|
||||
|
||||
self.assertRaises(BudgetError, jv.submit)
|
||||
|
||||
budget.load_from_db()
|
||||
budget.cancel()
|
||||
|
||||
def test_yearly_budget_crossed_stop(self):
|
||||
self.test_monthly_budget_crossed_ignore()
|
||||
|
||||
set_total_expense_zero("2013-02-28")
|
||||
|
||||
budget = make_budget()
|
||||
|
||||
jv = make_journal_entry("_Test Account Cost for Goods Sold - _TC",
|
||||
"_Test Bank - _TC", 150000, "_Test Cost Center - _TC")
|
||||
|
||||
self.assertRaises(BudgetError, jv.submit)
|
||||
|
||||
budget.cancel()
|
||||
|
||||
def test_monthly_budget_on_cancellation(self):
|
||||
budget = make_budget()
|
||||
frappe.db.set_value("Budget", budget, "action_if_accumulated_monthly_budget_exceeded", "Ignore")
|
||||
|
||||
set_total_expense_zero("2013-02-28")
|
||||
|
||||
budget = make_budget()
|
||||
|
||||
jv1 = make_journal_entry("_Test Account Cost for Goods Sold - _TC",
|
||||
"_Test Bank - _TC", 20000, "_Test Cost Center - _TC", submit=True)
|
||||
|
||||
@ -60,21 +66,27 @@ class TestBudget(unittest.TestCase):
|
||||
self.assertTrue(frappe.db.get_value("GL Entry",
|
||||
{"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)
|
||||
|
||||
budget.load_from_db()
|
||||
budget.cancel()
|
||||
|
||||
def test_monthly_budget_against_group_cost_center(self):
|
||||
budget = make_budget("_Test Company - _TC")
|
||||
frappe.db.set_value("Budget", budget, "action_if_accumulated_monthly_budget_exceeded", "Stop")
|
||||
|
||||
set_total_expense_zero("2013-02-28")
|
||||
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",
|
||||
"_Test Bank - _TC", 40000, "_Test Cost Center 2 - _TC")
|
||||
|
||||
self.assertRaises(BudgetError, jv.submit)
|
||||
|
||||
budget.load_from_db()
|
||||
budget.cancel()
|
||||
|
||||
def set_total_expense_zero(posting_date, cost_center=None):
|
||||
existing_expense = get_actual_expense({
|
||||
@ -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)
|
||||
|
||||
def make_budget(cost_center=None):
|
||||
existing_budget = frappe.db.get_value("Budget",
|
||||
{"cost_center": cost_center or "_Test Cost Center - _TC",
|
||||
"fiscal_year": "_Test Fiscal Year 2013", "company": "_Test Company"})
|
||||
budget = frappe.new_doc("Budget")
|
||||
budget.cost_center = cost_center or "_Test Cost Center - _TC"
|
||||
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"
|
||||
|
||||
budget.append("accounts", {
|
||||
"account": "_Test Account Cost for Goods Sold - _TC",
|
||||
"budget_amount": 100000
|
||||
})
|
||||
|
||||
budget.insert()
|
||||
budget.submit()
|
||||
|
||||
if not existing_budget:
|
||||
budget = frappe.new_doc("Budget")
|
||||
budget.cost_center = cost_center or "_Test Cost Center - _TC"
|
||||
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", {
|
||||
"account": "_Test Account Cost for Goods Sold - _TC",
|
||||
"budget_amount": 100000
|
||||
})
|
||||
|
||||
budget.insert()
|
||||
budget.submit()
|
||||
|
||||
return budget.name
|
||||
else:
|
||||
return existing_budget
|
||||
return budget
|
@ -70,7 +70,8 @@ def make_stock_entry(**args):
|
||||
"basic_rate": args.rate or args.basic_rate,
|
||||
"conversion_factor": 1.0,
|
||||
"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:
|
||||
|
@ -122,8 +122,8 @@ class TestStockEntry(unittest.TestCase):
|
||||
set_perpetual_inventory()
|
||||
|
||||
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",
|
||||
"warehouse": mr.get("items")[0].t_warehouse})
|
||||
|
||||
@ -149,9 +149,10 @@ class TestStockEntry(unittest.TestCase):
|
||||
set_perpetual_inventory()
|
||||
|
||||
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,
|
||||
[["_Test Item", "_Test Warehouse - _TC", -40.0]])
|
||||
|
Loading…
x
Reference in New Issue
Block a user