-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #262 from RitvikSardana/develop-ritvik-multi-accou…
…nt-category feat: multiple account and cost center support for fee category
- Loading branch information
Showing
15 changed files
with
983 additions
and
633 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 106 additions & 1 deletion
107
education/education/doctype/fee_category/test_fee_category.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,113 @@ | ||
# Copyright (c) 2015, Frappe Technologies and Contributors | ||
# See license.txt | ||
|
||
import frappe | ||
from frappe.tests.utils import FrappeTestCase | ||
from education.education.test_utils import ( | ||
create_fee_category, | ||
create_company, | ||
get_defaults, | ||
) | ||
|
||
|
||
class TestFeeCategory(FrappeTestCase): | ||
pass | ||
def setUp(self): | ||
create_fee_category("Tuition Fee") | ||
create_company("Dunder Mifflin Paper Co") | ||
|
||
def tearDown(self): | ||
frappe.db.rollback() | ||
|
||
def test_item_created(self): | ||
""" | ||
Test to check if the item master is created when a Fee Category is created. | ||
""" | ||
companies = frappe.db.get_all("Company", fields=["name"]) | ||
item = frappe.db.get_value( | ||
"Fee Category", filters={"name": "Tuition Fee"}, fieldname="item" | ||
) | ||
self.assertTrue(frappe.db.exists("Item", item)) | ||
|
||
item_group = frappe.db.get_value( | ||
"Item", filters={"name": item}, fieldname="item_group" | ||
) | ||
self.assertEqual(item_group, "Fee Component") | ||
|
||
def test_item_defaults_from_item_group(self): | ||
""" | ||
When creating a Fee Category, if there are no item defaults, then get defaults from Item Group | ||
""" | ||
defaults = get_defaults() | ||
|
||
item_group = frappe.get_doc("Item Group", "Fee Component") | ||
item_group.append( | ||
"item_group_defaults", | ||
{ | ||
"company": "_Test Company", | ||
"income_account": defaults.default_income_account, | ||
"selling_cost_center": defaults.cost_center, | ||
}, | ||
) | ||
item_group.save() | ||
|
||
fee_category = frappe.get_doc("Fee Category", "Tuition Fee") | ||
fee_category.description = "Test" | ||
fee_category.save() | ||
|
||
fee_category = frappe.get_doc("Fee Category", "Tuition Fee") | ||
fee_category_defaults = fee_category.get("item_defaults")[0] | ||
|
||
self.assertEqual(fee_category_defaults.company, "_Test Company") | ||
self.assertEqual( | ||
fee_category_defaults.income_account, defaults.default_income_account | ||
) | ||
self.assertEqual(fee_category_defaults.selling_cost_center, defaults.cost_center) | ||
|
||
def test_fee_component_defaults_same_as_item_defaults(self): | ||
""" | ||
When creating a Fee Category, if the defaults are set in Fee Category those should be saved in the Item Defaults aswell | ||
""" | ||
defaults = get_defaults() | ||
|
||
fee_category_name = "Test Fee Category" | ||
fee_category = create_fee_category(fee_category_name) | ||
fee_category.append( | ||
"item_defaults", | ||
{ | ||
"company": "_Test Company", | ||
"income_account": defaults.default_income_account, | ||
"selling_cost_center": defaults.cost_center, | ||
}, | ||
) | ||
fee_category.save() | ||
|
||
item = frappe.get_doc("Item", fee_category_name) | ||
item_defaults = item.get("item_defaults")[0] | ||
|
||
self.assertEqual(item_defaults.company, "_Test Company") | ||
self.assertEqual(item_defaults.income_account, defaults.default_income_account) | ||
self.assertEqual(item_defaults.selling_cost_center, defaults.cost_center) | ||
|
||
def test_fee_component_duplicate_default(self): | ||
""" | ||
When setting defaults if there are 2 defaults for the same company, then throw an error | ||
""" | ||
fee_component = frappe.get_doc("Fee Category", "Tuition Fee") | ||
# get any income account | ||
income_account = frappe.get_all("Account", fields=["name"], limit=1)[0]["name"] | ||
defaults = get_defaults() | ||
default_array = [ | ||
{ | ||
"company": "_Test Company", | ||
"income_account": income_account, | ||
"selling_cost_center": defaults.cost_center, | ||
}, | ||
{ | ||
"company": "_Test Company", | ||
"income_account": income_account, | ||
"selling_cost_center": defaults.cost_center, | ||
}, | ||
] | ||
for default in default_array: | ||
fee_component.append("item_defaults", default) | ||
self.assertRaises(frappe.ValidationError, fee_component.save) |
Empty file.
52 changes: 52 additions & 0 deletions
52
education/education/doctype/fee_category_default/fee_category_default.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{ | ||
"actions": [], | ||
"allow_rename": 1, | ||
"creation": "2024-05-28 11:36:10.928607", | ||
"doctype": "DocType", | ||
"editable_grid": 1, | ||
"engine": "InnoDB", | ||
"field_order": [ | ||
"company", | ||
"income_account", | ||
"selling_cost_center" | ||
], | ||
"fields": [ | ||
{ | ||
"fieldname": "company", | ||
"fieldtype": "Link", | ||
"ignore_user_permissions": 1, | ||
"in_list_view": 1, | ||
"label": "Company", | ||
"options": "Company", | ||
"reqd": 1 | ||
}, | ||
{ | ||
"fieldname": "selling_cost_center", | ||
"fieldtype": "Link", | ||
"in_list_view": 1, | ||
"label": "Default Cost Center", | ||
"link_filters": "[[\"Cost Center\",\"is_group\",\"=\",0],[\"Cost Center\",\"company\",\"=\",\"eval: doc.company\"]]", | ||
"options": "Cost Center" | ||
}, | ||
{ | ||
"fieldname": "income_account", | ||
"fieldtype": "Link", | ||
"in_list_view": 1, | ||
"label": "Default Income Account", | ||
"link_filters": "[[\"Account\",\"company\",\"=\",\"eval: doc.company\"],[\"Account\",\"is_group\",\"=\",0],[\"Account\",\"root_type\",\"=\",\"Income\"]]", | ||
"options": "Account" | ||
} | ||
], | ||
"index_web_pages_for_search": 1, | ||
"istable": 1, | ||
"links": [], | ||
"modified": "2024-06-28 13:05:14.403852", | ||
"modified_by": "Administrator", | ||
"module": "Education", | ||
"name": "Fee Category Default", | ||
"owner": "Administrator", | ||
"permissions": [], | ||
"sort_field": "creation", | ||
"sort_order": "DESC", | ||
"states": [] | ||
} |
9 changes: 9 additions & 0 deletions
9
education/education/doctype/fee_category_default/fee_category_default.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Copyright (c) 2024, Frappe Technologies Pvt. Ltd. and contributors | ||
# For license information, please see license.txt | ||
|
||
# import frappe | ||
from frappe.model.document import Document | ||
|
||
|
||
class FeeCategoryDefault(Document): | ||
pass |
Oops, something went wrong.