Esempio n. 1
0
    def onchange_zip_l10n_nl_postcode(self):
        if self.env.context.get('skip_postcode_check'):
            return

        if self.zip and self._check_country():
            # check is valid, otherwise display a warning
            if postcode.is_valid(self.zip):
                self._do_format()
            else:
                warning = self._get_warning()
                return {'warning': warning, }
Esempio n. 2
0
    def onchange_zip_l10n_nl_postcode(self):
        # if 'skip_postcode_check' passed in context: will disable the check
        if self.env.context.get("skip_postcode_check"):
            return

        if self.zip and self._l10n_nl_postcode_check_country():
            # check that the postcode is valid
            if postcode.is_valid(self.zip):
                # properly format the entered postcode
                self.zip = postcode.validate(self.zip)
            else:
                # display a warning
                warning_msg = self._l10n_nl_postcode_get_warning()
                return {"warning": warning_msg}
Esempio n. 3
0
def post_init_hook(cr, registry):
    """
    Post-install script. Properly format all postcodes
    already present on partners while installing the module.
    """
    logging.getLogger('odoo.addons.l10n_nl_postcode').info(
        'Migrating existing postcodes')

    env = api.Environment(cr, SUPERUSER_ID, {})
    partners = env['res.partner'].with_context(active_test=False).search([
        ('zip', '!=', False),
        ('country_id', '=', env.ref('base.nl').id),
    ])

    for partner in partners:
        # check whether postcode is valid, if so then format postcode
        #  otherwise ignore
        if partner.zip and postcode.is_valid(partner.zip):
            partner.zip = postcode.compact(partner.zip)