This commit is contained in:
pratu16x7 2017-06-20 14:08:01 +05:30
parent 36693e27be
commit 26b8f5c3ce
2 changed files with 13 additions and 44 deletions

View File

@ -17,10 +17,11 @@ class TestBatch(unittest.TestCase):
"item": "_Test Item"
}).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
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):
'''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)
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'''
if not frappe.db.exists("Batch", batch_name):

View File

@ -548,49 +548,16 @@ erpnext.stock.StockEntry = erpnext.stock.StockController.extend({
erpnext.stock.select_batch_and_serial_no = (frm, d = undefined) => {
let get_warehouse = (item) => {
let value = '';
if(frm.fields_dict.from_warehouse.disp_status === "Write") {
var value = cstr(item.s_warehouse) || '';
value = cstr(item.s_warehouse) || '';
return ['Source Warehouse', value];
} else {
var value = cstr(item.t_warehouse) || '';
value = cstr(item.t_warehouse) || '';
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) {
// 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);
@ -621,7 +588,7 @@ erpnext.stock.show_batch_serial_modal = (frm, item, item_code, qty, warehouse_de
{fieldname: 'batches', fieldtype: 'Table',
fields: [
{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 }};
}},
{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',
label: __('Select'),
get_query: function(doc) {
get_query: function() {
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) {
map_item_values(item, values, 'batch_no');
} else {
var row = frm.add_child("items");
let row = frm.add_child("items");
row.item_code = item.item_code;
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);
} 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);
}
}
@ -849,7 +816,7 @@ erpnext.stock.bind_batch_serial_dialog_qty = (dialog, warehouse_details) => {
let name = $row.attr('data-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');
row.doc[fieldname] = field.get_value();
batches_field.grid.set_value(fieldname, row.doc[fieldname], row.doc);