Commit ac5bde3
Callum Dickinson
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.
To make type-hinted record manager mixins possible, a **protocol** class called `RecordManagerProtocol` had to be created documenting the attributes and methods on the `RecordManagerBase` class intended for use by implementing classes. This protocol is used to set the type of the `self` parameter on mixin methods. `RecordManagerBase` now subclasses this protocol.
The `NamedRecordManagerBase` base class has 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 moved into `RecordManagerBase` to make it available for use in any custom manager class. `CodedRecordManagerBase` has been removed and its implemented moved directly into `ReferralCodeManager`, as it is not used by anything else.1 parent 33e5d51 commit ac5bde3
File tree
28 files changed
+1174
-832
lines changed- openstack_odooclient
- base
- record_manager
- managers
- mixins
28 files changed
+1174
-832
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | 21 | | |
27 | 22 | | |
28 | 23 | | |
| |||
77 | 72 | | |
78 | 73 | | |
79 | 74 | | |
| 75 | + | |
80 | 76 | | |
81 | 77 | | |
82 | 78 | | |
| |||
86 | 82 | | |
87 | 83 | | |
88 | 84 | | |
89 | | - | |
90 | 85 | | |
91 | 86 | | |
92 | 87 | | |
| |||
106 | 101 | | |
107 | 102 | | |
108 | 103 | | |
109 | | - | |
| 104 | + | |
| 105 | + | |
110 | 106 | | |
111 | 107 | | |
112 | 108 | | |
| |||
123 | 119 | | |
124 | 120 | | |
125 | 121 | | |
126 | | - | |
127 | 122 | | |
128 | 123 | | |
129 | 124 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
465 | 465 | | |
466 | 466 | | |
467 | 467 | | |
468 | | - | |
| 468 | + | |
469 | 469 | | |
470 | 470 | | |
471 | 471 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
0 commit comments