added status validation

This commit is contained in:
Anand Doshi 2012-12-28 19:42:49 +05:30
parent b72d8204e8
commit f9a3c8fcdc
19 changed files with 410 additions and 355 deletions

View File

@ -128,8 +128,13 @@ class DocType(TransactionBase):
# Validate # Validate
def validate(self): def validate(self):
self.validate_fiscal_year() self.validate_fiscal_year()
# Step 1:=> set status as "Draft"
webnotes.conn.set(self.doc, 'status', 'Draft') if not self.doc.status:
self.doc.status = "Draft"
import utilities
utilities.validate_status(self.doc.status, ["Draft", "Submitted", "Stopped",
"Cancelled"])
# Step 2:=> get Purchase Common Obj # Step 2:=> get Purchase Common Obj
pc_obj = get_obj(dt='Purchase Common') pc_obj = get_obj(dt='Purchase Common')

View File

@ -141,8 +141,12 @@ class DocType:
self.validate_schedule_date() self.validate_schedule_date()
self.validate_fiscal_year() self.validate_fiscal_year()
# set status as "Draft" if not self.doc.status:
webnotes.conn.set(self.doc, 'status', 'Draft') self.doc.status = "Draft"
import utilities
utilities.validate_status(self.doc.status, ["Draft", "Submitted", "Stopped",
"Cancelled"])
# Get Purchase Common Obj # Get Purchase Common Obj
pc_obj = get_obj(dt='Purchase Common') pc_obj = get_obj(dt='Purchase Common')

View File

@ -30,10 +30,16 @@ class DocType(TransactionBase):
self.doc.name = make_autoname(self.doc.naming_series + ".#####") self.doc.name = make_autoname(self.doc.naming_series + ".#####")
def validate(self): def validate(self):
if not self.doc.status:
self.doc.status = "Draft"
import utilities
utilities.validate_status(self.doc.status, ["Draft", "Submitted", "Stopped",
"Cancelled"])
self.validate_fiscal_year() self.validate_fiscal_year()
self.validate_common() self.validate_common()
self.set_in_words() self.set_in_words()
self.doc.status = "Draft"
def on_submit(self): def on_submit(self):
purchase_controller = webnotes.get_obj("Purchase Common") purchase_controller = webnotes.get_obj("Purchase Common")

View File

@ -57,6 +57,7 @@ class DocType:
def validate(self): def validate(self):
if not self.doc.status: if not self.doc.status:
self.doc.status = "Draft" self.doc.status = "Draft"
self.validate_dates() self.validate_dates()
self.validate_existing_appraisal() self.validate_existing_appraisal()
self.calculate_total() self.calculate_total()

View File

@ -64,7 +64,8 @@ class DocType:
def validate_fiscal_year(self): def validate_fiscal_year(self):
fy=sql("select year_start_date from `tabFiscal Year` where name='%s'"% self.doc.fiscal_year) fy=sql("select year_start_date from `tabFiscal Year` where name='%s'" % \
self.doc.fiscal_year)
ysd=fy and fy[0][0] or "" ysd=fy and fy[0][0] or ""
yed=add_days(str(ysd),365) yed=add_days(str(ysd),365)
if str(self.doc.att_date) < str(ysd) or str(self.doc.att_date) > str(yed): if str(self.doc.att_date) < str(ysd) or str(self.doc.att_date) > str(yed):
@ -86,12 +87,13 @@ class DocType:
elif emp[0][1] != 'Active': elif emp[0][1] != 'Active':
msgprint("Employee: %s is not Active" % self.doc.employee, raise_exception=1) msgprint("Employee: %s is not Active" % self.doc.employee, raise_exception=1)
# validate...
def validate(self): def validate(self):
import utilities
utilities.validate_status(self.doc.status, ["Present", "Absent", "Half Day"])
self.validate_fiscal_year() self.validate_fiscal_year()
self.validate_att_date() self.validate_att_date()
self.validate_duplicate_record() self.validate_duplicate_record()
#self.validate_status()
self.check_leave_record() self.check_leave_record()
def on_update(self): def on_update(self):

View File

@ -19,7 +19,7 @@ import webnotes
from webnotes.utils import getdate, validate_email_add from webnotes.utils import getdate, validate_email_add
from webnotes.model.doc import make_autoname from webnotes.model.doc import make_autoname
from webnotes import msgprint from webnotes import msgprint, _
sql = webnotes.conn.sql sql = webnotes.conn.sql
@ -40,6 +40,16 @@ class DocType:
self.doc.employee = self.doc.name self.doc.employee = self.doc.name
def validate(self):
import utilities
utilities.validate_status(self.doc.status, ["Active", "Left"])
self.doc.employee = self.doc.name
self.validate_date()
self.validate_email()
self.validate_name()
self.validate_status()
def get_retirement_date(self): def get_retirement_date(self):
import datetime import datetime
ret = {} ret = {}
@ -52,13 +62,6 @@ class DocType:
ret_sal_struct=sql("select name from `tabSalary Structure` where employee='%s' and is_active = 'Yes' and docstatus!= 2"%nm) ret_sal_struct=sql("select name from `tabSalary Structure` where employee='%s' and is_active = 'Yes' and docstatus!= 2"%nm)
return ret_sal_struct and ret_sal_struct[0][0] or '' return ret_sal_struct and ret_sal_struct[0][0] or ''
def validate(self):
self.doc.employee = self.doc.name
self.validate_date()
self.validate_email()
self.validate_name()
self.validate_status()
def on_update(self): def on_update(self):
self.update_user_default() self.update_user_default()

View File

@ -33,9 +33,8 @@ class DocType:
# if self.doc.exp_approver == self.doc.owner: # if self.doc.exp_approver == self.doc.owner:
# webnotes.msgprint("""Self Approval is not allowed.""", raise_exception=1) # webnotes.msgprint("""Self Approval is not allowed.""", raise_exception=1)
if self.doc.status not in ("Draft", "Approved", "Rejected"): import utilities
webnotes.msgprint("Status must be one of 'Draft', 'Approved' or 'Rejected'", utilities.validate_status(self.doc.status, ["Draft", "Approved", "Rejected"])
raise_exception=True)
self.validate_fiscal_year() self.validate_fiscal_year()
self.validate_exp_details() self.validate_exp_details()

View File

@ -33,9 +33,8 @@ class DocType:
def validate(self): def validate(self):
# if self.doc.leave_approver == self.doc.owner: # if self.doc.leave_approver == self.doc.owner:
# webnotes.msgprint("""Self Approval is not allowed.""", raise_exception=1) # webnotes.msgprint("""Self Approval is not allowed.""", raise_exception=1)
if self.doc.status not in ("Open", "Approved", "Rejected"): import utilities
webnotes.msgprint("Status must be one of 'Open', 'Approved' or 'Rejected'", utilities.validate_status(self.doc.status, ["Open", "Approved", "Rejected"])
raise_exception=True)
self.validate_to_date() self.validate_to_date()
self.validate_balance_leaves() self.validate_balance_leaves()

View File

@ -45,11 +45,11 @@ class DocType:
det = sql("select employee_name, branch, designation, department, grade from `tabEmployee` where name = '%s'" %self.doc.employee) det = sql("select employee_name, branch, designation, department, grade from `tabEmployee` where name = '%s'" %self.doc.employee)
if det: if det:
ret = { ret = {
'employee_name' : cstr(det[0][0]), 'employee_name': cstr(det[0][0]),
'branch' : cstr(det[0][1]), 'branch': cstr(det[0][1]),
'designation' : cstr(det[0][2]), 'designation': cstr(det[0][2]),
'department' : cstr(det[0][3]), 'department': cstr(det[0][3]),
'grade' : cstr(det[0][4]), 'grade': cstr(det[0][4]),
'backup_employee': cstr(self.doc.employee) 'backup_employee': cstr(self.doc.employee)
} }
return ret return ret
@ -59,10 +59,10 @@ class DocType:
#--------------------------------------------------------- #---------------------------------------------------------
def get_ss_values(self,employee): def get_ss_values(self,employee):
basic_info = sql("select bank_name, bank_ac_no, esic_card_no, pf_number from `tabEmployee` where name ='%s'" % employee) basic_info = sql("select bank_name, bank_ac_no, esic_card_no, pf_number from `tabEmployee` where name ='%s'" % employee)
ret = {'bank_name' : basic_info and basic_info[0][0] or '', ret = {'bank_name': basic_info and basic_info[0][0] or '',
'bank_ac_no' : basic_info and basic_info[0][1] or '', 'bank_ac_no': basic_info and basic_info[0][1] or '',
'esic_no' : basic_info and basic_info[0][2] or '', 'esic_no': basic_info and basic_info[0][2] or '',
'pf_no' : basic_info and basic_info[0][3] or ''} 'pf_no': basic_info and basic_info[0][3] or ''}
return ret return ret
# Make earning and deduction table # Make earning and deduction table
@ -85,7 +85,8 @@ class DocType:
self.make_table('Earning Type','earning_details','Salary Structure Earning') self.make_table('Earning Type','earning_details','Salary Structure Earning')
#Deduction List #Deduction List
self.make_table('Deduction Type','deduction_details', 'Salary Structure Deduction') self.make_table('Deduction Type','deduction_details',
'Salary Structure Deduction')
# Check if another active ss exists # Check if another active ss exists
@ -106,8 +107,6 @@ class DocType:
msgprint("Net pay can not be greater than CTC") msgprint("Net pay can not be greater than CTC")
raise Exception raise Exception
# Validate
#---------------------------------------------------------
def validate(self): def validate(self):
self.check_existing() self.check_existing()
self.validate_net_pay() self.validate_net_pay()

View File

@ -34,6 +34,10 @@ class DocType:
self.doclist = doclist self.doclist = doclist
def validate(self): def validate(self):
import utilities
utilities.validate_status(self.doc.status, ["Draft", "Submitted", "Stopped",
"In Process", "Completed", "Cancelled"])
if self.doc.production_item : if self.doc.production_item :
item_detail = sql("select name from `tabItem` where name = '%s' and docstatus != 2" item_detail = sql("select name from `tabItem` where name = '%s' and docstatus != 2"
% self.doc.production_item, as_dict = 1) % self.doc.production_item, as_dict = 1)

View File

@ -36,11 +36,19 @@ class DocType(TransactionBase):
self.tname = 'Installation Note Item' self.tname = 'Installation Note Item'
self.fname = 'installed_item_details' self.fname = 'installed_item_details'
# Autoname
# ---------
def autoname(self): def autoname(self):
self.doc.name = make_autoname(self.doc.naming_series+'.#####') self.doc.name = make_autoname(self.doc.naming_series+'.#####')
def validate(self):
self.validate_fiscal_year()
self.validate_installation_date()
self.check_item_table()
sales_com_obj = get_obj(dt = 'Sales Common')
sales_com_obj.check_active_sales_items(self)
sales_com_obj.get_prevdoc_date(self)
self.validate_mandatory()
self.validate_reference_value()
#fetch delivery note details #fetch delivery note details
#==================================== #====================================
@ -155,16 +163,6 @@ class DocType(TransactionBase):
msgprint("Installation Date can not be before Delivery Date "+cstr(d_date)+" for item "+d.item_code) msgprint("Installation Date can not be before Delivery Date "+cstr(d_date)+" for item "+d.item_code)
raise Exception raise Exception
def validate(self):
self.validate_fiscal_year()
self.validate_installation_date()
self.check_item_table()
sales_com_obj = get_obj(dt = 'Sales Common')
sales_com_obj.check_active_sales_items(self)
sales_com_obj.get_prevdoc_date(self)
self.validate_mandatory()
self.validate_reference_value()
def check_item_table(self): def check_item_table(self):
if not(getlist(self.doclist, 'installed_item_details')): if not(getlist(self.doclist, 'installed_item_details')):
msgprint("Please fetch items from Delivery Note selected") msgprint("Please fetch items from Delivery Note selected")

View File

@ -179,6 +179,10 @@ class DocType(TransactionBase):
# Validate # Validate
# -------- # --------
def validate(self): def validate(self):
import utilities
utilities.validate_status(self.doc.status, ["Draft", "Submitted",
"Order Confirmed", "Order Lost", "Cancelled"])
self.validate_fiscal_year() self.validate_fiscal_year()
self.validate_mandatory() self.validate_mandatory()
self.set_last_contact_date() self.set_last_contact_date()

View File

@ -226,8 +226,13 @@ class DocType(TransactionBase):
self.doc.in_words = sales_com_obj.get_total_in_words(dcc, self.doc.rounded_total) self.doc.in_words = sales_com_obj.get_total_in_words(dcc, self.doc.rounded_total)
self.doc.in_words_export = sales_com_obj.get_total_in_words(self.doc.currency, self.doc.rounded_total_export) self.doc.in_words_export = sales_com_obj.get_total_in_words(self.doc.currency, self.doc.rounded_total_export)
# set SO status if not self.doc.status:
self.doc.status='Draft' self.doc.status = "Draft"
import utilities
utilities.validate_status(self.doc.status, ["Draft", "Submitted", "Stopped",
"Cancelled"])
if not self.doc.billing_status: self.doc.billing_status = 'Not Billed' if not self.doc.billing_status: self.doc.billing_status = 'Not Billed'
if not self.doc.delivery_status: self.doc.delivery_status = 'Not Delivered' if not self.doc.delivery_status: self.doc.delivery_status = 'Not Delivered'

View File

@ -131,6 +131,9 @@ class DocType(TransactionBase):
def validate(self): def validate(self):
import utilities
utilities.validate_status(self.doc.status, ["Draft", "submitted", "Cancelled"])
self.so_required() self.so_required()
self.validate_fiscal_year() self.validate_fiscal_year()
self.validate_proj_cust() self.validate_proj_cust()

View File

@ -148,7 +148,13 @@ class DocType(TransactionBase):
def validate(self): def validate(self):
self.po_required() self.po_required()
self.validate_fiscal_year() self.validate_fiscal_year()
webnotes.conn.set(self.doc, 'status', 'Draft') # set status as "Draft"
if not self.doc.status:
self.doc.status = "Draft"
import utilities
utilities.validate_status(self.doc.status, ["Draft", "Submitted", "Cancelled"])
self.validate_accepted_rejected_qty() self.validate_accepted_rejected_qty()
self.validate_inspection() # Validate Inspection self.validate_inspection() # Validate Inspection
get_obj('Stock Ledger').validate_serial_no(self, 'purchase_receipt_details') get_obj('Stock Ledger').validate_serial_no(self, 'purchase_receipt_details')

View File

@ -65,6 +65,10 @@ class DocType(TransactionBase):
# validate # validate
# --------- # ---------
def validate(self): def validate(self):
import utilities
utilities.validate_status(self.doc.status, ["In Store", "Delivered",
"Not in Use", "Purchase Returned"])
self.validate_warranty_status() self.validate_warranty_status()
self.validate_amc_status() self.validate_amc_status()
self.validate_warehouse() self.validate_warehouse()

View File

@ -17,7 +17,7 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import webnotes import webnotes
from webnotes.utils import cstr, cint, flt, getdate, now from webnotes.utils import cstr, cint, flt, getdate, now, comma_or
from webnotes.model import db_exists, delete_doc from webnotes.model import db_exists, delete_doc
from webnotes.model.doc import Document, addchild from webnotes.model.doc import Document, addchild
from webnotes.model.wrapper import getlist, copy_doclist from webnotes.model.wrapper import getlist, copy_doclist
@ -35,6 +35,8 @@ class DocType(TransactionBase):
self.fname = 'mtn_details' self.fname = 'mtn_details'
def validate(self): def validate(self):
self.validate_purpose()
self.validate_serial_nos() self.validate_serial_nos()
pro_obj = self.doc.production_order and \ pro_obj = self.doc.production_order and \
get_obj('Production Order', self.doc.production_order) or None get_obj('Production Order', self.doc.production_order) or None
@ -58,6 +60,13 @@ class DocType(TransactionBase):
# update Production Order # update Production Order
self.update_production_order(0) self.update_production_order(0)
def validate_purpose(self):
valid_purposes = ["Material Issue", "Material Receipt", "Material Transfer",
"Manufacture/Repack", "Subcontract", "Sales Return", "Purchase Return"]
if self.doc.purpose not in valid_purposes:
msgprint(_("Purpose must be one of ") + comma_or(valid_purposes),
raise_exception=True)
def validate_serial_nos(self): def validate_serial_nos(self):
sl_obj = get_obj("Stock Ledger") sl_obj = get_obj("Stock Ledger")
sl_obj.scrub_serial_nos(self) sl_obj.scrub_serial_nos(self)

View File

@ -41,9 +41,8 @@ class DocType(TransactionBase):
def validate(self): def validate(self):
if session['user'] != 'Guest' and not self.doc.customer: if session['user'] != 'Guest' and not self.doc.customer:
msgprint("Please select Customer from whom issue is raised") msgprint("Please select Customer from whom issue is raised",
raise Exception raise_exception=True)
def on_cancel(self): def on_cancel(self):
lst = sql("select t1.name from `tabMaintenance Visit` t1, `tabMaintenance Visit Purpose` t2 where t2.parent = t1.name and t2.prevdoc_docname = '%s' and t1.docstatus!=2"%(self.doc.name)) lst = sql("select t1.name from `tabMaintenance Visit` t1, `tabMaintenance Visit Purpose` t2 where t2.parent = t1.name and t2.prevdoc_docname = '%s' and t1.docstatus!=2"%(self.doc.name))

View File

@ -16,7 +16,8 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import webnotes import webnotes
from webnotes.utils import cint from webnotes import _, msgprint
from webnotes.utils import cint, comma_or
@webnotes.whitelist() @webnotes.whitelist()
def get_sc_list(arg=None): def get_sc_list(arg=None):
@ -53,3 +54,7 @@ def get_report_list():
order by tabReport.name order by tabReport.name
limit %s, %s""" % \ limit %s, %s""" % \
("%s", cint(limit_start), cint(limit_page_length)), (module,), as_dict=True) ("%s", cint(limit_start), cint(limit_page_length)), (module,), as_dict=True)
def validate_status(status, options):
if status not in options:
msgprint(_("Status must be one of ") + comma_or(options), raise_exception=True)