validationupgradeadd-onmigrateodoo-16

Odoo migration : addons/phone_validation


In my odoo version 13, i use a custom OCA-module depending on the official addons/phone_validation:

class PhoneValidationMixin(models.AbstractModel):
    _inherit = "phone.validation.mixin"

After having migrated to v16, i wanted to re-install this module, but i got this Error:

Odoo Server Error
Traceback (most recent call last):
  File "/home/odoo/src/odoo/odoo/http.py", line 1584, in _serve_db
    return service_model.retrying(self._serve_ir_http, self.env)
  File "/home/odoo/src/odoo/odoo/service/model.py", line 133, in retrying
    result = func()
  File "/home/odoo/src/odoo/odoo/http.py", line 1611, in _serve_ir_http
    response = self.dispatcher.dispatch(rule.endpoint, args)
  File "/home/odoo/src/odoo/odoo/http.py", line 1815, in dispatch
    result = self.request.registry['ir.http']._dispatch(endpoint)
  File "/home/odoo/src/odoo/addons/website/models/ir_http.py", line 235, in _dispatch
    response = super()._dispatch(endpoint)
  File "/home/odoo/src/odoo/odoo/addons/base/models/ir_http.py", line 154, in _dispatch
    result = endpoint(**request.params)
  File "/home/odoo/src/odoo/odoo/http.py", line 697, in route_wrapper
    result = endpoint(self, *args, **params_ok)
  File "/home/odoo/src/odoo/addons/web/controllers/dataset.py", line 46, in call_button
    action = self._call_kw(model, method, args, kwargs)
  File "/home/odoo/src/odoo/addons/web/controllers/dataset.py", line 33, in _call_kw
    return call_kw(request.env[model], method, args, kwargs)
  File "/home/odoo/src/odoo/odoo/api.py", line 461, in call_kw
    result = _call_kw_multi(method, model, args, kwargs)
  File "/home/odoo/src/odoo/odoo/api.py", line 448, in _call_kw_multi
    result = method(recs, *args, **kwargs)
  File "<decorator-gen-74>", line 2, in button_immediate_install
  File "/home/odoo/src/odoo/odoo/addons/base/models/ir_module.py", line 74, in check_and_log
    return method(self, *args, **kwargs)
  File "/home/odoo/src/odoo/odoo/addons/base/models/ir_module.py", line 456, in button_immediate_install
    return self._button_immediate_function(type(self).button_install)
  File "/home/odoo/src/odoo/odoo/addons/base/models/ir_module.py", line 580, in _button_immediate_function
    registry = modules.registry.Registry.new(self._cr.dbname, update_module=True)
  File "<decorator-gen-14>", line 2, in new
  File "/home/odoo/src/odoo/odoo/tools/func.py", line 87, in locked
    return func(inst, *args, **kwargs)
  File "/home/odoo/src/odoo/odoo/modules/registry.py", line 90, in new
    odoo.modules.load_modules(registry, force_demo, status, update_module)
  File "/home/odoo/src/odoo/odoo/modules/loading.py", line 488, in load_modules
    processed_modules += load_marked_modules(cr, graph,
  File "/home/odoo/src/odoo/odoo/modules/loading.py", line 372, in load_marked_modules
    loaded, processed = load_module_graph(
  File "/home/odoo/src/odoo/odoo/modules/loading.py", line 197, in load_module_graph
    model_names = registry.load(cr, package)
  File "/home/odoo/src/odoo/odoo/modules/registry.py", line 247, in load
    model = cls._build_model(self, cr)
  File "/home/odoo/src/odoo/odoo/models.py", line 615, in _build_model
    raise TypeError("Model %r does not exist in registry." % name)
TypeError: Model 'phone.validation.mixin' does not exist in registry.

It seems that the standard model phone.validation.mixin has disappeared from this addons (phone_validation) in odoo v16.

enter image description here

How to deal with it please ?


Solution

  • I have solved it by copying/pasting the v13 model: "phone.validation.mixin" in my src/user/OCA-custom-module in the model where it was inherited originally:

    
    from odoo import models
    from odoo.addons.phone_validation.tools import phone_validation
    
    class PhoneValidationMixin(models.AbstractModel):
        _name = 'phone.validation.mixin'
        # _inherit = "phone.validation.mixin"
    
        def _phone_get_country(self):
            if 'country_id' in self and self.country_id:
                return self.country_id
            return self.env.company.country_id
    
        def phone_format(self, number, country=None, company=None):
            country = country or self._phone_get_country()
            if not country:
                return number
            return phone_validation.phone_format(
                number,
                country.code if country else None,
                country.phone_code if country else None,
                force_format='INTERNATIONAL',
                raise_exception=False
            )