Skip to content

Commit

Permalink
Merge pull request #22770 from frappe/version-14-hotfix
Browse files Browse the repository at this point in the history
chore: release v14
  • Loading branch information
ankush committed Oct 17, 2023
2 parents 330f8c4 + ab5d231 commit 9c68140
Show file tree
Hide file tree
Showing 15 changed files with 206 additions and 24 deletions.
14 changes: 14 additions & 0 deletions frappe/core/doctype/doctype/doctype.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from frappe.cache_manager import clear_controller_cache, clear_user_cache
from frappe.custom.doctype.custom_field.custom_field import create_custom_field
from frappe.custom.doctype.property_setter.property_setter import make_property_setter
from frappe.database import savepoint
from frappe.database.schema import validate_column_length, validate_column_name
from frappe.desk.notifications import delete_notification_count_for, get_filters_for
from frappe.desk.utils import validate_route_conflict
Expand Down Expand Up @@ -408,7 +409,9 @@ def on_update(self):
if self.flags.in_insert:
self.run_module_method("after_doctype_insert")

self.sync_doctype_layouts()
delete_notification_count_for(doctype=self.name)

frappe.clear_cache(doctype=self.name)

# clear user cache so that on the next reload this doctype is included in boot
Expand All @@ -419,6 +422,17 @@ def on_update(self):

clear_linked_doctype_cache()

@savepoint(catch=Exception)
def sync_doctype_layouts(self):
"""Sync Doctype Layout"""
doctype_layouts = frappe.get_all(
"DocType Layout", filters={"document_type": self.name}, pluck="name", ignore_ddl=True
)
for layout in doctype_layouts:
layout_doc = frappe.get_doc("DocType Layout", layout)
layout_doc.sync_fields()
layout_doc.save()

def setup_autoincrement_and_sequence(self):
"""Changes name type and makes sequence on change (if required)"""

Expand Down
2 changes: 1 addition & 1 deletion frappe/custom/doctype/doctype_layout/doctype_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def validate(self):

@frappe.whitelist()
def sync_fields(self):
doctype_fields = frappe.get_meta(self.document_type).fields
doctype_fields = frappe.get_meta(self.document_type, cached=False).fields

if self.is_new():
added_fields = [field.fieldname for field in doctype_fields]
Expand Down
3 changes: 1 addition & 2 deletions frappe/desk/doctype/tag/tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ def add_tags(tags, dt, docs, color=None):
for tag in tags:
DocTags(dt).add(doc, tag)

# return tag


@frappe.whitelist()
def remove_tag(tag, dt, dn):
Expand Down Expand Up @@ -143,6 +141,7 @@ def update_tags(doc, tags):
:param doc: Document to be added to global tags
"""
doc.check_permission("write")
new_tags = {tag.strip() for tag in tags.split(",") if tag}
existing_tags = [
tag.tag
Expand Down
7 changes: 5 additions & 2 deletions frappe/desk/doctype/todo/todo.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,11 @@
"label": "Color"
},
{
"allow_in_quick_entry": 1,
"default": "Today",
"fieldname": "date",
"fieldtype": "Date",
"in_list_view": 1,
"in_standard_filter": 1,
"label": "Due Date",
"oldfieldname": "date",
Expand Down Expand Up @@ -158,7 +161,7 @@
"icon": "fa fa-check",
"idx": 2,
"links": [],
"modified": "2021-09-16 11:36:34.586898",
"modified": "2023-10-05 07:44:38.476400",
"modified_by": "Administrator",
"module": "Desk",
"name": "ToDo",
Expand Down Expand Up @@ -196,4 +199,4 @@
"title_field": "description",
"track_changes": 1,
"track_seen": 1
}
}
13 changes: 11 additions & 2 deletions frappe/desk/query_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ def generate_report_result(
columns, result, message, chart, report_summary, skip_total_row = ljust_list(res, 6)
columns = [get_column_as_dict(col) for col in (columns or [])]
report_column_names = [col["fieldname"] for col in columns]

# convert to list of dicts

result = normalize_result(result, columns)

if report.custom_columns:
Expand Down Expand Up @@ -248,6 +248,14 @@ def run(


def add_custom_column_data(custom_columns, result):
doctype_names_from_custom_field = []
for column in custom_columns:
if len(column["fieldname"].split("-")) > 1:
# length greater than 1, means that the column is a custom field with confilicting fieldname
doctype_name = frappe.unscrub(column["fieldname"].split("-")[1])
doctype_names_from_custom_field.append(doctype_name)
column["fieldname"] = column["fieldname"].split("-")[0]

custom_column_data = get_data_for_custom_report(custom_columns, result)

for column in custom_columns:
Expand All @@ -265,6 +273,8 @@ def add_custom_column_data(custom_columns, result):
# possible if the row is empty
if not row_reference:
continue
if key[0] in doctype_names_from_custom_field:
column["fieldname"] = column.get("id")
row[column.get("fieldname")] = custom_column_data.get(key).get(row_reference)

return result
Expand Down Expand Up @@ -525,7 +535,6 @@ def get_data_for_custom_report(columns, result):
names = list(set(names))

doc_field_value_map[(doctype, fieldname)] = get_data_for_custom_field(doctype, fieldname, names)

return doc_field_value_map


Expand Down
2 changes: 1 addition & 1 deletion frappe/email/doctype/notification/notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ frappe.notification = {
if (frm.doc.channel === "Email") {
receiver_fields = $.map(fields, function (d) {
// Add User and Email fields from child into select dropdown
if (d.fieldtype == "Table") {
if (frappe.model.table_fields.includes(d.fieldtype)) {
let child_fields = frappe.get_doc("DocType", d.options).fields;
return $.map(child_fields, function (df) {
return df.options == "Email" ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ def sync_contacts_from_google_contacts(g_contact):
frappe.publish_realtime(
"import_google_contacts", dict(progress=idx + 1, total=len(results)), user=frappe.session.user
)
# Work-around to fix
# https://github.com/frappe/frappe/issues/22648
if not connection.get("names"):
continue

for name in connection.get("names"):
if name.get("metadata").get("primary"):
Expand Down
2 changes: 1 addition & 1 deletion frappe/public/js/frappe/form/formatters.js
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ frappe.form.get_formatter = function (fieldtype) {

frappe.format = function (value, df, options, doc) {
if (!df) df = { fieldtype: "Data" };
if (df.fieldname == "_user_tags") df.fieldtype = "Tag";
if (df.fieldname == "_user_tags") df = { ...df, fieldtype: "Tag" };
var fieldtype = df.fieldtype || "Data";

// format Dynamic Link as a Link
Expand Down
23 changes: 20 additions & 3 deletions frappe/public/js/frappe/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1606,38 +1606,55 @@ Object.assign(frappe.utils, {
get_filter_as_json(filters) {
// convert filter array to json
let filter = null;

if (filters.length) {
filter = {};
filters.forEach((arr) => {
filter[arr[1]] = [arr[2], arr[3]];
});
filter = JSON.stringify(filter);
}

return filter;
},

process_filter_expression(filter) {
return new Function(`return ${filter}`)();
},

get_filter_from_json(filter_json, doctype) {
// convert json to filter array
if (filter_json) {
if (!filter_json.length) {
return [];
}

const filters_json = new Function(`return ${filter_json}`)();
const filters_json = this.process_filter_expression(filter_json);
if (!doctype) {
// e.g. return {
// priority: (2) ['=', 'Medium'],
// status: (2) ['=', 'Open']
// }

// don't remove unless patch is created to convert all existing filters from object to array
// backward compatibility
if (Array.isArray(filters_json)) {
let filter = {};
filters_json.forEach((arr) => {
filter[arr[1]] = [arr[2], arr[3]];
});
return filter || [];
}
return filters_json || [];
}

// e.g. return [
// ['ToDo', 'status', '=', 'Open', false],
// ['ToDo', 'priority', '=', 'Medium', false]
// ]
if (Array.isArray(filters_json)) {
return filters_json;
}
// don't remove unless patch is created to convert all existing filters from object to array
// backward compatibility
return Object.keys(filters_json).map((filter) => {
let val = filters_json[filter];
return [doctype, filter, val[0], val[1], false];
Expand Down
26 changes: 21 additions & 5 deletions frappe/public/js/frappe/views/reports/query_report.js
Original file line number Diff line number Diff line change
Expand Up @@ -1690,8 +1690,13 @@ frappe.views.QueryReport = class QueryReport extends frappe.views.BaseList {
const insert_after_index = this.columns.findIndex(
(column) => column.label === values.insert_after
);

custom_columns.push({
fieldname: df.fieldname,
fieldname: this.columns
.map((column) => column.fieldname)
.includes(df.fieldname)
? df.fieldname + "-" + frappe.scrub(values.doctype)
: df.fieldname,
fieldtype: df.fieldtype,
label: df.label,
insert_after_index: insert_after_index,
Expand All @@ -1715,12 +1720,11 @@ frappe.views.QueryReport = class QueryReport extends frappe.views.BaseList {
const custom_data = r.message;
const link_field =
this.doctype_field_map[values.doctype].fieldname;

this.add_custom_column(
custom_columns,
custom_data,
link_field,
values.field,
values,
insert_after_index
);
d.hide();
Expand Down Expand Up @@ -1801,13 +1805,25 @@ frappe.views.QueryReport = class QueryReport extends frappe.views.BaseList {
}
}

add_custom_column(custom_column, custom_data, link_field, column_field, insert_after_index) {
add_custom_column(
custom_column,
custom_data,
link_field,
new_column_data,
insert_after_index
) {
const column = this.prepare_columns(custom_column);
const column_field = new_column_data.field;

this.columns.splice(insert_after_index + 1, 0, column[0]);

this.data.forEach((row) => {
row[column_field] = custom_data[row[link_field]];
if (column[0].fieldname.includes("-")) {
row[column_field + "-" + frappe.scrub(new_column_data.doctype)] =
custom_data[row[link_field]];
} else {
row[column_field] = custom_data[row[link_field]];
}
});

this.render_datatable();
Expand Down
1 change: 1 addition & 0 deletions frappe/public/js/frappe/views/reports/report_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ frappe.views.ReportView = class ReportView extends frappe.views.ListView {
this.setup_charts_area();
this.$datatable_wrapper = $('<div class="datatable-wrapper">');
this.$result.append(this.$datatable_wrapper);
this.settings.onload && this.settings.onload(this);
}

setup_charts_area() {
Expand Down
6 changes: 3 additions & 3 deletions frappe/public/js/frappe/widgets/quick_list_widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export default class QuickListWidget extends Widget {
delete this.filter_group;
}

this.filters = frappe.utils.get_filter_from_json(this.quick_list_filter, doctype);
this.filters = frappe.utils.process_filter_expression(this.quick_list_filter);

this.filter_group = new frappe.ui.FilterGroup({
parent: this.dialog.get_field("filter_area").$wrapper,
Expand Down Expand Up @@ -104,7 +104,7 @@ export default class QuickListWidget extends Widget {
primary_action: function () {
let old_filter = me.quick_list_filter;
let filters = me.filter_group.get_filters();
me.quick_list_filter = frappe.utils.get_filter_as_json(filters);
me.quick_list_filter = JSON.parse(filters);

this.hide();

Expand Down Expand Up @@ -203,7 +203,7 @@ export default class QuickListWidget extends Widget {

fields.push("modified");

let quick_list_filter = frappe.utils.get_filter_from_json(this.quick_list_filter);
let quick_list_filter = frappe.utils.process_filter_expression(this.quick_list_filter);

let args = {
method: "frappe.desk.reportview.get",
Expand Down
2 changes: 1 addition & 1 deletion frappe/public/js/frappe/widgets/shortcut_widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export default class ShortcutWidget extends Widget {

this.widget.addClass("shortcut-widget-box");

let filters = frappe.utils.get_filter_from_json(this.stats_filter);
let filters = frappe.utils.process_filter_expression(this.stats_filter);
if (this.type == "DocType" && filters) {
frappe.db
.count(this.link_to, {
Expand Down
4 changes: 2 additions & 2 deletions frappe/public/js/frappe/widgets/widget_dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ class QuickListDialog extends WidgetDialog {
process_data(data) {
if (this.filter_group) {
let filters = this.filter_group.get_filters();
data.quick_list_filter = frappe.utils.get_filter_as_json(filters);
data.quick_list_filter = JSON.stringify(filters);
}

data.label = data.label ? data.label : data.document_type;
Expand Down Expand Up @@ -540,7 +540,7 @@ class ShortcutDialog extends WidgetDialog {
process_data(data) {
if (this.dialog.get_value("type") == "DocType" && this.filter_group) {
let filters = this.filter_group.get_filters();
data.stats_filter = frappe.utils.get_filter_as_json(filters);
data.stats_filter = JSON.stringify(filters);
}

data.label = data.label ? data.label : frappe.model.unscrub(data.link_to);
Expand Down
Loading

0 comments on commit 9c68140

Please sign in to comment.