fixes in packing slip - packed qty validation
This commit is contained in:
parent
737e9db4db
commit
2249d9d858
@ -43,8 +43,8 @@ cur_frm.cscript.item_code = function(doc, cdt, cdn) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
cur_frm.cscript.onload = function(doc, cdt, cdn) {
|
cur_frm.cscript.onload_post_render = function(doc, cdt, cdn) {
|
||||||
if(doc.delivery_note) {
|
if(doc.delivery_note && doc.__islocal) {
|
||||||
var ps_detail = getchildren('Packing Slip Item', doc.name, 'item_details');
|
var ps_detail = getchildren('Packing Slip Item', doc.name, 'item_details');
|
||||||
if(!(flt(ps_detail[0].net_weight) && cstr(ps_detail[0].weight_uom))) {
|
if(!(flt(ps_detail[0].net_weight) && cstr(ps_detail[0].weight_uom))) {
|
||||||
cur_frm.cscript.update_item_details(doc);
|
cur_frm.cscript.update_item_details(doc);
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import webnotes
|
import webnotes
|
||||||
from webnotes.utils import flt, cint
|
from webnotes.utils import flt, cint, now
|
||||||
|
|
||||||
class DocType:
|
class DocType:
|
||||||
def __init__(self, d, dl):
|
def __init__(self, d, dl):
|
||||||
@ -56,6 +56,15 @@ class DocType:
|
|||||||
Validate if case nos overlap
|
Validate if case nos overlap
|
||||||
If they do, recommend next case no.
|
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)
|
||||||
|
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.'",
|
||||||
|
raise_exception=1)
|
||||||
|
|
||||||
|
|
||||||
res = webnotes.conn.sql("""\
|
res = webnotes.conn.sql("""\
|
||||||
SELECT name FROM `tabPacking Slip`
|
SELECT name FROM `tabPacking Slip`
|
||||||
WHERE delivery_note = %(delivery_note)s AND docstatus = 1 AND
|
WHERE delivery_note = %(delivery_note)s AND docstatus = 1 AND
|
||||||
@ -92,16 +101,24 @@ class DocType:
|
|||||||
item_codes = ", ".join([('"' + d.item_code + '"') for d in
|
item_codes = ", ".join([('"' + d.item_code + '"') for d in
|
||||||
self.doclist])
|
self.doclist])
|
||||||
|
|
||||||
|
items = [d.item_code for d in self.doclist.get({"parentfield": "item_details"})]
|
||||||
|
|
||||||
if not item_codes: webnotes.msgprint("No Items to Pack",
|
if not item_codes: webnotes.msgprint("No Items to Pack",
|
||||||
raise_exception=1)
|
raise_exception=1)
|
||||||
|
|
||||||
res = webnotes.conn.sql("""\
|
# gets item code, qty per item code, latest packed qty per item code and stock uom
|
||||||
SELECT item_code, IFNULL(SUM(qty), 0) as qty, IFNULL(packed_qty, 0) as packed_qty, stock_uom
|
res = webnotes.conn.sql("""select item_code, ifnull(sum(qty), 0) as qty,
|
||||||
FROM `tabDelivery Note Item`
|
(select sum(ifnull(psi.qty, 0) * (abs(ps.to_case_no - ps.from_case_no) + 1))
|
||||||
WHERE parent = "%s" AND item_code IN (%s)
|
from `tabPacking Slip` ps, `tabPacking Slip Item` psi
|
||||||
GROUP BY item_code""" % (self.doc.delivery_note, item_codes),
|
where ps.name = psi.parent and ps.docstatus = 1
|
||||||
as_dict=1)
|
and ps.delivery_note = dni.parent and psi.item_code=dni.item_code)
|
||||||
|
as packed_qty,
|
||||||
|
stock_uom
|
||||||
|
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, debug=1)
|
||||||
|
|
||||||
ps_item_qty = dict([[d.item_code, d.qty] for d in self.doclist])
|
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
|
no_of_cases = cint(self.doc.to_case_no) - cint(self.doc.from_case_no) + 1
|
||||||
@ -148,28 +165,29 @@ class DocType:
|
|||||||
dn_details, ps_item_qty, no_of_cases = self.get_details_for_packing()
|
dn_details, ps_item_qty, no_of_cases = self.get_details_for_packing()
|
||||||
|
|
||||||
for item in dn_details:
|
for item in dn_details:
|
||||||
if event=='submit':
|
new_packed_qty = flt(item['packed_qty'])
|
||||||
new_packed_qty = flt(item['packed_qty']) + (flt(ps_item_qty[item['item_code']]) * no_of_cases)
|
|
||||||
|
|
||||||
elif event=='cancel':
|
|
||||||
new_packed_qty = flt(item['packed_qty']) - (flt(ps_item_qty[item['item_code']]) * no_of_cases)
|
|
||||||
|
|
||||||
if (new_packed_qty < 0) or (new_packed_qty > flt(item['qty'])):
|
if (new_packed_qty < 0) or (new_packed_qty > flt(item['qty'])):
|
||||||
webnotes.msgprint("Invalid new packed quantity for item %s. \
|
webnotes.msgprint("Invalid new packed quantity for item %s. \
|
||||||
Please try again or contact support@erpnext.com" % item['item_code'], raise_exception=1)
|
Please try again or contact support@erpnext.com" % item['item_code'], raise_exception=1)
|
||||||
|
|
||||||
|
delivery_note_item = webnotes.conn.get_value("Delivery Note Item", {
|
||||||
|
"parent": self.doc.delivery_note, "item_code": item["item_code"]})
|
||||||
|
|
||||||
webnotes.conn.sql("""\
|
webnotes.conn.sql("""\
|
||||||
UPDATE `tabDelivery Note Item`
|
UPDATE `tabDelivery Note Item`
|
||||||
SET packed_qty = %s
|
SET packed_qty = %s
|
||||||
WHERE parent = %s AND item_code = %s""",
|
WHERE parent = %s AND item_code = %s""",
|
||||||
(new_packed_qty, self.doc.delivery_note, item['item_code']))
|
(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):
|
def update_item_details(self):
|
||||||
"""
|
"""
|
||||||
Fill empty columns in Packing Slip Item
|
Fill empty columns in Packing Slip Item
|
||||||
"""
|
"""
|
||||||
self.doc.from_case_no = self.get_recommended_case_no()
|
if not self.doc.from_case_no:
|
||||||
|
self.doc.from_case_no = self.get_recommended_case_no()
|
||||||
|
|
||||||
from webnotes.model.code import get_obj
|
from webnotes.model.code import get_obj
|
||||||
for d in self.doclist:
|
for d in self.doclist:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user