You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Replace supplementary record/manager classes with mixins
Records in Odoo can have some additional fields that are shared across many different record models using model inheritance.
To support adding these kinds of shared fields (and related methods) to record/manager classes in the OpenStack Odoo Client library in a more modular way, add support for the use of **mixins** to take advantage of Python's multiple inheritance to add such fields and methods to custom record/manager classes.
**Protocol** classes were created for `RecordBase` (called `RecordProtocol`) and `RecordManagerBase` (called `RecordManagerProtocol`) which contain common attribute/field type hints and method stubs. The mixin classes subclass these protocol classes to provide type hints within mixin classes as if they subclass the record/manager base classes (they can't do this directly for complicated reasons).
The implementations for the record and record manager base classes have been refactored to reduce duplication as part of this work.
The `NamedRecordManagerBase` and `CodedRecordManagerBase` classes have been reimplemented using mixins to not only utilise this paradigm inside the library itself, but also demonstrate its usage in a simple and practical way for anyone looking to write their own mixins.
The `get_by_unique_field` method provided by `RecordManagerWithUniqueFieldBase` has been incorporated into `RecordManagerBase` to make it available for use in any custom manager class.
Finally, a basic unit testing pipeline using `pytest` has been added. Initially a single test to make sure the package can be imported correctly has been added, but the plan is to expand coverage over time.
0 commit comments