Merge branch 'develop' into re-delete-after-deleting-dependent-doc

This commit is contained in:
Shariq Ansari 2023-06-14 12:18:26 +05:30 committed by GitHub
commit cc1e89c2f6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 96 additions and 37 deletions

View file

@ -141,11 +141,18 @@ jobs:
update_to_version 14
echo "Updating to last commit"
git checkout -q -f "$GITHUB_SHA"
rm -rf ~/frappe-bench/env
git checkout -q -f "$GITHUB_SHA"
bench -v setup env
bench --site test_site migrate
- name: Show bench output
if: ${{ always() }}
run: cat ~/frappe-bench/bench_start.log || true
run: |
cd ~/frappe-bench
cat bench_start.log || true
cd logs
for f in ./*.log*; do
echo "Printing log: $f";
cat $f
done

View file

@ -236,6 +236,13 @@ class File(Document):
):
return
if frappe.get_meta(self.attached_to_doctype).issingle:
frappe.db.set_single_value(
self.attached_to_doctype,
self.attached_to_field,
self.file_url,
)
else:
frappe.db.set_value(
self.attached_to_doctype,
self.attached_to_name,

View file

@ -81,6 +81,14 @@ class ToDo(Document):
)
assignments.reverse()
if frappe.get_meta(self.reference_type).issingle:
frappe.db.set_single_value(
self.reference_type,
"_assign",
json.dumps(assignments),
update_modified=False,
)
else:
frappe.db.set_value(
self.reference_type,
self.reference_name,

View file

@ -52,6 +52,9 @@ def _toggle_like(doctype, name, add, user=None):
liked_by.remove(user)
remove_like(doctype, name)
if frappe.get_meta(doctype).issingle:
frappe.db.set_single_value(doctype, "_liked_by", json.dumps(liked_by), update_modified=False)
else:
frappe.db.set_value(doctype, name, "_liked_by", json.dumps(liked_by), update_modified=False)
except frappe.db.ProgrammingError as e:

View file

@ -646,6 +646,9 @@ class BaseDocument:
def update_modified(self):
"""Update modified timestamp"""
self.set("modified", now())
if getattr(self.meta, "issingle", False):
frappe.db.set_single_value(self.doctype, "modified", self.modified, update_modified=False)
else:
frappe.db.set_value(self.doctype, self.name, "modified", self.modified, update_modified=False)
def _fix_numeric_types(self):

View file

@ -1123,7 +1123,7 @@ class Document(BaseDocument):
def reset_seen(self):
"""Clear _seen property and set current user as seen"""
if getattr(self.meta, "track_seen", False):
if getattr(self.meta, "track_seen", False) and not getattr(self.meta, "issingle", False):
frappe.db.set_value(
self.doctype, self.name, "_seen", json.dumps([frappe.session.user]), update_modified=False
)
@ -1182,6 +1182,16 @@ class Document(BaseDocument):
if self.name is None:
return
if self.meta.issingle:
frappe.db.set_single_value(
self.doctype,
fieldname,
value,
modified=self.modified,
modified_by=self.modified_by,
update_modified=update_modified,
)
else:
frappe.db.set_value(
self.doctype,
self.name,
@ -1375,7 +1385,7 @@ class Document(BaseDocument):
if not user:
user = frappe.session.user
if self.meta.track_seen and not frappe.flags.read_only:
if self.meta.track_seen and not frappe.flags.read_only and not self.meta.issingle:
_seen = self.get("_seen") or []
_seen = frappe.parse_json(_seen)

View file

@ -963,7 +963,17 @@ export default class GridRow {
}
var col = this;
let first_input_field = $(col).find('input[type="Text"]:first');
first_input_field.trigger("focus");
let input_in_focus = false;
$(col)
.find("input[type='text']")
.each(function () {
if ($(this).is(":focus")) {
input_in_focus = true;
}
});
!input_in_focus && first_input_field.trigger("focus");
if (event.pointerType == "touch") {
first_input_field.length && on_input_focus(first_input_field);

View file

@ -23,16 +23,23 @@ class TestAssign(FrappeTestCase):
if not frappe.db.exists("User", "test@example.com"):
frappe.get_doc({"doctype": "User", "email": "test@example.com", "first_name": "Test"}).insert()
added = assign(todo, "test@example.com")
self._test_basic_assign_on_document(todo)
def _test_basic_assign_on_document(self, doc):
added = assign(doc, "test@example.com")
self.assertTrue("test@example.com" in [d.owner for d in added])
frappe.desk.form.assign_to.remove(todo.doctype, todo.name, "test@example.com")
frappe.desk.form.assign_to.remove(doc.doctype, doc.name, "test@example.com")
# assignment is cleared
assignments = frappe.desk.form.assign_to.get(dict(doctype=todo.doctype, name=todo.name))
assignments = frappe.desk.form.assign_to.get(dict(doctype=doc.doctype, name=doc.name))
self.assertEqual(len(assignments), 0)
def test_assign_single(self):
c = frappe.get_doc("Contact Us Settings")
self._test_basic_assign_on_document(c)
def test_assignment_count(self):
frappe.db.delete("ToDo")

View file

@ -452,6 +452,13 @@ class TestDocument(FrappeTestCase):
frappe.exceptions.InvalidDates, doc.validate_from_to_dates, "start_date", "end_date"
)
def test_db_set_singles(self):
c = frappe.get_doc("Contact Us Settings")
key, val = "email_id", "admin1@example.com"
c.db_set(key, val)
changed_val = frappe.db.get_single_value(c.doctype, key)
self.assertEqual(val, changed_val)
class TestDocumentWebView(FrappeTestCase):
def get(self, path, user="Guest"):

View file

@ -17,10 +17,7 @@ class RedisQueue:
@classmethod
def get_connection(cls, username=None, password=None):
rq_url = frappe.local.conf.redis_queue
domain = rq_url.split("redis://", 1)[-1]
url = (username and f"redis://{username}:{password or ''}@{domain}") or rq_url
conn = redis.from_url(url)
conn = redis.from_url(frappe.conf.redis_queue, username=username, password=password)
conn.ping()
return conn