Пример #1
0
 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)
Пример #2
0
    def onchange_bsn_number(self):
        warning = {}
        for partner in self:
            if partner.bsn_number:
                # properly format the entered BSN
                partner.bsn_number = bsn.format(partner.bsn_number)

                # check is valid, otherwise display a warning
                if not bsn.is_valid(partner.bsn_number):
                    msg = _('The BSN you entered (%s) is not valid.')
                    warning = {
                        'title': _('Warning!'),
                        'message': msg % partner.bsn_number,
                    }

                # search for another partner with the same BSN
                args = [('bsn_number', '=', partner.bsn_number),
                        ('name', '!=', partner.name)]
                # refine search in case of multicompany setting
                if partner.company_id:
                    args += [('company_id', '=', partner.company_id.id)]
                other_partner = self.search(args, limit=1)
                # if another partner exists, display a warning
                if other_partner:
                    msg = _('Another person (%s) has the same BSN (%s).')
                    warning = {
                        'title': _('Warning!'),
                        'message': msg % (other_partner.name,
                                          other_partner.bsn_number)
                    }
        return {'warning': warning, }
Пример #3
0
 def _warn_bsn_invalid(self):
     self.ensure_one()
     warning = {}
     if not bsn.is_valid(self.bsn_number):
         msg = _('The BSN you entered (%s) is not valid.')
         warning = {
             'title': _('Warning!'),
             'message': msg % self.bsn_number,
         }
     return warning
Пример #4
0
 def _warn_bsn_invalid(self):
     self.ensure_one()
     warning = {}
     if not bsn.is_valid(self.bsn_number):
         msg = _("The BSN you entered (%s) is not valid.")
         warning = {
             "title": _("Warning!"),
             "message": msg % self.bsn_number
         }
     return warning
Пример #5
0
def validate(number):
    """Check if the number is a valid btw number. This checks the length,
    formatting and check digit."""
    number = compact(number)
    if not isdigits(number[:9]) or int(number[:9]) <= 0:
        raise InvalidFormat()
    if not isdigits(number[10:]) or int(number[10:]) <= 0:
        raise InvalidFormat()
    if len(number) != 12:
        raise InvalidLength()
    if number[9] != 'B':
        raise InvalidFormat()
    if not bsn.is_valid(number[:9]) and not mod_97_10.is_valid('NL' + number):
        raise InvalidChecksum()
    return number
Пример #6
0
 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)