mirror of
https://github.com/frappe/erpnext.git
synced 2026-08-08 04:01:46 +00:00
fix: resolve backport conflicts for version-15
install() holds the preset list inline on this branch, so the root is resolved there instead of in get_preset_records. Dropping the preset-record test with it -- there is no seam to call without running the whole installer. The patch test is adapted to this branch: TestItem does not roll back between tests, so it restores the original root name, and it passes parent_item_group explicitly since ItemGroup.validate skips root-defaulting under frappe.flags.in_test.
This commit is contained in:
@@ -1,12 +1,8 @@
|
||||
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
||||
# License: GNU General Public License v3. See license.txt
|
||||
|
||||
<<<<<<< HEAD
|
||||
|
||||
import unittest
|
||||
=======
|
||||
from unittest.mock import patch
|
||||
>>>>>>> e7088d8981 (fix: seed standard Item Groups under the existing tree root)
|
||||
|
||||
import frappe
|
||||
from frappe.utils.nestedset import (
|
||||
@@ -240,32 +236,11 @@ class TestItem(unittest.TestCase):
|
||||
"_Test Item Group B - 3",
|
||||
merge=True,
|
||||
)
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
|
||||
def test_preset_records_use_existing_root(self):
|
||||
from erpnext.setup.setup_wizard.operations import install_fixtures
|
||||
|
||||
with patch.object(install_fixtures, "get_root_of", return_value=TRANSLATED_ROOT):
|
||||
records = [
|
||||
r for r in install_fixtures.get_preset_records("India") if r["doctype"] == "Item Group"
|
||||
]
|
||||
|
||||
root_record, *child_records = records
|
||||
self.assertEqual(root_record["item_group_name"], TRANSLATED_ROOT)
|
||||
self.assertTrue(root_record["__condition"]())
|
||||
self.assertEqual({r["parent_item_group"] for r in child_records}, {TRANSLATED_ROOT})
|
||||
|
||||
with patch.object(install_fixtures, "get_root_of", return_value="All Item Groups"):
|
||||
root_record = next(
|
||||
r for r in install_fixtures.get_preset_records("India") if r["doctype"] == "Item Group"
|
||||
)
|
||||
self.assertFalse(root_record["__condition"]())
|
||||
|
||||
def test_patch_merges_seeded_root_into_existing_root(self):
|
||||
from erpnext.patches.v16_0.merge_seeded_item_group_root import execute
|
||||
|
||||
self._nest_root_under(TRANSLATED_ROOT)
|
||||
self.nest_root_under(TRANSLATED_ROOT)
|
||||
self.assertEqual(
|
||||
frappe.db.get_value("Item Group", "All Item Groups", "parent_item_group"), TRANSLATED_ROOT
|
||||
)
|
||||
@@ -273,40 +248,34 @@ class TestItem(unittest.TestCase):
|
||||
execute()
|
||||
|
||||
self.assertFalse(frappe.db.exists("Item Group", "All Item Groups"))
|
||||
self.assertEqual(
|
||||
frappe.get_all("Item Group", filters={"parent_item_group": ("is", "not set")}, pluck="name"),
|
||||
[TRANSLATED_ROOT],
|
||||
)
|
||||
self.assertEqual(self.get_root_names(), [TRANSLATED_ROOT])
|
||||
self.assertEqual(
|
||||
frappe.db.get_value("Item Group", "_Test Item Group B", "parent_item_group"), TRANSLATED_ROOT
|
||||
)
|
||||
self.test_basic_tree()
|
||||
|
||||
def _nest_root_under(self, new_root):
|
||||
# restore the original root name for the tests that follow
|
||||
frappe.rename_doc("Item Group", TRANSLATED_ROOT, "All Item Groups")
|
||||
self.assertEqual(self.get_root_names(), ["All Item Groups"])
|
||||
self.test_basic_tree()
|
||||
|
||||
def nest_root_under(self, new_root):
|
||||
"""Recreate the tree left behind by seeding a root under a pre-existing one."""
|
||||
frappe.get_doc({"doctype": "Item Group", "item_group_name": new_root, "is_group": 1}).insert()
|
||||
frappe.get_doc(
|
||||
{
|
||||
"doctype": "Item Group",
|
||||
"item_group_name": new_root,
|
||||
"is_group": 1,
|
||||
"parent_item_group": "All Item Groups",
|
||||
}
|
||||
).insert()
|
||||
|
||||
ig = frappe.qb.DocType("Item Group")
|
||||
frappe.qb.update(ig).set(ig.parent_item_group, "").where(ig.name == new_root).run()
|
||||
frappe.qb.update(ig).set(ig.parent_item_group, new_root).where(ig.name == "All Item Groups").run()
|
||||
rebuild_tree("Item Group")
|
||||
rebuild_tree("Item Group", "parent_item_group")
|
||||
|
||||
def _move_it_back(self):
|
||||
group_b = frappe.get_doc("Item Group", "_Test Item Group B")
|
||||
group_b.parent_item_group = "All Item Groups"
|
||||
group_b.save()
|
||||
self.test_basic_tree()
|
||||
|
||||
def _get_no_of_children(self, item_group):
|
||||
def get_no_of_children(item_groups, no_of_children):
|
||||
children = []
|
||||
for ig in item_groups:
|
||||
children += frappe.get_all("Item Group", filters={"parent_item_group": ig}, pluck="name")
|
||||
|
||||
if len(children):
|
||||
return get_no_of_children(children, no_of_children + len(children))
|
||||
else:
|
||||
return no_of_children
|
||||
|
||||
return get_no_of_children([item_group], 0)
|
||||
>>>>>>> e7088d8981 (fix: seed standard Item Groups under the existing tree root)
|
||||
def get_root_names(self):
|
||||
return frappe.db.sql_list(
|
||||
"""select name from `tabItem Group` where ifnull(parent_item_group, '')=''"""
|
||||
)
|
||||
|
||||
@@ -24,12 +24,8 @@ def read_lines(filename: str) -> list[str]:
|
||||
return (Path(__file__).parent.parent / "data" / filename).read_text().splitlines()
|
||||
|
||||
|
||||
<<<<<<< HEAD
|
||||
def install(country=None):
|
||||
=======
|
||||
def get_preset_records(country=None):
|
||||
root_item_group = get_root_of("Item Group") or _("All Item Groups")
|
||||
>>>>>>> e7088d8981 (fix: seed standard Item Groups under the existing tree root)
|
||||
records = [
|
||||
# ensure at least an empty Address Template exists for this Country
|
||||
{"doctype": "Address Template", "country": country},
|
||||
|
||||
Reference in New Issue
Block a user