[fix] [minor] material request sales order wise through production planning tool
This commit is contained in:
parent
dbb69dacff
commit
9ee20e8f5a
@ -36,12 +36,12 @@ class DocType(BuyingController):
|
|||||||
if flt(d.conversion_factor):
|
if flt(d.conversion_factor):
|
||||||
last_purchase_rate = flt(d.purchase_rate) / flt(d.conversion_factor)
|
last_purchase_rate = flt(d.purchase_rate) / flt(d.conversion_factor)
|
||||||
else:
|
else:
|
||||||
msgprint(_("Row ") + cstr(d.idx) + ": " +
|
webnotes.throw(_("Row ") + cstr(d.idx) + ": " +
|
||||||
_("UOM Conversion Factor is mandatory"), raise_exception=1)
|
_("UOM Conversion Factor is mandatory"))
|
||||||
|
|
||||||
# update last purchsae rate
|
# update last purchsae rate
|
||||||
if last_purchase_rate:
|
if last_purchase_rate:
|
||||||
webnotes.conn.sql("update `tabItem` set last_purchase_rate = %s where name = %s",
|
webnotes.conn.sql("""update `tabItem` set last_purchase_rate = %s where name = %s""",
|
||||||
(flt(last_purchase_rate), d.item_code))
|
(flt(last_purchase_rate), d.item_code))
|
||||||
|
|
||||||
def get_last_purchase_rate(self, obj):
|
def get_last_purchase_rate(self, obj):
|
||||||
@ -74,11 +74,11 @@ class DocType(BuyingController):
|
|||||||
for d in getlist( obj.doclist, obj.fname):
|
for d in getlist( obj.doclist, obj.fname):
|
||||||
# validation for valid qty
|
# validation for valid qty
|
||||||
if flt(d.qty) < 0 or (d.parenttype != 'Purchase Receipt' and not flt(d.qty)):
|
if flt(d.qty) < 0 or (d.parenttype != 'Purchase Receipt' and not flt(d.qty)):
|
||||||
msgprint("Please enter valid qty for item %s" % cstr(d.item_code))
|
webnotes.throw("Please enter valid qty for item %s" % cstr(d.item_code))
|
||||||
raise Exception
|
|
||||||
|
|
||||||
# udpate with latest quantities
|
# udpate with latest quantities
|
||||||
bin = webnotes.conn.sql("select projected_qty from `tabBin` where item_code = %s and warehouse = %s", (d.item_code, d.warehouse), as_dict = 1)
|
bin = webnotes.conn.sql("""select projected_qty from `tabBin` where
|
||||||
|
item_code = %s and warehouse = %s""", (d.item_code, d.warehouse), as_dict=1)
|
||||||
|
|
||||||
f_lst ={'projected_qty': bin and flt(bin[0]['projected_qty']) or 0, 'ordered_qty': 0, 'received_qty' : 0}
|
f_lst ={'projected_qty': bin and flt(bin[0]['projected_qty']) or 0, 'ordered_qty': 0, 'received_qty' : 0}
|
||||||
if d.doctype == 'Purchase Receipt Item':
|
if d.doctype == 'Purchase Receipt Item':
|
||||||
@ -87,22 +87,21 @@ class DocType(BuyingController):
|
|||||||
if d.fields.has_key(x):
|
if d.fields.has_key(x):
|
||||||
d.fields[x] = f_lst[x]
|
d.fields[x] = f_lst[x]
|
||||||
|
|
||||||
item = webnotes.conn.sql("select is_stock_item, is_purchase_item, is_sub_contracted_item, end_of_life from tabItem where name=%s",
|
item = webnotes.conn.sql("""select is_stock_item, is_purchase_item,
|
||||||
d.item_code)
|
is_sub_contracted_item, end_of_life from `tabItem` where name=%s""", d.item_code)
|
||||||
if not item:
|
if not item:
|
||||||
msgprint("Item %s does not exist in Item Master." % cstr(d.item_code), raise_exception=True)
|
webnotes.throw("Item %s does not exist in Item Master." % cstr(d.item_code))
|
||||||
|
|
||||||
from stock.utils import validate_end_of_life
|
from stock.utils import validate_end_of_life
|
||||||
validate_end_of_life(d.item_code, item[0][3])
|
validate_end_of_life(d.item_code, item[0][3])
|
||||||
|
|
||||||
# validate stock item
|
# validate stock item
|
||||||
if item[0][0]=='Yes' and d.qty and not d.warehouse:
|
if item[0][0]=='Yes' and d.qty and not d.warehouse:
|
||||||
msgprint("Warehouse is mandatory for %s, since it is a stock item" %
|
webnotes.throw("Warehouse is mandatory for %s, since it is a stock item" % d.item_code)
|
||||||
d.item_code, raise_exception=1)
|
|
||||||
|
|
||||||
# validate purchase item
|
# validate purchase item
|
||||||
if item[0][1] != 'Yes' and item[0][2] != 'Yes':
|
if item[0][1] != 'Yes' and item[0][2] != 'Yes':
|
||||||
msgprint("Item %s is not a purchase item or sub-contracted item. Please check" % (d.item_code), raise_exception=True)
|
webnotes.throw("Item %s is not a purchase item or sub-contracted item. Please check" % (d.item_code))
|
||||||
|
|
||||||
# list criteria that should not repeat if item is stock item
|
# list criteria that should not repeat if item is stock item
|
||||||
e = [d.schedule_date, d.item_code, d.description, d.warehouse, d.uom,
|
e = [d.schedule_date, d.item_code, d.description, d.warehouse, d.uom,
|
||||||
@ -113,21 +112,21 @@ class DocType(BuyingController):
|
|||||||
# if is not stock item
|
# if is not stock item
|
||||||
f = [d.schedule_date, d.item_code, d.description]
|
f = [d.schedule_date, d.item_code, d.description]
|
||||||
|
|
||||||
ch = webnotes.conn.sql("select is_stock_item from `tabItem` where name = '%s'"%d.item_code)
|
ch = webnotes.conn.sql("""select is_stock_item from `tabItem` where name = %s""", d.item_code)
|
||||||
|
|
||||||
if ch and ch[0][0] == 'Yes':
|
if ch and ch[0][0] == 'Yes':
|
||||||
# check for same items
|
# check for same items
|
||||||
if e in check_list:
|
if e in check_list:
|
||||||
msgprint("""Item %s has been entered more than once with same description, schedule date, warehouse and uom.\n
|
webnotes.throw("""Item %s has been entered more than once with same description, schedule date, warehouse and uom.\n
|
||||||
Please change any of the field value to enter the item twice""" % d.item_code, raise_exception = 1)
|
Please change any of the field value to enter the item twice""" % d.item_code)
|
||||||
else:
|
else:
|
||||||
check_list.append(e)
|
check_list.append(e)
|
||||||
|
|
||||||
elif ch and ch[0][0] == 'No':
|
elif ch and ch[0][0] == 'No':
|
||||||
# check for same items
|
# check for same items
|
||||||
if f in chk_dupl_itm:
|
if f in chk_dupl_itm:
|
||||||
msgprint("""Item %s has been entered more than once with same description, schedule date.\n
|
webnotes.throw("""Item %s has been entered more than once with same description, schedule date.\n
|
||||||
Please change any of the field value to enter the item twice.""" % d.item_code, raise_exception = 1)
|
Please change any of the field value to enter the item twice.""" % d.item_code)
|
||||||
else:
|
else:
|
||||||
chk_dupl_itm.append(f)
|
chk_dupl_itm.append(f)
|
||||||
|
|
||||||
@ -139,22 +138,24 @@ class DocType(BuyingController):
|
|||||||
# but if in Material Request uom KG it can change in PO
|
# but if in Material Request uom KG it can change in PO
|
||||||
|
|
||||||
get_qty = (transaction == 'Material Request - Purchase Order') and 'qty * conversion_factor' or 'qty'
|
get_qty = (transaction == 'Material Request - Purchase Order') and 'qty * conversion_factor' or 'qty'
|
||||||
qty = webnotes.conn.sql("select sum(%s) from `tab%s` where %s = '%s' and docstatus = 1 and parent != '%s'"% ( get_qty, curr_doctype, ref_tab_fname, ref_tab_dn, curr_parent_name))
|
qty = webnotes.conn.sql("""select sum(%s) from `tab%s` where %s = %s and
|
||||||
|
docstatus = 1 and parent != %s""", (get_qty, curr_doctype, ref_tab_fname, ref_tab_dn, curr_parent_name))
|
||||||
qty = qty and flt(qty[0][0]) or 0
|
qty = qty and flt(qty[0][0]) or 0
|
||||||
|
|
||||||
# get total qty of ref doctype
|
# get total qty of ref doctype
|
||||||
#--------------------
|
#--------------------
|
||||||
max_qty = webnotes.conn.sql("select qty from `tab%s` where name = '%s' and docstatus = 1"% (ref_doc_tname, ref_tab_dn))
|
max_qty = webnotes.conn.sql("""select qty from `tab%s` where name = %s
|
||||||
|
and docstatus = 1""", (ref_doc_tname, ref_tab_dn))
|
||||||
max_qty = max_qty and flt(max_qty[0][0]) or 0
|
max_qty = max_qty and flt(max_qty[0][0]) or 0
|
||||||
|
|
||||||
return cstr(qty)+'~~~'+cstr(max_qty)
|
return cstr(qty)+'~~~'+cstr(max_qty)
|
||||||
|
|
||||||
def check_for_stopped_status(self, doctype, docname):
|
def check_for_stopped_status(self, doctype, docname):
|
||||||
stopped = webnotes.conn.sql("select name from `tab%s` where name = '%s' and status = 'Stopped'" %
|
stopped = webnotes.conn.sql("""select name from `tab%s` where name = '%s' and
|
||||||
( doctype, docname))
|
status = 'Stopped'""", (doctype, docname))
|
||||||
if stopped:
|
if stopped:
|
||||||
msgprint("One cannot do any transaction against %s : %s, it's status is 'Stopped'" %
|
webnotes.throw("One cannot do any transaction against %s : %s, it's status is 'Stopped'" %
|
||||||
( doctype, docname), raise_exception=1)
|
(doctype, docname))
|
||||||
|
|
||||||
def check_docstatus(self, check, doctype, docname, detail_doctype = ''):
|
def check_docstatus(self, check, doctype, docname, detail_doctype = ''):
|
||||||
if check == 'Next':
|
if check == 'Next':
|
||||||
@ -162,12 +163,11 @@ class DocType(BuyingController):
|
|||||||
where t1.name = t2.parent and t2.prevdoc_docname = %s and t1.docstatus = 1"""
|
where t1.name = t2.parent and t2.prevdoc_docname = %s and t1.docstatus = 1"""
|
||||||
% (doctype, detail_doctype, '%s'), docname)
|
% (doctype, detail_doctype, '%s'), docname)
|
||||||
if submitted:
|
if submitted:
|
||||||
msgprint(cstr(doctype) + ": " + cstr(submitted[0][0])
|
webnotes.throw(cstr(doctype) + ": " + cstr(submitted[0][0])
|
||||||
+ _(" has already been submitted."), raise_exception=1)
|
+ _("has already been submitted."))
|
||||||
|
|
||||||
if check == 'Previous':
|
if check == 'Previous':
|
||||||
submitted = webnotes.conn.sql("""select name from `tab%s`
|
submitted = webnotes.conn.sql("""select name from `tab%s`
|
||||||
where docstatus = 1 and name = %s""" % (doctype, '%s'), docname)
|
where docstatus = 1 and name = %s""" % (doctype, '%s'), docname)
|
||||||
if not submitted:
|
if not submitted:
|
||||||
msgprint(cstr(doctype) + ": " + cstr(submitted[0][0])
|
webnotes.throw(cstr(doctype) + ": " + cstr(submitted[0][0]) + _("not submitted"))
|
||||||
+ _(" not submitted"), raise_exception=1)
|
|
||||||
|
@ -154,20 +154,20 @@ class DocType:
|
|||||||
for d in getlist(self.doclist, 'pp_details'):
|
for d in getlist(self.doclist, 'pp_details'):
|
||||||
self.validate_bom_no(d)
|
self.validate_bom_no(d)
|
||||||
if not flt(d.planned_qty):
|
if not flt(d.planned_qty):
|
||||||
webnotes.throw(_("Please Enter Planned Qty for item: %s at row no: %s") %
|
webnotes.throw("Please Enter Planned Qty for item: %s at row no: %s" %
|
||||||
(d.item_code, d.idx))
|
(d.item_code, d.idx))
|
||||||
|
|
||||||
def validate_bom_no(self, d):
|
def validate_bom_no(self, d):
|
||||||
if not d.bom_no:
|
if not d.bom_no:
|
||||||
webnotes.throw(_("Please enter bom no for item: %s at row no: %s") %
|
webnotes.throw("Please enter bom no for item: %s at row no: %s" %
|
||||||
(d.item_code, d.idx))
|
(d.item_code, d.idx))
|
||||||
else:
|
else:
|
||||||
bom = webnotes.conn.sql("""select name from `tabBOM` where name = %s and item = %s
|
bom = webnotes.conn.sql("""select name from `tabBOM` where name = %s and item = %s
|
||||||
and docstatus = 1 and is_active = 1""",
|
and docstatus = 1 and is_active = 1""",
|
||||||
(d.bom_no, d.item_code), as_dict = 1)
|
(d.bom_no, d.item_code), as_dict = 1)
|
||||||
if not bom:
|
if not bom:
|
||||||
webnotes.throw(_("""Incorrect BOM No: %s entered for item: %s at row no: %s
|
webnotes.throw("""Incorrect BOM No: %s entered for item: %s at row no: %s
|
||||||
May be BOM is inactive or for other item or does not exists in the system""") %
|
May be BOM is inactive or for other item or does not exists in the system""" %
|
||||||
(d.bom_no, d.item_doce, d.idx))
|
(d.bom_no, d.item_doce, d.idx))
|
||||||
|
|
||||||
def raise_production_order(self):
|
def raise_production_order(self):
|
||||||
@ -290,11 +290,12 @@ class DocType:
|
|||||||
for item_details in self.item_dict[item]:
|
for item_details in self.item_dict[item]:
|
||||||
item_list.append([item, item_details[1], item_details[2], item_details[0]])
|
item_list.append([item, item_details[1], item_details[2], item_details[0]])
|
||||||
item_qty = webnotes.conn.sql("""select warehouse, indented_qty, ordered_qty, actual_qty
|
item_qty = webnotes.conn.sql("""select warehouse, indented_qty, ordered_qty, actual_qty
|
||||||
from `tabBin` where item_code = %s""", item)
|
from `tabBin` where item_code = %s""", item, as_dict=1)
|
||||||
i_qty, o_qty, a_qty = 0, 0, 0
|
i_qty, o_qty, a_qty = 0, 0, 0
|
||||||
for w in item_qty:
|
for w in item_qty:
|
||||||
i_qty, o_qty, a_qty = i_qty + flt(w[1]), o_qty + flt(w[2]), a_qty + flt(w[3])
|
i_qty, o_qty, a_qty = i_qty + flt(w.indented_qty), o_qty + flt(w.ordered_qty), a_qty + flt(w.actual_qty)
|
||||||
item_list.append(['', '', '', '', w[0], flt(w[1]), flt(w[2]), flt(w[3])])
|
item_list.append(['', '', '', '', w.warehouse, flt(w.indented_qty),
|
||||||
|
flt(w.ordered_qty), flt(w.actual_qty)])
|
||||||
if item_qty:
|
if item_qty:
|
||||||
item_list.append(['', '', '', '', 'Total', i_qty, o_qty, a_qty])
|
item_list.append(['', '', '', '', 'Total', i_qty, o_qty, a_qty])
|
||||||
|
|
||||||
@ -405,7 +406,7 @@ class DocType:
|
|||||||
if purchase_request_list:
|
if purchase_request_list:
|
||||||
pur_req = ["""<a href="#Form/Material Request/%s" target="_blank">%s</a>""" % \
|
pur_req = ["""<a href="#Form/Material Request/%s" target="_blank">%s</a>""" % \
|
||||||
(p, p) for p in purchase_request_list]
|
(p, p) for p in purchase_request_list]
|
||||||
msgprint(_("Material Request(s) created: \n%s") %
|
msgprint("Material Request(s) created: \n%s" %
|
||||||
"\n".join(pur_req))
|
"\n".join(pur_req))
|
||||||
else:
|
else:
|
||||||
msgprint(_("Nothing to request"))
|
msgprint(_("Nothing to request"))
|
@ -38,18 +38,18 @@ class DocType(BuyingController):
|
|||||||
for so_no in so_items.keys():
|
for so_no in so_items.keys():
|
||||||
for item in so_items[so_no].keys():
|
for item in so_items[so_no].keys():
|
||||||
already_indented = webnotes.conn.sql("""select sum(qty) from `tabMaterial Request Item`
|
already_indented = webnotes.conn.sql("""select sum(qty) from `tabMaterial Request Item`
|
||||||
where item_code = '%s' and sales_order_no = '%s' and
|
where item_code = %s and sales_order_no = %s and
|
||||||
docstatus = 1 and parent != '%s'""" % (item, so_no, self.doc.name))
|
docstatus = 1 and parent != %s""", (item, so_no, self.doc.name))
|
||||||
already_indented = already_indented and flt(already_indented[0][0]) or 0
|
already_indented = already_indented and flt(already_indented[0][0]) or 0
|
||||||
|
|
||||||
actual_so_qty = webnotes.conn.sql("""select sum(qty) from `tabSales Order Item`
|
actual_so_qty = webnotes.conn.sql("""select sum(qty) from `tabSales Order Item`
|
||||||
where parent = '%s' and item_code = '%s' and docstatus = 1
|
where parent = %s and item_code = %s and docstatus = 1
|
||||||
group by parent""" % (so_no, item))
|
group by parent""", (so_no, item))
|
||||||
actual_so_qty = actual_so_qty and flt(actual_so_qty[0][0]) or 0
|
actual_so_qty = actual_so_qty and flt(actual_so_qty[0][0]) or 0
|
||||||
|
|
||||||
if actual_so_qty and (flt(so_items[so_no][item]) + already_indented > actual_so_qty):
|
if actual_so_qty and (flt(so_items[so_no][item]) + already_indented > actual_so_qty):
|
||||||
webnotes.throw(_("You can raise indent of maximum qty: %s for item: %s against sales order: %s\
|
webnotes.throw("You can raise indent of maximum qty: %s for item: %s against sales order: %s\
|
||||||
\n Anyway, you can add more qty in new row for the same item.")
|
\n Anyway, you can add more qty in new row for the same item."
|
||||||
% (actual_so_qty - already_indented, item, so_no))
|
% (actual_so_qty - already_indented, item, so_no))
|
||||||
|
|
||||||
def validate_schedule_date(self):
|
def validate_schedule_date(self):
|
||||||
@ -105,8 +105,10 @@ class DocType(BuyingController):
|
|||||||
self.update_bin(is_submit = 1, is_stopped = 0)
|
self.update_bin(is_submit = 1, is_stopped = 0)
|
||||||
|
|
||||||
def check_modified_date(self):
|
def check_modified_date(self):
|
||||||
mod_db = webnotes.conn.sql("select modified from `tabMaterial Request` where name = '%s'" % self.doc.name)
|
mod_db = webnotes.conn.sql("""select modified from `tabMaterial Request` where name = %s""",
|
||||||
date_diff = webnotes.conn.sql("select TIMEDIFF('%s', '%s')" % (mod_db[0][0], cstr(self.doc.modified)))
|
self.doc.name)
|
||||||
|
date_diff = webnotes.conn.sql("""select TIMEDIFF('%s', '%s')"""
|
||||||
|
% (mod_db[0][0], cstr(self.doc.modified)))
|
||||||
|
|
||||||
if date_diff and date_diff[0][0]:
|
if date_diff and date_diff[0][0]:
|
||||||
webnotes.throw(cstr(self.doc.doctype) + " => " + cstr(self.doc.name) + " has been modified. Please Refresh.")
|
webnotes.throw(cstr(self.doc.doctype) + " => " + cstr(self.doc.name) + " has been modified. Please Refresh.")
|
||||||
@ -120,7 +122,7 @@ class DocType(BuyingController):
|
|||||||
webnotes.conn.set(self.doc, 'status', cstr(status))
|
webnotes.conn.set(self.doc, 'status', cstr(status))
|
||||||
|
|
||||||
# Step 3:=> Acknowledge User
|
# Step 3:=> Acknowledge User
|
||||||
msgprint(self.doc.doctype + ": " + self.doc.name + _(" has been %s.") % ((status == 'Submitted') and 'Unstopped' or cstr(status)) )
|
msgprint(self.doc.doctype + ": " + self.doc.name + " has been %s." % ((status == 'Submitted') and 'Unstopped' or cstr(status)))
|
||||||
|
|
||||||
|
|
||||||
def on_cancel(self):
|
def on_cancel(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user