def set_total_expense_zero(posting_date, budget_against_field=None, budget_against_CC=None): if budget_against_field == "Project": budget_against = "_Test Project" else: budget_against = budget_against_CC or "_Test Cost Center - _TC" existing_expense = get_actual_expense( frappe._dict({ "account": "_Test Account Cost for Goods Sold - _TC", "cost_center": "_Test Cost Center - _TC", "monthly_end_date": posting_date, "company": "_Test Company", "fiscal_year": "_Test Fiscal Year 2013", "budget_against_field": budget_against_field, "budget_against": budget_against })) if existing_expense: if budget_against_field == "Cost Center": make_journal_entry("_Test Account Cost for Goods Sold - _TC", "_Test Bank - _TC", -existing_expense, "_Test Cost Center - _TC", posting_date="2013-02-28", submit=True) elif budget_against_field == "Project": make_journal_entry("_Test Account Cost for Goods Sold - _TC", "_Test Bank - _TC", -existing_expense, "_Test Cost Center - _TC", submit=True, project="_Test Project", posting_date="2013-02-28")
def test_rename_entries(self): je = make_journal_entry("_Test Account Cost for Goods Sold - _TC", "_Test Bank - _TC", 100, submit=True) rename_gle_sle_docs() naming_series = parse_naming_series(parts=frappe.get_meta("GL Entry").autoname.split(".")[:-1]) je = make_journal_entry("_Test Account Cost for Goods Sold - _TC", "_Test Bank - _TC", 100, submit=True) gl_entries = frappe.get_all("GL Entry", fields=["name", "to_rename"], filters={"voucher_type": "Journal Entry", "voucher_no": je.name}, order_by="creation" ) self.assertTrue(all(entry.to_rename == 1 for entry in gl_entries)) old_naming_series_current_value = frappe.db.sql("SELECT current from tabSeries where name = %s", naming_series)[0][0] rename_gle_sle_docs() new_gl_entries = frappe.get_all("GL Entry", fields=["name", "to_rename"], filters={"voucher_type": "Journal Entry", "voucher_no": je.name}, order_by="creation" ) self.assertTrue(all(entry.to_rename == 0 for entry in new_gl_entries)) self.assertTrue(all(new.name != old.name for new, old in zip(gl_entries, new_gl_entries))) new_naming_series_current_value = frappe.db.sql("SELECT current from tabSeries where name = %s", naming_series)[0][0] self.assertEquals(old_naming_series_current_value + 2, new_naming_series_current_value)
def set_total_expense_zero(posting_date, budget_against_field=None, budget_against_CC=None): if budget_against_field == "project": budget_against = "_Test Project" else: budget_against = budget_against_CC or "_Test Cost Center - _TC" fiscal_year = get_fiscal_year(nowdate())[0] args = frappe._dict({ "account": "_Test Account Cost for Goods Sold - _TC", "cost_center": "_Test Cost Center - _TC", "monthly_end_date": posting_date, "company": "_Test Company", "fiscal_year": fiscal_year, "budget_against_field": budget_against_field, }) if not args.get(budget_against_field): args[budget_against_field] = budget_against existing_expense = get_actual_expense(args) if existing_expense: if budget_against_field == "cost_center": make_journal_entry("_Test Account Cost for Goods Sold - _TC", "_Test Bank - _TC", -existing_expense, "_Test Cost Center - _TC", posting_date=nowdate(), submit=True) elif budget_against_field == "project": make_journal_entry("_Test Account Cost for Goods Sold - _TC", "_Test Bank - _TC", -existing_expense, "_Test Cost Center - _TC", submit=True, project="_Test Project", posting_date=nowdate())
def test_closing_entry(self): make_journal_entry("_Test Bank - _TC", "Sales - _TC", 400, "_Test Cost Center - _TC", submit=True) make_journal_entry("_Test Account Cost for Goods Sold - _TC", "_Test Bank - _TC", 600, "_Test Cost Center - _TC", submit=True) profit_or_loss = frappe.db.sql( """select sum(ifnull(t1.debit,0))-sum(ifnull(t1.credit,0)) as balance from `tabGL Entry` t1, `tabAccount` t2 where t1.account = t2.name and ifnull(t2.report_type, '') = 'Profit and Loss' and t2.docstatus < 2 and t2.company = '_Test Company' and t1.posting_date between '2013-01-01' and '2013-12-31'""") profit_or_loss = flt(profit_or_loss[0][0]) if profit_or_loss else 0 pcv = self.make_period_closing_voucher() gle_value = frappe.db.sql( """select ifnull(debit, 0) - ifnull(credit, 0) from `tabGL Entry` where voucher_type='Period Closing Voucher' and voucher_no=%s and account = '_Test Account Reserves and Surplus - _TC'""", pcv.name) gle_value = flt(gle_value[0][0]) if gle_value else 0 self.assertEqual(gle_value, profit_or_loss)
def test_closing_entry(self): year_start_date = get_fiscal_year(today())[1] make_journal_entry("_Test Bank - _TC", "Sales - _TC", 400, "_Test Cost Center - _TC", posting_date=now(), submit=True) make_journal_entry("_Test Account Cost for Goods Sold - _TC", "_Test Bank - _TC", 600, "_Test Cost Center - _TC", posting_date=now(), submit=True) random_expense_account = frappe.db.sql(""" select t1.account, sum(t1.debit) - sum(t1.credit) as balance, sum(t1.debit_in_account_currency) - sum(t1.credit_in_account_currency) \ as balance_in_account_currency from `tabGL Entry` t1, `tabAccount` t2 where t1.account = t2.name and t2.root_type = 'Expense' and t2.docstatus < 2 and t2.company = '_Test Company' and t1.posting_date between %s and %s group by t1.account having sum(t1.debit) > sum(t1.credit) limit 1""", (year_start_date, today()), as_dict=True) profit_or_loss = frappe.db.sql("""select sum(t1.debit) - sum(t1.credit) as balance from `tabGL Entry` t1, `tabAccount` t2 where t1.account = t2.name and t2.report_type = 'Profit and Loss' and t2.docstatus < 2 and t2.company = '_Test Company' and t1.posting_date between %s and %s""", (year_start_date, today())) profit_or_loss = flt(profit_or_loss[0][0]) if profit_or_loss else 0 pcv = self.make_period_closing_voucher() # Check value for closing account gle_amount_for_closing_account = frappe.db.sql("""select debit - credit from `tabGL Entry` where voucher_type='Period Closing Voucher' and voucher_no=%s and account = '_Test Account Reserves and Surplus - _TC'""", pcv.name) gle_amount_for_closing_account = flt(gle_amount_for_closing_account[0][0]) \ if gle_amount_for_closing_account else 0 self.assertEqual(gle_amount_for_closing_account, profit_or_loss) if random_expense_account: # Check posted value for teh above random_expense_account gle_for_random_expense_account = frappe.db.sql(""" select debit - credit as amount, debit_in_account_currency - credit_in_account_currency as amount_in_account_currency from `tabGL Entry` where voucher_type='Period Closing Voucher' and voucher_no=%s and account =%s""", (pcv.name, random_expense_account[0].account), as_dict=True) self.assertEqual(gle_for_random_expense_account[0].amount, -1*random_expense_account[0].balance) self.assertEqual(gle_for_random_expense_account[0].amount_in_account_currency, -1*random_expense_account[0].balance_in_account_currency)
def set_total_expense_zero(posting_date, cost_center=None): existing_expense = get_actual_expense({ "account": "_Test Account Cost for Goods Sold - _TC", "cost_center": cost_center or "_Test Cost Center - _TC", "monthly_end_date": posting_date, "company": "_Test Company", "fiscal_year": "_Test Fiscal Year 2013" }, cost_center or "_Test Cost Center - _TC") make_journal_entry("_Test Account Cost for Goods Sold - _TC", "_Test Bank - _TC", -existing_expense, "_Test Cost Center - _TC", submit=True)
def set_total_expense_zero(posting_date, cost_center=None): existing_expense = get_actual_expense( { "account": "_Test Account Cost for Goods Sold - _TC", "cost_center": cost_center or "_Test Cost Center - _TC", "monthly_end_date": posting_date, "company": "_Test Company", "fiscal_year": "_Test Fiscal Year 2013" }, cost_center or "_Test Cost Center - _TC") make_journal_entry("_Test Account Cost for Goods Sold - _TC", "_Test Bank - _TC", -existing_expense, "_Test Cost Center - _TC", submit=True)
def test_monthly_budget_against_parent_group_cost_center(self): cost_center = "_Test Cost Center 3 - _TC" if not frappe.db.exists("Cost Center", cost_center): frappe.get_doc({ 'doctype': 'Cost Center', 'cost_center_name': '_Test Cost Center 3', 'parent_cost_center': "_Test Company - _TC", 'company': '_Test Company', 'is_group': 0 }).insert(ignore_permissions=True) budget = make_budget("Cost Center", cost_center) 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, cost_center) self.assertRaises(BudgetError, jv.submit) budget.load_from_db() budget.cancel() jv.cancel() frappe.delete_doc('Journal Entry', jv.name) frappe.delete_doc('Cost Center', cost_center)
def test_exception_approver_role(self): set_total_expense_zero(nowdate(), "cost_center") budget = make_budget(budget_against="Cost Center") 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", posting_date=nowdate()) self.assertRaises(BudgetError, jv.submit) frappe.db.set_value('Company', budget.company, 'exception_budget_approver_role', 'Accounts User') jv.submit() self.assertEqual( frappe.db.get_value('Journal Entry', jv.name, 'docstatus'), 1) jv.cancel() frappe.db.set_value('Company', budget.company, 'exception_budget_approver_role', '') budget.load_from_db() budget.cancel()
def make_payment_jv(party, unallocated_amount, against_dt=None, against_dn=None, against_amount=None, unallocated_rows=None): from erpnext.accounts.doctype.journal_entry.test_journal_entry import make_journal_entry party_type = party.doctype party_account = "_Test Payable - _TC" if party_type == "Supplier" else "_Test Receivable - _TC" total_amount = unallocated_amount if against_dt and against_dn and against_amount: total_amount += against_amount if party_type == "Supplier": total_amount = -1 * total_amount jv = make_journal_entry("_Test Bank - _TC", party_account, total_amount, save=False) jv.accounts[1].update({"party_type": party_type, "party": party.name}) if jv.accounts[1].debit_in_account_currency: jv.accounts[1].debit_in_account_currency = abs(unallocated_amount) else: jv.accounts[1].credit_in_account_currency = abs(unallocated_amount) if unallocated_rows: if jv.accounts[1].debit_in_account_currency: jv.accounts[ 1].debit_in_account_currency = unallocated_amount / unallocated_rows else: jv.accounts[ 1].credit_in_account_currency = unallocated_amount / unallocated_rows for i in range(unallocated_rows - 1): jv.append("accounts", jv.accounts[1].as_dict()) if against_dt and against_dn and against_amount: if unallocated_amount: allocated_row = jv.append("accounts", jv.accounts[1].as_dict()) else: allocated_row = jv.accounts[1] allocated_row.update({ "reference_type": against_dt, "reference_name": against_dn }) if allocated_row.debit_in_account_currency: allocated_row.debit_in_account_currency = against_amount if against_amount > 0 else 0 allocated_row.credit_in_account_currency = abs( against_amount) if against_amount < 0 else 0 else: allocated_row.credit_in_account_currency = against_amount if against_amount > 0 else 0 allocated_row.debit_in_account_currency = abs( against_amount) if against_amount < 0 else 0 jv.insert() jv.submit() return jv
def test_finance_book(self): finance_book = self.create_finance_book() # create jv entry jv = make_journal_entry("_Test Bank - _TC", "_Test Receivable - _TC", 100, save=False) jv.accounts[1].update({ "party_type": "Customer", "party": "_Test Customer" }) jv.finance_book = finance_book.finance_book_name jv.submit() # check the Finance Book in the GL Entry gl_entries = frappe.get_all("GL Entry", fields=["name", "finance_book"], filters={ "voucher_type": "Journal Entry", "voucher_no": jv.name }) for gl_entry in gl_entries: self.assertEqual(gl_entry.finance_book, finance_book.name)
def test_monthly_budget_crossed_stop2(self): set_total_expense_zero(nowdate(), "project") budget = make_budget(budget_against="Project") frappe.db.set_value("Budget", budget.name, "action_if_accumulated_monthly_budget_exceeded", "Stop") project = frappe.get_value("Project", {"project_name": "_Test Project"}) jv = make_journal_entry( "_Test Account Cost for Goods Sold - _TC", "_Test Bank - _TC", 40000, "_Test Cost Center - _TC", project=project, posting_date=nowdate(), ) self.assertRaises(BudgetError, jv.submit) budget.load_from_db() budget.cancel()
def test_monthly_budget_on_cancellation2(self): set_total_expense_zero(nowdate(), "project") budget = make_budget(budget_against="Project") month = now_datetime().month if month > 10: month = 10 for i in range(month): jv = make_journal_entry("_Test Account Cost for Goods Sold - _TC", "_Test Bank - _TC", 20000, "_Test Cost Center - _TC", posting_date=nowdate(), submit=True, project="_Test Project") self.assertTrue( frappe.db.get_value("GL Entry", { "voucher_type": "Journal Entry", "voucher_no": jv.name })) frappe.db.set_value("Budget", budget.name, "action_if_accumulated_monthly_budget_exceeded", "Stop") self.assertRaises(BudgetError, jv.cancel) budget.load_from_db() budget.cancel()
def test_monthly_budget_against_parent_group_cost_center(self): cost_center = "_Test Cost Center 3 - _TC" if not frappe.db.exists("Cost Center", cost_center): frappe.get_doc({ 'doctype': 'Cost Center', 'cost_center_name': '_Test Cost Center 3', 'parent_cost_center': "_Test Company - _TC", 'company': '_Test Company', 'is_group': 0 }).insert(ignore_permissions=True) budget = make_budget(budget_against="Cost Center", cost_center=cost_center) 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, cost_center, posting_date=nowdate()) self.assertRaises(BudgetError, jv.submit) budget.load_from_db() budget.cancel() jv.cancel()
def test_round_off_entry(self): frappe.db.set_value("Company", "_Test Company", "round_off_account", "_Test Write Off - _TC") frappe.db.set_value( "Company", "_Test Company", "round_off_cost_center", "_Test Cost Center - _TC" ) jv = make_journal_entry( "_Test Account Cost for Goods Sold - _TC", "_Test Bank - _TC", 100, "_Test Cost Center - _TC", submit=False, ) jv.get("accounts")[0].debit = 100.01 jv.flags.ignore_validate = True jv.submit() round_off_entry = frappe.db.sql( """select name from `tabGL Entry` where voucher_type='Journal Entry' and voucher_no = %s and account='_Test Write Off - _TC' and cost_center='_Test Cost Center - _TC' and debit = 0 and credit = '.01'""", jv.name, ) self.assertTrue(round_off_entry)
def test_valid_from_based_on_existing_gle(self): # GLE posted against Sub Cost Center 1 on today jv = make_journal_entry( "_Test Cash - _TC", "Sales - _TC", 100, cost_center="Main Cost Center 1 - _TC", posting_date=today(), submit=True, ) # try to set valid from as yesterday cca = create_cost_center_allocation( "_Test Company", "Main Cost Center 1 - _TC", { "Sub Cost Center 1 - _TC": 60, "Sub Cost Center 2 - _TC": 40 }, valid_from=add_days(today(), -1), save=False, ) self.assertRaises(InvalidDateError, cca.save) jv.cancel()
def test_closing_entry(self): frappe.db.sql("delete from `tabGL Entry` where company='Test PCV Company'") company = create_company() cost_center = create_cost_center("Test Cost Center 1") jv1 = make_journal_entry( amount=400, account1="Cash - TPC", account2="Sales - TPC", cost_center=cost_center, posting_date=now(), save=False, ) jv1.company = company jv1.save() jv1.submit() jv2 = make_journal_entry( amount=600, account1="Cost of Goods Sold - TPC", account2="Cash - TPC", cost_center=cost_center, posting_date=now(), save=False, ) jv2.company = company jv2.save() jv2.submit() pcv = self.make_period_closing_voucher() surplus_account = pcv.closing_account_head expected_gle = ( ("Cost of Goods Sold - TPC", 0.0, 600.0), (surplus_account, 600.0, 400.0), ("Sales - TPC", 400.0, 0.0), ) pcv_gle = frappe.db.sql( """ select account, debit, credit from `tabGL Entry` where voucher_no=%s order by account """, (pcv.name), ) self.assertEqual(pcv_gle, expected_gle)
def test_yearly_budget_crossed_stop1(self): set_total_expense_zero("2013-02-28", "Cost Center") budget = make_budget(budget_against="Cost Center") 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_yearly_budget_crossed_stop(self): 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_yearly_budget_crossed_stop2(self): set_total_expense_zero("2013-02-28", "Project") budget = make_budget(budget_against="Project") jv = make_journal_entry("_Test Account Cost for Goods Sold - _TC", "_Test Bank - _TC", 150000, "_Test Cost Center - _TC", project="_Test Project", posting_date="2013-03-28") self.assertRaises(BudgetError, jv.submit) budget.cancel()
def test_yearly_budget_crossed_stop2(self): set_total_expense_zero(nowdate(), "project") budget = make_budget(budget_against="Project") jv = make_journal_entry("_Test Account Cost for Goods Sold - _TC", "_Test Bank - _TC", 250000, "_Test Cost Center - _TC", project="_Test Project", posting_date=nowdate()) self.assertRaises(BudgetError, jv.submit) budget.cancel()
def test_monthly_budget_on_cancellation2(self): set_total_expense_zero("2013-02-28", "Project") budget = make_budget(budget_against="Project") jv1 = make_journal_entry("_Test Account Cost for Goods Sold - _TC", "_Test Bank - _TC", 20000, "_Test Cost Center - _TC", posting_date="2013-02-28", submit=True, project="_Test Project") self.assertTrue( frappe.db.get_value("GL Entry", { "voucher_type": "Journal Entry", "voucher_no": jv1.name })) jv2 = make_journal_entry("_Test Account Cost for Goods Sold - _TC", "_Test Bank - _TC", 20000, "_Test Cost Center - _TC", posting_date="2013-02-28", submit=True, project="_Test Project") self.assertTrue( frappe.db.get_value("GL Entry", { "voucher_type": "Journal Entry", "voucher_no": jv2.name })) 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_validate_account_currency(self): from erpnext.accounts.doctype.journal_entry.test_journal_entry import make_journal_entry if not frappe.db.get_value("Account", "Test Currency Account - _TC"): acc = frappe.new_doc("Account") acc.account_name = "Test Currency Account" acc.parent_account = "Tax Assets - _TC" acc.company = "_Test Company" acc.insert() else: acc = frappe.get_doc("Account", "Test Currency Account - _TC") self.assertEqual(acc.account_currency, "INR") # Make a JV against this account make_journal_entry( "Test Currency Account - _TC", "Miscellaneous Expenses - _TC", 100, submit=True ) acc.account_currency = "USD" self.assertRaises(frappe.ValidationError, acc.save)
def test_monthly_budget_crossed_ignore(self): set_total_expense_zero("2013-02-28", "Cost Center") budget = make_budget(budget_against="Cost Center") 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_ignore(self): 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 set_total_expense_zero(posting_date, budget_against_field=None, budget_against_CC=None): if budget_against_field == "Project": budget_against = "_Test Project" else: budget_against = budget_against_CC or "_Test Cost Center - _TC" existing_expense = get_actual_expense(frappe._dict({ "account": "_Test Account Cost for Goods Sold - _TC", "cost_center": "_Test Cost Center - _TC", "monthly_end_date": posting_date, "company": "_Test Company", "fiscal_year": "_Test Fiscal Year 2013", "budget_against_field": budget_against_field, "budget_against": budget_against })) if existing_expense: if budget_against_field == "Cost Center": make_journal_entry("_Test Account Cost for Goods Sold - _TC", "_Test Bank - _TC", -existing_expense, "_Test Cost Center - _TC", submit=True) elif budget_against_field == "Project": make_journal_entry("_Test Account Cost for Goods Sold - _TC", "_Test Bank - _TC", -existing_expense, "_Test Cost Center - _TC", submit=True, project="_Test Project")
def test_monthly_budget_crossed_stop1(self): set_total_expense_zero("2013-02-28", "Cost Center") budget = make_budget(budget_against="Cost Center") 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_period_closing_with_finance_book_entries(self): frappe.db.sql("delete from `tabGL Entry` where company='Test PCV Company'") company = create_company() surplus_account = create_account() cost_center = create_cost_center("Test Cost Center 1") si = create_sales_invoice( company=company, income_account="Sales - TPC", expense_account="Cost of Goods Sold - TPC", cost_center=cost_center, rate=400, debit_to="Debtors - TPC", currency="USD", customer="_Test Customer USD", ) jv = make_journal_entry( account1="Cash - TPC", account2="Sales - TPC", amount=400, cost_center=cost_center, posting_date=now(), ) jv.company = company jv.finance_book = create_finance_book().name jv.save() jv.submit() pcv = self.make_period_closing_voucher() surplus_account = pcv.closing_account_head expected_gle = ( (surplus_account, 0.0, 400.0, None), (surplus_account, 0.0, 400.0, jv.finance_book), ("Sales - TPC", 400.0, 0.0, None), ("Sales - TPC", 400.0, 0.0, jv.finance_book), ) pcv_gle = frappe.db.sql( """ select account, debit, credit, finance_book from `tabGL Entry` where voucher_no=%s order by account, finance_book """, (pcv.name), ) self.assertEqual(pcv_gle, expected_gle)
def test_monthly_budget_on_cancellation(self): 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) self.assertTrue(frappe.db.get_value("GL Entry", {"voucher_type": "Journal Entry", "voucher_no": jv1.name})) jv2 = make_journal_entry("_Test Account Cost for Goods Sold - _TC", "_Test Bank - _TC", 20000, "_Test Cost Center - _TC", submit=True) self.assertTrue(frappe.db.get_value("GL Entry", {"voucher_type": "Journal Entry", "voucher_no": jv2.name})) 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_crossed_stop2(self): set_total_expense_zero("2013-02-28", "Project") budget = make_budget(budget_against="Project") 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", project="_Test Project", posting_date="2013-02-28") self.assertRaises(BudgetError, jv.submit) budget.load_from_db() budget.cancel()
def test_monthly_budget_against_group_cost_center(self): set_total_expense_zero(nowdate(), "cost_center") set_total_expense_zero(nowdate(), "cost_center", "_Test Cost Center 2 - _TC") budget = make_budget(budget_against="Cost Center", cost_center="_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", posting_date=nowdate()) self.assertRaises(BudgetError, jv.submit) budget.load_from_db() budget.cancel()
def test_monthly_budget_against_group_cost_center(self): 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 test_dimension_against_journal_entry(self): je = make_journal_entry("Sales - _TC", "Sales Expenses - _TC", 500, save=False) je.accounts[0].update({"department": "_Test Department - _TC"}) je.accounts[1].update({"department": "_Test Department - _TC"}) je.accounts[0].update({"location": "Block 1"}) je.accounts[1].update({"location": "Block 1"}) je.save() je.submit() gle = frappe.get_doc("GL Entry", {"voucher_no": je.name, "account": "Sales - _TC"}) gle1 = frappe.get_doc("GL Entry", {"voucher_no": je.name, "account": "Sales Expenses - _TC"}) self.assertEqual(gle.get('department'), "_Test Department - _TC") self.assertEqual(gle1.get('department'), "_Test Department - _TC")
def test_closing_entry(self): make_journal_entry("_Test Account Bank Account - _TC", "Sales - _TC", 400, "_Test Cost Center - _TC", submit=True) make_journal_entry("_Test Account Cost for Goods Sold - _TC", "_Test Account Bank Account - _TC", 600, "_Test Cost Center - _TC", submit=True) profit_or_loss = frappe.db.sql("""select sum(ifnull(t1.debit,0))-sum(ifnull(t1.credit,0)) as balance from `tabGL Entry` t1, `tabAccount` t2 where t1.account = t2.name and ifnull(t2.report_type, '') = 'Profit and Loss' and t2.docstatus < 2 and t2.company = '_Test Company' and t1.posting_date between '2013-01-01' and '2013-12-31'""") profit_or_loss = flt(profit_or_loss[0][0]) if profit_or_loss else 0 pcv = self.make_period_closing_voucher() gle_value = frappe.db.sql("""select ifnull(debit, 0) - ifnull(credit, 0) from `tabGL Entry` where voucher_type='Period Closing Voucher' and voucher_no=%s and account = '_Test Account Reserves and Surplus - _TC'""", pcv.name) gle_value = flt(gle_value[0][0]) if gle_value else 0 self.assertEqual(gle_value, profit_or_loss)
def test_round_off_entry(self): frappe.db.set_value("Company", "_Test Company", "round_off_account", "_Test Write Off - _TC") frappe.db.set_value("Company", "_Test Company", "round_off_cost_center", "_Test Cost Center - _TC") jv = make_journal_entry("_Test Account Cost for Goods Sold - _TC", "_Test Bank - _TC", 100, "_Test Cost Center - _TC", submit=False) jv.get("accounts")[0].debit = 100.01 jv.flags.ignore_validate = True jv.submit() round_off_entry = frappe.db.sql("""select name from `tabGL Entry` where voucher_type='Journal Entry' and voucher_no = %s and account='_Test Write Off - _TC' and cost_center='_Test Cost Center - _TC' and debit = 0 and credit = '.01'""", jv.name) self.assertTrue(round_off_entry)
def test_finance_book(self): finance_book = self.create_finance_book() # create jv entry jv = make_journal_entry("_Test Bank - _TC", "_Test Receivable - _TC", 100, save=False) jv.accounts[1].update({ "party_type": "Customer", "party": "_Test Customer" }) jv.finance_book = finance_book.finance_book_name jv.submit() # check the Finance Book in the GL Entry gl_entries = frappe.get_all("GL Entry", fields=["name", "finance_book"], filters={"voucher_type": "Journal Entry", "voucher_no": jv.name}) for gl_entry in gl_entries: self.assertEqual(gl_entry.finance_book, finance_book.name)
def test_exception_approver_role(self): set_total_expense_zero("2013-02-28", "Cost Center") budget = make_budget(budget_against="Cost Center") 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", posting_date="2013-03-02") self.assertRaises(BudgetError, jv.submit) frappe.db.set_value('Company', budget.company, 'exception_budget_approver_role', 'Accounts User') jv.submit() self.assertEqual(frappe.db.get_value('Journal Entry', jv.name, 'docstatus'), 1) jv.cancel() frappe.db.set_value('Company', budget.company, 'exception_budget_approver_role', '') budget.load_from_db() budget.cancel()
def test_gle_based_on_cost_center_allocation(self): cca = create_cost_center_allocation( "_Test Company", "Main Cost Center 1 - _TC", { "Sub Cost Center 1 - _TC": 60, "Sub Cost Center 2 - _TC": 40 }, ) jv = make_journal_entry("_Test Cash - _TC", "Sales - _TC", 100, cost_center="Main Cost Center 1 - _TC", submit=True) expected_values = [["Sub Cost Center 1 - _TC", 0.0, 60], ["Sub Cost Center 2 - _TC", 0.0, 40]] gle = frappe.qb.DocType("GL Entry") gl_entries = (frappe.qb.from_(gle).select( gle.cost_center, gle.debit, gle.credit).where(gle.voucher_type == "Journal Entry").where( gle.voucher_no == jv.name).where( gle.account == "Sales - _TC").orderby( gle.cost_center)).run(as_dict=1) self.assertTrue(gl_entries) for i, gle in enumerate(gl_entries): self.assertEqual(expected_values[i][0], gle.cost_center) self.assertEqual(expected_values[i][1], gle.debit) self.assertEqual(expected_values[i][2], gle.credit) cca.cancel() jv.cancel()