Skip to content

Commit ba2bdb8

Browse files
author
Callum Dickinson
committed
Add/fix missing/incorrect field definitions for records
* Add the missing `active` field to the `Product` record class. * Add the missing `sale_ok` field to the `Product` record class. * Fix the incorrect `default_code` field definition on the `Product` record class, by making it optional. * Add the missing `invoice_count` field to the `SaleOrder` record class. * Add the missing `invoice_ids` and `invoices` fields to the `SaleOrder` record class. * Fix a bug where new-style union type hints were not being handled by the parser, due to `typing.get_origin` returning a different origin type from the older `typing.Union` construct.
1 parent b1164c0 commit ba2bdb8

File tree

7 files changed

+102
-8
lines changed

7 files changed

+102
-8
lines changed

changelog.d/12.added.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add/fix missing/incorrect field definitions for records

docs/managers/product.md

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,16 @@ The record class currently implements the following fields and methods.
254254
For more information on attributes and methods common to all record types,
255255
see [Record Attributes and Methods](index.md#attributes-and-methods).
256256

257+
### `active`
258+
259+
```python
260+
active: bool
261+
```
262+
263+
Whether or not this product is active (enabled).
264+
265+
*Added in version 0.2.0.*
266+
257267
### `categ_id`
258268

259269
```python
@@ -311,14 +321,15 @@ and caches it for subsequent accesses.
311321
### `default_code`
312322

313323
```python
314-
default_code: str
324+
default_code: str | Literal[False]
315325
```
316326

317-
The Default Code for this product.
327+
The Default Code for this product, if set.
318328

319329
In the OpenStack Integration add-on, this is used to store
320330
the rated unit for the service product.
321331

332+
*Changed in version 0.2.0*: Made `default_code` optional.
322333

323334
### `description`
324335

@@ -346,7 +357,6 @@ The list price of the product.
346357

347358
This becomes the unit price of the product on invoices.
348359

349-
350360
### `name`
351361

352362
```python
@@ -355,6 +365,16 @@ name: str
355365

356366
The name of the product.
357367

368+
### `sale_ok`
369+
370+
```python
371+
sale_ok: bool
372+
```
373+
374+
Whether or not this product is sellable.
375+
376+
*Added in version 0.2.0.*
377+
358378
### `uom_id`
359379

360380
```python

docs/managers/sale-order.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,39 @@ display_name: str
187187

188188
The display name of the sale order.
189189

190+
### `invoice_count`
191+
192+
```python
193+
invoice_count: int
194+
```
195+
196+
The number of [invoices (account moves)](account-move.md) generated from the sale order.
197+
198+
*Added in version 0.2.0.*
199+
200+
### `invoice_ids`
201+
202+
```python
203+
invoice_ids: list[int]
204+
```
205+
206+
A list of IDs for [invoices (account moves)](account-move.md) generated from the sale order.
207+
208+
*Added in version 0.2.0.*
209+
210+
### `invoices`
211+
212+
```python
213+
invoices: list[AccountMove]
214+
```
215+
216+
The [invoices (account moves)](account-move.md) generated from the sale order.
217+
218+
This fetches the full records from Odoo once,
219+
and caches them for subsequent accesses.
220+
221+
*Added in version 0.2.0.*
222+
190223
### `invoice_status`
191224

192225
```python

openstack_odooclient/base/record.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
from dataclasses import dataclass
2121
from datetime import date, datetime
22-
from types import MappingProxyType
22+
from types import MappingProxyType, UnionType
2323
from typing import (
2424
TYPE_CHECKING,
2525
Annotated,
@@ -392,7 +392,8 @@ def _getattr_model_ref(
392392
# The following is for decoding a singular model ref value.
393393
# Check if the model ref is optional, and if it is,
394394
# return the desired value for when the value is empty.
395-
if get_type_origin(attr_type) is Union:
395+
attr_type_origin = get_type_origin(attr_type)
396+
if attr_type_origin is Union or attr_type_origin is UnionType:
396397
unsupported_union = (
397398
"Only unions of the format Optional[T], "
398399
"Union[T, type(None)] or Union[T, Literal[False]] "

openstack_odooclient/base/record_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ def get(
360360
:param optional: Return ``None`` if not found, defaults to ``False``
361361
:raises RecordNotFoundError: Record with the given ID not found
362362
:return: List of records
363-
:rtype: Record | list[str, Any]
363+
:rtype: Record | dict[str, Any]
364364
"""
365365
try:
366366
return self.list(

openstack_odooclient/managers/product.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@
2727

2828

2929
class Product(RecordBase["ProductManager"]):
30+
active: bool
31+
"""Whether or not this product is active (enabled).
32+
33+
*Added in version 0.2.0.*
34+
"""
35+
3036
categ_id: Annotated[int, ModelRef("categ_id", ProductCategory)]
3137
"""The ID for the category this product is under."""
3238

@@ -53,11 +59,13 @@ class Product(RecordBase["ProductManager"]):
5359
and caches it for subsequent accesses.
5460
"""
5561

56-
default_code: str
57-
"""The Default Code for this product.
62+
default_code: str | Literal[False]
63+
"""The Default Code for this product, if set.
5864
5965
In the OpenStack Integration add-on, this is used to store
6066
the rated unit for the service product.
67+
68+
*Changed in version 0.2.0*: Made `default_code` optional.
6169
"""
6270

6371
description: str
@@ -75,6 +83,12 @@ class Product(RecordBase["ProductManager"]):
7583
name: str
7684
"""The name of the product."""
7785

86+
sale_ok: bool
87+
"""Whether or not this product is sellable.
88+
89+
*Added in version 0.2.0.*
90+
"""
91+
7892
uom_id: Annotated[int, ModelRef("uom_id", Uom)]
7993
"""The ID for the Unit of Measure for this product."""
8094

openstack_odooclient/managers/sale_order.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,30 @@ class SaleOrder(RecordBase["SaleOrderManager"]):
5454
display_name: str
5555
"""The display name of the sale order."""
5656

57+
invoice_count: int
58+
"""The number of invoices generated from the sale order.
59+
60+
*Added in version 0.2.0.*
61+
"""
62+
63+
invoice_ids: Annotated[list[int], ModelRef("invoice_ids", AccountMove)]
64+
"""A list of IDs for invoices generated from the sale order.
65+
66+
*Added in version 0.2.0.*
67+
"""
68+
69+
invoices: Annotated[
70+
list[AccountMove],
71+
ModelRef("invoice_ids", AccountMove),
72+
]
73+
"""The invoices generated from the sale order.
74+
75+
This fetches the full records from Odoo once,
76+
and caches them for subsequent accesses.
77+
78+
*Added in version 0.2.0.*
79+
"""
80+
5781
invoice_status: Literal["no", "to invoice", "invoiced", "upselling"]
5882
"""The current invoicing status of this sale order.
5983
@@ -188,6 +212,7 @@ def create_invoices(self, sale_order: int | SaleOrder) -> None:
188212

189213

190214
# NOTE(callumdickinson): Import here to avoid circular imports.
215+
from .account_move import AccountMove # noqa: E402
191216
from .currency import Currency # noqa: E402
192217
from .partner import Partner # noqa: E402
193218
from .project import Project # noqa: E402

0 commit comments

Comments
 (0)