def search(self, args, offset=0, limit=None, order=None, count=False): res_domain = [] for domain in args: if (len(domain) > 2 and domain[0] == "bsn_number" and isinstance(domain[2], str) and domain[2] and domain[1] not in expression.NEGATIVE_TERM_OPERATORS and not self.env.context.get( "skip_formatted_bsn_number_search")): operator = domain[1] bsn_number = domain[2] bsn_compact = bsn.compact(bsn_number) bsn_domain = expression.OR([ [('bsn_number', operator, bsn_number)], [('bsn_number', operator, bsn_compact)], ]) if bsn.is_valid(bsn_number): bsn_format = bsn.format(bsn_number) bsn_domain = expression.OR([ bsn_domain, [('bsn_number', operator, bsn_format)], ]) res_domain += bsn_domain else: res_domain.append(domain) return super().search(res_domain, offset=offset, limit=limit, order=order, count=count)
def compact(number): """Convert the number to the minimal representation. This strips the number of any valid separators and removes surrounding whitespace.""" number = clean(number, ' -.').upper().strip() if number.startswith('NL'): number = number[2:] return bsn.compact(number[:-3]) + number[-3:]
def validate(number): """Check if the number is a valid onderwijsnummer. This checks the length and whether the check digit is correct and whether it starts with the right sequence.""" number = compact(number) if not number.isdigit() or int(number) <= 0: raise InvalidFormat() if not number.startswith('10'): raise InvalidFormat() if len(number) != 9: raise InvalidLength() if checksum(number) != 5: raise InvalidChecksum() return number
def search(self, args, offset=0, limit=None, order=None, count=False): res_domain = [] for domain in args: if (len(domain) > 2 and domain[0] == "bsn_number" and isinstance(domain[2], str) and domain[2]): operator = domain[1] bsn_number = domain[2] bsn_compact = bsn.compact(bsn_number) bsn_domain = expression.OR([ [("bsn_number", operator, bsn_number)], [("bsn_number", operator, bsn_compact)], ]) if bsn.is_valid(bsn_number): bsn_format = bsn.format(bsn_number) bsn_domain = expression.OR( [bsn_domain, [("bsn_number", operator, bsn_format)]]) res_domain += bsn_domain else: res_domain.append(domain) return super().search(res_domain, offset=offset, limit=limit, order=order, count=count)