Skip to content

Conversation

@Callum027
Copy link
Collaborator

@Callum027 Callum027 commented Dec 11, 2025

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.

@Callum027 Callum027 self-assigned this Dec 11, 2025
@Callum027
Copy link
Collaborator Author

Callum027 commented Dec 11, 2025

Need to update the documentation for this change.

@Callum027
Copy link
Collaborator Author

Callum027 commented Dec 11, 2025

Add release note.

@Callum027 Callum027 changed the base branch from main to callum/type-fixes-2 December 14, 2025 18:39
@Callum027 Callum027 force-pushed the callum/use-mixins branch 3 times, most recently from dd19e6d to 65c580f Compare December 14, 2025 20:56
Base automatically changed from callum/type-fixes-2 to main December 15, 2025 22:21
@Callum027 Callum027 marked this pull request as ready for review December 15, 2025 22:23
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.
@adrianjarvis adrianjarvis merged commit 495a6b3 into main Dec 15, 2025
11 checks passed
@Callum027 Callum027 deleted the callum/use-mixins branch December 15, 2025 22:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants