From c822c54f558383f2f7c92a688d3db8b198aa2bb8 Mon Sep 17 00:00:00 2001 From: hasnain2808 Date: Wed, 12 May 2021 17:03:25 +0530 Subject: [PATCH 01/14] fix: allow updating naming series --- .../document_naming_rule.js | 41 +++++++++++++++++++ .../document_naming_rule.py | 5 +++ 2 files changed, 46 insertions(+) diff --git a/frappe/core/doctype/document_naming_rule/document_naming_rule.js b/frappe/core/doctype/document_naming_rule/document_naming_rule.js index 56b5c2fdf4..dcb60cd7d5 100644 --- a/frappe/core/doctype/document_naming_rule/document_naming_rule.js +++ b/frappe/core/doctype/document_naming_rule/document_naming_rule.js @@ -4,6 +4,7 @@ frappe.ui.form.on('Document Naming Rule', { refresh: function(frm) { frm.trigger('document_type'); + frm.trigger("add_button") }, document_type: (frm) => { // update the select field options with fieldnames @@ -20,5 +21,45 @@ frappe.ui.form.on('Document Naming Rule', { ); }); } + }, + add_button: (frm) => { + frm.add_custom_button(__('Update Counter'), function() { + + const fields = [{ + fieldtype: 'Data', + fieldname: 'new_counter', + label: __('New Counter'), + default: frm.doc.counter, + reqd: 1, + description: __('This will update the counter and will affect all documents that will be created') + }] + + let primary_action_label = __('Save'); + + let primary_action = (fields) => { + debugger + frappe.call({ + method: 'frappe.core.doctype.document_naming_rule.document_naming_rule.update_current', + args: { + name: frm.doc.name, + new_counter: fields.new_counter + }, + callback: function() { + frm.set_value("counter", fields.new_counter) + dialog.hide() + } + }) + }; + + var dialog = new frappe.ui.Dialog({ + title: __('Update Counter Value for Prefix: ' + frm.doc.prefix), + fields, + primary_action_label, + primary_action + }); + + dialog.show() + + }); } }); diff --git a/frappe/core/doctype/document_naming_rule/document_naming_rule.py b/frappe/core/doctype/document_naming_rule/document_naming_rule.py index 4b34293af6..13d54dffdd 100644 --- a/frappe/core/doctype/document_naming_rule/document_naming_rule.py +++ b/frappe/core/doctype/document_naming_rule/document_naming_rule.py @@ -30,3 +30,8 @@ class DocumentNamingRule(Document): counter = frappe.db.get_value(self.doctype, self.name, 'counter', for_update=True) or 0 doc.name = self.prefix + ('%0'+str(self.prefix_digits)+'d') % (counter + 1) frappe.db.set_value(self.doctype, self.name, 'counter', counter + 1) + +@frappe.whitelist() +def update_current(name, new_counter): + frappe.db.set_value('Document Naming Rule', name, 'counter', new_counter) + frappe.db.commit() From c246c82a85d8a83fc71193905bf75febef89634a Mon Sep 17 00:00:00 2001 From: Mohammad Hasnain Mohsin Rajan Date: Wed, 12 May 2021 17:10:35 +0530 Subject: [PATCH 02/14] fix: remove debugger --- frappe/core/doctype/document_naming_rule/document_naming_rule.js | 1 - 1 file changed, 1 deletion(-) diff --git a/frappe/core/doctype/document_naming_rule/document_naming_rule.js b/frappe/core/doctype/document_naming_rule/document_naming_rule.js index dcb60cd7d5..5d1540588d 100644 --- a/frappe/core/doctype/document_naming_rule/document_naming_rule.js +++ b/frappe/core/doctype/document_naming_rule/document_naming_rule.js @@ -37,7 +37,6 @@ frappe.ui.form.on('Document Naming Rule', { let primary_action_label = __('Save'); let primary_action = (fields) => { - debugger frappe.call({ method: 'frappe.core.doctype.document_naming_rule.document_naming_rule.update_current', args: { From bb4be327511eb7f736282fee6eaf5ee6d88ebc7a Mon Sep 17 00:00:00 2001 From: Mohammad Hasnain Mohsin Rajan Date: Wed, 12 May 2021 17:15:18 +0530 Subject: [PATCH 03/14] chore: add semicolons --- .../document_naming_rule/document_naming_rule.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/frappe/core/doctype/document_naming_rule/document_naming_rule.js b/frappe/core/doctype/document_naming_rule/document_naming_rule.js index 5d1540588d..e837ca2d6c 100644 --- a/frappe/core/doctype/document_naming_rule/document_naming_rule.js +++ b/frappe/core/doctype/document_naming_rule/document_naming_rule.js @@ -4,7 +4,7 @@ frappe.ui.form.on('Document Naming Rule', { refresh: function(frm) { frm.trigger('document_type'); - frm.trigger("add_button") + frm.trigger("add_button"); }, document_type: (frm) => { // update the select field options with fieldnames @@ -32,7 +32,7 @@ frappe.ui.form.on('Document Naming Rule', { default: frm.doc.counter, reqd: 1, description: __('This will update the counter and will affect all documents that will be created') - }] + }]; let primary_action_label = __('Save'); @@ -44,10 +44,10 @@ frappe.ui.form.on('Document Naming Rule', { new_counter: fields.new_counter }, callback: function() { - frm.set_value("counter", fields.new_counter) - dialog.hide() + frm.set_value("counter", fields.new_counter); + dialog.hide(); } - }) + }); }; var dialog = new frappe.ui.Dialog({ @@ -57,7 +57,7 @@ frappe.ui.form.on('Document Naming Rule', { primary_action }); - dialog.show() + dialog.show(); }); } From ed1a9e15591b7e8d4e1053fd97e528bbfb9cc43d Mon Sep 17 00:00:00 2001 From: hasnain2808 Date: Thu, 13 May 2021 09:55:27 +0530 Subject: [PATCH 04/14] fix: do not show counter on unsaved forms --- .../core/doctype/document_naming_rule/document_naming_rule.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frappe/core/doctype/document_naming_rule/document_naming_rule.js b/frappe/core/doctype/document_naming_rule/document_naming_rule.js index e837ca2d6c..23a22ee33c 100644 --- a/frappe/core/doctype/document_naming_rule/document_naming_rule.js +++ b/frappe/core/doctype/document_naming_rule/document_naming_rule.js @@ -4,7 +4,7 @@ frappe.ui.form.on('Document Naming Rule', { refresh: function(frm) { frm.trigger('document_type'); - frm.trigger("add_button"); + if(!frm.doc.__islocal) frm.trigger("add_button"); }, document_type: (frm) => { // update the select field options with fieldnames From 90f786b0e5641f8c03b7e7e33988c82412aa4d4b Mon Sep 17 00:00:00 2001 From: Mohammad Hasnain Mohsin Rajan Date: Thu, 13 May 2021 09:57:10 +0530 Subject: [PATCH 05/14] chore: spaces --- .../core/doctype/document_naming_rule/document_naming_rule.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frappe/core/doctype/document_naming_rule/document_naming_rule.js b/frappe/core/doctype/document_naming_rule/document_naming_rule.js index 23a22ee33c..7dbf533975 100644 --- a/frappe/core/doctype/document_naming_rule/document_naming_rule.js +++ b/frappe/core/doctype/document_naming_rule/document_naming_rule.js @@ -4,7 +4,7 @@ frappe.ui.form.on('Document Naming Rule', { refresh: function(frm) { frm.trigger('document_type'); - if(!frm.doc.__islocal) frm.trigger("add_button"); + if (!frm.doc.__islocal) frm.trigger("add_button"); }, document_type: (frm) => { // update the select field options with fieldnames From 2e1c4650baf004c2a0e756d388bd4389c9335853 Mon Sep 17 00:00:00 2001 From: Mohammad Hasnain Mohsin Rajan Date: Thu, 13 May 2021 19:54:56 +0530 Subject: [PATCH 06/14] Update frappe/core/doctype/document_naming_rule/document_naming_rule.js Co-authored-by: Suraj Shetty <13928957+surajshetty3416@users.noreply.github.com> --- .../core/doctype/document_naming_rule/document_naming_rule.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frappe/core/doctype/document_naming_rule/document_naming_rule.js b/frappe/core/doctype/document_naming_rule/document_naming_rule.js index 7dbf533975..5e77e71820 100644 --- a/frappe/core/doctype/document_naming_rule/document_naming_rule.js +++ b/frappe/core/doctype/document_naming_rule/document_naming_rule.js @@ -51,7 +51,7 @@ frappe.ui.form.on('Document Naming Rule', { }; var dialog = new frappe.ui.Dialog({ - title: __('Update Counter Value for Prefix: ' + frm.doc.prefix), + title: __('Update Counter Value for Prefix: {0}', [frm.doc.prefix]), fields, primary_action_label, primary_action From 969e2b6db95d1c865730776921e853cdeb0284ef Mon Sep 17 00:00:00 2001 From: Mohammad Hasnain Mohsin Rajan Date: Thu, 20 May 2021 20:04:40 +0530 Subject: [PATCH 07/14] fix: allow only system manager Co-authored-by: Suraj Shetty <13928957+surajshetty3416@users.noreply.github.com> --- frappe/core/doctype/document_naming_rule/document_naming_rule.py | 1 + 1 file changed, 1 insertion(+) diff --git a/frappe/core/doctype/document_naming_rule/document_naming_rule.py b/frappe/core/doctype/document_naming_rule/document_naming_rule.py index 13d54dffdd..7fa7c73efd 100644 --- a/frappe/core/doctype/document_naming_rule/document_naming_rule.py +++ b/frappe/core/doctype/document_naming_rule/document_naming_rule.py @@ -33,5 +33,6 @@ class DocumentNamingRule(Document): @frappe.whitelist() def update_current(name, new_counter): + frappe.only_for('System Manager') frappe.db.set_value('Document Naming Rule', name, 'counter', new_counter) frappe.db.commit() From 730bcc8c035bc5aec5173f1feb0b06a2e5c664de Mon Sep 17 00:00:00 2001 From: Mohammad Hasnain Mohsin Rajan Date: Thu, 20 May 2021 20:05:00 +0530 Subject: [PATCH 08/14] fix: do not explicitly commit Co-authored-by: Suraj Shetty <13928957+surajshetty3416@users.noreply.github.com> --- frappe/core/doctype/document_naming_rule/document_naming_rule.py | 1 - 1 file changed, 1 deletion(-) diff --git a/frappe/core/doctype/document_naming_rule/document_naming_rule.py b/frappe/core/doctype/document_naming_rule/document_naming_rule.py index 7fa7c73efd..653c056caa 100644 --- a/frappe/core/doctype/document_naming_rule/document_naming_rule.py +++ b/frappe/core/doctype/document_naming_rule/document_naming_rule.py @@ -35,4 +35,3 @@ class DocumentNamingRule(Document): def update_current(name, new_counter): frappe.only_for('System Manager') frappe.db.set_value('Document Naming Rule', name, 'counter', new_counter) - frappe.db.commit() From e16988b887d129c13fe30f9d67e27ff0fad93a82 Mon Sep 17 00:00:00 2001 From: Mohammad Hasnain Mohsin Rajan Date: Thu, 20 May 2021 20:05:58 +0530 Subject: [PATCH 09/14] chore: change description --- .../core/doctype/document_naming_rule/document_naming_rule.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frappe/core/doctype/document_naming_rule/document_naming_rule.js b/frappe/core/doctype/document_naming_rule/document_naming_rule.js index 5e77e71820..f4b7428aff 100644 --- a/frappe/core/doctype/document_naming_rule/document_naming_rule.js +++ b/frappe/core/doctype/document_naming_rule/document_naming_rule.js @@ -31,7 +31,7 @@ frappe.ui.form.on('Document Naming Rule', { label: __('New Counter'), default: frm.doc.counter, reqd: 1, - description: __('This will update the counter and will affect all documents that will be created') + description: __('Updating counter may lead to document name conflicts if not done properly') }]; let primary_action_label = __('Save'); From c9dc4ee441eae931b0d1918ba18fd0ce81df5967 Mon Sep 17 00:00:00 2001 From: Mohammad Hasnain Mohsin Rajan Date: Fri, 21 May 2021 11:38:36 +0530 Subject: [PATCH 10/14] Update frappe/core/doctype/document_naming_rule/document_naming_rule.js Co-authored-by: Suraj Shetty <13928957+surajshetty3416@users.noreply.github.com> --- .../core/doctype/document_naming_rule/document_naming_rule.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frappe/core/doctype/document_naming_rule/document_naming_rule.js b/frappe/core/doctype/document_naming_rule/document_naming_rule.js index f4b7428aff..cd85615f5f 100644 --- a/frappe/core/doctype/document_naming_rule/document_naming_rule.js +++ b/frappe/core/doctype/document_naming_rule/document_naming_rule.js @@ -31,7 +31,7 @@ frappe.ui.form.on('Document Naming Rule', { label: __('New Counter'), default: frm.doc.counter, reqd: 1, - description: __('Updating counter may lead to document name conflicts if not done properly') + description: __('Warning: Updating counter may lead to document name conflicts if not done properly') }]; let primary_action_label = __('Save'); From bcb4c5182ffdb9d7d70b239d8ee6b222ece63f0e Mon Sep 17 00:00:00 2001 From: Mohammad Hasnain Mohsin Rajan Date: Fri, 21 May 2021 11:38:43 +0530 Subject: [PATCH 11/14] Update frappe/core/doctype/document_naming_rule/document_naming_rule.js Co-authored-by: Suraj Shetty <13928957+surajshetty3416@users.noreply.github.com> --- .../core/doctype/document_naming_rule/document_naming_rule.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frappe/core/doctype/document_naming_rule/document_naming_rule.js b/frappe/core/doctype/document_naming_rule/document_naming_rule.js index cd85615f5f..b1123cba28 100644 --- a/frappe/core/doctype/document_naming_rule/document_naming_rule.js +++ b/frappe/core/doctype/document_naming_rule/document_naming_rule.js @@ -50,7 +50,7 @@ frappe.ui.form.on('Document Naming Rule', { }); }; - var dialog = new frappe.ui.Dialog({ + const dialog = new frappe.ui.Dialog({ title: __('Update Counter Value for Prefix: {0}', [frm.doc.prefix]), fields, primary_action_label, From 3f056d147dea656dd531c7e794da05a513aa44f7 Mon Sep 17 00:00:00 2001 From: Mohammad Hasnain Mohsin Rajan Date: Fri, 21 May 2021 11:38:49 +0530 Subject: [PATCH 12/14] Update frappe/core/doctype/document_naming_rule/document_naming_rule.js Co-authored-by: Suraj Shetty <13928957+surajshetty3416@users.noreply.github.com> --- .../core/doctype/document_naming_rule/document_naming_rule.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frappe/core/doctype/document_naming_rule/document_naming_rule.js b/frappe/core/doctype/document_naming_rule/document_naming_rule.js index b1123cba28..3aea9e04a7 100644 --- a/frappe/core/doctype/document_naming_rule/document_naming_rule.js +++ b/frappe/core/doctype/document_naming_rule/document_naming_rule.js @@ -4,7 +4,7 @@ frappe.ui.form.on('Document Naming Rule', { refresh: function(frm) { frm.trigger('document_type'); - if (!frm.doc.__islocal) frm.trigger("add_button"); + if (!frm.doc.__islocal) frm.trigger("add_update_counter_button"); }, document_type: (frm) => { // update the select field options with fieldnames From fa53c47e58cf7f8c85bd1ba13ad6973ec998b2d0 Mon Sep 17 00:00:00 2001 From: Mohammad Hasnain Mohsin Rajan Date: Fri, 21 May 2021 11:38:57 +0530 Subject: [PATCH 13/14] Update frappe/core/doctype/document_naming_rule/document_naming_rule.js Co-authored-by: Suraj Shetty <13928957+surajshetty3416@users.noreply.github.com> --- .../core/doctype/document_naming_rule/document_naming_rule.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frappe/core/doctype/document_naming_rule/document_naming_rule.js b/frappe/core/doctype/document_naming_rule/document_naming_rule.js index 3aea9e04a7..0f0bdd149c 100644 --- a/frappe/core/doctype/document_naming_rule/document_naming_rule.js +++ b/frappe/core/doctype/document_naming_rule/document_naming_rule.js @@ -22,7 +22,7 @@ frappe.ui.form.on('Document Naming Rule', { }); } }, - add_button: (frm) => { + add_update_counter_button: (frm) => { frm.add_custom_button(__('Update Counter'), function() { const fields = [{ From 58400d6214ec61ff9733a4caf46bad18dff71880 Mon Sep 17 00:00:00 2001 From: Mohammad Hasnain Mohsin Rajan Date: Fri, 21 May 2021 14:15:14 +0530 Subject: [PATCH 14/14] Update frappe/core/doctype/document_naming_rule/document_naming_rule.js Co-authored-by: Suraj Shetty <13928957+surajshetty3416@users.noreply.github.com> --- .../core/doctype/document_naming_rule/document_naming_rule.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frappe/core/doctype/document_naming_rule/document_naming_rule.js b/frappe/core/doctype/document_naming_rule/document_naming_rule.js index 0f0bdd149c..097a4e9a6e 100644 --- a/frappe/core/doctype/document_naming_rule/document_naming_rule.js +++ b/frappe/core/doctype/document_naming_rule/document_naming_rule.js @@ -44,7 +44,7 @@ frappe.ui.form.on('Document Naming Rule', { new_counter: fields.new_counter }, callback: function() { - frm.set_value("counter", fields.new_counter); + frm.set_value("counter", fields.new_counter); dialog.hide(); } });