mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-04 04:39:11 +00:00
[minor]
This commit is contained in:
@@ -17,10 +17,11 @@ class TestBatch(unittest.TestCase):
|
|||||||
"item": "_Test Item"
|
"item": "_Test Item"
|
||||||
}).save)
|
}).save)
|
||||||
|
|
||||||
def make_batch_item(self, item_name):
|
@classmethod
|
||||||
|
def make_batch_item(cls, item_name):
|
||||||
from erpnext.stock.doctype.item.test_item import make_item
|
from erpnext.stock.doctype.item.test_item import make_item
|
||||||
if not frappe.db.exists(item_name):
|
if not frappe.db.exists(item_name):
|
||||||
make_item(item_name, dict(has_batch_no = 1))
|
make_item(item_name, dict(has_batch_no = 1, create_new_batch = 1))
|
||||||
|
|
||||||
def test_purchase_receipt(self, batch_qty = 100):
|
def test_purchase_receipt(self, batch_qty = 100):
|
||||||
'''Test automated batch creation from Purchase Receipt'''
|
'''Test automated batch creation from Purchase Receipt'''
|
||||||
@@ -162,7 +163,8 @@ class TestBatch(unittest.TestCase):
|
|||||||
|
|
||||||
self.assertEquals(get_batch_qty('batch a', '_Test Warehouse - _TC'), 90)
|
self.assertEquals(get_batch_qty('batch a', '_Test Warehouse - _TC'), 90)
|
||||||
|
|
||||||
def make_new_batch_and_entry(self, item_name, batch_name, warehouse):
|
@classmethod
|
||||||
|
def make_new_batch_and_entry(cls, item_name, batch_name, warehouse):
|
||||||
'''Make a new stock entry for given target warehouse and batch name of item'''
|
'''Make a new stock entry for given target warehouse and batch name of item'''
|
||||||
|
|
||||||
if not frappe.db.exists("Batch", batch_name):
|
if not frappe.db.exists("Batch", batch_name):
|
||||||
|
|||||||
@@ -548,49 +548,16 @@ erpnext.stock.StockEntry = erpnext.stock.StockController.extend({
|
|||||||
|
|
||||||
erpnext.stock.select_batch_and_serial_no = (frm, d = undefined) => {
|
erpnext.stock.select_batch_and_serial_no = (frm, d = undefined) => {
|
||||||
let get_warehouse = (item) => {
|
let get_warehouse = (item) => {
|
||||||
|
let value = '';
|
||||||
if(frm.fields_dict.from_warehouse.disp_status === "Write") {
|
if(frm.fields_dict.from_warehouse.disp_status === "Write") {
|
||||||
var value = cstr(item.s_warehouse) || '';
|
value = cstr(item.s_warehouse) || '';
|
||||||
return ['Source Warehouse', value];
|
return ['Source Warehouse', value];
|
||||||
} else {
|
} else {
|
||||||
var value = cstr(item.t_warehouse) || '';
|
value = cstr(item.t_warehouse) || '';
|
||||||
return ['Target Warehouse', value];
|
return ['Target Warehouse', value];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let show_modal_with_oldest_batch = (item, item_code, total_qty, warehouse_details, has_batch) => {
|
|
||||||
frappe.call({
|
|
||||||
method: 'erpnext.stock.doctype.batch.batch.get_batches_by_oldest',
|
|
||||||
args: {
|
|
||||||
warehouse: warehouse_details[1],
|
|
||||||
item_code: item_code
|
|
||||||
},
|
|
||||||
callback: (r) => {
|
|
||||||
if (r.message) {
|
|
||||||
var batch_rows_by_oldest = [];
|
|
||||||
if(warehouse_details[0] === 'Source Warehouse') {
|
|
||||||
var qty = total_qty;
|
|
||||||
for(var i = 0; i < r.message.length; i++) {
|
|
||||||
var batch_row = {name: 'batch 1'};
|
|
||||||
batch_row.batch_no = r.message[i].batch_no;
|
|
||||||
batch_row.available_qty = r.message[i].qty;
|
|
||||||
if (parseInt(qty) <= parseInt(r.message[i].qty)) {
|
|
||||||
batch_row.selected_qty = qty;
|
|
||||||
batch_rows_by_oldest.push(batch_row);
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
batch_row.selected_qty = r.message[i].qty;
|
|
||||||
qty -= r.message[i].qty;
|
|
||||||
batch_rows_by_oldest.push(batch_row);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
erpnext.stock.show_batch_serial_modal(frm, item, item_code, total_qty,
|
|
||||||
warehouse_details, has_batch, batch_rows_by_oldest);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if(d && d.has_batch_no && !d.batch_no) {
|
if(d && d.has_batch_no && !d.batch_no) {
|
||||||
// show_modal_with_oldest_batch(d, d.item_code, d.qty, get_warehouse(d), 1);
|
// show_modal_with_oldest_batch(d, d.item_code, d.qty, get_warehouse(d), 1);
|
||||||
erpnext.stock.show_batch_serial_modal(frm, d, d.item_code, d.qty, get_warehouse(d), 1);
|
erpnext.stock.show_batch_serial_modal(frm, d, d.item_code, d.qty, get_warehouse(d), 1);
|
||||||
@@ -621,7 +588,7 @@ erpnext.stock.show_batch_serial_modal = (frm, item, item_code, qty, warehouse_de
|
|||||||
{fieldname: 'batches', fieldtype: 'Table',
|
{fieldname: 'batches', fieldtype: 'Table',
|
||||||
fields: [
|
fields: [
|
||||||
{fieldtype:'Link', fieldname:'batch_no', options: 'Batch',
|
{fieldtype:'Link', fieldname:'batch_no', options: 'Batch',
|
||||||
label: __('Select Batch'), in_list_view:1, get_query: function(doc) {
|
label: __('Select Batch'), in_list_view:1, get_query: function() {
|
||||||
return {filters: {item: item_code }};
|
return {filters: {item: item_code }};
|
||||||
}},
|
}},
|
||||||
{fieldtype:'Float', read_only:1, fieldname:'available_qty',
|
{fieldtype:'Float', read_only:1, fieldname:'available_qty',
|
||||||
@@ -644,7 +611,7 @@ erpnext.stock.show_batch_serial_modal = (frm, item, item_code, qty, warehouse_de
|
|||||||
{
|
{
|
||||||
fieldtype: 'Link', fieldname: 'serial_no_select', options: 'Serial No',
|
fieldtype: 'Link', fieldname: 'serial_no_select', options: 'Serial No',
|
||||||
label: __('Select'),
|
label: __('Select'),
|
||||||
get_query: function(doc) {
|
get_query: function() {
|
||||||
return { filters: {item_code: item_code}};
|
return { filters: {item_code: item_code}};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -694,7 +661,7 @@ erpnext.stock.show_batch_serial_modal = (frm, item, item_code, qty, warehouse_de
|
|||||||
if(i === 0) {
|
if(i === 0) {
|
||||||
map_item_values(item, values, 'batch_no');
|
map_item_values(item, values, 'batch_no');
|
||||||
} else {
|
} else {
|
||||||
var row = frm.add_child("items");
|
let row = frm.add_child("items");
|
||||||
row.item_code = item.item_code;
|
row.item_code = item.item_code;
|
||||||
map_item_values(row, values, 'batch_no');
|
map_item_values(row, values, 'batch_no');
|
||||||
}
|
}
|
||||||
@@ -746,7 +713,7 @@ erpnext.stock.bind_batch_serial_dialog_qty = (dialog, warehouse_details) => {
|
|||||||
});
|
});
|
||||||
qty_field.set_input(total_qty);
|
qty_field.set_input(total_qty);
|
||||||
} else {
|
} else {
|
||||||
var serial_numbers = serial_no_list_field.get_value().replace(/\n/g, ' ').match(/\S+/g) || [];
|
let serial_numbers = serial_no_list_field.get_value().replace(/\n/g, ' ').match(/\S+/g) || [];
|
||||||
qty_field.set_input(serial_numbers.length);
|
qty_field.set_input(serial_numbers.length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -849,7 +816,7 @@ erpnext.stock.bind_batch_serial_dialog_qty = (dialog, warehouse_details) => {
|
|||||||
let name = $row.attr('data-name');
|
let name = $row.attr('data-name');
|
||||||
let row = batches_field.grid.grid_rows_by_docname[name];
|
let row = batches_field.grid.grid_rows_by_docname[name];
|
||||||
|
|
||||||
var field = row.on_grid_fields_dict[fieldname];
|
let field = row.on_grid_fields_dict[fieldname];
|
||||||
field.$input.trigger('blur');
|
field.$input.trigger('blur');
|
||||||
row.doc[fieldname] = field.get_value();
|
row.doc[fieldname] = field.get_value();
|
||||||
batches_field.grid.set_value(fieldname, row.doc[fieldname], row.doc);
|
batches_field.grid.set_value(fieldname, row.doc[fieldname], row.doc);
|
||||||
|
|||||||
Reference in New Issue
Block a user