From b62c4edf0211d2743b1e17ed967d05825b3fed8b Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Thu, 27 Dec 2012 15:35:58 +0530 Subject: [PATCH] added is_item_table_empty validation in submit event of purchase common --- .../doctype/purchase_invoice/purchase_invoice.py | 6 ++++-- buying/doctype/purchase_common/purchase_common.js | 13 ------------- buying/doctype/purchase_common/purchase_common.py | 9 +++++++-- buying/doctype/purchase_order/purchase_order.py | 7 ++++--- buying/doctype/purchase_request/purchase_request.js | 7 ++----- buying/doctype/purchase_request/purchase_request.py | 3 +++ .../supplier_quotation/supplier_quotation.py | 3 +++ stock/doctype/purchase_receipt/purchase_receipt.py | 8 +++++--- 8 files changed, 28 insertions(+), 28 deletions(-) diff --git a/accounts/doctype/purchase_invoice/purchase_invoice.py b/accounts/doctype/purchase_invoice/purchase_invoice.py index 7d858a9dc4..dc17071308 100644 --- a/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -482,6 +482,9 @@ class DocType(TransactionBase): def on_submit(self): + purchase_controller = webnotes.get_obj("Purchase Common") + purchase_controller.is_item_table_empty(self) + self.check_prev_docstatus() # Check for Approving Authority @@ -492,8 +495,7 @@ class DocType(TransactionBase): self.make_gl_entries() self.update_against_document_in_jv() - - get_obj(dt = 'Purchase Common').update_prevdoc_detail(self, is_submit = 1) + purchase_controller.update_prevdoc_detail(self, is_submit = 1) def make_gl_entries(self, is_cancel = 0): diff --git a/buying/doctype/purchase_common/purchase_common.js b/buying/doctype/purchase_common/purchase_common.js index f4cfc299d6..519905a010 100644 --- a/buying/doctype/purchase_common/purchase_common.js +++ b/buying/doctype/purchase_common/purchase_common.js @@ -280,21 +280,8 @@ cur_frm.cscript.import_ref_rate = function(doc, cdt, cdn) { cur_frm.cscript.calc_amount(doc, 5); } -//==================== check if item table is blank ============================================== -var is_item_table = function(doc,cdt,cdn) { - // Step 1 :=>Get all childrens/ rows from Detail Table - var cl = getchildren(tname, doc.name, fname); - // Step 2 :=> If there are no rows then set validated = false, this will stop further execution of code. - if (cl.length == 0) { - alert("There is no item in table"); validated = false; - } -} - //==================== Validate ==================================================================== cur_frm.cscript.validate = function(doc, cdt, cdn) { - // Step 1:=> check if item table is blank - is_item_table(doc,cdt,cdn); - // Step 2:=> Calculate Amount cur_frm.cscript.calc_amount(doc, 1); // calculate advances if pv diff --git a/buying/doctype/purchase_common/purchase_common.py b/buying/doctype/purchase_common/purchase_common.py index e8b725ed92..bb342287e4 100644 --- a/buying/doctype/purchase_common/purchase_common.py +++ b/buying/doctype/purchase_common/purchase_common.py @@ -22,14 +22,14 @@ from webnotes.model import db_exists from webnotes.model.doc import Document, addchild from webnotes.model.wrapper import getlist, copy_doclist from webnotes.model.code import get_obj -from webnotes import form, msgprint +from webnotes import form, msgprint, _ sql = webnotes.conn.sql from utilities.transaction_base import TransactionBase class DocType(TransactionBase): - def __init__(self, doc, doclist=[]): + def __init__(self, doc, doclist=None): self.doc = doc self.doclist = doclist @@ -64,6 +64,11 @@ class DocType(TransactionBase): self.msg = [] + def is_item_table_empty(self, obj): + if not len(obj.doclist.get({"parentfield": obj.fname})): + msgprint(_("Hey there! You need to put at least one item in \ + the item table."), raise_exception=True) + def get_default_schedule_date( self, obj): for d in getlist( obj.doclist, obj.fname): diff --git a/buying/doctype/purchase_order/purchase_order.py b/buying/doctype/purchase_order/purchase_order.py index 812f59c740..85a11ed813 100644 --- a/buying/doctype/purchase_order/purchase_order.py +++ b/buying/doctype/purchase_order/purchase_order.py @@ -220,10 +220,11 @@ class DocType(TransactionBase): # On Submit def on_submit(self): - pc_obj = get_obj(dt ='Purchase Common') + purchase_controller = webnotes.get_obj("Purchase Common") + purchase_controller.is_item_table_empty(self) # Step 1 :=> Update Previous Doc i.e. update pending_qty and Status accordingly - pc_obj.update_prevdoc_detail(self, is_submit = 1) + purchase_controller.update_prevdoc_detail(self, is_submit = 1) # Step 2 :=> Update Bin self.update_bin(is_submit = 1, is_stopped = 0) @@ -236,7 +237,7 @@ class DocType(TransactionBase): "last_purchase_order", self.doc.name) # Step 5 :=> Update last purchase rate - pc_obj.update_last_purchase_rate(self, is_submit = 1) + purchase_controller.update_last_purchase_rate(self, is_submit = 1) # Step 6 :=> Set Status webnotes.conn.set(self.doc,'status','Submitted') diff --git a/buying/doctype/purchase_request/purchase_request.js b/buying/doctype/purchase_request/purchase_request.js index 510762a0f2..f46518f0bf 100644 --- a/buying/doctype/purchase_request/purchase_request.js +++ b/buying/doctype/purchase_request/purchase_request.js @@ -50,22 +50,19 @@ cur_frm.cscript.refresh = function(doc, cdt, cdn) { erpnext.hide_naming_series(); if(doc.docstatus == 1 && doc.status != 'Stopped'){ + cur_frm.add_custom_button("Make Supplier Quotation", cur_frm.cscript.make_supplier_quotation); if(flt(doc.per_ordered, 2) < 100) { cur_frm.add_custom_button('Make Purchase Order', cur_frm.cscript['Make Purchase Order']); cur_frm.add_custom_button('Stop Purchase Request', cur_frm.cscript['Stop Purchase Request']); } cur_frm.add_custom_button('Send SMS', cur_frm.cscript.send_sms); - cur_frm.add_custom_button("Make Supplier Quotation", cur_frm.cscript.make_supplier_quotation); + } if(doc.docstatus == 1 && doc.status == 'Stopped') cur_frm.add_custom_button('Unstop Purchase Request', cur_frm.cscript['Unstop Purchase Request']) } -//======================= validation =================================== -cur_frm.cscript.validate = function(doc,cdt,cdn){ - is_item_table(doc,cdt,cdn); -} //======================= transaction date ============================= cur_frm.cscript.transaction_date = function(doc,cdt,cdn){ if(doc.__islocal){ diff --git a/buying/doctype/purchase_request/purchase_request.py b/buying/doctype/purchase_request/purchase_request.py index 7d0e08e440..3f7f932c25 100644 --- a/buying/doctype/purchase_request/purchase_request.py +++ b/buying/doctype/purchase_request/purchase_request.py @@ -178,6 +178,9 @@ class DocType: get_obj('Warehouse', d.warehouse).update_bin(args) def on_submit(self): + purchase_controller = webnotes.get_obj("Purchase Common") + purchase_controller.is_item_table_empty(self) + webnotes.conn.set(self.doc,'status','Submitted') self.update_bin(is_submit = 1, is_stopped = 0) diff --git a/buying/doctype/supplier_quotation/supplier_quotation.py b/buying/doctype/supplier_quotation/supplier_quotation.py index e5861e5389..cac4bab5f3 100644 --- a/buying/doctype/supplier_quotation/supplier_quotation.py +++ b/buying/doctype/supplier_quotation/supplier_quotation.py @@ -36,6 +36,9 @@ class DocType(TransactionBase): self.doc.status = "Draft" def on_submit(self): + purchase_controller = webnotes.get_obj("Purchase Common") + purchase_controller.is_item_table_empty(self) + webnotes.conn.set(self.doc, "status", "Submitted") def on_cancel(self): diff --git a/stock/doctype/purchase_receipt/purchase_receipt.py b/stock/doctype/purchase_receipt/purchase_receipt.py index e5e1fe110e..5e60753a18 100644 --- a/stock/doctype/purchase_receipt/purchase_receipt.py +++ b/stock/doctype/purchase_receipt/purchase_receipt.py @@ -284,15 +284,17 @@ class DocType(TransactionBase): # on submit def on_submit(self): + purchase_controller = webnotes.get_obj("Purchase Common") + purchase_controller.is_item_table_empty(self) + # Check for Approving Authority get_obj('Authorization Control').validate_approving_authority(self.doc.doctype, self.doc.company, self.doc.grand_total) # Set status as Submitted webnotes.conn.set(self.doc,'status', 'Submitted') - pc_obj = get_obj('Purchase Common') # Update Previous Doc i.e. update pending_qty and Status accordingly - pc_obj.update_prevdoc_detail(self, is_submit = 1) + purchase_controller.update_prevdoc_detail(self, is_submit = 1) # Update Serial Record get_obj('Stock Ledger').update_serial_record(self, 'purchase_receipt_details', is_submit = 1, is_incoming = 1) @@ -301,7 +303,7 @@ class DocType(TransactionBase): self.update_stock(is_submit = 1) # Update last purchase rate - pc_obj.update_last_purchase_rate(self, 1) + purchase_controller.update_last_purchase_rate(self, 1)