Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:frappe/frappe into fetch-backups…
Browse files Browse the repository at this point in the history
…-api
  • Loading branch information
gavindsouza committed Jul 23, 2020
2 parents 0ba3fb5 + e43e4eb commit 2c07502
Show file tree
Hide file tree
Showing 48 changed files with 1,235 additions and 1,394 deletions.
1 change: 1 addition & 0 deletions frappe/contacts/address_and_contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ def delete_contact_and_address(doctype, docname):
if len(doc.links)==1:
doc.delete()

@frappe.whitelist()
def filter_dynamic_link_doctypes(doctype, txt, searchfield, start, page_len, filters):
if not txt: txt = ""

Expand Down
16 changes: 9 additions & 7 deletions frappe/contacts/doctype/address/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,23 +230,25 @@ def get_company_address(company):

return ret

@frappe.whitelist()
def address_query(doctype, txt, searchfield, start, page_len, filters):
from frappe.desk.reportview import get_match_cond

link_doctype = filters.pop('link_doctype')
link_name = filters.pop('link_name')

condition = ""
meta = frappe.get_meta("Address")
for fieldname, value in iteritems(filters):
condition += " and {field}={value}".format(
field=fieldname,
value=value
)
if meta.get_field(fieldname) or fieldname in frappe.db.DEFAULT_COLUMNS:
condition += " and {field}={value}".format(
field=fieldname,
value=frappe.db.escape(value))

meta = frappe.get_meta("Address")
searchfields = meta.get_search_fields()

if searchfield:
if searchfield and (meta.get_field(searchfield)\
or searchfield in frappe.db.DEFAULT_COLUMNS):
searchfields.append(searchfield)

search_condition = ''
Expand Down Expand Up @@ -289,4 +291,4 @@ def get_condensed_address(doc):
return ", ".join([doc.get(d) for d in fields if doc.get(d)])

def update_preferred_address(address, field):
frappe.db.set_value('Address', address, field, 0)
frappe.db.set_value('Address', address, field, 0)
16 changes: 6 additions & 10 deletions frappe/contacts/doctype/contact/contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,19 +182,17 @@ def update_contact(doc, method):
contact.flags.ignore_mandatory = True
contact.save(ignore_permissions=True)

@frappe.whitelist()
def contact_query(doctype, txt, searchfield, start, page_len, filters):
from frappe.desk.reportview import get_match_cond

if not frappe.get_meta("Contact").get_field(searchfield)\
or searchfield not in frappe.db.DEFAULT_COLUMNS:
return []

link_doctype = filters.pop('link_doctype')
link_name = filters.pop('link_name')

condition = ""
for fieldname, value in iteritems(filters):
condition += " and {field}={value}".format(
field=fieldname,
value=value
)

return frappe.db.sql("""select
`tabContact`.name, `tabContact`.first_name, `tabContact`.last_name
from
Expand All @@ -209,9 +207,7 @@ def contact_query(doctype, txt, searchfield, start, page_len, filters):
order by
if(locate(%(_txt)s, `tabContact`.name), locate(%(_txt)s, `tabContact`.name), 99999),
`tabContact`.idx desc, `tabContact`.name
limit %(start)s, %(page_len)s """.format(
mcond=get_match_cond(doctype),
key=searchfield), {
limit %(start)s, %(page_len)s """.format(mcond=get_match_cond(doctype), key=searchfield), {
'txt': '%' + txt + '%',
'_txt': txt.replace("%", ""),
'start': start,
Expand Down
2 changes: 1 addition & 1 deletion frappe/core/doctype/communication/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def prepare_to_notify(doc, print_html=None, print_format=None, attachments=None)

if doc.sender:
# combine for sending to get the format 'Jane <[email protected]>'
doc.sender = formataddr([doc.sender_full_name, doc.sender])
doc.sender = get_formatted_email(doc.sender_full_name, mail=doc.sender)

doc.attachments = []

Expand Down
2 changes: 1 addition & 1 deletion frappe/core/doctype/report/report.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
frappe.ui.form.on('Report', {
refresh: function(frm) {
if(!frappe.boot.developer_mode && frappe.session.user !== 'Administrator') {
if (frm.doc.is_standard && !frappe.boot.developer_mode) {
// make the document read-only
frm.set_read_only();
}
Expand Down
19 changes: 13 additions & 6 deletions frappe/core/page/dashboard/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,19 +172,26 @@ class Dashboard {
set_dropdown() {
this.page.clear_menu();

this.page.add_menu_item('Edit...', () => {
this.page.add_menu_item(__('Edit'), () => {
frappe.set_route('Form', 'Dashboard', frappe.dashboard.dashboard_name);
}, 1);
});

this.page.add_menu_item('New...', () => {
this.page.add_menu_item(__('New'), () => {
frappe.new_doc('Dashboard');
}, 1);
});

this.page.add_menu_item(__('Refresh All'), () => {
this.chart_group &&
this.chart_group.widgets_list.forEach(chart => chart.refresh());
this.number_card_group &&
this.number_card_group.widgets_list.forEach(card => card.render_card());
});

frappe.db.get_list("Dashboard").then(dashboards => {
frappe.db.get_list('Dashboard').then(dashboards => {
dashboards.map(dashboard => {
let name = dashboard.name;
if(name != this.dashboard_name){
this.page.add_menu_item(name, () => frappe.set_route("dashboard", name));
this.page.add_menu_item(name, () => frappe.set_route("dashboard", name), 1);
}
});
});
Expand Down
2 changes: 0 additions & 2 deletions frappe/desk/doctype/dashboard/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ frappe.ui.form.on('Dashboard', {
return {
filters: {
is_public: 1,
is_standard: 1,
}
};
});
Expand All @@ -22,7 +21,6 @@ frappe.ui.form.on('Dashboard', {
return {
filters: {
is_public: 1,
is_standard: 1,
}
};
});
Expand Down
62 changes: 12 additions & 50 deletions frappe/desk/doctype/dashboard_chart/dashboard_chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ frappe.ui.form.on('Dashboard Chart', {
frm.set_df_property('x_field', 'options', []);
frm.set_value('filters_json', '{}');
frm.set_value('dynamic_filters_json', '{}');
frm.set_value('use_report_chart', 0);
frm.trigger('set_chart_report_filters');
},

Expand Down Expand Up @@ -175,6 +176,9 @@ frappe.ui.form.on('Dashboard Chart', {

set_chart_field_options: function(frm) {
let filters = frm.doc.filters_json.length > 2 ? JSON.parse(frm.doc.filters_json) : null;
if (frm.doc.dynamic_filters_json && frm.doc.dynamic_filters_json.length > 2) {
filters = frappe.dashboard_utils.get_all_filters(frm.doc);
}
frappe.xcall(
'frappe.desk.query_report.run',
{
Expand All @@ -184,16 +188,13 @@ frappe.ui.form.on('Dashboard Chart', {
}
).then(data => {
frm.report_data = data;
if (!data.chart) {
frm.set_value('is_custom', 0);
frm.set_df_property('is_custom', 'hidden', 1);
} else {
frm.set_df_property('is_custom', 'hidden', 0);
}
let report_has_chart = Boolean(data.chart);

if (!frm.doc.is_custom) {
frm.set_df_property('use_report_chart', 'hidden', !report_has_chart);

if (!frm.doc.use_report_chart) {
if (data.result.length) {
frm.field_options = frappe.report_utils.get_possible_chart_options(data.columns, data);
frm.field_options = frappe.report_utils.get_field_options_from_report(data.columns, data);
frm.set_df_property('x_field', 'options', frm.field_options.non_numeric_fields);
if (!frm.field_options.numeric_fields.length) {
frappe.msgprint(__(`Report has no numeric fields, please change the Report Name`));
Expand Down Expand Up @@ -435,49 +436,10 @@ frappe.ui.form.on('Dashboard Chart', {
frm.trigger('set_dynamic_filters_in_table');

let filters = JSON.parse(frm.doc.filters_json || '[]');
let fields = [
{
fieldtype: 'HTML',
fieldname: 'description',
options:
`<div>
<p>Set dynamic filter values in JavaScript for the required fields here.
</p>
<p>Ex:
<code>frappe.defaults.get_user_default("Company")</code>
</p>
</div>`
}
];

if (is_document_type) {
if (frm.dynamic_filters) {
filters = [...filters, ...frm.dynamic_filters];
}
filters.forEach(f => {
for (let field of fields) {
if (field.fieldname == f[0] + ':' + f[1]) {
return;
}
}
if (f[2] == '=') {
fields.push({
label: `${f[1]} (${f[0]})`,
fieldname: f[0] + ':' + f[1],
fieldtype: 'Data',
});
}
});
} else {
filters = {...frm.dynamic_filters, ...filters};
for (let key of Object.keys(filters)) {
fields.push({
label: key,
fieldname: key,
fieldtype: 'Data',
});
}
}
let fields = frappe.dashboard_utils.get_fields_for_dynamic_filter_dialog(
is_document_type, filters, frm.dynamic_filters
);

frm.dynamic_filter_table.on('click', () => {
let dialog = new frappe.ui.Dialog({
Expand Down
43 changes: 18 additions & 25 deletions frappe/desk/doctype/dashboard_chart/dashboard_chart.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"chart_name",
"chart_type",
"report_name",
"is_custom",
"use_report_chart",
"x_field",
"y_axis",
"source",
Expand Down Expand Up @@ -194,33 +194,27 @@
"label": "To Date"
},
{
"depends_on": "eval:doc.chart_type == 'Report' && doc.report_name && !doc.is_custom",
"depends_on": "eval:doc.chart_type == 'Report' && doc.report_name && !doc.use_report_chart",
"fieldname": "x_field",
"fieldtype": "Select",
"label": "X Field",
"mandatory_depends_on": "eval: doc.report_name && !doc.is_custom"
"mandatory_depends_on": "eval: doc.report_name && !doc.use_report_chart"
},
{
"depends_on": "eval:doc.chart_type === 'Report'",
"fieldname": "report_name",
"fieldtype": "Link",
"label": "Report Name",
"mandatory_depends_on": "eval:doc.chart_type === 'Report'",
"options": "Report",
"set_only_once": 1
},
{
"default": "0",
"depends_on": "eval: doc.report_name",
"fieldname": "is_custom",
"fieldtype": "Check",
"label": "Is Custom"
},
{
"depends_on": "eval:doc.chart_type == 'Report' && doc.report_name && !doc.is_custom",
"depends_on": "eval:doc.chart_type == 'Report' && doc.report_name && !doc.use_report_chart",
"fieldname": "y_axis",
"fieldtype": "Table",
"label": "Y Axis",
"mandatory_depends_on": "eval:doc.report_name && !doc.is_custom",
"mandatory_depends_on": "eval:doc.report_name && !doc.use_report_chart",
"options": "Dashboard Chart Field"
},
{
Expand All @@ -246,38 +240,37 @@
"default": "0",
"fieldname": "is_standard",
"fieldtype": "Check",
"label": "Is Standard",
"show_days": 1,
"show_seconds": 1
"label": "Is Standard"
},
{
"depends_on": "eval: doc.is_standard",
"fieldname": "module",
"fieldtype": "Link",
"label": "Module",
"mandatory_depends_on": "eval: doc.is_standard",
"options": "Module Def",
"show_days": 1,
"show_seconds": 1
"options": "Module Def"
},
{
"fieldname": "dynamic_filters_json",
"fieldtype": "Code",
"label": "Dynamic Filters JSON",
"options": "JSON",
"show_days": 1,
"show_seconds": 1
"options": "JSON"
},
{
"fieldname": "dynamic_filters_section",
"fieldtype": "Section Break",
"label": "Dynamic Filters",
"show_days": 1,
"show_seconds": 1
"label": "Dynamic Filters"
},
{
"default": "0",
"depends_on": "eval: doc.report_name",
"fieldname": "use_report_chart",
"fieldtype": "Check",
"label": "Use Report Chart"
}
],
"links": [],
"modified": "2020-07-10 16:09:47.102062",
"modified": "2020-07-21 16:37:07.763482",
"modified_by": "Administrator",
"module": "Desk",
"name": "Dashboard Chart",
Expand Down
Loading

0 comments on commit 2c07502

Please sign in to comment.