From 9a2dff6675bceea25b6502dac6f98be6a1f57572 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 17 Apr 2013 17:21:31 +0530 Subject: [PATCH 1/2] packing slip refactored --- patches/patch_list.py | 3 +- stock/doctype/delivery_note/delivery_note.js | 21 +-- stock/doctype/delivery_note/delivery_note.py | 14 +- .../delivery_note_item/delivery_note_item.txt | 13 +- stock/doctype/packing_slip/packing_slip.js | 42 ++---- stock/doctype/packing_slip/packing_slip.py | 136 +++++++----------- stock/doctype/packing_slip/packing_slip.txt | 10 +- 7 files changed, 85 insertions(+), 154 deletions(-) diff --git a/patches/patch_list.py b/patches/patch_list.py index 57dde996d7..79e6f59c7e 100644 --- a/patches/patch_list.py +++ b/patches/patch_list.py @@ -231,7 +231,6 @@ patch_list = [ "patches.march_2013.p12_set_item_tax_rate_in_json", "patches.march_2013.p07_update_valuation_rate", "patches.march_2013.p08_create_aii_accounts", - # "patches.march_2013.p03_update_buying_amount", "patches.april_2013.p01_update_serial_no_valuation_rate", "patches.april_2013.p02_add_country_and_currency", "patches.april_2013.p03_fixes_for_lead_in_quotation", @@ -242,5 +241,5 @@ patch_list = [ "execute:webnotes.delete_doc('Search Criteria', 'time_log_summary')", "patches.april_2013.p04_update_role_in_pages", "patches.april_2013.p05_fixes_in_reverse_modules", - "execute:webnotes.reload_doc('stock', 'DocType Mapper', 'Delivery Note-Packing Slip')" + "execute:webnotes.delete_doc('DocType Mapper', 'Delivery Note-Packing Slip')" ] \ No newline at end of file diff --git a/stock/doctype/delivery_note/delivery_note.js b/stock/doctype/delivery_note/delivery_note.js index f47040d0d0..8d09cbd676 100644 --- a/stock/doctype/delivery_note/delivery_note.js +++ b/stock/doctype/delivery_note/delivery_note.js @@ -158,7 +158,6 @@ cur_frm.fields_dict['sales_order_no'].get_query = function(doc) { } -// ****************************** DELIVERY TYPE ************************************ cur_frm.cscript.delivery_type = function(doc, cdt, cdn) { if (doc.delivery_type = 'Sample') cfn_set_fields(doc, cdt, cdn); } @@ -185,7 +184,6 @@ cur_frm.fields_dict['transporter_name'].get_query = function(doc) { return 'SELECT DISTINCT `tabSupplier`.`name` FROM `tabSupplier` WHERE `tabSupplier`.supplier_type = "transporter" AND `tabSupplier`.docstatus != 2 AND `tabSupplier`.%(key)s LIKE "%s" ORDER BY `tabSupplier`.`name` LIMIT 50'; } -//-----------------------------------Make Sales Invoice---------------------------------------------- cur_frm.cscript['Make Sales Invoice'] = function() { var doc = cur_frm.doc n = wn.model.make_new_doc_and_get_name('Sales Invoice'); @@ -201,7 +199,6 @@ cur_frm.cscript['Make Sales Invoice'] = function() { ); } -//-----------------------------------Make Installation Note---------------------------------------------- cur_frm.cscript['Make Installation Note'] = function() { var doc = cur_frm.doc; if(doc.per_installed < 99.99){ @@ -221,31 +218,19 @@ cur_frm.cscript['Make Installation Note'] = function() { msgprint("Item installation is already completed") } -//-----------------------------------Make Sales Invoice---------------------------------------------- cur_frm.cscript['Make Packing Slip'] = function() { - var doc = cur_frm.doc n = wn.model.make_new_doc_and_get_name('Packing Slip'); - $c('dt_map', args={ - 'docs':wn.model.compress([locals['Packing Slip'][n]]), - 'from_doctype':doc.doctype, - 'to_doctype':'Packing Slip', - 'from_docname':doc.name, - 'from_to_list':"[['Delivery Note','Packing Slip'],['Delivery Note Item','Packing Slip Item']]" - }, function(r,rt) { - loaddoc('Packing Slip', n); - } - ); + ps = locals["Packing Slip"][n]; + ps.delivery_note = cur_frm.doc.name; + loaddoc('Packing Slip', n); } //get query select Territory -//======================================================================================================================= cur_frm.fields_dict['territory'].get_query = function(doc,cdt,cdn) { return 'SELECT `tabTerritory`.`name`,`tabTerritory`.`parent_territory` FROM `tabTerritory` WHERE `tabTerritory`.`is_group` = "No" AND `tabTerritory`.`docstatus`!= 2 AND `tabTerritory`.%(key)s LIKE "%s" ORDER BY `tabTerritory`.`name` ASC LIMIT 50'; } -//------------------------for printing without amount---------- - var set_print_hide= function(doc, cdt, cdn){ var dn_fields = wn.meta.docfield_map['Delivery Note']; var dn_item_fields = wn.meta.docfield_map['Delivery Note Item']; diff --git a/stock/doctype/delivery_note/delivery_note.py b/stock/doctype/delivery_note/delivery_note.py index 0019698da1..15e24ef293 100644 --- a/stock/doctype/delivery_note/delivery_note.py +++ b/stock/doctype/delivery_note/delivery_note.py @@ -20,7 +20,7 @@ import webnotes from webnotes.utils import cstr, flt, getdate, cint from webnotes.model.bean import getlist from webnotes.model.code import get_obj -from webnotes import msgprint +from webnotes import msgprint, _ import webnotes.defaults @@ -333,17 +333,15 @@ class DocType(SellingController): """ Cancel submitted packing slips related to this delivery note """ - res = webnotes.conn.sql("""\ - SELECT name, count(*) FROM `tabPacking Slip` - WHERE delivery_note = %s AND docstatus = 1 - """, self.doc.name) + res = webnotes.conn.sql("""SELECT name FROM `tabPacking Slip` WHERE delivery_note = %s + AND docstatus = 1""", self.doc.name) - if res and res[0][1]>0: + if res: from webnotes.model.bean import Bean for r in res: ps = Bean(dt='Packing Slip', dn=r[0]) ps.cancel() - webnotes.msgprint("%s Packing Slip(s) Cancelled" % res[0][1]) + webnotes.msgprint(_("Packing Slip(s) Cancelled")) def update_stock_ledger(self, update_stock): @@ -421,4 +419,4 @@ class DocType(SellingController): if gl_entries: from accounts.general_ledger import make_gl_entries - make_gl_entries(gl_entries) + make_gl_entries(gl_entries) \ No newline at end of file diff --git a/stock/doctype/delivery_note_item/delivery_note_item.txt b/stock/doctype/delivery_note_item/delivery_note_item.txt index fb3dd413ef..f3b24171d5 100644 --- a/stock/doctype/delivery_note_item/delivery_note_item.txt +++ b/stock/doctype/delivery_note_item/delivery_note_item.txt @@ -2,7 +2,7 @@ { "creation": "2013-03-26 11:03:09", "docstatus": 0, - "modified": "2013-03-28 15:42:41", + "modified": "2013-04-17 17:20:45", "modified_by": "Administrator", "owner": "Administrator" }, @@ -332,17 +332,6 @@ "read_only": 1, "width": "150px" }, - { - "allow_on_submit": 1, - "default": "0", - "doctype": "DocField", - "fieldname": "packed_qty", - "fieldtype": "Float", - "label": "Packed Quantity", - "no_copy": 1, - "print_hide": 1, - "read_only": 1 - }, { "doctype": "DocField", "fieldname": "prevdoc_doctype", diff --git a/stock/doctype/packing_slip/packing_slip.js b/stock/doctype/packing_slip/packing_slip.js index 5ece164c68..18a248660d 100644 --- a/stock/doctype/packing_slip/packing_slip.js +++ b/stock/doctype/packing_slip/packing_slip.js @@ -23,52 +23,36 @@ cur_frm.fields_dict['item_details'].grid.get_field('item_code').get_query = function(doc, cdt, cdn) { var query = 'SELECT name, item_name, description FROM `tabItem` WHERE name IN ( \ SELECT item_code FROM `tabDelivery Note Item` dnd \ - WHERE parent="' + doc.delivery_note + '" AND IFNULL(qty, 0) > IFNULL(packed_qty, 0)) AND %(key)s LIKE "%s" LIMIT 50'; + WHERE parent="' + doc.delivery_note + '" AND IFNULL(qty, 0) > IFNULL(packed_qty, 0)) \ + AND %(key)s LIKE "%s" LIMIT 50'; return query; } - -// Fetch item details -cur_frm.add_fetch("item_code", "item_name", "item_name"); -cur_frm.add_fetch("item_code", "stock_uom", "stock_uom"); -cur_frm.add_fetch("item_code", "net_weight", "net_weight"); -cur_frm.add_fetch("item_code", "weight_uom", "weight_uom"); - cur_frm.cscript.onload_post_render = function(doc, cdt, cdn) { if(doc.delivery_note && doc.__islocal) { - var ps_detail = getchildren('Packing Slip Item', doc.name, 'item_details'); - if(!(flt(ps_detail.net_weight) && cstr(ps_detail.weight_uom))) { - cur_frm.cscript.update_item_details(doc); - } + cur_frm.cscript.get_items(doc, cdt, cdn); } } -cur_frm.cscript.refresh = function(doc, dt, dn) { - if(!doc.amended_from) { - hide_field('misc_details'); - } else { - unhide_field('misc_details'); - } -} - - -cur_frm.cscript.update_item_details = function(doc) { - $c_obj(make_doclist(doc.doctype, doc.name), 'update_item_details', '', function(r, rt) { - if(r.exc) { - msgprint(r.exc); - } else { - refresh_many(['item_details', 'naming_series', 'from_case_no', 'to_case_no']) +cur_frm.cscript.get_items = function(doc, cdt, cdn) { + this.frm.call({ + doc: this.frm.doc, + method: "get_items", + callback: function(r) { + if(!r.exc) cur_frm.refresh(); } }); } +cur_frm.cscript.refresh = function(doc, dt, dn) { + cur_frm.toggle_display("misc_details", doc.amended_from); +} cur_frm.cscript.validate = function(doc, cdt, cdn) { cur_frm.cscript.validate_case_nos(doc); cur_frm.cscript.validate_calculate_item_details(doc); } - // To Case No. cannot be less than From Case No. cur_frm.cscript.validate_case_nos = function(doc) { doc = locals[doc.doctype][doc.name]; @@ -99,7 +83,7 @@ cur_frm.cscript.validate_calculate_item_details = function(doc) { cur_frm.cscript.validate_duplicate_items = function(doc, ps_detail) { for(var i=0; i self.doc.to_case_no: - webnotes.msgprint("'To Case No.' cannot be less than 'From Case No.'", + webnotes.msgprint(_("'To Case No.' cannot be less than 'From Case No.'"), raise_exception=1) res = webnotes.conn.sql("""SELECT name FROM `tabPacking Slip` WHERE delivery_note = %(delivery_note)s AND docstatus = 1 AND (from_case_no BETWEEN %(from_case_no)s AND %(to_case_no)s - OR to_case_no BETWEEN %(from_case_no)s AND %(to_case_no)s) + OR to_case_no BETWEEN %(from_case_no)s AND %(to_case_no)s + OR %(from_case_no)s BETWEEN from_case_no AND to_case_no) """, self.doc.fields) if res: - webnotes.msgprint("""Case No(s). already in use. Please rectify and try again. - Recommended From Case No. = %s""" % self.get_recommended_case_no(), + webnotes.msgprint(_("""Case No(s) already in use. Please rectify and try again. + Recommended From Case No. = %s""") % self.get_recommended_case_no(), raise_exception=1) - def validate_qty(self): """ Check packed qty across packing slips and delivery note @@ -82,8 +83,9 @@ class DocType: dn_details, ps_item_qty, no_of_cases = self.get_details_for_packing() for item in dn_details: - new_packed_qty = (flt(ps_item_qty[item['item_code']]) * no_of_cases) + flt(item['packed_qty']) - if new_packed_qty > flt(item['qty']): + new_packed_qty = (flt(ps_item_qty[item['item_code']]) * no_of_cases) + \ + flt(item['packed_qty']) + if new_packed_qty > flt(item['qty']) and no_of_cases: self.recommend_new_qty(item, ps_item_qty, no_of_cases) @@ -95,26 +97,25 @@ class DocType: * No. of Cases of this packing slip """ - items = [d.item_code for d in self.doclist.get({"parentfield": "item_details"})] + rows = [d.item_code for d in self.doclist.get({"parentfield": "item_details"})] - if not items: webnotes.msgprint("No Items to Pack", - raise_exception=1) + condition = "" + if rows: + condition = " and item_code in (%s)" % (", ".join(["%s"]*len(rows))) # gets item code, qty per item code, latest packed qty per item code and stock uom res = webnotes.conn.sql("""select item_code, ifnull(sum(qty), 0) as qty, (select sum(ifnull(psi.qty, 0) * (abs(ps.to_case_no - ps.from_case_no) + 1)) from `tabPacking Slip` ps, `tabPacking Slip Item` psi where ps.name = psi.parent and ps.docstatus = 1 - and ps.delivery_note = dni.parent and psi.item_code=dni.item_code) - as packed_qty, - stock_uom + and ps.delivery_note = dni.parent and psi.item_code=dni.item_code) as packed_qty, + stock_uom, item_name from `tabDelivery Note Item` dni - where parent=%s and item_code in (%s) - group by item_code""" % ("%s", ", ".join(["%s"]*len(items))), - tuple([self.doc.delivery_note] + items), as_dict=1) - - ps_item_qty = dict([[d.item_code, d.qty] for d in self.doclist]) + where parent=%s %s + group by item_code""" % ("%s", condition), + tuple([self.doc.delivery_note] + rows), as_dict=1) + ps_item_qty = dict([[d.item_code, d.qty] for d in self.doclist]) no_of_cases = cint(self.doc.to_case_no) - cint(self.doc.from_case_no) + 1 return res, ps_item_qty, no_of_cases @@ -134,45 +135,6 @@ class DocType: Recommended quantity for %(item_code)s = %(recommended_qty)s %(stock_uom)s""" % item, raise_exception=1) - - def on_submit(self): - """ - * Update packed qty for all items - """ - self.update_packed_qty(event='submit') - - - def on_cancel(self): - """ - * Update packed qty for all items - """ - self.update_packed_qty(event='cancel') - - - def update_packed_qty(self, event=''): - """ - Updates packed qty for all items - """ - if event not in ['submit', 'cancel']: - raise Exception('update_packed_quantity can only be called on submit or cancel') - - # Get Delivery Note Items, Item Quantity Dict and No. of Cases for this Packing slip - dn_details, ps_item_qty, no_of_cases = self.get_details_for_packing() - - for item in dn_details: - new_packed_qty = flt(item['packed_qty']) - if (new_packed_qty < 0) or (new_packed_qty > flt(item['qty'])): - webnotes.msgprint("""Invalid new packed quantity for item %s. - Please try again or contact support@erpnext.com""" % - item['item_code'], raise_exception=1) - - webnotes.conn.sql("""UPDATE `tabDelivery Note Item` - SET packed_qty = %s WHERE parent = %s AND item_code = %s""", - (new_packed_qty, self.doc.delivery_note, item['item_code'])) - - webnotes.conn.set_value("Delivery Note", self.doc.delivery_note, "modified", now()) - - def update_item_details(self): """ Fill empty columns in Packing Slip Item @@ -181,17 +143,12 @@ class DocType: self.doc.from_case_no = self.get_recommended_case_no() for d in self.doclist.get({"parentfield": "item_details"}): - self.set_item_details(d) - - - def set_item_details(self, row): - res = webnotes.conn.sql("""SELECT net_weight, weight_uom FROM `tabItem` - WHERE name=%s""", row.item_code, as_dict=1) + res = webnotes.conn.get_value("Item", d.item_code, + ["net_weight", "weight_uom"], as_dict=True) - if res and len(res)>0: - row.net_weight = res[0]["net_weight"] - row.weight_uom = res[0]["weight_uom"] - + if res and len(res)>0: + d.net_weight = res["net_weight"] + d.weight_uom = res["weight_uom"] def get_recommended_case_no(self): """ @@ -200,5 +157,18 @@ class DocType: """ recommended_case_no = webnotes.conn.sql("""SELECT MAX(to_case_no) FROM `tabPacking Slip` WHERE delivery_note = %(delivery_note)s AND docstatus=1""", self.doc.fields) - - return cint(recommended_case_no[0][0]) + 1 \ No newline at end of file + + return cint(recommended_case_no[0][0]) + 1 + + def get_items(self): + self.doclist = self.doc.clear_table(self.doclist, "item_details", 1) + + dn_details = self.get_details_for_packing()[0] + for item in dn_details: + if flt(item.qty) > flt(item.packed_qty): + ch = addchild(self.doc, 'item_details', 'Packing Slip Item', self.doclist) + ch.item_code = item.item_code + ch.item_name = item.item_name + ch.stock_uom = item.stock_uom + ch.qty = flt(item.qty) - flt(item.packed_qty) + self.update_item_details() \ No newline at end of file diff --git a/stock/doctype/packing_slip/packing_slip.txt b/stock/doctype/packing_slip/packing_slip.txt index 32ac16bb41..f13b971e1c 100644 --- a/stock/doctype/packing_slip/packing_slip.txt +++ b/stock/doctype/packing_slip/packing_slip.txt @@ -1,8 +1,8 @@ [ { - "creation": "2013-03-07 18:50:31", + "creation": "2013-04-11 15:32:24", "docstatus": 0, - "modified": "2013-04-05 15:40:59", + "modified": "2013-04-16 17:33:38", "modified_by": "Administrator", "owner": "Administrator" }, @@ -130,6 +130,12 @@ "label": "Package Item Details", "read_only": 0 }, + { + "doctype": "DocField", + "fieldname": "get_items", + "fieldtype": "Button", + "label": "Get Items" + }, { "doctype": "DocField", "fieldname": "item_details", From 47ef15b04ba78ee875c81bb496b9f985b77f3117 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 17 Apr 2013 17:35:14 +0530 Subject: [PATCH 2/2] removed errprint --- stock/doctype/stock_ledger/stock_ledger.py | 1 - 1 file changed, 1 deletion(-) diff --git a/stock/doctype/stock_ledger/stock_ledger.py b/stock/doctype/stock_ledger/stock_ledger.py index 469c94bb2f..3c83de3260 100644 --- a/stock/doctype/stock_ledger/stock_ledger.py +++ b/stock/doctype/stock_ledger/stock_ledger.py @@ -84,7 +84,6 @@ class DocType: item_details = webnotes.conn.sql("""select item_group, warranty_period from `tabItem` where name = '%s' and (ifnull(end_of_life,'')='' or end_of_life = '0000-00-00' or end_of_life > now()) """ %(d.item_code), as_dict=1) - webnotes.errprint([d.item_code, d.valuation_rate]) s.purchase_document_type = obj.doc.doctype s.purchase_document_no = obj.doc.name