[minor] added filter for batch no field in purchase transaction (#9038)

* [minor] added filter for batch no field in purchase transaction

* [minor] filter the batch based on item_code instead of get_batch_no method

* [minor] filter based on item_code for Purchase Invoice with update stock
This commit is contained in:
Makarand Bauskar 2017-06-02 17:28:40 +05:30 committed by Nabin Hait
parent 5f98dddd0c
commit c196d740e5
3 changed files with 35 additions and 39 deletions

View File

@ -98,6 +98,13 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
frm.cscript.calculate_taxes_and_totals();
});
var me = this;
if(this.frm.fields_dict["items"].grid.get_field('batch_no')) {
this.frm.set_query("batch_no", "items", function(doc, cdt, cdn) {
return me.set_query_for_batch(doc, cdt, cdn)
});
}
},
onload: function() {
var me = this;
@ -1129,4 +1136,32 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
return method
},
set_query_for_batch: function(doc, cdt, cdn) {
// Show item's batches in the dropdown of batch no
var me = this;
var item = frappe.get_doc(cdt, cdn);
if(!item.item_code) {
frappe.throw(__("Please enter Item Code to get batch no"));
} else if (doc.doctype == "Purchase Receipt" ||
(doc.doctype == "Purchase Invoice" && doc.update_stock)) {
return {
filters: {'item': item.item_code}
}
} else {
filters = {
'item_code': item.item_code,
'posting_date': me.frm.doc.posting_date || frappe.datetime.nowdate(),
}
if(item.warehouse) filters["warehouse"] = item.warehouse
return {
query : "erpnext.controllers.queries.get_batch_no",
filters: filters
}
}
},
});

View File

@ -73,34 +73,6 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
return me.set_query_for_batch(doc, cdt, cdn)
});
}
if(this.frm.fields_dict["items"].grid.get_field('batch_no')) {
this.frm.set_query("batch_no", "items", function(doc, cdt, cdn) {
return me.set_query_for_batch(doc, cdt, cdn)
});
}
},
set_query_for_batch: function(doc, cdt, cdn) {
// Show item's batches in the dropdown of batch no
var me = this;
var item = frappe.get_doc(cdt, cdn);
if(!item.item_code) {
frappe.throw(__("Please enter Item Code to get batch no"));
} else {
filters = {
'item_code': item.item_code,
'posting_date': me.frm.doc.posting_date || frappe.datetime.nowdate(),
}
if(item.warehouse) filters["warehouse"] = item.warehouse
return {
query : "erpnext.controllers.queries.get_batch_no",
filters: filters
}
}
},
refresh: function() {

View File

@ -145,17 +145,6 @@ cur_frm.fields_dict['items'].grid.get_field('project').get_query = function(doc,
}
}
cur_frm.fields_dict['items'].grid.get_field('batch_no').get_query= function(doc, cdt, cdn) {
var d = locals[cdt][cdn];
if(d.item_code) {
return {
filters: {'item': d.item_code}
}
}
else
msgprint(__("Please enter Item Code."));
}
cur_frm.cscript.select_print_heading = function(doc, cdt, cdn) {
if(doc.select_print_heading)
cur_frm.pformat.print_heading = doc.select_print_heading;