feat!: add pick batch button (#25413)

* feat!: add pick batch button

BREAKING CHANGE: replaces setup_serial_no with setup_serial_or_batch_no.

* refactor: use setup_serial_or_batch_no instead of setup_serial_no

* refactor: use setup_serial_or_batch_no instead of setup_serial_no

* refactor: use setup_serial_or_batch_no instead of setup_serial_no

* style: add sider review changes

* refactor: make consice, extract function

* refactor: camel to snake casing
This commit is contained in:
Alan 2021-05-07 20:30:04 +05:30 committed by GitHub
parent 90e671905a
commit c6dc9eaf2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 31 additions and 27 deletions

View File

@ -356,11 +356,11 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte
},
items_on_form_rendered: function() {
erpnext.setup_serial_no();
erpnext.setup_serial_or_batch_no();
},
packed_items_on_form_rendered: function(doc, grid_row) {
erpnext.setup_serial_no();
erpnext.setup_serial_or_batch_no();
},
make_sales_return: function() {

View File

@ -48,31 +48,24 @@ $.extend(erpnext, {
return cint(frappe.boot.sysdefaults.allow_stale);
},
setup_serial_no: function() {
var grid_row = cur_frm.open_grid_row();
if(!grid_row || !grid_row.grid_form.fields_dict.serial_no ||
grid_row.grid_form.fields_dict.serial_no.get_status()!=="Write") return;
setup_serial_or_batch_no: function() {
let grid_row = cur_frm.open_grid_row();
if (!grid_row || !grid_row.grid_form.fields_dict.serial_no ||
grid_row.grid_form.fields_dict.serial_no.get_status() !== "Write") return;
var $btn = $('<button class="btn btn-sm btn-default">'+__("Add Serial No")+'</button>')
.appendTo($("<div>")
.css({"margin-bottom": "10px", "margin-top": "10px"})
.appendTo(grid_row.grid_form.fields_dict.serial_no.$wrapper));
frappe.model.get_value('Item', {'name': grid_row.doc.item_code},
['has_serial_no', 'has_batch_no'], ({has_serial_no, has_batch_no}) => {
Object.assign(grid_row.doc, {has_serial_no, has_batch_no});
var me = this;
$btn.on("click", function() {
let callback = '';
let on_close = '';
frappe.model.get_value('Item', {'name':grid_row.doc.item_code}, 'has_serial_no',
(data) => {
if(data) {
grid_row.doc.has_serial_no = data.has_serial_no;
me.show_serial_batch_selector(grid_row.frm, grid_row.doc,
callback, on_close, true);
}
if (has_serial_no) {
attach_selector_button(__("Add Serial No"),
grid_row.grid_form.fields_dict.serial_no.$wrapper, this, grid_row);
} else if (has_batch_no) {
attach_selector_button(__("Pick Batch No"),
grid_row.grid_form.fields_dict.batch_no.$wrapper, this, grid_row);
}
);
});
}
);
},
route_to_adjustment_jv: (args) => {
@ -743,3 +736,14 @@ $(document).on('app_ready', function() {
});
}
});
function attach_selector_button(inner_text, append_loction, context, grid_row) {
let $btn_div = $("<div>").css({"margin-bottom": "10px", "margin-top": "10px"})
.appendTo(append_loction);
let $btn = $(`<button class="btn btn-sm btn-default">${inner_text}</button>`)
.appendTo($btn_div);
$btn.on("click", function() {
context.show_serial_batch_selector(grid_row.frm, grid_row.doc, "", "", true);
});
}

View File

@ -273,11 +273,11 @@ erpnext.stock.DeliveryNoteController = erpnext.selling.SellingController.extend(
},
items_on_form_rendered: function(doc, grid_row) {
erpnext.setup_serial_no();
erpnext.setup_serial_or_batch_no();
},
packed_items_on_form_rendered: function(doc, grid_row) {
erpnext.setup_serial_no();
erpnext.setup_serial_or_batch_no();
},
close_delivery_note: function(doc){

View File

@ -996,7 +996,7 @@ erpnext.stock.StockEntry = erpnext.stock.StockController.extend({
},
items_on_form_rendered: function(doc, grid_row) {
erpnext.setup_serial_no();
erpnext.setup_serial_or_batch_no();
},
toggle_related_fields: function(doc) {