mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-15 11:09:17 +00:00
[fix] [minor] material request sales order wise through production planning tool
This commit is contained in:
@@ -36,13 +36,13 @@ class DocType(BuyingController):
|
||||
if flt(d.conversion_factor):
|
||||
last_purchase_rate = flt(d.purchase_rate) / flt(d.conversion_factor)
|
||||
else:
|
||||
msgprint(_("Row ") + cstr(d.idx) + ": " +
|
||||
_("UOM Conversion Factor is mandatory"), raise_exception=1)
|
||||
webnotes.throw(_("Row ") + cstr(d.idx) + ": " +
|
||||
_("UOM Conversion Factor is mandatory"))
|
||||
|
||||
# update last purchsae rate
|
||||
if last_purchase_rate:
|
||||
webnotes.conn.sql("update `tabItem` set last_purchase_rate = %s where name = %s",
|
||||
(flt(last_purchase_rate),d.item_code))
|
||||
webnotes.conn.sql("""update `tabItem` set last_purchase_rate = %s where name = %s""",
|
||||
(flt(last_purchase_rate), d.item_code))
|
||||
|
||||
def get_last_purchase_rate(self, obj):
|
||||
"""get last purchase rates for all items"""
|
||||
@@ -74,11 +74,11 @@ class DocType(BuyingController):
|
||||
for d in getlist( obj.doclist, obj.fname):
|
||||
# validation for valid 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))
|
||||
raise Exception
|
||||
webnotes.throw("Please enter valid qty for item %s" % cstr(d.item_code))
|
||||
|
||||
# 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}
|
||||
if d.doctype == 'Purchase Receipt Item':
|
||||
@@ -87,22 +87,21 @@ class DocType(BuyingController):
|
||||
if d.fields.has_key(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",
|
||||
d.item_code)
|
||||
item = webnotes.conn.sql("""select is_stock_item, is_purchase_item,
|
||||
is_sub_contracted_item, end_of_life from `tabItem` where name=%s""", d.item_code)
|
||||
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
|
||||
validate_end_of_life(d.item_code, item[0][3])
|
||||
|
||||
# validate stock item
|
||||
if item[0][0]=='Yes' and d.qty and not d.warehouse:
|
||||
msgprint("Warehouse is mandatory for %s, since it is a stock item" %
|
||||
d.item_code, raise_exception=1)
|
||||
webnotes.throw("Warehouse is mandatory for %s, since it is a stock item" % d.item_code)
|
||||
|
||||
# validate purchase item
|
||||
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
|
||||
e = [d.schedule_date, d.item_code, d.description, d.warehouse, d.uom,
|
||||
@@ -113,25 +112,25 @@ class DocType(BuyingController):
|
||||
# if is not stock item
|
||||
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':
|
||||
# check for same items
|
||||
if e in check_list:
|
||||
msgprint("""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)
|
||||
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)
|
||||
else:
|
||||
check_list.append(e)
|
||||
|
||||
elif ch and ch[0][0] == 'No':
|
||||
# check for same items
|
||||
if f in chk_dupl_itm:
|
||||
msgprint("""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)
|
||||
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)
|
||||
else:
|
||||
chk_dupl_itm.append(f)
|
||||
|
||||
def get_qty(self,curr_doctype,ref_tab_fname,ref_tab_dn,ref_doc_tname, transaction, curr_parent_name):
|
||||
def get_qty(self, curr_doctype, ref_tab_fname, ref_tab_dn, ref_doc_tname, transaction, curr_parent_name):
|
||||
# Get total Quantities of current doctype (eg. PR) except for qty of this transaction
|
||||
#------------------------------
|
||||
# please check as UOM changes from Material Request - Purchase Order ,so doing following else uom should be same .
|
||||
@@ -139,35 +138,36 @@ class DocType(BuyingController):
|
||||
# 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'
|
||||
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
|
||||
|
||||
# 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
|
||||
|
||||
return cstr(qty)+'~~~'+cstr(max_qty)
|
||||
|
||||
def check_for_stopped_status(self, doctype, docname):
|
||||
stopped = webnotes.conn.sql("select name from `tab%s` where name = '%s' and status = 'Stopped'" %
|
||||
( doctype, docname))
|
||||
stopped = webnotes.conn.sql("""select name from `tab%s` where name = '%s' and
|
||||
status = 'Stopped'""", (doctype, docname))
|
||||
if stopped:
|
||||
msgprint("One cannot do any transaction against %s : %s, it's status is 'Stopped'" %
|
||||
( doctype, docname), raise_exception=1)
|
||||
webnotes.throw("One cannot do any transaction against %s : %s, it's status is 'Stopped'" %
|
||||
(doctype, docname))
|
||||
|
||||
def check_docstatus(self, check, doctype, docname , detail_doctype = ''):
|
||||
def check_docstatus(self, check, doctype, docname, detail_doctype = ''):
|
||||
if check == 'Next':
|
||||
submitted = webnotes.conn.sql("""select t1.name from `tab%s` t1,`tab%s` t2
|
||||
where t1.name = t2.parent and t2.prevdoc_docname = %s and t1.docstatus = 1"""
|
||||
% (doctype, detail_doctype, '%s'), docname)
|
||||
if submitted:
|
||||
msgprint(cstr(doctype) + ": " + cstr(submitted[0][0])
|
||||
+ _(" has already been submitted."), raise_exception=1)
|
||||
webnotes.throw(cstr(doctype) + ": " + cstr(submitted[0][0])
|
||||
+ _("has already been submitted."))
|
||||
|
||||
if check == 'Previous':
|
||||
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:
|
||||
msgprint(cstr(doctype) + ": " + cstr(submitted[0][0])
|
||||
+ _(" not submitted"), raise_exception=1)
|
||||
webnotes.throw(cstr(doctype) + ": " + cstr(submitted[0][0]) + _("not submitted"))
|
||||
|
||||
Reference in New Issue
Block a user