Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
rvalyi committed Jan 13, 2025
1 parent 985f72c commit c53951e
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions spec_driven_model/models/spec_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,27 +75,29 @@ def _build_model(cls, pool, cr):
class as long as the generated spec mixins inherit from some
spec.mixin.<schema_name> mixin.
"""
parents = cls._inherit
parents = [parents] if isinstance(parents, str) else (parents or [])
if hasattr(cls, "_spec_schema"): # when called via _register_hook
schema = cls._spec_schema
version = cls._spec_version.replace(".", "")[:2]
else:
mod = import_module(".".join(cls.__module__.split(".")[:-1]))
schema = mod.spec_schema

if schema and "spec.mixin" not in [
c._name for c in pool[f"spec.mixin.{schema}"].__bases__
]:
spec_mixin = pool[f"spec.mixin.{schema}"]
spec_mixin._inherit = list(spec_mixin._inherit) + ["spec.mixin"]
spec_mixin._BaseModel__base_classes = (
pool["spec.mixin"],
) + spec_mixin._BaseModel__base_classes
spec_mixin.__bases__ = (pool["spec.mixin"],) + spec_mixin.__bases__

parents = [
item[0] if isinstance(item, list) else item for item in list(cls._inherit)
]
for parent in parents:
# this will register that the spec mixins where injected in this class
cls._map_concrete(cr.dbname, parent, cls._name)
super_parents = pool[parent]._inherit
if isinstance(super_parents, str):
super_parents = [super_parents]
else:
super_parents = super_parents or []
for super_parent in super_parents:
if not super_parent.startswith("spec.mixin.") or "spec.mixin" in [
c._name for c in pool[super_parent].__bases__
]:
continue
pool[super_parent]._inherit = list(pool[super_parent]._inherit) + [
"spec.mixin"
]
pool[super_parent].__bases__ = (pool["spec.mixin"],) + pool[
super_parent
].__bases__

return super()._build_model(pool, cr)

@api.model
Expand Down

0 comments on commit c53951e

Please sign in to comment.