Beispiel #1
0
 def validate(self, record, softvalidation=False, pre_validate=None):
     if self.attrs.get('readonly'):
         return True
     invalid = False
     self.get_state_attrs(record)['domain_readonly'] = False
     domain = simplify(self.validation_domains(record, pre_validate))
     if not softvalidation:
         if not self.check_required(record):
             invalid = 'required'
             logging.getLogger('root').debug('Field %s of %s is required' %
                                             (self.name, record.model_name))
     if isinstance(domain, bool):
         if not domain:
             invalid = 'domain'
             logging.getLogger('root').debug(
                 'Invalid domain on Field %s of'
                 ' %s : %s' % (self.name, record.model_name, str(domain)))
     elif domain == [('id', '=', None)]:
         invalid = 'domain'
         logging.getLogger('root').debug(
             'Invalid domain on Field %s of'
             ' %s : %s' % (self.name, record.model_name, str(domain)))
     else:
         unique, leftpart, value = unique_value(domain)
         if unique:
             # If the inverted domain is so constraint that only one value
             # is possible we should use it. But we must also pay attention
             # to the fact that the original domain might be a 'OR' domain
             # and thus not preventing the modification of fields.
             if value is False:
                 # XXX to remove once server domains are fixed
                 value = None
             setdefault = True
             group_domain = record.group.get_domain()
             if group_domain:
                 original_domain = merge(group_domain)
             else:
                 original_domain = merge(domain)
             domain_readonly = original_domain[0] == 'AND'
             if '.' in leftpart:
                 recordpart, localpart = leftpart.split('.', 1)
                 constraintfields = set()
                 if domain_readonly:
                     for leaf in localize_domain(original_domain[1:]):
                         constraintfields.add(leaf[0])
                 if localpart != 'id' or recordpart not in constraintfields:
                     setdefault = False
             if setdefault and not pre_validate:
                 self.set_client(record, value)
                 self.get_state_attrs(record)['domain_readonly'] = (
                     domain_readonly)
         if not eval_domain(domain, EvalEnvironment(record)):
             invalid = domain
             logging.getLogger('root').debug(
                 'Invalid domain on Field %s of'
                 ' %s : %s' % (self.name, record.model_name, str(domain)))
     self.get_state_attrs(record)['invalid'] = invalid
     return not invalid
Beispiel #2
0
 def validate(self, record, softvalidation=False, pre_validate=None):
     if self.attrs.get('readonly'):
         return True
     invalid = False
     self.get_state_attrs(record)['domain_readonly'] = False
     domain = simplify(self.validation_domains(record, pre_validate))
     if not softvalidation:
         if not self.check_required(record):
             invalid = 'required'
             logging.getLogger('root').debug('Field %s of %s is required' %
                 (self.name, record.model_name))
     if isinstance(domain, bool):
         if not domain:
             invalid = 'domain'
             logging.getLogger('root').debug('Invalid domain on Field %s of'
                 ' %s : %s' % (self.name, record.model_name, str(domain)))
     elif domain == [('id', '=', None)]:
         invalid = 'domain'
         logging.getLogger('root').debug('Invalid domain on Field %s of'
             ' %s : %s' % (self.name, record.model_name, str(domain)))
     else:
         unique, leftpart, value = unique_value(domain)
         if unique:
             # If the inverted domain is so constraint that only one value
             # is possible we should use it. But we must also pay attention
             # to the fact that the original domain might be a 'OR' domain
             # and thus not preventing the modification of fields.
             if value is False:
                 # XXX to remove once server domains are fixed
                 value = None
             setdefault = True
             group_domain = record.group.get_domain()
             if group_domain:
                 original_domain = merge(group_domain)
             else:
                 original_domain = merge(domain)
             domain_readonly = original_domain[0] == 'AND'
             if '.' in leftpart:
                 recordpart, localpart = leftpart.split('.', 1)
                 constraintfields = set()
                 if domain_readonly:
                     for leaf in localize_domain(original_domain[1:]):
                         constraintfields.add(leaf[0])
                 if localpart != 'id' or recordpart not in constraintfields:
                     setdefault = False
             if setdefault and not pre_validate:
                 self.set_client(record, value)
                 self.get_state_attrs(record)['domain_readonly'] = (
                     domain_readonly)
         if not eval_domain(domain, EvalEnvironment(record)):
             invalid = domain
             logging.getLogger('root').debug('Invalid domain on Field %s of'
                 ' %s : %s' % (self.name, record.model_name, str(domain)))
     self.get_state_attrs(record)['invalid'] = invalid
     return not invalid
Beispiel #3
0
 def validate(self, record, softvalidation=False):
     if self.attrs.get('readonly'):
         return True
     res = True
     self.get_state_attrs(record)['domain_readonly'] = False
     inverted_domain, domain = self.validation_domains(record)
     if not softvalidation:
         res = res and self.check_required(record)
     if isinstance(domain, bool):
         res = res and domain
     elif domain == [('id', '=', False)]:
         res = False
     else:
         if (isinstance(inverted_domain, list) and len(inverted_domain) == 1
                 and inverted_domain[0][1] == '='):
             # If the inverted domain is so constraint that only one value
             # is possible we should use it. But we must also pay attention
             # to the fact that the original domain might be a 'OR' domain
             # and thus not preventing the modification of fields.
             leftpart, _, value = inverted_domain[0][:3]
             if value is False:
                 # XXX to remove once server domains are fixed
                 value = None
             setdefault = True
             original_domain = merge(record.group.domain)
             domain_readonly = original_domain[0] == 'AND'
             if '.' in leftpart:
                 recordpart, localpart = leftpart.split('.', 1)
                 constraintfields = set()
                 if domain_readonly:
                     for leaf in localize_domain(original_domain[1:]):
                         constraintfields.add(leaf[0])
                 if localpart != 'id' or recordpart not in constraintfields:
                     setdefault = False
             if setdefault:
                 self.set_client(record, value)
                 self.get_state_attrs(record)['domain_readonly'] = (
                     domain_readonly)
         res = res and eval_domain(domain, EvalEnvironment(record))
     self.get_state_attrs(record)['valid'] = res
     return res
Beispiel #4
0
 def validate(self, record, softvalidation=False):
     if self.attrs.get('readonly'):
         return True
     res = True
     self.get_state_attrs(record)['domain_readonly'] = False
     inverted_domain, domain = self.validation_domains(record)
     if not softvalidation:
         res = res and self.check_required(record)
     if isinstance(domain, bool):
         res = res and domain
     elif domain == [('id', '=', False)]:
         res = False
     else:
         if (isinstance(inverted_domain, list)
                 and len(inverted_domain) == 1
                 and inverted_domain[0][1] == '='):
             # If the inverted domain is so constraint that only one value
             # is possible we should use it. But we must also pay attention
             # to the fact that the original domain might be a 'OR' domain
             # and thus not preventing the modification of fields.
             leftpart, _, value = inverted_domain[0][:3]
             if value is False:
                 # XXX to remove once server domains are fixed
                 value = None
             setdefault = True
             if '.' in leftpart:
                 recordpart, localpart = leftpart.split('.', 1)
                 original_domain = merge(record.group.domain)
                 constraintfields = set()
                 if original_domain[0] == 'AND':
                     for leaf in localize_domain(original_domain[1:]):
                         constraintfields.add(leaf[0])
                 if localpart != 'id' or recordpart not in constraintfields:
                     setdefault = False
             if setdefault:
                 self.set_client(record, value)
                 self.get_state_attrs(record)['domain_readonly'] = True
         res = res and eval_domain(domain, EvalEnvironment(record))
     self.get_state_attrs(record)['valid'] = res
     return res