Browse Source

Merge pull request #13204 from hasnain2808/allow-naming-series-update

version-14
Suraj Shetty 4 years ago
committed by GitHub
parent
commit
df0143f948
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 0 deletions
  1. +40
    -0
      frappe/core/doctype/document_naming_rule/document_naming_rule.js
  2. +5
    -0
      frappe/core/doctype/document_naming_rule/document_naming_rule.py

+ 40
- 0
frappe/core/doctype/document_naming_rule/document_naming_rule.js View File

@@ -4,6 +4,7 @@
frappe.ui.form.on('Document Naming Rule', {
refresh: function(frm) {
frm.trigger('document_type');
if (!frm.doc.__islocal) frm.trigger("add_update_counter_button");
},
document_type: (frm) => {
// update the select field options with fieldnames
@@ -20,5 +21,44 @@ frappe.ui.form.on('Document Naming Rule', {
);
});
}
},
add_update_counter_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: __('Warning: Updating counter may lead to document name conflicts if not done properly')
}];

let primary_action_label = __('Save');

let primary_action = (fields) => {
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();
}
});
};

const dialog = new frappe.ui.Dialog({
title: __('Update Counter Value for Prefix: {0}', [frm.doc.prefix]),
fields,
primary_action_label,
primary_action
});

dialog.show();

});
}
});

+ 5
- 0
frappe/core/doctype/document_naming_rule/document_naming_rule.py View File

@@ -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.only_for('System Manager')
frappe.db.set_value('Document Naming Rule', name, 'counter', new_counter)

Loading…
Cancel
Save