@@ -180,12 +180,12 @@ the type hint should be defined as shown below.
180180``` python
181181from __future__ import annotations
182182
183- from typing import Literal, Union
183+ from typing import Literal
184184
185185from openstack_odooclient import RecordBase
186186
187187class CustomRecord (RecordBase[" CustomRecordManager" ]):
188- custom_field: Union[ str , Literal[False ] ]
188+ custom_field: str | Literal[False ]
189189 """ Description of the field."""
190190```
191191
@@ -197,12 +197,10 @@ the type hint should be defined as shown below instead.
197197``` python
198198from __future__ import annotations
199199
200- from typing import Optional
201-
202200from openstack_odooclient import RecordBase
203201
204202class CustomRecord (RecordBase[" CustomRecordManager" ]):
205- custom_field: Optional[ str ]
203+ custom_field: str | None
206204 """ Description of the field."""
207205```
208206
@@ -223,8 +221,9 @@ The type of the alias **must** match the type of the target field.
223221``` python
224222from __future__ import annotations
225223
224+ from typing import Annotated
225+
226226from openstack_odooclient import FieldAlias, RecordBase
227- from typing_extensions import Annotated
228227
229228class CustomRecord (RecordBase[" CustomRecordManager" ]):
230229 custom_field: str
@@ -265,8 +264,9 @@ The first is to expose the record's ID directly as an integer.
265264``` python
266265from __future__ import annotations
267266
267+ from typing import Annotated
268+
268269from openstack_odooclient import ModelRef, RecordBase, User
269- from typing_extensions import Annotated
270270
271271class CustomRecord (RecordBase[" CustomRecordManager" ]):
272272 user_id: Annotated[int , ModelRef(" user_id" , User)]
@@ -278,8 +278,9 @@ The second is to expose the target record's display name as a string.
278278``` python
279279from __future__ import annotations
280280
281+ from typing import Annotated
282+
281283from openstack_odooclient import ModelRef, RecordBase, User
282- from typing_extensions import Annotated
283284
284285class CustomRecord (RecordBase[" CustomRecordManager" ]):
285286 user_name: Annotated[str , ModelRef(" user_id" , User)]
@@ -291,8 +292,9 @@ The third and final one is to define the target record itself as a record object
291292``` python
292293from __future__ import annotations
293294
295+ from typing import Annotated
296+
294297from openstack_odooclient import ModelRef, RecordBase, User
295- from typing_extensions import Annotated
296298
297299class CustomRecord (RecordBase[" CustomRecordManager" ]):
298300 user: Annotated[User, ModelRef(" user_id" , User)]
@@ -315,8 +317,9 @@ The final result should be the following fields defined on your record class.
315317``` python
316318from __future__ import annotations
317319
320+ from typing import Annotated
321+
318322from openstack_odooclient import ModelRef, RecordBase, User
319- from typing_extensions import Annotated
320323
321324class CustomRecord (RecordBase[" CustomRecordManager" ]):
322325 user_id: Annotated[int , ModelRef(" user_id" , User)]
@@ -339,25 +342,24 @@ and [creating new records](index.md#create).
339342The record ID or the record object can be passed directly to those methods
340343(the record display name is not guaranteed to be unique, and thus, not accepted).
341344
342- Record references can be made optional by encasing the type hint with ` Optional ` .
345+ Record references can be made optional by unioning with ` None ` .
343346If the record reference is not set, ` None ` will be returned.
344347
345348``` python
346349from __future__ import annotations
347350
348- from typing import Optional
351+ from typing import Annotated
349352
350353from openstack_odooclient import ModelRef, RecordBase, User
351- from typing_extensions import Annotated
352354
353355class CustomRecord (RecordBase[" CustomRecordManager" ]):
354- user_id: Annotated[Optional[ int ] , ModelRef(" user_id" , User)]
356+ user_id: Annotated[int | None , ModelRef(" user_id" , User)]
355357 """ ID for the user that owns this record."""
356358
357- user_name: Annotated[Optional[ str ] , ModelRef(" user_id" , User)]
359+ user_name: Annotated[str | None , ModelRef(" user_id" , User)]
358360 """ Name of the user that owns this record."""
359361
360- user: Annotated[Optional[ User] , ModelRef(" user_id" , User)]
362+ user: Annotated[User | None , ModelRef(" user_id" , User)]
361363 """ The user that owns this record.
362364
363365 This fetches the full record from Odoo once,
@@ -371,19 +373,19 @@ In the below example, `Self` resolves to `CustomRecord`.
371373``` python
372374from __future__ import annotations
373375
374- from typing import Optional
376+ from typing import Annotated
375377
376378from openstack_odooclient import ModelRef, RecordBase
377- from typing_extensions import Annotated, Self
379+ from typing_extensions import Self
378380
379381class CustomRecord (RecordBase[" CustomRecordManager" ]):
380- record_id: Annotated[Optional[ int ] , ModelRef(" user_id" , Self)]
382+ record_id: Annotated[int | None , ModelRef(" user_id" , Self)]
381383 """ ID for the record related to this one, if set.."""
382384
383- record_name: Annotated[Optional[ str ] , ModelRef(" user_id" , Self)]
385+ record_name: Annotated[str | None , ModelRef(" user_id" , Self)]
384386 """ Name of the record related to this one, if set."""
385387
386- record: Annotated[Optional[ Self] , ModelRef(" user_id" , Self)]
388+ record: Annotated[Self | None , ModelRef(" user_id" , Self)]
387389 """ The record related to this one, if set.
388390
389391 This fetches the full record from Odoo once,
@@ -408,13 +410,12 @@ The first is to expose the record IDs directly as a list of integers.
408410``` python
409411from __future__ import annotations
410412
411- from typing import List
413+ from typing import Annotated
412414
413415from openstack_odooclient import ModelRef, RecordBase, Product
414- from typing_extensions import Annotated
415416
416417class CustomRecord (RecordBase[" CustomRecordManager" ]):
417- product_ids: Annotated[List [int ], ModelRef(" product_id" , Product)]
418+ product_ids: Annotated[list [int ], ModelRef(" product_id" , Product)]
418419 """ The list of IDs for the products to use."""
419420```
420421
@@ -423,13 +424,12 @@ The second and final one is to expose the records as a list of record objects.
423424``` python
424425from __future__ import annotations
425426
426- from typing import List
427+ from typing import Annotated
427428
428429from openstack_odooclient import ModelRef, RecordBase, Product
429- from typing_extensions import Annotated
430430
431431class CustomRecord (RecordBase[" CustomRecordManager" ]):
432- products: Annotated[List [Product], ModelRef(" product_id" , Product)]
432+ products: Annotated[list [Product], ModelRef(" product_id" , Product)]
433433 """ The list of products to use.
434434
435435 This fetches the full records from Odoo once,
@@ -449,16 +449,15 @@ The final result should be the following fields defined on your record class.
449449``` python
450450from __future__ import annotations
451451
452- from typing import List
452+ from typing import Annotated
453453
454454from openstack_odooclient import ModelRef, RecordBase, Product
455- from typing_extensions import Annotated
456455
457456class CustomRecord (RecordBase[" CustomRecordManager" ]):
458- product_ids: Annotated[List [int ], ModelRef(" product_id" , Product)]
457+ product_ids: Annotated[list [int ], ModelRef(" product_id" , Product)]
459458 """ The list of IDs for the products to use."""
460459
461- products: Annotated[List [Product], ModelRef(" product_id" , Product)]
460+ products: Annotated[list [Product], ModelRef(" product_id" , Product)]
462461 """ The list of products to use.
463462
464463 This fetches the full records from Odoo once,
@@ -478,16 +477,16 @@ In the below example, `Self` resolves to `CustomRecord`.
478477``` python
479478from __future__ import annotations
480479
481- from typing import List
480+ from typing import Annotated
482481
483482from openstack_odooclient import ModelRef, RecordBase
484- from typing_extensions import Annotated, Self
483+ from typing_extensions import Self
485484
486485class CustomRecord (RecordBase[" CustomRecordManager" ]):
487- child_ids: Annotated[List [int ], ModelRef(" child_id" , Self)]
486+ child_ids: Annotated[list [int ], ModelRef(" child_id" , Self)]
488487 """ The list of IDs for the child records."""
489488
490- children: Annotated[List [Self], ModelRef(" child_id" , Self)]
489+ children: Annotated[list [Self], ModelRef(" child_id" , Self)]
491490 """ The list of child records.
492491
493492 This fetches the full records from Odoo once,
@@ -511,16 +510,15 @@ Below is an example of two record classes that correctly reference each other.
511510``` python title="parent.py"
512511from __future__ import annotations
513512
514- from typing import List
513+ from typing import Annotated
515514
516515from openstack_odooclient import ModelRef, RecordBase, RecordManagerBase
517- from typing_extensions import Annotated
518516
519517class Parent (RecordBase[" ParentManager" ]):
520- child_ids: Annotated[List [int ], ModelRef(" child_id" , Child)]
518+ child_ids: Annotated[list [int ], ModelRef(" child_id" , Child)]
521519 """ The list of IDs for the children records."""
522520
523- children: Annotated[List [Parent], ModelRef(" child_id" , Child)]
521+ children: Annotated[list [Parent], ModelRef(" child_id" , Child)]
524522 """ The list of children records.
525523
526524 This fetches the full records from Odoo once,
@@ -537,19 +535,18 @@ from .child import Child # noqa: E402
537535``` python title="child.py"
538536from __future__ import annotations
539537
540- from typing import Optional
538+ from typing import Annotated
541539
542540from openstack_odooclient import ModelRef, RecordBase, RecordManagerBase
543- from typing_extensions import Annotated
544541
545542class Child (RecordBase[" ChildManager" ]):
546- parent_id: Annotated[Optional[ int ] , ModelRef(" parent_id" , Parent)]
543+ parent_id: Annotated[int | None , ModelRef(" parent_id" , Parent)]
547544 """ ID for the parent record, if it has one."""
548545
549- parent_name: Annotated[Optional[ str ] , ModelRef(" parent_id" , Parent)]
546+ parent_name: Annotated[str | None , ModelRef(" parent_id" , Parent)]
550547 """ Name of the parent record, if it has one."""
551548
552- parent: Annotated[Optional[ Parent] , ModelRef(" parent_id" , Parent)]
549+ parent: Annotated[Parent | None , ModelRef(" parent_id" , Parent)]
553550 """ The parent record, if it has one.
554551
555552 This fetches the full record from Odoo once,
@@ -686,8 +683,6 @@ Below is a simple example of a custom record type and its manager class.
686683``` python
687684from __future__ import annotations
688685
689- from typing import List, Union
690-
691686from openstack_odooclient import RecordBase, RecordManagerBase
692687
693688class CustomRecord (RecordBase[" CustomRecordManager" ]):
@@ -710,8 +705,6 @@ This will allow manager methods to be used by calling them on the manager object
710705``` python
711706from __future__ import annotations
712707
713- from typing import List, Union
714-
715708from openstack_odooclient import Client, RecordBase, RecordManagerBase
716709
717710class CustomRecord (RecordBase[" CustomRecordManager" ]):
@@ -736,8 +729,6 @@ custom manager class.
736729``` python
737730from __future__ import annotations
738731
739- from typing import List, Union
740-
741732from openstack_odooclient import RecordBase, RecordManagerBase
742733
743734class CustomRecord (RecordBase[" CustomRecordManager" ]):
@@ -768,8 +759,6 @@ Methods can be defined on manager classes to provide additional functionality.
768759``` python
769760from __future__ import annotations
770761
771- from typing import List, Union
772-
773762from openstack_odooclient import RecordBase, RecordManagerBase
774763
775764class CustomRecord (RecordBase[" CustomRecordManager" ]):
@@ -780,10 +769,10 @@ class CustomRecordManager(RecordManagerBase[CustomRecord]):
780769 env_name = " custom.record"
781770 record_class = CustomRecord
782771
783- def search_by_custom_field (self , custom_field : str ) -> List [Record]:
772+ def search_by_custom_field (self , custom_field : str ) -> list [Record]:
784773 return self .search([(" custom_field" , " ilike" , custom_field)])
785774
786- def perform_action (self , custom_record : Union[ int , CustomRecord] ) -> None :
775+ def perform_action (self , custom_record : int | CustomRecord) -> None :
787776 self ._env.perform_action(
788777 (
789778 custom_record.id
0 commit comments