Fetch serial no by default

This commit is contained in:
Kanchan Chauhan 2016-10-25 23:15:39 +05:30
parent df366a6e9c
commit 0a3f2c818a
3 changed files with 109 additions and 67 deletions

View File

@ -379,60 +379,6 @@ cur_frm.fields_dict['items'].grid.get_field('batch_no').get_query = function(doc
}
}
cur_frm.cscript.item_code = function(doc, cdt, cdn) {
var d = locals[cdt][cdn];
if(d.item_code) {
args = {
'item_code' : d.item_code,
'warehouse' : cstr(d.s_warehouse) || cstr(d.t_warehouse),
'transfer_qty' : d.transfer_qty,
'serial_no ' : d.serial_no,
'bom_no' : d.bom_no,
'expense_account' : d.expense_account,
'cost_center' : d.cost_center,
'company' : cur_frm.doc.company
};
return frappe.call({
doc: cur_frm.doc,
method: "get_item_details",
args: args,
callback: function(r) {
if(r.message) {
var d = locals[cdt][cdn];
$.each(r.message, function(k, v) {
d[k] = v;
});
refresh_field("items");
}
}
});
}
}
cur_frm.cscript.barcode = function(doc, cdt, cdn) {
var d = locals[cdt][cdn];
if (d.barcode) {
frappe.call({
method: "erpnext.stock.get_item_details.get_item_code",
args: {"barcode": d.barcode },
callback: function(r) {
if (!r.exe){
frappe.model.set_value(cdt, cdn, "item_code", r.message);
}
}
});
}
}
cur_frm.cscript.uom = function(doc, cdt, cdn) {
var d = locals[cdt][cdn];
if(d.uom && d.item_code){
var arg = {'item_code':d.item_code, 'uom':d.uom, 'qty':d.qty}
return get_server_fields('get_uom_details', JSON.stringify(arg),
'items', doc, cdt, cdn, 1);
}
}
cur_frm.cscript.validate = function(doc, cdt, cdn) {
cur_frm.cscript.validate_items(doc);
}
@ -453,18 +399,100 @@ cur_frm.cscript.cost_center = function(doc, cdt, cdn) {
erpnext.utils.copy_value_in_all_row(doc, cdt, cdn, "items", "cost_center");
}
cur_frm.cscript.company = function(doc, cdt, cdn) {
if(doc.company) {
var company_doc = frappe.get_doc(":Company", doc.company);
if(company_doc.default_letter_head) {
cur_frm.set_value("letter_head", company_doc.default_letter_head);
}
}
}
frappe.ui.form.on('Landed Cost Taxes and Charges', {
amount: function(frm) {
frm.cscript.calculate_amount();
}
})
frappe.ui.form.on('Stock Entry Detail', {
qty: function(frm, cdt, cdn) {
frm.events.set_serial_no(frm, cdt, cdn);
},
s_warehouse: function(frm, cdt, cdn) {
frm.events.set_serial_no(frm, cdt, cdn);
},
barcode: function(doc, cdt, cdn) {
var d = locals[cdt][cdn];
if (d.barcode) {
frappe.call({
method: "erpnext.stock.get_item_details.get_item_code",
args: {"barcode": d.barcode },
callback: function(r) {
if (!r.exe){
frappe.model.set_value(cdt, cdn, "item_code", r.message);
}
}
});
}
},
uom: function(doc, cdt, cdn) {
var d = locals[cdt][cdn];
if(d.uom && d.item_code){
var arg = {'item_code':d.item_code, 'uom':d.uom, 'qty':d.qty}
return get_server_fields('get_uom_details', JSON.stringify(arg),
'items', doc, cdt, cdn, 1);
}
},
item_code: function(doc, cdt, cdn) {
var d = locals[cdt][cdn];
if(d.item_code) {
args = {
'item_code' : d.item_code,
'warehouse' : cstr(d.s_warehouse) || cstr(d.t_warehouse),
'transfer_qty' : d.transfer_qty,
'serial_no ' : d.serial_no,
'bom_no' : d.bom_no,
'expense_account' : d.expense_account,
'cost_center' : d.cost_center,
'company' : cur_frm.doc.company,
'qty' : d.qty
};
return frappe.call({
doc: cur_frm.doc,
method: "get_item_details",
args: args,
callback: function(r) {
if(r.message) {
var d = locals[cdt][cdn];
$.each(r.message, function(k, v) {
d[k] = v;
});
refresh_field("items");
}
}
});
}
}
})
frappe.ui.form.on('Stock Entry', {
company: function(doc, cdt, cdn) {
if(doc.company) {
var company_doc = frappe.get_doc(":Company", doc.company);
if(company_doc.default_letter_head) {
cur_frm.set_value("letter_head", company_doc.default_letter_head);
}
}
},
set_serial_no: function(doc, cdt, cdn) {
var d = frappe.model.get_doc(cdt, cdn);
if(!d.item_code && !d.s_warehouse && !d.qty) return;
var args = {
'item_code' : d.item_code,
'warehouse' : cstr(d.s_warehouse),
'qty' : d.qty
};
frappe.call({
method: "erpnext.stock.doctype.stock_entry.stock_entry.get_serial_no",
args: {"args": args},
callback: function(r) {
if (!r.exe){
frappe.model.set_value(cdt, cdn, "serial_no", r.message);
}
}
});
},
})

View File

@ -8,7 +8,7 @@ from frappe import _
from frappe.utils import cstr, cint, flt, comma_or, getdate, nowdate, formatdate, format_time
from erpnext.stock.utils import get_incoming_rate
from erpnext.stock.stock_ledger import get_previous_sle, NegativeStockError
from erpnext.stock.get_item_details import get_bin_details, get_default_cost_center, get_conversion_factor
from erpnext.stock.get_item_details import get_bin_details, get_default_cost_center, get_conversion_factor, process_args, get_serial_nos_by_fifo
from erpnext.manufacturing.doctype.bom.bom import validate_bom_no
import json
@ -472,7 +472,8 @@ class StockEntry(StockController):
'conversion_factor' : 1,
'batch_no' : '',
'actual_qty' : 0,
'basic_rate' : 0
'basic_rate' : 0,
'serial_no' : ''
}
for d in [["Account", "expense_account", "default_expense_account"],
["Cost Center", "cost_center", "cost_center"]]:
@ -831,3 +832,16 @@ def get_warehouse_details(args):
}
return ret
@frappe.whitelist()
def get_serial_no(args):
if isinstance(args, basestring):
args = json.loads(args)
args = frappe._dict(args)
if args.get('warehouse'):
if frappe.get_value('Item', {'item_code': args.item_code}, "has_serial_no") == 1:
args = json.dumps({"item_code": args.get('item_code'),"warehouse": args.get('warehouse'),"qty": args.get('qty')})
args = process_args(args)
serial_no = get_serial_nos_by_fifo(args)
return serial_no

View File

@ -75,7 +75,7 @@ def get_item_details(args):
if args.get("doctype") in ("Sales Invoice", "Delivery Note"):
if item_doc.has_serial_no == 1 and not args.serial_no:
out.serial_no = get_serial_nos_by_fifo(args, item_doc)
out.serial_no = get_serial_nos_by_fifo(args)
if args.transaction_date and item.lead_time_days:
out.schedule_date = out.lead_time_date = add_days(args.transaction_date,
@ -339,7 +339,7 @@ def get_pos_profile(company):
return pos_profile and pos_profile[0] or None
def get_serial_nos_by_fifo(args, item_doc):
def get_serial_nos_by_fifo(args):
if frappe.db.get_single_value("Stock Settings", "automatically_set_serial_nos_based_on_fifo"):
return "\n".join(frappe.db.sql_list("""select name from `tabSerial No`
where item_code=%(item_code)s and warehouse=%(warehouse)s