Merge pull request #57389 from mihir-kandoi/fix/translated-default-record-lookups

fix: do not translate default record lookup keys
This commit is contained in:
Mihir Kandoi
2026-07-23 13:06:35 +05:30
committed by GitHub
4 changed files with 47 additions and 19 deletions

View File

@@ -459,11 +459,11 @@ def make_return_doc(doctype: str, source_name: str, target_doc=None, return_agai
# look for Print Heading "Credit Note"
if not doc.select_print_heading:
doc.select_print_heading = frappe.get_cached_value("Print Heading", _("Credit Note"))
doc.select_print_heading = frappe.get_cached_value("Print Heading", "Credit Note")
elif doctype == "Purchase Invoice":
# look for Print Heading "Debit Note"
doc.select_print_heading = frappe.get_cached_value("Print Heading", _("Debit Note"))
doc.select_print_heading = frappe.get_cached_value("Print Heading", "Debit Note")
elif doctype == "Delivery Note":
# manual additions to the return should hit the return warehous, too
doc.set_warehouse = default_warehouse_for_sales_return

View File

@@ -23,7 +23,7 @@ from frappe.utils import (
nowdate,
today,
)
from frappe.utils.nestedset import NestedSet, rebuild_tree
from frappe.utils.nestedset import NestedSet, get_root_of, rebuild_tree
from erpnext.accounts.doctype.account.account import get_account_currency
from erpnext.accounts.doctype.financial_report_template.financial_report_template import (
@@ -501,91 +501,92 @@ class Company(NestedSet):
)
def create_default_departments(self):
root = get_root_of("Department") or "All Departments"
records = [
# Department
{
"doctype": "Department",
"department_name": _("All Departments"),
"department_name": root,
"is_group": 1,
"parent_department": "",
"__condition": lambda: not frappe.db.exists("Department", _("All Departments")),
"__condition": lambda: not frappe.db.exists("Department", root),
},
{
"doctype": "Department",
"department_name": _("Accounts"),
"parent_department": _("All Departments"),
"parent_department": root,
"company": self.name,
},
{
"doctype": "Department",
"department_name": _("Marketing"),
"parent_department": _("All Departments"),
"parent_department": root,
"company": self.name,
},
{
"doctype": "Department",
"department_name": _("Sales"),
"parent_department": _("All Departments"),
"parent_department": root,
"company": self.name,
},
{
"doctype": "Department",
"department_name": _("Purchase"),
"parent_department": _("All Departments"),
"parent_department": root,
"company": self.name,
},
{
"doctype": "Department",
"department_name": _("Operations"),
"parent_department": _("All Departments"),
"parent_department": root,
"company": self.name,
},
{
"doctype": "Department",
"department_name": _("Production"),
"parent_department": _("All Departments"),
"parent_department": root,
"company": self.name,
},
{
"doctype": "Department",
"department_name": _("Dispatch"),
"parent_department": _("All Departments"),
"parent_department": root,
"company": self.name,
},
{
"doctype": "Department",
"department_name": _("Customer Service"),
"parent_department": _("All Departments"),
"parent_department": root,
"company": self.name,
},
{
"doctype": "Department",
"department_name": _("Human Resources"),
"parent_department": _("All Departments"),
"parent_department": root,
"company": self.name,
},
{
"doctype": "Department",
"department_name": _("Management"),
"parent_department": _("All Departments"),
"parent_department": root,
"company": self.name,
},
{
"doctype": "Department",
"department_name": _("Quality Management"),
"parent_department": _("All Departments"),
"parent_department": root,
"company": self.name,
},
{
"doctype": "Department",
"department_name": _("Research & Development"),
"parent_department": _("All Departments"),
"parent_department": root,
"company": self.name,
},
{
"doctype": "Department",
"department_name": _("Legal"),
"parent_department": _("All Departments"),
"parent_department": root,
"company": self.name,
},
]

View File

@@ -1,11 +1,13 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
import json
from unittest.mock import patch
import frappe
from frappe import _
from frappe.query_builder.functions import IfNull
from frappe.utils import random_string
from frappe.utils.nestedset import get_root_of
from erpnext.accounts.doctype.account.chart_of_accounts.chart_of_accounts import (
get_charts_for_country,
@@ -187,6 +189,31 @@ class TestCompany(ERPNextTestSuite):
return get_no_of_children([company], 0)
def test_default_departments_ignore_session_translations(self):
self.assertEqual(get_root_of("Department"), "All Departments")
translations = {"All Departments": "Alle Abteilungen", "Accounts": "Buchhaltung"}
with patch("frappe.translate.get_all_translations", return_value=translations):
company = frappe.new_doc("Company")
company.company_name = "Dept Translation Test Co"
company.abbr = "DTTC"
company.default_currency = "INR"
company.country = "India"
company.insert()
self.assertFalse(frappe.db.exists("Department", "Alle Abteilungen"))
self.assertEqual(
frappe.get_all("Department", filters={"parent_department": ("is", "not set")}, pluck="name"),
["All Departments"],
)
departments = frappe.get_all(
"Department", filters={"company": company.name}, fields=["name", "parent_department"]
)
self.assertTrue(departments)
self.assertEqual({d.parent_department for d in departments}, {"All Departments"})
self.assertIn("Buchhaltung - DTTC", [d.name for d in departments])
def test_change_parent_company(self):
child_company = frappe.get_doc("Company", "_Test Company 5")

View File

@@ -291,7 +291,7 @@ class Item(Document):
if not price_list:
price_list = frappe.get_single_value(
"Selling Settings", "selling_price_list"
) or frappe.db.get_value("Price List", _("Standard Selling"))
) or frappe.db.get_value("Price List", "Standard Selling")
if price_list:
item_price = frappe.get_doc(
{