def to_python(self, value): _uid = RequestUID(value=value, converter=self) env = api.Environment(request.cr, _uid, request.context) record_id = None field = getattr(request.registry[self.model], "_seo_url_field", None) if field and field in request.registry[self.model]._fields: cur_lang = (request.context or {}).get("lang", "en_US") langs = [cur_lang] + [ lang for lang, _ in env["res.lang"].sudo().get_installed() if lang != cur_lang ] for lang in langs: res = (env[self.model].with_context(lang=lang).sudo().search([ (field, "=", value) ])) if res: record_id = res[0].id break if record_id: return env[self.model].browse(record_id) # fallback to original implementation self.regex = _UNSLUG_RE.pattern return super().to_python(value)
def to_python(self, value): matching = re.match(self.regex, value) _uid = RequestUID(value=value, match=matching, converter=self) record_id = int(matching.group(2)) env = api.Environment(request.cr, _uid, request.context) if record_id < 0: # limited support for negative IDs due to our slug pattern, assume abs() if not found if not env[self.model].browse(record_id).exists(): record_id = abs(record_id) return env[self.model].browse(record_id)