diff --git a/erpnext/accounts/doctype/cost_center/cost_center.py b/erpnext/accounts/doctype/cost_center/cost_center.py index 558c51605dc7..07cc0764e389 100644 --- a/erpnext/accounts/doctype/cost_center/cost_center.py +++ b/erpnext/accounts/doctype/cost_center/cost_center.py @@ -4,7 +4,6 @@ import frappe from frappe import _ -from frappe.utils import cint from frappe.utils.nestedset import NestedSet from erpnext.accounts.utils import validate_field_number diff --git a/erpnext/accounts/doctype/cost_center_allocation/cost_center_allocation.js b/erpnext/accounts/doctype/cost_center_allocation/cost_center_allocation.js index bdc7b1814caf..ab0baab24a0f 100644 --- a/erpnext/accounts/doctype/cost_center_allocation/cost_center_allocation.js +++ b/erpnext/accounts/doctype/cost_center_allocation/cost_center_allocation.js @@ -9,7 +9,7 @@ frappe.ui.form.on('Cost Center Allocation', { "company": frm.doc.company }); } - + frm.set_query('main_cost_center', function() { return { filters: filters diff --git a/erpnext/accounts/doctype/cost_center_allocation/cost_center_allocation.py b/erpnext/accounts/doctype/cost_center_allocation/cost_center_allocation.py index 00a591aa5825..bad3fb4f96c3 100644 --- a/erpnext/accounts/doctype/cost_center_allocation/cost_center_allocation.py +++ b/erpnext/accounts/doctype/cost_center_allocation/cost_center_allocation.py @@ -58,11 +58,9 @@ def validate_backdated_allocation(self): if future_allocation: frappe.msgprint(_("Another Cost Center Allocation record {0} applicable from {1}, hence this allocation will be applicable upto {2}") - .format( - frappe.bold(future_allocation.name), - frappe.bold(format_date(future_allocation.valid_from)), - frappe.bold(format_date(add_days(future_allocation.valid_from, -1))) - ), title=_("Warning!"), indicator="orange", alert=1 + .format(frappe.bold(future_allocation.name), frappe.bold(format_date(future_allocation.valid_from)), + frappe.bold(format_date(add_days(future_allocation.valid_from, -1)))), + title=_("Warning!"), indicator="orange", alert=1 ) def validate_main_cost_center(self): diff --git a/erpnext/accounts/doctype/cost_center_allocation/test_cost_center_allocation.py b/erpnext/accounts/doctype/cost_center_allocation/test_cost_center_allocation.py index 137ab7de24e3..9cf4c002172b 100644 --- a/erpnext/accounts/doctype/cost_center_allocation/test_cost_center_allocation.py +++ b/erpnext/accounts/doctype/cost_center_allocation/test_cost_center_allocation.py @@ -1,13 +1,21 @@ # Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and Contributors # See license.txt -import frappe import unittest -from frappe.utils import today, add_days + +import frappe +from frappe.utils import add_days, today + from erpnext.accounts.doctype.cost_center.test_cost_center import create_cost_center +from erpnext.accounts.doctype.cost_center_allocation.cost_center_allocation import ( + InvalidChildCostCenter, + InvalidDateError, + InvalidMainCostCenter, + MainCostCenterCantBeChild, + WrongPercentageAllocation, +) from erpnext.accounts.doctype.journal_entry.test_journal_entry import make_journal_entry -from erpnext.accounts.doctype.cost_center_allocation.cost_center_allocation import (MainCostCenterCantBeChild, - InvalidMainCostCenter, InvalidChildCostCenter, WrongPercentageAllocation, InvalidDateError) + class TestCostCenterAllocation(unittest.TestCase): def setUp(self): @@ -22,7 +30,7 @@ def test_gle_based_on_cost_center_allocation(self): "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) @@ -77,14 +85,13 @@ def test_invalid_main_cost_center(self): "Sub Cost Center 2 - _TC": 100 }, save=False ) - + self.assertRaises(InvalidMainCostCenter, cca2.save) cca1.cancel() - - + def test_if_child_cost_center_has_any_allocation_record(self): - # Check if any child cost center is used as main cost center in any other existing allocation + # Check if any child cost center is used as main cost center in any other existing allocation cca1 = create_cost_center_allocation("_Test Company", "Main Cost Center 1 - _TC", { "Sub Cost Center 1 - _TC": 60, @@ -98,7 +105,7 @@ def test_if_child_cost_center_has_any_allocation_record(self): "Sub Cost Center 1 - _TC": 40 }, save=False ) - + self.assertRaises(InvalidChildCostCenter, cca2.save) cca1.cancel() @@ -128,7 +135,6 @@ def test_valid_from_based_on_existing_gle(self): self.assertRaises(InvalidDateError, cca.save) jv.cancel() - def create_cost_center_allocation(company, main_cost_center, allocation_percentages, valid_from=None, valid_upto=None, save=True, submit=True): diff --git a/erpnext/accounts/doctype/cost_center_allocation_percentage/cost_center_allocation_percentage.py b/erpnext/accounts/doctype/cost_center_allocation_percentage/cost_center_allocation_percentage.py index 92148846b787..7d20efb6d5ec 100644 --- a/erpnext/accounts/doctype/cost_center_allocation_percentage/cost_center_allocation_percentage.py +++ b/erpnext/accounts/doctype/cost_center_allocation_percentage/cost_center_allocation_percentage.py @@ -4,5 +4,6 @@ # import frappe from frappe.model.document import Document + class CostCenterAllocationPercentage(Document): pass diff --git a/erpnext/accounts/general_ledger.py b/erpnext/accounts/general_ledger.py index 6b73e3cb1c46..55bc9673c18f 100644 --- a/erpnext/accounts/general_ledger.py +++ b/erpnext/accounts/general_ledger.py @@ -2,8 +2,9 @@ # License: GNU General Public License v3. See license.txt -import frappe import copy + +import frappe from frappe import _ from frappe.model.meta import get_field_precision from frappe.utils import cint, cstr, flt, formatdate, getdate, now @@ -101,7 +102,7 @@ def get_cost_center_allocation_data(company, posting_date): for d in records: cc_allocation.setdefault(d.main_cost_center, frappe._dict())\ .setdefault(d.cost_center, d.percentage) - + return cc_allocation def merge_similar_entries(gl_map, precision=None): diff --git a/erpnext/patches/v14_0/migrate_cost_center_allocations.py b/erpnext/patches/v14_0/migrate_cost_center_allocations.py index d101307d8ba1..3d217d89e2fb 100644 --- a/erpnext/patches/v14_0/migrate_cost_center_allocations.py +++ b/erpnext/patches/v14_0/migrate_cost_center_allocations.py @@ -1,6 +1,7 @@ import frappe from frappe.utils import today + def execute(): for dt in ("cost_center_allocation", "cost_center_allocation_percentage"): frappe.reload_doc('accounts', 'doctype', dt) @@ -22,7 +23,6 @@ def create_new_cost_center_allocation_records(cc_allocations): "cost_center": child_cc, "percentage": percentage })) - cca.save() cca.submit()