Ver a proveniência

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

version-14
Suraj Shetty há 4 anos
committed by GitHub
ascendente
cometimento
df0143f948
Não foi encontrada uma chave conhecida para esta assinatura, na base de dados ID da chave GPG: 4AEE18F83AFDEB23
2 ficheiros alterados com 45 adições e 0 eliminações
  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 Ver ficheiro

@@ -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 Ver ficheiro

@@ -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)

Carregando…
Cancelar
Guardar