packing slip refactored

This commit is contained in:
Nabin Hait 2013-04-17 17:21:31 +05:30
parent 8f148249ac
commit 9a2dff6675
7 changed files with 85 additions and 154 deletions

View File

@ -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')"
]

View File

@ -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'];

View File

@ -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)

View File

@ -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",

View File

@ -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<ps_detail.length; i++) {
for(var j=0; j<ps_detail.length; j++) {
if(i!=j && ps_detail[i].dn_detail && ps_detail[i].dn_detail==ps_detail[j].dn_detail) {
if(i!=j && ps_detail[i].item_code && ps_detail[i].item_code==ps_detail[j].item_code) {
msgprint("You have entered duplicate items. Please rectify and try again.");
validated = false;
return;

View File

@ -16,13 +16,14 @@
from __future__ import unicode_literals
import webnotes
from webnotes.utils import flt, cint, now
from webnotes.utils import flt, cint
from webnotes import msgprint, _
from webnotes.model.doc import addchild
class DocType:
def __init__(self, d, dl):
self.doc, self.doclist = d, dl
def validate(self):
"""
* Validate existence of submitted Delivery Note
@ -32,48 +33,48 @@ class DocType:
It is necessary to validate case nos before checking quantity
"""
self.validate_delivery_note()
self.validate_items_mandatory()
self.validate_case_nos()
self.validate_qty()
def validate_delivery_note(self):
"""
Validates if delivery note has status as submitted
Validates if delivery note has status as draft
"""
res = webnotes.conn.sql("""SELECT docstatus FROM `tabDelivery Note`
WHERE name=%(delivery_note)s""", self.doc.fields)
if not(res and res[0][0]==0):
webnotes.msgprint("""Invalid Delivery Note. Delivery Note should exist
and should be in draft state. Please rectify and try again.""", raise_exception=1)
if cint(webnotes.conn.get_value("Delivery Note", self.doc.delivery_note, "docstatus")) != 0:
msgprint(_("""Invalid Delivery Note. Delivery Note should exist and should be in
draft state. Please rectify and try again."""), raise_exception=1)
def validate_items_mandatory(self):
rows = [d.item_code for d in self.doclist.get({"parentfield": "item_details"})]
if not rows:
webnotes.msgprint(_("No Items to Pack"), raise_exception=1)
def validate_case_nos(self):
"""
Validate if case nos overlap
If they do, recommend next case no.
Validate if case nos overlap. If they do, recommend next case no.
"""
if not cint(self.doc.from_case_no):
webnotes.msgprint("Please specify a valid 'From Case No.'", raise_exception=1)
webnotes.msgprint(_("Please specify a valid 'From Case No.'"), raise_exception=1)
elif not self.doc.to_case_no:
self.doc.to_case_no = self.doc.from_case_no
elif self.doc.from_case_no > 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 <b>From Case No. = %s</b>""" % self.get_recommended_case_no(),
webnotes.msgprint(_("""Case No(s) already in use. Please rectify and try again.
Recommended <b>From Case No. = %s</b>""") % 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:
<b>Recommended quantity for %(item_code)s = %(recommended_qty)s
%(stock_uom)s</b>""" % 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
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()

View File

@ -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",