stock entry incoming rate fixes and batch no get_query

This commit is contained in:
Nabin Hait 2012-12-03 15:56:19 +05:30
parent d61e4fd317
commit dd4c679899
7 changed files with 434 additions and 431 deletions

View File

@ -304,6 +304,29 @@ cur_frm.cscript.barcode = function(doc, cdt, cdn) {
get_server_fields('get_barcode_details', d.barcode, cur_frm.cscript.fname, doc, cdt, cdn, 1, callback); get_server_fields('get_barcode_details', d.barcode, cur_frm.cscript.fname, doc, cdt, cdn, 1, callback);
} }
cur_frm.fields_dict[cur_frm.cscript.fname].grid.get_field('batch_no').get_query =
function(doc, cdt, cdn) {
var d = locals[cdt][cdn];
if(d.item_code) {
if (d.warehouse) {
return "select batch_no from `tabStock Ledger Entry` sle \
where item_code = '" + d.item_code + "' and warehouse = '" + d.warehouse +
"' and ifnull(is_cancelled, 'No') = 'No' and batch_no like '%s' \
and exists(select * from `tabBatch` where \
name = sle.batch_no and expiry_date >= '" + doc.posting_date +
"' and docstatus != 2) group by batch_no having sum(actual_qty) > 0 \
order by batch_no desc limit 50";
} else {
return "SELECT name FROM tabBatch WHERE docstatus != 2 AND item = '" +
d.item_code + "' and expiry_date >= '" + doc.posting_date +
"' AND name like '%s' ORDER BY name DESC LIMIT 50";
}
} else {
msgprint("Please enter Item Code to get batch no");
}
}
// *********************** QUANTITY *************************** // *********************** QUANTITY ***************************
cur_frm.cscript.qty = function(doc, cdt, cdn) { cur_frm.cscript.recalc(doc, 1); } cur_frm.cscript.qty = function(doc, cdt, cdn) { cur_frm.cscript.recalc(doc, 1); }

View File

@ -134,16 +134,6 @@ cur_frm.cscript.new_contact = function(){
loaddoc('Contact', tn); loaddoc('Contact', tn);
} }
//========================= Overloaded query for link batch_no =============================================================
cur_frm.fields_dict['delivery_note_details'].grid.get_field('batch_no').get_query= function(doc, cdt, cdn) {
var d = locals[cdt][cdn];
if(d.item_code){
return "SELECT tabBatch.name, tabBatch.description FROM tabBatch WHERE tabBatch.docstatus != 2 AND tabBatch.item = '"+ d.item_code +"' AND `tabBatch`.`name` like '%s' ORDER BY `tabBatch`.`name` DESC LIMIT 50"
}
else{
alert("Please enter Item Code.");
}
}
// ***************** Get project name ***************** // ***************** Get project name *****************
cur_frm.fields_dict['project_name'].get_query = function(doc, cdt, cdn) { cur_frm.fields_dict['project_name'].get_query = function(doc, cdt, cdn) {

View File

@ -8,68 +8,77 @@
// //
// This program is distributed in the hope that it will be useful, // This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details. // GNU General Public License for more details.
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
cur_frm.cscript.onload = function(doc, cdt, cdn) { cur_frm.cscript.onload = function(doc, cdt, cdn) {
if (!doc.posting_date) doc.posting_date = dateutil.obj_to_str(new Date()); if (!doc.posting_date) doc.posting_date = dateutil.obj_to_str(new Date());
if (!doc.transfer_date) doc.transfer_date = dateutil.obj_to_str(new Date()); if (!doc.transfer_date) doc.transfer_date = dateutil.obj_to_str(new Date());
if(!doc.purpose) set_multiple(cdt, cdn, {purpose:'Material Issue'}); if(!doc.purpose) set_multiple(cdt, cdn, {purpose:'Material Issue'});
cfn_set_fields(doc, cdt, cdn); cfn_set_fields(doc, cdt, cdn);
} }
var cfn_set_fields = function(doc, cdt, cdn) { var cfn_set_fields = function(doc, cdt, cdn) {
lst = ['supplier','supplier_name','supplier_address','customer','customer_name','customer_address']; lst = ['supplier', 'supplier_name', 'supplier_address',
if (in_list(['Material Issue', 'Material Transfer', 'Material Receipt', 'Sales Return', 'Purchase Return', 'Production Order', 'Subcontracting', 'Other'], doc.purpose)) { 'customer', 'customer_name', 'customer_address'];
hide_field(lst); if (in_list(['Material Issue', 'Material Transfer', 'Material Receipt', 'Sales Return',
$(cur_frm.fields_dict.contact_section.row.wrapper).toggle(false); 'Purchase Return', 'Production Order', 'Subcontracting', 'Other'], doc.purpose)) {
} else unhide_field(lst); hide_field(lst);
$(cur_frm.fields_dict.contact_section.row.wrapper).toggle(false);
} else unhide_field(lst);
if (doc.purpose == 'Production Order' || doc.purpose == 'Other') {
unhide_field('get_items');
hide_field(['from_warehouse', 'to_warehouse','purchase_receipt_no',
'delivery_note_no', 'sales_invoice_no','warehouse_html',
'transporter', 'is_excisable_goods', 'excisable_goods']);
if (doc.purpose=='Production Order') unhide_field(['production_order', 'process']);
else {
doc.production_order = doc.process = '';
hide_field(['production_order', 'process']);
}
doc.from_warehouse = '';
doc.to_warehouse = '';
refresh_field(['from_warehosue', 'to_warehouse']);
if (doc.process == 'Backflush' || doc.purpose == 'Other') {
unhide_field('fg_completed_qty');
}
else{
hide_field('fg_completed_qty');
doc.fg_completed_qty = 0;
}
} else {
unhide_field(['from_warehouse', 'to_warehouse']);
hide_field(['production_order', 'process', 'get_items', 'fg_completed_qty',
'purchase_receipt_no','delivery_note_no', 'sales_invoice_no']);
doc.production_order = '';
doc.process = '';
doc.fg_completed_qty = 0;
}
if (doc.purpose == 'Production Order' || doc.purpose == 'Other'){ if(doc.purpose == 'Purchase Return') {
unhide_field('get_items'); doc.customer = doc.customer_name = doc.customer_address =
hide_field(['from_warehouse', 'to_warehouse','purchase_receipt_no','delivery_note_no', 'sales_invoice_no','warehouse_html', 'transporter', 'is_excisable_goods', 'excisable_goods']); doc.delivery_note_no = doc.sales_invoice_no = '';
if (doc.purpose=='Production Order') unhide_field(['production_order', 'process']); unhide_field(['supplier','supplier_name','supplier_address','purchase_receipt_no']);
else hide_field(['production_order', 'process']); $(cur_frm.fields_dict.contact_section.row.wrapper).toggle(true);
}
doc.from_warehouse = ''; else if(doc.purpose == 'Sales Return'){
doc.to_warehouse = ''; doc.supplier=doc.supplier_name = doc.supplier_address=doc.purchase_receipt_no='';
refresh_field(['from_warehosue', 'to_warehouse']); unhide_field(['customer', 'customer_name', 'customer_address',
if (doc.process == 'Backflush' || doc.purpose == 'Other'){ 'delivery_note_no', 'sales_invoice_no']);
unhide_field('fg_completed_qty'); $(cur_frm.fields_dict.contact_section.row.wrapper).toggle(true);
} } else{
else{ doc.customer = doc.customer_name = doc.customer_address =
hide_field('fg_completed_qty'); doc.delivery_note_no = doc.sales_invoice_no = doc.supplier =
doc.fg_completed_qty = 0; doc.supplier_name = doc.supplier_address = doc.purchase_receipt_no = '';
} }
} refresh_many(lst);
else{
unhide_field(['from_warehouse', 'to_warehouse']);
hide_field(['production_order', 'process', 'get_items', 'fg_completed_qty','purchase_receipt_no','delivery_note_no', 'sales_invoice_no']);
doc.production_order = '';
doc.process = '';
doc.fg_completed_qty = 0;
}
if(doc.purpose == 'Purchase Return'){
doc.customer=doc.customer_name = doc.customer_address=doc.delivery_note_no=doc.sales_invoice_no='';
unhide_field(['supplier','supplier_name','supplier_address','purchase_receipt_no']);
$(cur_frm.fields_dict.contact_section.row.wrapper).toggle(true);
}
else if(doc.purpose == 'Sales Return'){
doc.supplier=doc.supplier_name = doc.supplier_address=doc.purchase_receipt_no='';
unhide_field(['customer','customer_name','customer_address','delivery_note_no', 'sales_invoice_no']);
$(cur_frm.fields_dict.contact_section.row.wrapper).toggle(true);
} else{
doc.customer=doc.customer_name=doc.customer_address=doc.delivery_note_no=doc.sales_invoice_no='';
doc.supplier=doc.supplier_name = doc.supplier_address=doc.purchase_receipt_no='';
}
refresh_many(lst);
} }
//Refresh //Refresh
@ -77,47 +86,44 @@ cur_frm.cscript.refresh = function(doc, cdt, cdn) {
erpnext.hide_naming_series(); erpnext.hide_naming_series();
//India related //India related
excise_flds = ['is_excisable_goods', 'excisable_goods', 'under_rule'] excise_flds = ['is_excisable_goods', 'excisable_goods', 'under_rule'];
if(wn.control_panel.country == 'India') unhide_field(excise_flds); if(wn.control_panel.country == 'India') unhide_field(excise_flds);
else hide_field(excise_flds); else hide_field(excise_flds);
} }
cur_frm.cscript.delivery_note_no = function(doc,cdt,cdn){ cur_frm.cscript.delivery_note_no = function(doc,cdt,cdn){
if(doc.delivery_note_no) get_server_fields('get_cust_values','','',doc,cdt,cdn,1); if(doc.delivery_note_no) get_server_fields('get_cust_values','','',doc,cdt,cdn,1);
} }
cur_frm.cscript.sales_invoice_no = function(doc,cdt,cdn){ cur_frm.cscript.sales_invoice_no = function(doc,cdt,cdn){
if(doc.sales_invoice_no) get_server_fields('get_cust_values','','',doc,cdt,cdn,1); if(doc.sales_invoice_no) get_server_fields('get_cust_values','','',doc,cdt,cdn,1);
} }
cur_frm.cscript.customer = function(doc,cdt,cdn){ cur_frm.cscript.customer = function(doc,cdt,cdn){
if(doc.customer) get_server_fields('get_cust_addr','','',doc,cdt,cdn,1); if(doc.customer) get_server_fields('get_cust_addr','','',doc,cdt,cdn,1);
} }
cur_frm.cscript.purchase_receipt_no = function(doc,cdt,cdn){ cur_frm.cscript.purchase_receipt_no = function(doc,cdt,cdn){
if(doc.purchase_receipt_no) get_server_fields('get_supp_values','','',doc,cdt,cdn,1); if(doc.purchase_receipt_no) get_server_fields('get_supp_values','','',doc,cdt,cdn,1);
} }
cur_frm.cscript.supplier = function(doc,cdt,cdn){ cur_frm.cscript.supplier = function(doc,cdt,cdn){
if(doc.supplier) get_server_fields('get_supp_addr','','',doc,cdt,cdn,1); if(doc.supplier) get_server_fields('get_supp_addr','','',doc,cdt,cdn,1);
} }
cur_frm.fields_dict['production_order'].get_query = function(doc) { cur_frm.fields_dict['production_order'].get_query = function(doc) {
return 'SELECT DISTINCT `tabProduction Order`.`name` FROM `tabProduction Order` WHERE `tabProduction Order`.`docstatus` = 1 AND `tabProduction Order`.`qty` > ifnull(`tabProduction Order`.`produced_qty`,0) AND `tabProduction Order`.`name` like "%s" ORDER BY `tabProduction Order`.`name` DESC LIMIT 50'; return 'SELECT DISTINCT `tabProduction Order`.`name` FROM `tabProduction Order` WHERE `tabProduction Order`.`docstatus` = 1 AND `tabProduction Order`.`qty` > ifnull(`tabProduction Order`.`produced_qty`,0) AND `tabProduction Order`.`name` like "%s" ORDER BY `tabProduction Order`.`name` DESC LIMIT 50';
} }
cur_frm.cscript.purpose = function(doc, cdt, cdn) { cur_frm.cscript.purpose = function(doc, cdt, cdn) {
cfn_set_fields(doc, cdt, cdn); cfn_set_fields(doc, cdt, cdn);
} }
cur_frm.cscript.process = function(doc, cdt, cdn) { cur_frm.cscript.process = function(doc, cdt, cdn) {
cfn_set_fields(doc, cdt, cdn); cfn_set_fields(doc, cdt, cdn);
} }
//
// item code - only if quantity present in source warehosue // item code - only if quantity present in source warehosue
// //
var fld = cur_frm.fields_dict['mtn_details'].grid.get_field('item_code'); var fld = cur_frm.fields_dict['mtn_details'].grid.get_field('item_code');
@ -147,9 +153,7 @@ fld.get_query = function(doc, cdt, cdn) {
} }
} }
//
// copy over source and target warehouses // copy over source and target warehouses
//
cur_frm.fields_dict['mtn_details'].grid.onrowadd = function(doc, cdt, cdn){ cur_frm.fields_dict['mtn_details'].grid.onrowadd = function(doc, cdt, cdn){
var d = locals[cdt][cdn]; var d = locals[cdt][cdn];
if(!d.s_warehouse && doc.from_warehouse) { if(!d.s_warehouse && doc.from_warehouse) {
@ -162,73 +166,88 @@ cur_frm.fields_dict['mtn_details'].grid.onrowadd = function(doc, cdt, cdn){
} }
} }
//========================= Overloaded query for link batch_no ============================================================= // Overloaded query for link batch_no
cur_frm.fields_dict['mtn_details'].grid.get_field('batch_no').get_query= function(doc, cdt, cdn) { cur_frm.fields_dict['mtn_details'].grid.get_field('batch_no').get_query = function(doc, cdt, cdn) {
var d = locals[cdt][cdn]; var d = locals[cdt][cdn];
if(d.item_code){ if(d.item_code) {
return "SELECT tabBatch.name, tabBatch.description FROM tabBatch WHERE tabBatch.docstatus != 2 AND tabBatch.item = '"+ d.item_code +"' AND `tabBatch`.`name` like '%s' ORDER BY `tabBatch`.`name` DESC LIMIT 50" if (d.s_warehouse) {
} return "select batch_no from `tabStock Ledger Entry` sle \
else{ where item_code = '" + d.item_code + "' and warehouse = '" + d.s_warehouse +
alert("Please enter Item Code."); "' and ifnull(is_cancelled, 'No') = 'No' and batch_no like '%s' \
} and exists(select * from `tabBatch` where \
name = sle.batch_no and expiry_date >= '" + doc.posting_date +
"' and docstatus != 2) group by batch_no having sum(actual_qty) > 0 \
order by batch_no desc limit 50";
} else {
return "SELECT name FROM tabBatch WHERE docstatus != 2 AND item = '" +
d.item_code + "' and expiry_date >= '" + doc.posting_date +
"' AND name like '%s' ORDER BY name DESC LIMIT 50";
}
} else {
msgprint("Please enter Item Code to get batch no");
}
} }
//==================================================================================================================
cur_frm.cscript.item_code = function(doc, cdt, cdn) { cur_frm.cscript.item_code = function(doc, cdt, cdn) {
var d = locals[cdt][cdn]; var d = locals[cdt][cdn];
// get values args = {
args = { 'item_code' : d.item_code,
'item_code' : d.item_code, 'warehouse' : cstr(d.s_warehouse) || cstr(d.t_warehouse),
'warehouse' : cstr(d.s_warehouse), 'transfer_qty' : d.transfer_qty,
'transfer_qty' : d.transfer_qty, 'serial_no' : d.serial_no,
'serial_no' : d.serial_no 'fg_item' : d.fg_item,
}; 'bom_no' : d.bom_no
get_server_fields('get_item_details',JSON.stringify(args),'mtn_details',doc,cdt,cdn,1); };
get_server_fields('get_item_details',JSON.stringify(args),'mtn_details',doc,cdt,cdn,1);
} }
//================================================================================================================== cur_frm.cscript.s_warehouse = function(doc, cdt, cdn) {
var d = locals[cdt][cdn];
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,
'fg_item' : d.fg_item,
'bom_no' : d.bom_no
}
get_server_fields('get_warehouse_details', JSON.stringify(args),
'mtn_details', doc, cdt, cdn, 1);
}
cur_frm.cscript.t_warehouse = cur_frm.cscript.s_warehouse;
cur_frm.cscript.transfer_qty = function(doc,cdt,cdn) { cur_frm.cscript.transfer_qty = function(doc,cdt,cdn) {
var d = locals[cdt][cdn]; var d = locals[cdt][cdn];
if (doc.from_warehouse && (flt(d.transfer_qty) > flt(d.actual_qty))) { if (doc.from_warehouse && (flt(d.transfer_qty) > flt(d.actual_qty))) {
alert("Transfer Quantity is more than Available Qty"); alert("Transfer Quantity is more than Available Qty");
} }
} }
//==================================================================================================================
cur_frm.cscript.qty = function(doc, cdt, cdn) { cur_frm.cscript.qty = function(doc, cdt, cdn) {
var d = locals[cdt][cdn]; var d = locals[cdt][cdn];
set_multiple('Stock Entry Detail', d.name, {'transfer_qty': flt(d.qty) * flt(d.conversion_factor)}, 'mtn_details'); set_multiple('Stock Entry Detail', d.name, {'transfer_qty': flt(d.qty) * flt(d.conversion_factor)}, 'mtn_details');
refresh_field('mtn_details'); refresh_field('mtn_details');
} }
//==================================================================================================================
cur_frm.cscript.uom = function(doc, cdt, cdn) { cur_frm.cscript.uom = function(doc, cdt, cdn) {
var d = locals[cdt][cdn]; var d = locals[cdt][cdn];
if(d.uom && d.item_code){ if(d.uom && d.item_code){
var arg = {'item_code':d.item_code, 'uom':d.uom, 'qty':d.qty} var arg = {'item_code':d.item_code, 'uom':d.uom, 'qty':d.qty}
get_server_fields('get_uom_details',JSON.stringify(arg),'mtn_details', doc, cdt, cdn, 1); get_server_fields('get_uom_details',JSON.stringify(arg),'mtn_details', doc, cdt, cdn, 1);
} }
} }
//==================================================================================================================
//validate
cur_frm.cscript.validate = function(doc, cdt, cdn) { cur_frm.cscript.validate = function(doc, cdt, cdn) {
cur_frm.cscript.validate_items(doc); cur_frm.cscript.validate_items(doc);
} }
//==================================================================================================================
//validate items
cur_frm.cscript.validate_items = function(doc) { cur_frm.cscript.validate_items = function(doc) {
cl = getchildren('Stock Entry Detail',doc.name,'mtn_details'); cl = getchildren('Stock Entry Detail',doc.name,'mtn_details');
if (!cl.length) { if (!cl.length) {
alert("Item table can not be blank"); alert("Item table can not be blank");
validated = false; validated = false;
} }
} }
cur_frm.fields_dict.customer.get_query = erpnext.utils.customer_query; cur_frm.fields_dict.customer.get_query = erpnext.utils.customer_query;

View File

@ -35,8 +35,6 @@ class DocType(TransactionBase):
self.item_dict = {} self.item_dict = {}
self.fname = 'mtn_details' self.fname = 'mtn_details'
# get item details
# ----------------
def get_item_details(self, arg): def get_item_details(self, arg):
import json import json
arg, actual_qty, in_rate = json.loads(arg), 0, 0 arg, actual_qty, in_rate = json.loads(arg), 0, 0
@ -45,27 +43,23 @@ class DocType(TransactionBase):
if not item: if not item:
msgprint("Item is not active", raise_exception=1) msgprint("Item is not active", raise_exception=1)
if arg.get('warehouse'):
actual_qty = self.get_as_on_stock(arg.get('item_code'), arg.get('warehouse'), self.doc.posting_date, self.doc.posting_time)
in_rate = self.get_incoming_rate(arg.get('item_code'), arg.get('warehouse'), self.doc.posting_date, self.doc.posting_time, arg.get('transfer_qty'), arg.get('serial_no')) or 0
ret = { ret = {
'uom' : item and item[0]['stock_uom'] or '', 'uom' : item and item[0]['stock_uom'] or '',
'stock_uom' : item and item[0]['stock_uom'] or '', 'stock_uom' : item and item[0]['stock_uom'] or '',
'description' : item and item[0]['description'] or '', 'description' : item and item[0]['description'] or '',
'item_name' : item and item[0]['item_name'] or '', 'item_name' : item and item[0]['item_name'] or '',
'actual_qty' : actual_qty,
'qty' : 0, 'qty' : 0,
'transfer_qty' : 0, 'transfer_qty' : 0,
'incoming_rate' : in_rate,
'conversion_factor' : 1, 'conversion_factor' : 1,
'batch_no' : '' 'batch_no' : '',
'actual_qty' : 0,
'incoming_rate' : 0
} }
stock_and_rate = arg.get('warehouse') and self.get_warehouse_details(json.dumps(arg)) or {}
ret.update(stock_and_rate)
return ret return ret
# Get UOM Details
# ----------------
def get_uom_details(self, arg = ''): def get_uom_details(self, arg = ''):
arg, ret = eval(arg), {} arg, ret = eval(arg), {}
uom = sql("select conversion_factor from `tabUOM Conversion Detail` where parent = %s and uom = %s", (arg['item_code'],arg['uom']), as_dict = 1) uom = sql("select conversion_factor from `tabUOM Conversion Detail` where parent = %s and uom = %s", (arg['item_code'],arg['uom']), as_dict = 1)
@ -79,27 +73,43 @@ class DocType(TransactionBase):
} }
return ret return ret
def get_warehouse_details(self, arg):
import json
arg, actual_qty, in_rate = json.loads(arg), 0, 0
ret = {
"actual_qty" : self.get_as_on_stock(arg.get('item_code'), arg.get('warehouse'),
self.doc.posting_date, self.doc.posting_time),
"incoming_rate" : self.get_incoming_rate(arg.get('item_code'),
arg.get('warehouse'), self.doc.posting_date, self.doc.posting_time,
arg.get('transfer_qty'), arg.get('serial_no'), arg.get('fg_item'),
arg.get('bom_no')) or 0
}
return ret
# get stock and incoming rate on posting date
# ---------------------------------------------
def get_stock_and_rate(self, bom_no = ''): def get_stock_and_rate(self, bom_no = ''):
""" get stock and incoming rate on posting date"""
for d in getlist(self.doclist, 'mtn_details'): for d in getlist(self.doclist, 'mtn_details'):
# assign parent warehouse # assign parent warehouse
d.s_warehouse = cstr(d.s_warehouse) or self.doc.purpose != 'Production Order' and self.doc.from_warehouse or '' d.s_warehouse = cstr(d.s_warehouse) or self.doc.purpose != 'Production Order' \
d.t_warehouse = cstr(d.t_warehouse) or self.doc.purpose != 'Production Order' and self.doc.to_warehouse or '' and self.doc.from_warehouse or ''
d.t_warehouse = cstr(d.t_warehouse) or self.doc.purpose != 'Production Order' \
and self.doc.to_warehouse or ''
# get current stock at source warehouse # get current stock at source warehouse
d.actual_qty = d.s_warehouse and self.get_as_on_stock(d.item_code, d.s_warehouse, self.doc.posting_date, self.doc.posting_time) or 0 d.actual_qty = self.get_as_on_stock(d.item_code, d.s_warehouse or d.t_warehouse,
self.doc.posting_date, self.doc.posting_time) or 0
# get incoming rate # get incoming rate
if not flt(d.incoming_rate): if not flt(d.incoming_rate):
d.incoming_rate = self.get_incoming_rate(d.item_code, d.s_warehouse, self.doc.posting_date, self.doc.posting_time, d.transfer_qty, d.serial_no, d.fg_item, d.bom_no or bom_no) d.incoming_rate = self.get_incoming_rate(d.item_code,
d.s_warehouse or d.t_warehouse, self.doc.posting_date,
self.doc.posting_time, d.transfer_qty, d.serial_no,
d.fg_item, d.bom_no or bom_no)
# Get stock qty on any date
# ---------------------------
def get_as_on_stock(self, item, wh, dt, tm): def get_as_on_stock(self, item, wh, dt, tm):
"""Get stock qty on any date"""
bin = sql("select name from tabBin where item_code = %s and warehouse = %s", (item, wh)) bin = sql("select name from tabBin where item_code = %s and warehouse = %s", (item, wh))
bin_id = bin and bin[0][0] or '' bin_id = bin and bin[0][0] or ''
prev_sle = bin_id and get_obj('Bin', bin_id).get_prev_sle(dt, tm) or {} prev_sle = bin_id and get_obj('Bin', bin_id).get_prev_sle(dt, tm) or {}
@ -107,17 +117,15 @@ class DocType(TransactionBase):
return qty return qty
# Get incoming rate def get_incoming_rate(self, item, wh, dt, tm, qty=0, serial_no='', fg_item=0, bom_no=''):
# -------------------
def get_incoming_rate(self, item, wh, dt, tm, qty = 0, serial_no = '', fg_item = 0, bom_no = ''):
in_rate = 0 in_rate = 0
if fg_item and bom_no: if fg_item and bom_no:
# re-calculate cost for production item from bom in_rate = webnotes.conn.sql("""select ifnull(total_cost, 0) / ifnull(quantity, 1)
get_obj('BOM Control').calculate_cost(bom_no) from `tabBOM` where name = %s and docstatus=1""", bom_no, debug=1)
bom_obj = get_obj('BOM', bom_no) in_rate = in_rate and in_rate[0][0] or 0
in_rate = flt(bom_obj.doc.total_cost) / (flt(bom_obj.doc.quantity) or 1)
elif wh: elif wh:
in_rate = get_obj('Valuation Control').get_incoming_rate(dt, tm, item, wh, qty, serial_no) in_rate = get_obj('Valuation Control').get_incoming_rate(dt, tm,
item, wh, qty, serial_no)
return in_rate return in_rate
@ -205,6 +213,10 @@ class DocType(TransactionBase):
def validate_bom_no(self): def validate_bom_no(self):
if self.doc.bom_no: if self.doc.bom_no:
if not webnotes.conn.sql("""select name from tabBOM where name = %s and docstatus = 1
and ifnull(is_active, 'No') = 'Yes'""", self.doc.bom_no):
msgprint("""BOM: %s not found, may be it has been cancelled or inactivated""" %
self.doc.bom_no, raise_exception=1)
if not self.doc.fg_completed_qty: if not self.doc.fg_completed_qty:
msgprint("Please enter FG Completed Qty", raise_exception=1) msgprint("Please enter FG Completed Qty", raise_exception=1)
@ -215,7 +227,8 @@ class DocType(TransactionBase):
self.validate_for_production_order(pro_obj) self.validate_for_production_order(pro_obj)
bom_no = pro_obj.doc.bom_no bom_no = pro_obj.doc.bom_no
fg_qty = (self.doc.process == 'Backflush') and flt(self.doc.fg_completed_qty) or flt(pro_obj.doc.qty) fg_qty = (self.doc.process == 'Backflush') and flt(self.doc.fg_completed_qty) \
or flt(pro_obj.doc.qty)
use_multi_level_bom = pro_obj.doc.use_multi_level_bom use_multi_level_bom = pro_obj.doc.use_multi_level_bom
elif self.doc.purpose == 'Other': elif self.doc.purpose == 'Other':
self.validate_bom_no() self.validate_bom_no()
@ -234,22 +247,30 @@ class DocType(TransactionBase):
if self.doc.process == 'Backflush': if self.doc.process == 'Backflush':
sw = '' sw = ''
tw = cstr(pro_obj.doc.fg_warehouse) tw = cstr(pro_obj.doc.fg_warehouse)
fg_item_dict = {cstr(pro_obj.doc.production_item) : [self.doc.fg_completed_qty, pro_obj.doc.description, pro_obj.doc.stock_uom]} fg_item_dict = {
cstr(pro_obj.doc.production_item) : [self.doc.fg_completed_qty,
pro_obj.doc.description, pro_obj.doc.stock_uom]
}
elif self.doc.purpose == 'Other' and self.doc.bom_no: elif self.doc.purpose == 'Other' and self.doc.bom_no:
sw, tw = '', '' sw, tw = '', ''
item = sql("select item, description, uom from `tabBOM` where name = %s", self.doc.bom_no, as_dict=1) item = sql("select item, description, uom from `tabBOM` where name = %s", self.doc.bom_no, as_dict=1)
fg_item_dict = {item[0]['item'] : [self.doc.fg_completed_qty, item[0]['description'], item[0]['uom']]} fg_item_dict = {
item[0]['item'] : [self.doc.fg_completed_qty,
item[0]['description'], item[0]['uom']]
}
if fg_item_dict: if fg_item_dict:
self.add_to_stock_entry_detail(sw, tw, fg_item_dict, fg_item = 1, bom_no = bom_no) self.add_to_stock_entry_detail(sw, tw, fg_item_dict, fg_item = 1, bom_no = bom_no)
self.get_stock_and_rate()
def validate_transfer_qty(self): def validate_transfer_qty(self):
for d in getlist(self.doclist, 'mtn_details'): for d in getlist(self.doclist, 'mtn_details'):
if flt(d.transfer_qty) <= 0: if flt(d.transfer_qty) <= 0:
msgprint("Transfer Quantity can not be less than or equal to zero at Row No " + cstr(d.idx)) msgprint("Transfer Quantity can not be less than or equal to zero \
raise Exception at Row No " + cstr(d.idx), raise_exception=1)
def calc_amount(self): def calc_amount(self):
@ -326,8 +347,10 @@ class DocType(TransactionBase):
self.validate_incoming_rate() self.validate_incoming_rate()
self.validate_bom_belongs_to_item() self.validate_bom_belongs_to_item()
self.calc_amount() self.calc_amount()
get_obj('Sales Common').validate_fiscal_year(self.doc.fiscal_year,self.doc.posting_date,'Posting Date') get_obj('Sales Common').validate_fiscal_year(self.doc.fiscal_year,
self.doc.posting_date, 'Posting Date')
if self.doc.purpose == 'Other':
self.validate_bom_no()
# If target warehouse exists, incoming rate is mandatory # If target warehouse exists, incoming rate is mandatory
# -------------------------------------------------------- # --------------------------------------------------------

View File

@ -4,7 +4,7 @@
"docstatus": 0, "docstatus": 0,
"creation": "2012-11-28 11:26:22", "creation": "2012-11-28 11:26:22",
"modified_by": "Administrator", "modified_by": "Administrator",
"modified": "2012-11-30 14:10:02" "modified": "2012-12-03 12:00:59"
}, },
{ {
"is_submittable": 1, "is_submittable": 1,
@ -414,7 +414,9 @@
}, },
{ {
"print_hide": 1, "print_hide": 1,
"description": "Get valuation rate and available stock at source/target warehouse on mentioned posting date-time. If serialized item, please press this button after entering serial nos.",
"oldfieldtype": "Button", "oldfieldtype": "Button",
"colour": "White:FFF",
"doctype": "DocField", "doctype": "DocField",
"label": "Get Stock and Rate", "label": "Get Stock and Rate",
"options": "get_stock_and_rate", "options": "get_stock_and_rate",

View File

@ -1,266 +1,218 @@
# DocType, Stock Entry Detail
[ [
{
# These values are common in all dictionaries "owner": "Administrator",
{ "docstatus": 0,
'creation': '2012-04-13 11:56:38', "creation": "2012-07-03 13:29:47",
'docstatus': 0, "modified_by": "Administrator",
'modified': '2012-05-01 16:16:20', "modified": "2012-12-03 11:37:17"
'modified_by': u'Administrator', },
'owner': u'Administrator' {
}, "istable": 1,
"autoname": "MTND/.######",
# These values are common for all DocType "name": "__common__",
{ "default_print_format": "Standard",
'autoname': u'MTND/.######', "doctype": "DocType",
'colour': u'White:FFF', "module": "Stock"
'default_print_format': u'Standard', },
'doctype': 'DocType', {
'istable': 1, "name": "__common__",
'module': u'Stock', "parent": "Stock Entry Detail",
'name': '__common__', "doctype": "DocField",
'section_style': u'Tray', "parenttype": "DocType",
'server_code_error': u' ', "parentfield": "fields"
'show_in_menu': 0, },
'version': 1 {
}, "name": "Stock Entry Detail",
"doctype": "DocType"
# These values are common for all DocField },
{ {
'doctype': u'DocField', "oldfieldtype": "Link",
'name': '__common__', "doctype": "DocField",
'parent': u'Stock Entry Detail', "label": "Source Warehouse",
'parentfield': u'fields', "oldfieldname": "s_warehouse",
'parenttype': u'DocType' "options": "Warehouse",
}, "fieldname": "s_warehouse",
"fieldtype": "Link",
# DocType, Stock Entry Detail "permlevel": 0,
{ "in_filter": 1
'doctype': 'DocType', },
'name': u'Stock Entry Detail' {
}, "oldfieldtype": "Link",
"doctype": "DocField",
# DocField "label": "Target Warehouse",
{ "oldfieldname": "t_warehouse",
'doctype': u'DocField', "options": "Warehouse",
'fieldname': u's_warehouse', "fieldname": "t_warehouse",
'fieldtype': u'Link', "fieldtype": "Link",
'in_filter': 1, "permlevel": 0,
'label': u'Source Warehouse', "in_filter": 1
'oldfieldname': u's_warehouse', },
'oldfieldtype': u'Link', {
'options': u'Warehouse', "oldfieldtype": "Link",
'permlevel': 0 "doctype": "DocField",
}, "label": "Item Code",
"oldfieldname": "item_code",
# DocField "permlevel": 0,
{ "trigger": "Client",
'doctype': u'DocField', "fieldname": "item_code",
'fieldname': u't_warehouse', "fieldtype": "Link",
'fieldtype': u'Link', "search_index": 1,
'in_filter': 1, "reqd": 1,
'label': u'Target Warehouse', "options": "Item",
'oldfieldname': u't_warehouse', "in_filter": 1
'oldfieldtype': u'Link', },
'options': u'Warehouse', {
'permlevel': 0 "oldfieldtype": "Text",
}, "doctype": "DocField",
"label": "Description",
# DocField "oldfieldname": "description",
{ "width": "300px",
'doctype': u'DocField', "fieldname": "description",
'fieldname': u'item_code', "fieldtype": "Text",
'fieldtype': u'Link', "permlevel": 0
'in_filter': 1, },
'label': u'Item Code', {
'oldfieldname': u'item_code', "oldfieldtype": "Currency",
'oldfieldtype': u'Link', "doctype": "DocField",
'options': u'Item', "label": "Qty",
'permlevel': 0, "oldfieldname": "qty",
'reqd': 1, "trigger": "Client",
'search_index': 1, "fieldname": "qty",
'trigger': u'Client' "fieldtype": "Currency",
}, "reqd": 1,
"permlevel": 0
# DocField },
{ {
'doctype': u'DocField', "oldfieldtype": "Link",
'fieldname': u'description', "colour": "White:FFF",
'fieldtype': u'Text', "doctype": "DocField",
'label': u'Description', "label": "UOM",
'oldfieldname': u'description', "oldfieldname": "uom",
'oldfieldtype': u'Text', "trigger": "Client",
'permlevel': 0, "fieldname": "uom",
'width': u'300px' "fieldtype": "Link",
}, "reqd": 1,
"options": "UOM",
# DocField "permlevel": 0
{ },
'doctype': u'DocField', {
'fieldname': u'qty', "oldfieldtype": "Currency",
'fieldtype': u'Currency', "doctype": "DocField",
'label': u'Qty', "label": "Valuation Rate",
'oldfieldname': u'qty', "oldfieldname": "incoming_rate",
'oldfieldtype': u'Currency', "fieldname": "incoming_rate",
'permlevel': 0, "fieldtype": "Currency",
'reqd': 1, "reqd": 0,
'trigger': u'Client' "permlevel": 0
}, },
{
# DocField "oldfieldtype": "Currency",
{ "doctype": "DocField",
'colour': u'White:FFF', "label": "Amount",
'doctype': u'DocField', "oldfieldname": "amount",
'fieldname': u'uom', "fieldname": "amount",
'fieldtype': u'Link', "fieldtype": "Currency",
'label': u'UOM', "permlevel": 1
'oldfieldname': u'uom', },
'oldfieldtype': u'Link', {
'options': u'UOM', "no_copy": 1,
'permlevel': 0, "oldfieldtype": "Text",
'reqd': 1, "doctype": "DocField",
'trigger': u'Client' "label": "Serial No",
}, "oldfieldname": "serial_no",
"fieldname": "serial_no",
# DocField "fieldtype": "Text",
{ "reqd": 0,
'doctype': u'DocField', "permlevel": 0
'fieldname': u'incoming_rate', },
'fieldtype': u'Currency', {
'label': u'Incoming Rate', "print_hide": 1,
'oldfieldname': u'incoming_rate', "oldfieldtype": "Link",
'oldfieldtype': u'Currency', "doctype": "DocField",
'permlevel': 0, "label": "Batch No",
'reqd': 0 "oldfieldname": "batch_no",
}, "trigger": "Client",
"fieldname": "batch_no",
# DocField "fieldtype": "Link",
{ "options": "Batch",
'doctype': u'DocField', "permlevel": 0
'fieldname': u'amount', },
'fieldtype': u'Currency', {
'label': u'Amount', "print_hide": 1,
'oldfieldname': u'amount', "oldfieldtype": "Currency",
'oldfieldtype': u'Currency', "doctype": "DocField",
'permlevel': 1 "label": "Reqd Qty",
}, "oldfieldname": "reqd_qty",
"fieldname": "reqd_qty",
# DocField "fieldtype": "Currency",
{ "permlevel": 3,
'doctype': u'DocField', "in_filter": 0
'fieldname': u'serial_no', },
'fieldtype': u'Text', {
'label': u'Serial No', "print_hide": 1,
'no_copy': 1, "no_copy": 1,
'oldfieldname': u'serial_no', "oldfieldtype": "Read Only",
'oldfieldtype': u'Text', "doctype": "DocField",
'permlevel': 0, "label": "Actual Qty (at source/target)",
'reqd': 0 "oldfieldname": "actual_qty",
}, "fieldname": "actual_qty",
"fieldtype": "Read Only",
# DocField "search_index": 1,
{ "reqd": 0,
'doctype': u'DocField', "permlevel": 1,
'fieldname': u'batch_no', "in_filter": 1
'fieldtype': u'Link', },
'label': u'Batch No', {
'oldfieldname': u'batch_no', "oldfieldtype": "Currency",
'oldfieldtype': u'Link', "doctype": "DocField",
'options': u'Batch', "label": "Conversion Factor",
'permlevel': 0, "oldfieldname": "conversion_factor",
'print_hide': 1, "fieldname": "conversion_factor",
'trigger': u'Client' "fieldtype": "Currency",
}, "reqd": 1,
"permlevel": 1
# DocField },
{ {
'doctype': u'DocField', "oldfieldtype": "Currency",
'fieldname': u'reqd_qty', "doctype": "DocField",
'fieldtype': u'Currency', "label": "Stock Qty",
'in_filter': 0, "oldfieldname": "transfer_qty",
'label': u'Reqd Qty', "fieldname": "transfer_qty",
'oldfieldname': u'reqd_qty', "fieldtype": "Currency",
'oldfieldtype': u'Currency', "reqd": 1,
'permlevel': 3, "permlevel": 1
'print_hide': 1 },
}, {
"oldfieldtype": "Link",
# DocField "doctype": "DocField",
{ "label": "Stock UOM",
'doctype': u'DocField', "oldfieldname": "stock_uom",
'fieldname': u'actual_qty', "options": "UOM",
'fieldtype': u'Read Only', "fieldname": "stock_uom",
'in_filter': 1, "fieldtype": "Link",
'label': u'Actual Qty (at source)', "search_index": 0,
'no_copy': 1, "reqd": 1,
'oldfieldname': u'actual_qty', "permlevel": 1,
'oldfieldtype': u'Read Only', "in_filter": 0
'permlevel': 1, },
'print_hide': 1, {
'reqd': 0, "description": "BOM No. for a Finished Good Item",
'search_index': 1 "doctype": "DocField",
}, "label": "BOM No",
"options": "BOM",
# DocField "fieldname": "bom_no",
{ "fieldtype": "Link",
'doctype': u'DocField', "permlevel": 0
'fieldname': u'conversion_factor', },
'fieldtype': u'Currency', {
'label': u'Conversion Factor', "print_hide": 1,
'oldfieldname': u'conversion_factor', "oldfieldtype": "Check",
'oldfieldtype': u'Currency', "doctype": "DocField",
'permlevel': 1, "label": "FG Item",
'reqd': 1 "oldfieldname": "fg_item",
}, "fieldname": "fg_item",
"fieldtype": "Check",
# DocField "permlevel": 0,
{ "in_filter": 1
'doctype': u'DocField', }
'fieldname': u'transfer_qty',
'fieldtype': u'Currency',
'label': u'Stock Qty',
'oldfieldname': u'transfer_qty',
'oldfieldtype': u'Currency',
'permlevel': 1,
'reqd': 1
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'stock_uom',
'fieldtype': u'Link',
'in_filter': 0,
'label': u'Stock UOM',
'oldfieldname': u'stock_uom',
'oldfieldtype': u'Link',
'options': u'UOM',
'permlevel': 1,
'reqd': 1,
'search_index': 0
},
# DocField
{
'description': u'BOM No. for a Finished Good Item',
'doctype': u'DocField',
'fieldname': u'bom_no',
'fieldtype': u'Link',
'label': u'BOM No.',
'options': u'BOM',
'permlevel': 0
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'fg_item',
'fieldtype': u'Check',
'in_filter': 1,
'label': u'FG Item',
'oldfieldname': u'fg_item',
'oldfieldtype': u'Check',
'permlevel': 0,
'print_hide': 1
}
] ]

View File

@ -37,15 +37,12 @@ class DocType:
if (batch_bal + self.doc.actual_qty) < 0: if (batch_bal + self.doc.actual_qty) < 0:
msgprint("""Not enough quantity (requested: %(actual_qty)s, current: %(batch_bal)s in Batch msgprint("""Not enough quantity (requested: %(actual_qty)s, current: %(batch_bal)s in Batch
<b>%(batch_no)s</b> for Item <b>%(item_code)s</b> at Warehouse<b>%(warehouse)s</b> <b>%(batch_no)s</b> for Item <b>%(item_code)s</b> at Warehouse <b>%(warehouse)s</b>
as on %(posting_date)s %(posting_time)s""" % self.doc.fields, raise_exception = 1) as on %(posting_date)s %(posting_time)s""" % self.doc.fields, raise_exception = 1)
self.doc.fields.pop('batch_bal') self.doc.fields.pop('batch_bal')
# mandatory
# ---------
def validate_mandatory(self): def validate_mandatory(self):
mandatory = ['warehouse','transaction_date','posting_date','voucher_type','voucher_no','actual_qty','company','fiscal_year'] mandatory = ['warehouse','transaction_date','posting_date','voucher_type','voucher_no','actual_qty','company','fiscal_year']
for k in mandatory: for k in mandatory:
@ -55,9 +52,6 @@ class DocType:
if not sql("select name from tabWarehouse where name = '%s'" % self.doc.fields.get(k)): if not sql("select name from tabWarehouse where name = '%s'" % self.doc.fields.get(k)):
msgprint("Warehouse: '%s' does not exist in the system. Please check." % self.doc.fields.get(k), raise_exception = 1) msgprint("Warehouse: '%s' does not exist in the system. Please check." % self.doc.fields.get(k), raise_exception = 1)
# validate for item
# -----------------
def validate_item(self): def validate_item(self):
item_det = sql("select name, has_batch_no, docstatus from tabItem where name = '%s'" % self.doc.item_code) item_det = sql("select name, has_batch_no, docstatus from tabItem where name = '%s'" % self.doc.item_code)