From 2236f0aef0840dfb5d88bd9defd49f1d856c244e Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Tue, 11 Sep 2018 16:50:46 +0530 Subject: [PATCH] fix(test): multiple test cases fixed --- .../accounts/doctype/budget/test_budget.py | 29 +++++++++---------- .../doctype/journal_entry/test_records.json | 18 ++++++++---- .../sales_invoice/test_sales_invoice.py | 3 ++ .../v7_0/convert_timelog_to_timesheet.py | 5 ++-- .../v7_0/convert_timelogbatch_to_timesheet.py | 8 +++-- .../purchase_receipt/test_purchase_receipt.py | 3 +- 6 files changed, 40 insertions(+), 26 deletions(-) diff --git a/erpnext/accounts/doctype/budget/test_budget.py b/erpnext/accounts/doctype/budget/test_budget.py index 69c988a582..b3d0dc1e40 100644 --- a/erpnext/accounts/doctype/budget/test_budget.py +++ b/erpnext/accounts/doctype/budget/test_budget.py @@ -18,7 +18,7 @@ class TestBudget(unittest.TestCase): 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) + "_Test Bank - _TC", 40000, "_Test Cost Center - _TC", posting_date="2013-02-28", submit=True) self.assertTrue(frappe.db.get_value("GL Entry", {"voucher_type": "Journal Entry", "voucher_no": jv.name})) @@ -33,7 +33,7 @@ class TestBudget(unittest.TestCase): 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") + "_Test Bank - _TC", 40000, "_Test Cost Center - _TC", posting_date="2013-02-28") self.assertRaises(BudgetError, jv.submit) @@ -46,9 +46,9 @@ class TestBudget(unittest.TestCase): 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") + "_Test Bank - _TC", 40000, "_Test Cost Center - _TC", posting_date="2013-03-02") self.assertRaises(BudgetError, jv.submit) @@ -121,7 +121,7 @@ class TestBudget(unittest.TestCase): 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") + "_Test Bank - _TC", 40000, "_Test Cost Center - _TC", project="_Test Project", posting_date="2013-02-28") self.assertRaises(BudgetError, jv.submit) @@ -134,7 +134,7 @@ class TestBudget(unittest.TestCase): 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") + "_Test Bank - _TC", 150000, "_Test Cost Center - _TC", posting_date="2013-03-28") self.assertRaises(BudgetError, jv.submit) @@ -146,7 +146,7 @@ class TestBudget(unittest.TestCase): 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") + "_Test Bank - _TC", 150000, "_Test Cost Center - _TC", project="_Test Project", posting_date="2013-03-28") self.assertRaises(BudgetError, jv.submit) @@ -158,13 +158,13 @@ class TestBudget(unittest.TestCase): budget = make_budget(budget_against="Cost Center") 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", posting_date="2013-02-28", 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) + "_Test Bank - _TC", 20000, "_Test Cost Center - _TC", posting_date="2013-02-28", submit=True) self.assertTrue(frappe.db.get_value("GL Entry", {"voucher_type": "Journal Entry", "voucher_no": jv2.name})) @@ -182,13 +182,13 @@ class TestBudget(unittest.TestCase): 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", submit=True, project="_Test Project") + "_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", submit=True, project="_Test Project") + "_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})) @@ -200,7 +200,6 @@ class TestBudget(unittest.TestCase): budget.load_from_db() budget.cancel() - def test_monthly_budget_against_group_cost_center(self): set_total_expense_zero("2013-02-28", "Cost Center") set_total_expense_zero("2013-02-28", "Cost Center", "_Test Cost Center 2 - _TC") @@ -209,7 +208,7 @@ class TestBudget(unittest.TestCase): 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") + "_Test Bank - _TC", 40000, "_Test Cost Center 2 - _TC", posting_date="2013-02-28") self.assertRaises(BudgetError, jv.submit) @@ -261,10 +260,10 @@ def set_total_expense_zero(posting_date, budget_against_field=None, budget_again 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) + "_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") + "_Test Bank - _TC", -existing_expense, "_Test Cost Center - _TC", submit=True, project="_Test Project", posting_date="2013-02-28") def make_budget(**args): args = frappe._dict(args) diff --git a/erpnext/accounts/doctype/journal_entry/test_records.json b/erpnext/accounts/doctype/journal_entry/test_records.json index b67fc31687..5077305cf2 100644 --- a/erpnext/accounts/doctype/journal_entry/test_records.json +++ b/erpnext/accounts/doctype/journal_entry/test_records.json @@ -12,14 +12,16 @@ "credit_in_account_currency": 400.0, "debit_in_account_currency": 0.0, "doctype": "Journal Entry Account", - "parentfield": "accounts" + "parentfield": "accounts", + "cost_center": "_Test Cost Center - _TC" }, { "account": "_Test Bank - _TC", "credit_in_account_currency": 0.0, "debit_in_account_currency": 400.0, "doctype": "Journal Entry Account", - "parentfield": "accounts" + "parentfield": "accounts", + "cost_center": "_Test Cost Center - _TC" } ], "naming_series": "_T-Journal Entry-", @@ -42,14 +44,16 @@ "credit_in_account_currency": 0.0, "debit_in_account_currency": 400.0, "doctype": "Journal Entry Account", - "parentfield": "accounts" + "parentfield": "accounts", + "cost_center": "_Test Cost Center - _TC" }, { "account": "_Test Bank - _TC", "credit_in_account_currency": 400.0, "debit_in_account_currency": 0.0, "doctype": "Journal Entry Account", - "parentfield": "accounts" + "parentfield": "accounts", + "cost_center": "_Test Cost Center - _TC" } ], "naming_series": "_T-Journal Entry-", @@ -72,7 +76,8 @@ "credit_in_account_currency": 0.0, "debit_in_account_currency": 400.0, "doctype": "Journal Entry Account", - "parentfield": "accounts" + "parentfield": "accounts", + "cost_center": "_Test Cost Center - _TC" }, { "account": "Sales - _TC", @@ -80,7 +85,8 @@ "credit_in_account_currency": 400.0, "debit_in_account_currency": 0.0, "doctype": "Journal Entry Account", - "parentfield": "accounts" + "parentfield": "accounts", + "cost_center": "_Test Cost Center - _TC" } ], "naming_series": "_T-Journal Entry-", diff --git a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py index b0fbc98c4e..94037c7d0a 100644 --- a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py @@ -1496,6 +1496,9 @@ class TestSalesInvoice(unittest.TestCase): for gle in gl_entries: self.assertEqual(expected_values[gle.account]["cost_center"], gle.cost_center) + + accounts_settings.allow_cost_center_in_entry_of_bs_account = 0 + accounts_settings.save() def create_sales_invoice(**args): diff --git a/erpnext/patches/v7_0/convert_timelog_to_timesheet.py b/erpnext/patches/v7_0/convert_timelog_to_timesheet.py index d21758d031..4177e07630 100644 --- a/erpnext/patches/v7_0/convert_timelog_to_timesheet.py +++ b/erpnext/patches/v7_0/convert_timelog_to_timesheet.py @@ -1,6 +1,4 @@ import frappe -from erpnext.manufacturing.doctype.work_order.work_order \ - import make_timesheet, add_timesheet_detail def execute(): frappe.reload_doc('projects', 'doctype', 'task') @@ -8,6 +6,9 @@ def execute(): if not frappe.db.table_exists("Time Log"): return + from erpnext.manufacturing.doctype.work_order.work_order \ + import make_timesheet, add_timesheet_detail + for data in frappe.db.sql("select * from `tabTime Log`", as_dict=1): if data.task: company = frappe.db.get_value("Task", data.task, "company") diff --git a/erpnext/patches/v7_0/convert_timelogbatch_to_timesheet.py b/erpnext/patches/v7_0/convert_timelogbatch_to_timesheet.py index e23669b0f2..41364cabec 100644 --- a/erpnext/patches/v7_0/convert_timelogbatch_to_timesheet.py +++ b/erpnext/patches/v7_0/convert_timelogbatch_to_timesheet.py @@ -1,9 +1,13 @@ import frappe from frappe.utils import cint -from erpnext.manufacturing.doctype.work_order.work_order import add_timesheet_detail -from erpnext.patches.v7_0.convert_timelog_to_timesheet import get_timelog_data def execute(): + if not frappe.db.exists("DocType", "Time Log Batch"): + return + + from erpnext.manufacturing.doctype.work_order.work_order import add_timesheet_detail + from erpnext.patches.v7_0.convert_timelog_to_timesheet import get_timelog_data + for tlb in frappe.get_all('Time Log Batch', fields=["*"], filters = [["docstatus", "<", "2"]]): time_sheet = frappe.new_doc('Timesheet') diff --git a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py index a2da9246a2..8d2744becc 100644 --- a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py @@ -383,8 +383,9 @@ class TestPurchaseReceipt(unittest.TestCase): 'location_name': 'Test Location' }).insert() - pr = make_purchase_receipt() set_perpetual_inventory(1, pr.company) + pr = make_purchase_receipt() + stock_in_hand_account = get_inventory_account(pr.company, pr.get("items")[0].warehouse) gl_entries = get_gl_entries("Purchase Receipt", pr.name)