diff --git a/selling/doctype/sales_common/sales_common.js b/selling/doctype/sales_common/sales_common.js index 4807dc1af4..c5eed98f71 100644 --- a/selling/doctype/sales_common/sales_common.js +++ b/selling/doctype/sales_common/sales_common.js @@ -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); } +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 *************************** cur_frm.cscript.qty = function(doc, cdt, cdn) { cur_frm.cscript.recalc(doc, 1); } diff --git a/stock/doctype/delivery_note/delivery_note.js b/stock/doctype/delivery_note/delivery_note.js index 62958112a1..10739d2770 100644 --- a/stock/doctype/delivery_note/delivery_note.js +++ b/stock/doctype/delivery_note/delivery_note.js @@ -134,16 +134,6 @@ cur_frm.cscript.new_contact = function(){ 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 ***************** cur_frm.fields_dict['project_name'].get_query = function(doc, cdt, cdn) { diff --git a/stock/doctype/stock_entry/stock_entry.js b/stock/doctype/stock_entry/stock_entry.js index bf7582652f..5805b2aa92 100644 --- a/stock/doctype/stock_entry/stock_entry.js +++ b/stock/doctype/stock_entry/stock_entry.js @@ -8,68 +8,77 @@ // // This program is distributed in the hope that it will be useful, // 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. // // You should have received a copy of the GNU General Public License -// along with this program. If not, see . +// along with this program. If not, see . cur_frm.cscript.onload = function(doc, cdt, cdn) { - 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.purpose) set_multiple(cdt, cdn, {purpose:'Material Issue'}); - cfn_set_fields(doc, cdt, cdn); + 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.purpose) set_multiple(cdt, cdn, {purpose:'Material Issue'}); + cfn_set_fields(doc, cdt, cdn); } var cfn_set_fields = function(doc, cdt, cdn) { - lst = ['supplier','supplier_name','supplier_address','customer','customer_name','customer_address']; - if (in_list(['Material Issue', 'Material Transfer', 'Material Receipt', 'Sales Return', 'Purchase Return', 'Production Order', 'Subcontracting', 'Other'], doc.purpose)) { - hide_field(lst); - $(cur_frm.fields_dict.contact_section.row.wrapper).toggle(false); - } else unhide_field(lst); + lst = ['supplier', 'supplier_name', 'supplier_address', + 'customer', 'customer_name', 'customer_address']; + if (in_list(['Material Issue', 'Material Transfer', 'Material Receipt', 'Sales Return', + 'Purchase Return', 'Production Order', 'Subcontracting', 'Other'], doc.purpose)) { + 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']); + } - 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 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; - } - + 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 == '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); + 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 @@ -77,47 +86,44 @@ cur_frm.cscript.refresh = function(doc, cdt, cdn) { erpnext.hide_naming_series(); //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); else hide_field(excise_flds); } - 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){ - 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){ - 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){ - 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){ - 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) { - 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) { - cfn_set_fields(doc, cdt, cdn); + cfn_set_fields(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 // 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 -// cur_frm.fields_dict['mtn_details'].grid.onrowadd = function(doc, cdt, cdn){ var d = locals[cdt][cdn]; 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 ============================================================= -cur_frm.fields_dict['mtn_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."); - } +// Overloaded query for link batch_no +cur_frm.fields_dict['mtn_details'].grid.get_field('batch_no').get_query = function(doc, cdt, cdn) { + var d = locals[cdt][cdn]; + if(d.item_code) { + if (d.s_warehouse) { + return "select batch_no from `tabStock Ledger Entry` sle \ + where item_code = '" + d.item_code + "' and warehouse = '" + d.s_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"); + } } -//================================================================================================================== - cur_frm.cscript.item_code = function(doc, cdt, cdn) { - var d = locals[cdt][cdn]; - // get values - args = { - 'item_code' : d.item_code, - 'warehouse' : cstr(d.s_warehouse), - 'transfer_qty' : d.transfer_qty, - 'serial_no' : d.serial_no - }; - get_server_fields('get_item_details',JSON.stringify(args),'mtn_details',doc,cdt,cdn,1); + 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_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) { - var d = locals[cdt][cdn]; - if (doc.from_warehouse && (flt(d.transfer_qty) > flt(d.actual_qty))) { - alert("Transfer Quantity is more than Available Qty"); - } + var d = locals[cdt][cdn]; + if (doc.from_warehouse && (flt(d.transfer_qty) > flt(d.actual_qty))) { + alert("Transfer Quantity is more than Available Qty"); + } } - -//================================================================================================================== - cur_frm.cscript.qty = function(doc, 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'); - refresh_field('mtn_details'); + var d = locals[cdt][cdn]; + set_multiple('Stock Entry Detail', d.name, {'transfer_qty': flt(d.qty) * flt(d.conversion_factor)}, 'mtn_details'); + refresh_field('mtn_details'); } -//================================================================================================================== - 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} - get_server_fields('get_uom_details',JSON.stringify(arg),'mtn_details', doc, cdt, cdn, 1); - } + var d = locals[cdt][cdn]; + if(d.uom && d.item_code){ + 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); + } } -//================================================================================================================== -//validate 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) { - cl = getchildren('Stock Entry Detail',doc.name,'mtn_details'); - if (!cl.length) { - alert("Item table can not be blank"); - validated = false; - } + cl = getchildren('Stock Entry Detail',doc.name,'mtn_details'); + if (!cl.length) { + alert("Item table can not be blank"); + validated = false; + } } cur_frm.fields_dict.customer.get_query = erpnext.utils.customer_query; diff --git a/stock/doctype/stock_entry/stock_entry.py b/stock/doctype/stock_entry/stock_entry.py index 29f58bc0bd..67f1643fde 100644 --- a/stock/doctype/stock_entry/stock_entry.py +++ b/stock/doctype/stock_entry/stock_entry.py @@ -35,8 +35,6 @@ class DocType(TransactionBase): self.item_dict = {} self.fname = 'mtn_details' - # get item details - # ---------------- def get_item_details(self, arg): import json arg, actual_qty, in_rate = json.loads(arg), 0, 0 @@ -44,28 +42,24 @@ class DocType(TransactionBase): item = sql("select stock_uom, description, item_name from `tabItem` where name = %s and (ifnull(end_of_life,'')='' or end_of_life ='0000-00-00' or end_of_life > now())", (arg.get('item_code')), as_dict = 1) if not item: 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 = { 'uom' : item and item[0]['stock_uom'] or '', 'stock_uom' : item and item[0]['stock_uom'] or '', 'description' : item and item[0]['description'] or '', 'item_name' : item and item[0]['item_name'] or '', - 'actual_qty' : actual_qty, 'qty' : 0, 'transfer_qty' : 0, - 'incoming_rate' : in_rate, '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 - # Get UOM Details - # ---------------- def get_uom_details(self, 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) @@ -78,28 +72,44 @@ class DocType(TransactionBase): 'transfer_qty' : flt(arg['qty']) * flt(uom[0]['conversion_factor']), } return ret - - - # get stock and incoming rate on posting date - # --------------------------------------------- + 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 + + def get_stock_and_rate(self, bom_no = ''): + """ get stock and incoming rate on posting date""" for d in getlist(self.doclist, 'mtn_details'): # assign parent warehouse - d.s_warehouse = cstr(d.s_warehouse) or self.doc.purpose != 'Production Order' 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 '' + d.s_warehouse = cstr(d.s_warehouse) or self.doc.purpose != 'Production Order' \ + 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 - 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 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): + """Get stock qty on any date""" bin = sql("select name from tabBin where item_code = %s and warehouse = %s", (item, wh)) bin_id = bin and bin[0][0] 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 - # 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 if fg_item and bom_no: - # re-calculate cost for production item from bom - get_obj('BOM Control').calculate_cost(bom_no) - bom_obj = get_obj('BOM', bom_no) - in_rate = flt(bom_obj.doc.total_cost) / (flt(bom_obj.doc.quantity) or 1) + in_rate = webnotes.conn.sql("""select ifnull(total_cost, 0) / ifnull(quantity, 1) + from `tabBOM` where name = %s and docstatus=1""", bom_no, debug=1) + in_rate = in_rate and in_rate[0][0] or 0 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 @@ -205,6 +213,10 @@ class DocType(TransactionBase): def validate_bom_no(self): 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: msgprint("Please enter FG Completed Qty", raise_exception=1) @@ -215,7 +227,8 @@ class DocType(TransactionBase): self.validate_for_production_order(pro_obj) 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 elif self.doc.purpose == 'Other': self.validate_bom_no() @@ -234,22 +247,30 @@ class DocType(TransactionBase): if self.doc.process == 'Backflush': sw = '' 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: sw, tw = '', '' 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: 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): for d in getlist(self.doclist, 'mtn_details'): if flt(d.transfer_qty) <= 0: - msgprint("Transfer Quantity can not be less than or equal to zero at Row No " + cstr(d.idx)) - raise Exception + msgprint("Transfer Quantity can not be less than or equal to zero \ + at Row No " + cstr(d.idx), raise_exception=1) def calc_amount(self): @@ -326,8 +347,10 @@ class DocType(TransactionBase): self.validate_incoming_rate() self.validate_bom_belongs_to_item() 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 # -------------------------------------------------------- diff --git a/stock/doctype/stock_entry/stock_entry.txt b/stock/doctype/stock_entry/stock_entry.txt index 24412b88cf..5d2a79d5b7 100644 --- a/stock/doctype/stock_entry/stock_entry.txt +++ b/stock/doctype/stock_entry/stock_entry.txt @@ -4,7 +4,7 @@ "docstatus": 0, "creation": "2012-11-28 11:26:22", "modified_by": "Administrator", - "modified": "2012-11-30 14:10:02" + "modified": "2012-12-03 12:00:59" }, { "is_submittable": 1, @@ -414,7 +414,9 @@ }, { "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", + "colour": "White:FFF", "doctype": "DocField", "label": "Get Stock and Rate", "options": "get_stock_and_rate", diff --git a/stock/doctype/stock_entry_detail/stock_entry_detail.txt b/stock/doctype/stock_entry_detail/stock_entry_detail.txt index 031bd8f42f..503dd5b438 100644 --- a/stock/doctype/stock_entry_detail/stock_entry_detail.txt +++ b/stock/doctype/stock_entry_detail/stock_entry_detail.txt @@ -1,266 +1,218 @@ -# DocType, Stock Entry Detail [ - - # These values are common in all dictionaries - { - 'creation': '2012-04-13 11:56:38', - 'docstatus': 0, - 'modified': '2012-05-01 16:16:20', - 'modified_by': u'Administrator', - 'owner': u'Administrator' - }, - - # These values are common for all DocType - { - 'autoname': u'MTND/.######', - 'colour': u'White:FFF', - 'default_print_format': u'Standard', - 'doctype': 'DocType', - 'istable': 1, - 'module': u'Stock', - 'name': '__common__', - 'section_style': u'Tray', - 'server_code_error': u' ', - 'show_in_menu': 0, - 'version': 1 - }, - - # These values are common for all DocField - { - 'doctype': u'DocField', - 'name': '__common__', - 'parent': u'Stock Entry Detail', - 'parentfield': u'fields', - 'parenttype': u'DocType' - }, - - # DocType, Stock Entry Detail - { - 'doctype': 'DocType', - 'name': u'Stock Entry Detail' - }, - - # DocField - { - 'doctype': u'DocField', - 'fieldname': u's_warehouse', - 'fieldtype': u'Link', - 'in_filter': 1, - 'label': u'Source Warehouse', - 'oldfieldname': u's_warehouse', - 'oldfieldtype': u'Link', - 'options': u'Warehouse', - 'permlevel': 0 - }, - - # DocField - { - 'doctype': u'DocField', - 'fieldname': u't_warehouse', - 'fieldtype': u'Link', - 'in_filter': 1, - 'label': u'Target Warehouse', - 'oldfieldname': u't_warehouse', - 'oldfieldtype': u'Link', - 'options': u'Warehouse', - 'permlevel': 0 - }, - - # DocField - { - 'doctype': u'DocField', - 'fieldname': u'item_code', - 'fieldtype': u'Link', - 'in_filter': 1, - 'label': u'Item Code', - 'oldfieldname': u'item_code', - 'oldfieldtype': u'Link', - 'options': u'Item', - 'permlevel': 0, - 'reqd': 1, - 'search_index': 1, - 'trigger': u'Client' - }, - - # DocField - { - 'doctype': u'DocField', - 'fieldname': u'description', - 'fieldtype': u'Text', - 'label': u'Description', - 'oldfieldname': u'description', - 'oldfieldtype': u'Text', - 'permlevel': 0, - 'width': u'300px' - }, - - # DocField - { - 'doctype': u'DocField', - 'fieldname': u'qty', - 'fieldtype': u'Currency', - 'label': u'Qty', - 'oldfieldname': u'qty', - 'oldfieldtype': u'Currency', - 'permlevel': 0, - 'reqd': 1, - 'trigger': u'Client' - }, - - # DocField - { - 'colour': u'White:FFF', - 'doctype': u'DocField', - 'fieldname': u'uom', - 'fieldtype': u'Link', - 'label': u'UOM', - 'oldfieldname': u'uom', - 'oldfieldtype': u'Link', - 'options': u'UOM', - 'permlevel': 0, - 'reqd': 1, - 'trigger': u'Client' - }, - - # DocField - { - 'doctype': u'DocField', - 'fieldname': u'incoming_rate', - 'fieldtype': u'Currency', - 'label': u'Incoming Rate', - 'oldfieldname': u'incoming_rate', - 'oldfieldtype': u'Currency', - 'permlevel': 0, - 'reqd': 0 - }, - - # DocField - { - 'doctype': u'DocField', - 'fieldname': u'amount', - 'fieldtype': u'Currency', - 'label': u'Amount', - 'oldfieldname': u'amount', - 'oldfieldtype': u'Currency', - 'permlevel': 1 - }, - - # DocField - { - 'doctype': u'DocField', - 'fieldname': u'serial_no', - 'fieldtype': u'Text', - 'label': u'Serial No', - 'no_copy': 1, - 'oldfieldname': u'serial_no', - 'oldfieldtype': u'Text', - 'permlevel': 0, - 'reqd': 0 - }, - - # DocField - { - 'doctype': u'DocField', - 'fieldname': u'batch_no', - 'fieldtype': u'Link', - 'label': u'Batch No', - 'oldfieldname': u'batch_no', - 'oldfieldtype': u'Link', - 'options': u'Batch', - 'permlevel': 0, - 'print_hide': 1, - 'trigger': u'Client' - }, - - # DocField - { - 'doctype': u'DocField', - 'fieldname': u'reqd_qty', - 'fieldtype': u'Currency', - 'in_filter': 0, - 'label': u'Reqd Qty', - 'oldfieldname': u'reqd_qty', - 'oldfieldtype': u'Currency', - 'permlevel': 3, - 'print_hide': 1 - }, - - # DocField - { - 'doctype': u'DocField', - 'fieldname': u'actual_qty', - 'fieldtype': u'Read Only', - 'in_filter': 1, - 'label': u'Actual Qty (at source)', - 'no_copy': 1, - 'oldfieldname': u'actual_qty', - 'oldfieldtype': u'Read Only', - 'permlevel': 1, - 'print_hide': 1, - 'reqd': 0, - 'search_index': 1 - }, - - # DocField - { - 'doctype': u'DocField', - 'fieldname': u'conversion_factor', - 'fieldtype': u'Currency', - 'label': u'Conversion Factor', - 'oldfieldname': u'conversion_factor', - 'oldfieldtype': u'Currency', - 'permlevel': 1, - 'reqd': 1 - }, - - # DocField - { - '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 - } + { + "owner": "Administrator", + "docstatus": 0, + "creation": "2012-07-03 13:29:47", + "modified_by": "Administrator", + "modified": "2012-12-03 11:37:17" + }, + { + "istable": 1, + "autoname": "MTND/.######", + "name": "__common__", + "default_print_format": "Standard", + "doctype": "DocType", + "module": "Stock" + }, + { + "name": "__common__", + "parent": "Stock Entry Detail", + "doctype": "DocField", + "parenttype": "DocType", + "parentfield": "fields" + }, + { + "name": "Stock Entry Detail", + "doctype": "DocType" + }, + { + "oldfieldtype": "Link", + "doctype": "DocField", + "label": "Source Warehouse", + "oldfieldname": "s_warehouse", + "options": "Warehouse", + "fieldname": "s_warehouse", + "fieldtype": "Link", + "permlevel": 0, + "in_filter": 1 + }, + { + "oldfieldtype": "Link", + "doctype": "DocField", + "label": "Target Warehouse", + "oldfieldname": "t_warehouse", + "options": "Warehouse", + "fieldname": "t_warehouse", + "fieldtype": "Link", + "permlevel": 0, + "in_filter": 1 + }, + { + "oldfieldtype": "Link", + "doctype": "DocField", + "label": "Item Code", + "oldfieldname": "item_code", + "permlevel": 0, + "trigger": "Client", + "fieldname": "item_code", + "fieldtype": "Link", + "search_index": 1, + "reqd": 1, + "options": "Item", + "in_filter": 1 + }, + { + "oldfieldtype": "Text", + "doctype": "DocField", + "label": "Description", + "oldfieldname": "description", + "width": "300px", + "fieldname": "description", + "fieldtype": "Text", + "permlevel": 0 + }, + { + "oldfieldtype": "Currency", + "doctype": "DocField", + "label": "Qty", + "oldfieldname": "qty", + "trigger": "Client", + "fieldname": "qty", + "fieldtype": "Currency", + "reqd": 1, + "permlevel": 0 + }, + { + "oldfieldtype": "Link", + "colour": "White:FFF", + "doctype": "DocField", + "label": "UOM", + "oldfieldname": "uom", + "trigger": "Client", + "fieldname": "uom", + "fieldtype": "Link", + "reqd": 1, + "options": "UOM", + "permlevel": 0 + }, + { + "oldfieldtype": "Currency", + "doctype": "DocField", + "label": "Valuation Rate", + "oldfieldname": "incoming_rate", + "fieldname": "incoming_rate", + "fieldtype": "Currency", + "reqd": 0, + "permlevel": 0 + }, + { + "oldfieldtype": "Currency", + "doctype": "DocField", + "label": "Amount", + "oldfieldname": "amount", + "fieldname": "amount", + "fieldtype": "Currency", + "permlevel": 1 + }, + { + "no_copy": 1, + "oldfieldtype": "Text", + "doctype": "DocField", + "label": "Serial No", + "oldfieldname": "serial_no", + "fieldname": "serial_no", + "fieldtype": "Text", + "reqd": 0, + "permlevel": 0 + }, + { + "print_hide": 1, + "oldfieldtype": "Link", + "doctype": "DocField", + "label": "Batch No", + "oldfieldname": "batch_no", + "trigger": "Client", + "fieldname": "batch_no", + "fieldtype": "Link", + "options": "Batch", + "permlevel": 0 + }, + { + "print_hide": 1, + "oldfieldtype": "Currency", + "doctype": "DocField", + "label": "Reqd Qty", + "oldfieldname": "reqd_qty", + "fieldname": "reqd_qty", + "fieldtype": "Currency", + "permlevel": 3, + "in_filter": 0 + }, + { + "print_hide": 1, + "no_copy": 1, + "oldfieldtype": "Read Only", + "doctype": "DocField", + "label": "Actual Qty (at source/target)", + "oldfieldname": "actual_qty", + "fieldname": "actual_qty", + "fieldtype": "Read Only", + "search_index": 1, + "reqd": 0, + "permlevel": 1, + "in_filter": 1 + }, + { + "oldfieldtype": "Currency", + "doctype": "DocField", + "label": "Conversion Factor", + "oldfieldname": "conversion_factor", + "fieldname": "conversion_factor", + "fieldtype": "Currency", + "reqd": 1, + "permlevel": 1 + }, + { + "oldfieldtype": "Currency", + "doctype": "DocField", + "label": "Stock Qty", + "oldfieldname": "transfer_qty", + "fieldname": "transfer_qty", + "fieldtype": "Currency", + "reqd": 1, + "permlevel": 1 + }, + { + "oldfieldtype": "Link", + "doctype": "DocField", + "label": "Stock UOM", + "oldfieldname": "stock_uom", + "options": "UOM", + "fieldname": "stock_uom", + "fieldtype": "Link", + "search_index": 0, + "reqd": 1, + "permlevel": 1, + "in_filter": 0 + }, + { + "description": "BOM No. for a Finished Good Item", + "doctype": "DocField", + "label": "BOM No", + "options": "BOM", + "fieldname": "bom_no", + "fieldtype": "Link", + "permlevel": 0 + }, + { + "print_hide": 1, + "oldfieldtype": "Check", + "doctype": "DocField", + "label": "FG Item", + "oldfieldname": "fg_item", + "fieldname": "fg_item", + "fieldtype": "Check", + "permlevel": 0, + "in_filter": 1 + } ] \ No newline at end of file diff --git a/stock/doctype/stock_ledger_entry/stock_ledger_entry.py b/stock/doctype/stock_ledger_entry/stock_ledger_entry.py index facd052ca5..e6c4deeec5 100644 --- a/stock/doctype/stock_ledger_entry/stock_ledger_entry.py +++ b/stock/doctype/stock_ledger_entry/stock_ledger_entry.py @@ -37,15 +37,12 @@ class DocType: if (batch_bal + self.doc.actual_qty) < 0: msgprint("""Not enough quantity (requested: %(actual_qty)s, current: %(batch_bal)s in Batch - %(batch_no)s for Item %(item_code)s at Warehouse%(warehouse)s + %(batch_no)s for Item %(item_code)s at Warehouse %(warehouse)s as on %(posting_date)s %(posting_time)s""" % self.doc.fields, raise_exception = 1) self.doc.fields.pop('batch_bal') - # mandatory - # --------- - def validate_mandatory(self): mandatory = ['warehouse','transaction_date','posting_date','voucher_type','voucher_no','actual_qty','company','fiscal_year'] 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)): 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): item_det = sql("select name, has_batch_no, docstatus from tabItem where name = '%s'" % self.doc.item_code)