Python constraints (error) message -


i have written function below in python. works if user selects holiday start-date , holiday end-date time correctly accepts, else show error message 'error: entered invalid date or time' shown in figenter image description here

python code:

def _date_start_end_validate(self, cr, uid, ids, context=none):         sr_ids = self.search(cr, 1 ,[], context=context)         self_obj in self.browse(cr, uid, ids, context=context):             if self_obj.date_start >= self_obj.date_end:                 return false         return true  _constraints = [(_date_start_end_validate, 'error: entered invalid date or time', ['dates'])] 

i need display start-date showing error here, date should displayed.

how start-date information in constraints.

try below code may use full.

def _date_start_end_validate(self, cr, uid, ids, context=none):

sr_ids = self.search(cr, 1 ,[], context=context)  self_obj in self.browse(cr, uid, ids, context=context):      if self_obj.date_start >= self_obj.date_end:          return false  return true 

def _check_msg_with_start_date(self, cr, uid, ids, context):

data = self.browse(cr, uid, ids, context=context)  return "error: entered invalid date or time {} ".format(data.date_start) 

_constraints = [

(_date_start_end_validate, lambda self, *a, **kw: self._check_msg_with_start_date(*a, **kw), ['date_start','date_end']) 

]

thanks & regards

ankit h gandhi


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -