Merge branch 'develop' into fix-update-docfield-property-function

This commit is contained in:
Ahmed Hasanin 2023-03-29 10:21:08 +02:00 committed by GitHub
commit 80f9cfdc78
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 59 additions and 55 deletions

View file

@ -187,18 +187,13 @@ class TestDocShare(FrappeTestCase):
Assigning a document to a user without access must not share the document,
if sharing disabled.
"""
from frappe.desk.form.assign_to import add, get
from frappe.desk.form.assign_to import add
frappe.share.add("Event", self.event.name, self.user, share=1)
frappe.set_user(self.user)
# Assign to 'test1@example.com'
add({"doctype": "Event", "name": self.event.name, "assign_to": ["test1@example.com"]})
# Check if assigned to 'test1@example.com'
assignments = get(dict(doctype="Event", name=self.event.name))
self.assertEqual(len(assignments), 1)
# Check if not shared with 'test1@example.com'
shared_users = [x.user for x in frappe.share.get_users("Event", self.event.name)]
self.assertNotIn("test1@example.com", shared_users)
self.assertRaises(
frappe.ValidationError,
add,
{"doctype": "Event", "name": self.event.name, "assign_to": ["test1@example.com"]},
)

View file

@ -488,6 +488,9 @@ def update_options_for_fieldtype(fieldtype: str, old: str, new: str) -> None:
if frappe.conf.developer_mode:
for name in frappe.get_all("DocField", filters={"options": old}, pluck="parent"):
if name in (old, new):
continue
doctype = frappe.get_doc("DocType", name)
save = False
for f in doctype.fields:
@ -496,11 +499,11 @@ def update_options_for_fieldtype(fieldtype: str, old: str, new: str) -> None:
save = True
if save:
doctype.save()
else:
DocField = frappe.qb.DocType("DocField")
frappe.qb.update(DocField).set(DocField.options, new).where(
(DocField.fieldtype == fieldtype) & (DocField.options == old)
).run()
DocField = frappe.qb.DocType("DocField")
frappe.qb.update(DocField).set(DocField.options, new).where(
(DocField.fieldtype == fieldtype) & (DocField.options == old)
).run()
frappe.qb.update(CustomField).set(CustomField.options, new).where(
(CustomField.fieldtype == fieldtype) & (CustomField.options == old)

View file

@ -1,49 +1,51 @@
<div class="clearfix"></div>
{% for(var i=0, l=contact_list.length; i<l; i++) { %}
{% for(const contact of contact_list) { %}
<div class="address-box">
<p class="h6 flex align-center">
{%= contact_list[i].first_name %} {%= contact_list[i].last_name %}
{% if(contact_list[i].is_primary_contact) { %}
{%= contact.first_name %} {%= contact.last_name %}
{% if(contact.is_primary_contact) { %}
<span class="text-muted">&nbsp;({%= __("Primary") %})</span>
{% } %}
{% if(contact_list[i].designation){ %}
<span class="text-muted">&ndash; {%= contact_list[i].designation %}</span>
{% if(contact.designation){ %}
<span class="text-muted">&ndash; {%= contact.designation %}</span>
{% } %}
<a href="/app/Form/Contact/{%= encodeURIComponent(contact_list[i].name) %}"
<a href="/app/Form/Contact/{%= encodeURIComponent(contact.name) %}"
class="btn btn-xs btn-default ml-auto">
{%= __("Edit") %}
</a>
</p>
{% if (contact_list[i].phones || contact_list[i].email_ids) { %}
{% if (contact.phone || contact.mobile_no || contact.phone_nos.length > 0) { %}
<p>
{% if(contact_list[i].phone) { %}
{%= __("Phone") %}: {%= contact_list[i].phone %}<span class="text-muted"> ({%= __("Primary") %})</span><br>
{% if(contact.phone) { %}
<a href="tel:{%= frappe.utils.escape_html(contact.phone) %}">{%= frappe.utils.escape_html(contact.phone) %}</a> &#183; <span class="text-muted">{%= __("Primary Phone") %}</span><br>
{% endif %}
{% if(contact_list[i].mobile_no) { %}
{%= __("Mobile No") %}: {%= contact_list[i].mobile_no %}<span class="text-muted"> ({%= __("Primary") %})</span><br>
{% if(contact.mobile_no) { %}
<a href="tel:{%= frappe.utils.escape_html(contact.mobile_no) %}">{%= frappe.utils.escape_html(contact.mobile_no) %}</a> &#183; <span class="text-muted">{%= __("Primary Mobile") %}</span><br>
{% endif %}
{% if(contact_list[i].phone_nos) { %}
{% for(var j=0, k=contact_list[i].phone_nos.length; j<k; j++) { %}
{%= __("Phone") %}: {%= contact_list[i].phone_nos[j].phone %}<br>
{% } %}
{% endif %}
</p>
<p>
{% if(contact_list[i].email_id) { %}
{%= __("Email") %}: {%= contact_list[i].email_id %}<span class="text-muted"> ({%= __("Primary") %})</span><br>
{% endif %}
{% if(contact_list[i].email_ids) { %}
{% for(var j=0, k=contact_list[i].email_ids.length; j<k; j++) { %}
{%= __("Email") %}: {%= contact_list[i].email_ids[j].email_id %}<br>
{% if(contact.phone_nos) { %}
{% for(const phone_no of contact.phone_nos) { %}
<a href="tel:{%= frappe.utils.escape_html(phone_no.phone) %}">{%= frappe.utils.escape_html(phone_no.phone) %}</a><br>
{% } %}
{% endif %}
</p>
{% endif %}
{% if (contact.email_id || contact.email_ids.length > 0) { %}
<p>
{% if (contact_list[i].address) { %}
{%= __("Address") %}: {%= contact_list[i].address %}<br>
{% endif %}
{% if(contact.email_id) { %}
<a href="mailto:{%= frappe.utils.escape_html(contact.email_id) %}">{%= frappe.utils.escape_html(contact.email_id) %}</a> &#183; <span class="text-muted">{%= __("Primary Email") %}</span><br>
{% endif %}
{% if(contact.email_ids) { %}
{% for(const email_id of contact.email_ids) { %}
<a href="mailto:{%= frappe.utils.escape_html(email_id.email_id) %}">{%= frappe.utils.escape_html(email_id.email_id) %}</a><br>
{% } %}
{% endif %}
</p>
{% endif %}
{% if (contact.address) { %}
<p>
{%= contact.address %}
</p>
{% endif %}
</div>
{% } %}
{% if(!contact_list.length) { %}
@ -51,4 +53,4 @@
{% } %}
<p><button class="btn btn-xs btn-default btn-contact">
{{ __("New Contact") }}</button>
</p>
</p>

View file

@ -8,6 +8,7 @@ from frappe.core.doctype.doctype.test_doctype import new_doctype
from frappe.query_builder import Field
from frappe.query_builder.functions import Max
from frappe.tests.utils import FrappeTestCase
from frappe.utils import random_string
from frappe.utils.nestedset import (
NestedSetChildExistsError,
NestedSetInvalidMergeError,
@ -213,6 +214,12 @@ class TestNestedSet(FrappeTestCase):
remove_subtree("Test Tree DocType", "Parent 2")
self.test_basic_tree()
def test_rename_nestedset(self):
doctype = new_doctype(is_tree=True).insert()
# Rename doctype
frappe.rename_doc("DocType", doctype.name, "Test " + random_string(10), force=True)
def test_merge_groups(self):
global records
el = {"some_fieldname": "Parent 2", "parent_test_tree_doctype": "Root Node", "is_group": 1}

View file

@ -9,14 +9,9 @@ from unittest.mock import patch
import frappe
from frappe.core.doctype.doctype.test_doctype import new_doctype
from frappe.exceptions import DoesNotExistError, ValidationError
from frappe.exceptions import DoesNotExistError
from frappe.model.base_document import get_controller
from frappe.model.rename_doc import (
bulk_rename,
get_fetch_fields,
update_document_title,
update_linked_doctypes,
)
from frappe.model.rename_doc import bulk_rename, update_document_title
from frappe.modules.utils import get_doc_path
from frappe.tests.utils import FrappeTestCase
from frappe.utils import add_to_date, now
@ -255,14 +250,16 @@ class TestRenameDoc(FrappeTestCase):
)
def test_deprecated_utils(self):
from frappe.model.rename_doc import get_fetch_fields, update_linked_doctypes
stdout = StringIO()
with redirect_stdout(stdout), patch_db(["set_value"]):
get_fetch_fields("User", "ToDo", ["Activity Log"])
self.assertTrue("Function frappe.model.rename_doc.get_fetch_fields" in stdout.getvalue())
self.assertIn("Function frappe.model.rename_doc.get_fetch_fields", stdout.getvalue())
update_linked_doctypes("User", "ToDo", "str", "str")
self.assertTrue("Function frappe.model.rename_doc.update_linked_doctypes" in stdout.getvalue())
self.assertIn("Function frappe.model.rename_doc.update_linked_doctypes", stdout.getvalue())
def test_doc_rename_method(self):
name = choice(self.available_documents)

View file

@ -143,7 +143,7 @@ def change_settings(doctype, settings_dict):
# change setting
for key, value in settings_dict.items():
setattr(settings, key, value)
settings.save()
settings.save(ignore_permissions=True)
# singles are cached by default, clear to avoid flake
frappe.db.value_cache[settings] = {}
yield # yield control to calling function
@ -153,7 +153,7 @@ def change_settings(doctype, settings_dict):
settings = frappe.get_doc(doctype)
for key, value in previous_settings.items():
setattr(settings, key, value)
settings.save()
settings.save(ignore_permissions=True)
def timeout(seconds=30, error_message="Test timed out."):