Пример #1
0
 def domain_get(self, record):
     if record.value.get(self.name):
         model = record.value[self.name][0]
     else:
         model = None
     screen_domain, attr_domain = self.domains_get(record)
     return concat(localize_domain(
             filter_leaf(screen_domain, self.name, model),
             strip_target=True), attr_domain)
Пример #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
Пример #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
             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
Пример #4
0
 def validate(self, record, softvalidation=False, pre_validate=None):
     if self.attrs.get('readonly'):
         return True
     invalid = False
     ldomain = localize_domain(domain_inversion(
             record.group.clean4inversion(pre_validate or []), self.name,
             EvalEnvironment(record)), self.name)
     if isinstance(ldomain, bool):
         if ldomain:
             ldomain = []
         else:
             ldomain = [('id', '=', None)]
     for record2 in record.value.get(self.name, []):
         if not record2.loaded and record2.id >= 0 and not pre_validate:
             continue
         if not record2.validate(softvalidation=softvalidation,
                 pre_validate=ldomain):
             invalid = 'children'
     test = super(O2MField, self).validate(record, softvalidation,
         pre_validate)
     if test and invalid:
         self.get_state_attrs(record)['invalid'] = invalid
         return False
     return test
Пример #5
0
 def domain_get(self, record):
     screen_domain, attr_domain = self.domains_get(record)
     return localize_domain(inverse_leaf(screen_domain)) + attr_domain
Пример #6
0
 def domain_get(self, record):
     screen_domain, attr_domain = self.domains_get(record)
     return concat(localize_domain(screen_domain), attr_domain)
Пример #7
0
 def domain_get(self, record):
     screen_domain, attr_domain = self.domains_get(record)
     return concat(localize_domain(inverse_leaf(screen_domain), self.name),
         attr_domain)
Пример #8
0
 def domain_get(self, record):
     screen_domain, attr_domain = self.domains_get(record)
     return concat(localize_domain(screen_domain), attr_domain)
Пример #9
0
 def domain_get(self, record):
     screen_domain, attr_domain = self.domains_get(record)
     return concat(localize_domain(inverse_leaf(screen_domain), self.name),
                   attr_domain)