-
Notifications
You must be signed in to change notification settings - Fork 0
Replace supplementary record/manager classes with mixins #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Collaborator
Author
|
|
Collaborator
Author
|
|
ac5bde3 to
b544728
Compare
Callum027
commented
Dec 12, 2025
Callum027
commented
Dec 12, 2025
Callum027
commented
Dec 12, 2025
b544728 to
a0e9e7d
Compare
Callum027
commented
Dec 12, 2025
a0e9e7d to
ddccb85
Compare
dd19e6d to
65c580f
Compare
34f1999 to
5be5e6a
Compare
65c580f to
1f1b2b5
Compare
1f1b2b5 to
f9cb504
Compare
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.
f9cb504 to
e38d6b0
Compare
adrianjarvis
approved these changes
Dec 15, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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(calledRecordProtocol) andRecordManagerBase(calledRecordManagerProtocol) 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
NamedRecordManagerBaseandCodedRecordManagerBaseclasses 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_fieldmethod provided byRecordManagerWithUniqueFieldBasehas been incorporated intoRecordManagerBaseto make it available for use in any custom manager class.Finally, a basic unit testing pipeline using
pytesthas 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.