diff --git a/frappe/core/doctype/translation/translation.py b/frappe/core/doctype/translation/translation.py index a285806589..c8226db5b0 100644 --- a/frappe/core/doctype/translation/translation.py +++ b/frappe/core/doctype/translation/translation.py @@ -23,70 +23,6 @@ class Translation(Document): def on_trash(self): clear_user_translation_cache(self.language) - def contribute(self): - pass - - def get_contribution_status(self): - pass - - -@frappe.whitelist() -def create_translations(translation_map, language): - from frappe.frappeclient import FrappeClient - - translation_map = json.loads(translation_map) - translation_map_to_send = frappe._dict({}) - # first create / update local user translations - for source_id, translation_dict in translation_map.items(): - translation_dict = frappe._dict(translation_dict) - existing_doc_name = frappe.get_all( - "Translation", - { - "source_text": translation_dict.source_text, - "context": translation_dict.context or "", - "language": language, - }, - ) - translation_map_to_send[source_id] = translation_dict - if existing_doc_name: - frappe.db.set_value( - "Translation", - existing_doc_name[0].name, - { - "translated_text": translation_dict.translated_text, - "contributed": 1, - "contribution_status": "Pending", - }, - ) - translation_map_to_send[source_id].name = existing_doc_name[0].name - else: - doc = frappe.get_doc( - { - "doctype": "Translation", - "source_text": translation_dict.source_text, - "contributed": 1, - "contribution_status": "Pending", - "translated_text": translation_dict.translated_text, - "context": translation_dict.context, - "language": language, - } - ) - doc.insert() - translation_map_to_send[source_id].name = doc.name - - params = { - "language": language, - "contributor_email": frappe.session.user, - "contributor_name": frappe.utils.get_fullname(frappe.session.user), - "translation_map": json.dumps(translation_map_to_send), - } - - translator = FrappeClient(get_translator_url()) - added_translations = translator.post_api("translator.api.add_translations", params=params) - - for local_docname, remote_docname in added_translations.items(): - frappe.db.set_value("Translation", local_docname, "contribution_docname", remote_docname) - def clear_user_translation_cache(lang): frappe.cache.hdel(USER_TRANSLATION_KEY, lang) diff --git a/frappe/database/database.py b/frappe/database/database.py index 6616592fd7..1f2a1eeba9 100644 --- a/frappe/database/database.py +++ b/frappe/database/database.py @@ -33,6 +33,7 @@ from frappe.query_builder.functions import Count from frappe.utils import CallbackManager from frappe.utils import cast as cast_fieldtype from frappe.utils import cint, get_datetime, get_table_name, getdate, now, sbool +from frappe.utils.deprecations import deprecation_warning IFNULL_PATTERN = re.compile(r"ifnull\(", flags=re.IGNORECASE) INDEX_PATTERN = re.compile(r"\s*\([^)]+\)\s*") @@ -888,6 +889,22 @@ class Database: :param update_modified: default True. Set as false, if you don't want to update the timestamp. :param debug: Print the query in the developer / js console. """ + from frappe.model.utils import is_single_doctype + + if (dn is None or dt == dn) and is_single_doctype(dt): + deprecation_warning( + "Calling db.set_value on single doctype is deprecated. This behaviour will be removed in future. Use db.set_single_value instead." + ) + self.set_single_value( + doctype=dt, + fieldname=field, + value=val, + debug=debug, + update_modified=update_modified, + modified=modified, + modified_by=modified_by, + ) + return to_update = self._get_update_dict( field, val, modified=modified, modified_by=modified_by, update_modified=update_modified diff --git a/frappe/model/utils/__init__.py b/frappe/model/utils/__init__.py index 2935872fc7..f8f5b21de4 100644 --- a/frappe/model/utils/__init__.py +++ b/frappe/model/utils/__init__.py @@ -133,3 +133,13 @@ def is_virtual_doctype(doctype: str): if frappe.db.has_column("DocType", "is_virtual"): return frappe.db.get_value("DocType", doctype, "is_virtual") return False + + +@site_cache() +def is_single_doctype(doctype: str) -> bool: + from frappe.model.base_document import DOCTYPES_FOR_DOCTYPE + + if doctype in DOCTYPES_FOR_DOCTYPE: + return False + + return frappe.db.get_value("DocType", doctype, "issingle") diff --git a/frappe/tests/test_db.py b/frappe/tests/test_db.py index 3d103e3ab5..f026726cfa 100644 --- a/frappe/tests/test_db.py +++ b/frappe/tests/test_db.py @@ -718,6 +718,11 @@ class TestDBSetValue(FrappeTestCase): updated_value = frappe.db.get_value("ToDo", self.todo1.name, "description") self.assertEqual(updated_value, "test_set_value change 1") + @patch("frappe.db.set_single_value") + def test_set_single_value_with_set_value(self, single_set): + frappe.db.set_value("Contact Us Settings", None, "country", "India") + single_set.assert_called_once() + def test_update_single_row_multiple_columns(self): description, status = "Upated by test_update_single_row_multiple_columns", "Closed"