Skip to content
Snippets Groups Projects

:ambulance: Fix Switch converter to call post_hook, :sparkles: Xref converter:

Merged Vincent Hatakeyama requested to merge topic/18.0/fix-switch-and-xref into branch/18.0
7 files
+ 118
− 51
Compare changes
  • Side-by-side
  • Inline
Files
7
+ 17
− 6
@@ -38,5 +38,5 @@
_inherit = "ir.model.data"
@api.model
def generate_name(self) -> str:
def generate_name(self, prefix: str = "") -> str:
"""Generate an xref for odoo record;
@@ -42,4 +42,5 @@
"""Generate an xref for odoo record;
:param prefix: prefix to use before the name.
:return: a UUID from a string of 32 hex digit
"""
@@ -43,7 +44,7 @@
:return: a UUID from a string of 32 hex digit
"""
return uuid.uuid4().hex
return prefix + uuid.uuid4().hex
@api.model
def object_to_module_and_name(
@@ -47,9 +48,12 @@
@api.model
def object_to_module_and_name(
self, record_set: models.BaseModel, module: str | None = _XREF_IMD_MODULE
self,
record_set: models.BaseModel,
module: str | None = _XREF_IMD_MODULE,
prefix: str = "",
) -> tuple[str, str]:
"""Retrieve an xref pointing to the specified Odoo record; create one
when missing.
:param module: Name of the module to use. None to use any name, if no
xmlid exists "" will be used as the module name.
@@ -51,8 +55,9 @@
) -> tuple[str, str]:
"""Retrieve an xref pointing to the specified Odoo record; create one
when missing.
:param module: Name of the module to use. None to use any name, if no
xmlid exists "" will be used as the module name.
:param prefix: prefix to use before the name.
:return: tuple module and name
"""
record_set.ensure_one()
@@ -63,6 +68,8 @@
]
if module is not None:
domain.append(("module", "=", module))
if prefix:
domain.append(("name", "=like", f"{prefix}%"))
# Find an existing xref. See class docstring for details.
imd = self.sudo().search(domain, limit=1)
@@ -70,7 +77,7 @@
return imd.module, imd.name
# Could not find an existing xref; create one.
name = self.generate_name()
name = self.generate_name(prefix)
if module is None:
module = ""
self.set_xmlid(record_set, name, module)
@@ -78,9 +85,12 @@
@api.model
def object_to_xmlid(
self, record_set: models.BaseModel, module: str | None = _XREF_IMD_MODULE
self,
record_set: models.BaseModel,
module: str | None = _XREF_IMD_MODULE,
prefix: str = "",
) -> str:
"""Retrieve an xref pointing to the specified Odoo record; create one
when missing.
:param module: Name of the module to use. None to use any name, if no
xmlid exists "" will be used as the module name.
@@ -82,7 +92,8 @@
) -> str:
"""Retrieve an xref pointing to the specified Odoo record; create one
when missing.
:param module: Name of the module to use. None to use any name, if no
xmlid exists "" will be used as the module name.
:param prefix: prefix to use before the name.
"""
return "{0[0]}.{0[1]}".format(
@@ -87,6 +98,6 @@
"""
return "{0[0]}.{0[1]}".format(
self.object_to_module_and_name(record_set, module)
self.object_to_module_and_name(record_set, module, prefix)
)
@api.model
Loading