diff --git a/cypress/integration/control_duration.js b/cypress/integration/control_duration.js index f304abd3d9..edad759216 100644 --- a/cypress/integration/control_duration.js +++ b/cypress/integration/control_duration.js @@ -4,14 +4,14 @@ context('Control Duration', () => { cy.visit('/desk#workspace/Website'); }); - function get_dialog_with_duration(show_days=1, show_seconds=1) { + function get_dialog_with_duration(hide_days=0, hide_seconds=0) { return cy.dialog({ title: 'Duration', fields: [{ 'fieldname': 'duration', 'fieldtype': 'Duration', - 'show_seconds': show_days, - 'show_days': show_seconds + 'hide_days': hide_days, + 'hide_seconds': hide_seconds }] }); } @@ -37,7 +37,7 @@ context('Control Duration', () => { }); it('should hide days or seconds according to duration options', () => { - get_dialog_with_duration(0, 0).as('dialog'); + get_dialog_with_duration(1, 1).as('dialog'); cy.get('.frappe-control[data-fieldname=duration] input').first().click(); cy.get('.duration-input[data-duration=days]').should('not.be.visible'); cy.get('.duration-input[data-duration=seconds]').should('not.be.visible'); diff --git a/frappe/core/doctype/docfield/docfield.json b/frappe/core/doctype/docfield/docfield.json index 83d3c18453..aab59a5a0a 100644 --- a/frappe/core/doctype/docfield/docfield.json +++ b/frappe/core/doctype/docfield/docfield.json @@ -13,8 +13,8 @@ "fieldname", "precision", "length", - "show_days", - "show_seconds", + "hide_days", + "hide_seconds", "reqd", "search_index", "in_list_view", @@ -453,18 +453,18 @@ "fieldtype": "Column Break" }, { - "default": "1", - "depends_on": "eval:doc.fieldtype === \"Duration\";", - "fieldname": "show_days", + "default": "0", + "depends_on": "eval:doc.fieldtype=='Duration'", + "fieldname": "hide_days", "fieldtype": "Check", - "label": "Show Days" + "label": "Hide Days" }, { - "default": "1", - "depends_on": "eval:doc.fieldtype === \"Duration\";", - "fieldname": "show_seconds", + "default": "0", + "depends_on": "eval:doc.fieldtype=='Duration'", + "fieldname": "hide_seconds", "fieldtype": "Check", - "label": "Show Seconds" + "label": "Hide Seconds" }, { "default": "0", @@ -477,7 +477,7 @@ "idx": 1, "istable": 1, "links": [], - "modified": "2020-05-15 09:06:25.224411", + "modified": "2020-02-06 09:06:25.224413", "modified_by": "Administrator", "module": "Core", "name": "DocField", diff --git a/frappe/custom/doctype/custom_field/custom_field.json b/frappe/custom/doctype/custom_field/custom_field.json index 77490c8c43..6fa7b29161 100644 --- a/frappe/custom/doctype/custom_field/custom_field.json +++ b/frappe/custom/doctype/custom_field/custom_field.json @@ -16,8 +16,8 @@ "column_break_6", "fieldtype", "precision", - "show_seconds", - "show_days", + "hide_seconds", + "hide_days", "options", "fetch_from", "fetch_if_empty", @@ -383,22 +383,18 @@ "label": "In Preview" }, { - "default": "1", - "depends_on": "eval:doc.fieldtype === \"Duration\";", - "fieldname": "show_seconds", + "default": "0", + "depends_on": "eval:doc.fieldtype=='Duration'", + "fieldname": "hide_seconds", "fieldtype": "Check", - "label": "Show Seconds", - "show_days": 1, - "show_seconds": 1 + "label": "Hide Seconds" }, { - "default": "1", - "depends_on": "eval:doc.fieldtype === \"Duration\";", - "fieldname": "show_days", + "default": "0", + "depends_on": "eval:doc.fieldtype=='Duration'", + "fieldname": "hide_days", "fieldtype": "Check", - "label": "Show Days", - "show_days": 1, - "show_seconds": 1 + "label": "Hide Days" }, { "default": "0", @@ -411,7 +407,7 @@ "icon": "fa fa-glass", "idx": 1, "links": [], - "modified": "2020-05-15 23:43:00.123572", + "modified": "2020-02-06 23:43:00.123575", "modified_by": "Administrator", "module": "Custom", "name": "Custom Field", diff --git a/frappe/custom/doctype/customize_form_field/customize_form_field.json b/frappe/custom/doctype/customize_form_field/customize_form_field.json index f422c36e61..267213517c 100644 --- a/frappe/custom/doctype/customize_form_field/customize_form_field.json +++ b/frappe/custom/doctype/customize_form_field/customize_form_field.json @@ -11,8 +11,8 @@ "label", "fieldtype", "fieldname", - "show_seconds", - "show_days", + "hide_seconds", + "hide_days", "reqd", "unique", "in_list_view", @@ -393,22 +393,18 @@ "label": "In Preview" }, { - "default": "1", - "depends_on": "eval:doc.fieldtype === \"Duration\";", - "fieldname": "show_seconds", + "default": "0", + "depends_on": "eval:doc.fieldtype=='Duration'", + "fieldname": "hide_seconds", "fieldtype": "Check", - "label": "Show Seconds", - "show_days": 1, - "show_seconds": 1 + "label": "Hide Seconds" }, { - "default": "1", - "depends_on": "eval:doc.fieldtype === \"Duration\";", - "fieldname": "show_days", + "default": "0", + "depends_on": "eval:doc.fieldtype=='Duration'", + "fieldname": "hide_days", "fieldtype": "Check", - "label": "Show Days", - "show_days": 1, - "show_seconds": 1 + "label": "Hide Days" }, { "default": "0", @@ -421,7 +417,7 @@ "idx": 1, "istable": 1, "links": [], - "modified": "2020-05-15 23:45:46.810869", + "modified": "2020-06-02 23:45:46.810868", "modified_by": "Administrator", "module": "Custom", "name": "Customize Form Field", diff --git a/frappe/public/js/frappe/form/controls/duration.js b/frappe/public/js/frappe/form/controls/duration.js index 58df8e15e6..e70afd6e65 100644 --- a/frappe/public/js/frappe/form/controls/duration.js +++ b/frappe/public/js/frappe/form/controls/duration.js @@ -13,10 +13,10 @@ frappe.ui.form.ControlDuration = frappe.ui.form.ControlData.extend({ ` ); this.$wrapper.append(this.$picker); - this.build_numeric_input("days", !this.duration_options.show_days); + this.build_numeric_input("days", this.duration_options.hide_days); this.build_numeric_input("hours", false); this.build_numeric_input("minutes", false); - this.build_numeric_input("seconds", !this.duration_options.show_seconds); + this.build_numeric_input("seconds", this.duration_options.hide_seconds); this.set_duration_picker_value(this.value); this.$picker.hide(); this.bind_events(); @@ -130,10 +130,10 @@ frappe.ui.form.ControlDuration = frappe.ui.form.ControlData.extend({ if (this.inputs) { total_duration.minutes = parseInt(this.inputs.minutes.val()); total_duration.hours = parseInt(this.inputs.hours.val()); - if (this.duration_options.show_days) { + if (!this.duration_options.hide_days) { total_duration.days = parseInt(this.inputs.days.val()); } - if (this.duration_options.show_seconds) { + if (!this.duration_options.hide_seconds) { total_duration.seconds = parseInt(this.inputs.seconds.val()); } } diff --git a/frappe/public/js/frappe/ui/filters/filters.js b/frappe/public/js/frappe/ui/filters/filters.js index f8f0535b83..a775413d39 100644 --- a/frappe/public/js/frappe/ui/filters/filters.js +++ b/frappe/public/js/frappe/ui/filters/filters.js @@ -202,8 +202,8 @@ frappe.ui.FilterList = Class.extend({ value = {0:"No", 1:"Yes"}[cint(value)]; } else if (field.df.original_type === "Duration") { let duration_options = { - show_days: field.df.show_days, - show_seconds: field.df.show_seconds + hide_days: field.df.hide_days, + hide_seconds: field.df.hide_seconds }; value = frappe.utils.get_formatted_duration(value, duration_options); } diff --git a/frappe/public/js/frappe/utils/utils.js b/frappe/public/js/frappe/utils/utils.js index f4dde5804f..38c22c9c9f 100644 --- a/frappe/public/js/frappe/utils/utils.js +++ b/frappe/public/js/frappe/utils/utils.js @@ -856,7 +856,7 @@ Object.assign(frappe.utils, { minutes: Math.floor(secs % 3600 / 60), seconds: Math.floor(secs % 60) }; - if (!duration_options.show_days) { + if (duration_options.hide_days) { total_duration.hours = Math.floor(secs / 3600); total_duration.days = 0; } @@ -882,8 +882,8 @@ Object.assign(frappe.utils, { get_duration_options: function(docfield) { let duration_options = { - show_days: docfield.show_days, - show_seconds: docfield.show_seconds + hide_days: docfield.hide_days, + hide_seconds: docfield.hide_seconds }; return duration_options; } diff --git a/frappe/utils/data.py b/frappe/utils/data.py index 1a4604ffff..a046aca144 100644 --- a/frappe/utils/data.py +++ b/frappe/utils/data.py @@ -336,7 +336,7 @@ def format_datetime(datetime_string, format_string=None): formatted_datetime = datetime.strftime('%Y-%m-%d %H:%M:%S') return formatted_datetime -def format_duration(seconds, show_days=True): +def format_duration(seconds, hide_days=False): total_duration = { 'days': math.floor(seconds / (3600 * 24)), 'hours': math.floor(seconds % (3600 * 24) / 3600), @@ -344,7 +344,7 @@ def format_duration(seconds, show_days=True): 'seconds': math.floor(seconds % 60) } - if not show_days: + if hide_days: total_duration['hours'] = math.floor(seconds / 3600) total_duration['days'] = 0 diff --git a/frappe/utils/formatters.py b/frappe/utils/formatters.py index d7646eeb71..d68102ae9e 100644 --- a/frappe/utils/formatters.py +++ b/frappe/utils/formatters.py @@ -91,7 +91,7 @@ def format_value(value, df=None, doc=None, currency=None, translated=False): return ', '.join(values) elif df.get("fieldtype") == "Duration": - show_days = df.show_days - return format_duration(value, show_days) + hide_days = df.hide_days + return format_duration(value, hide_days) return value