Skip to content

Commit

Permalink
[IMP] Odoo getter: Better handle empty fields
Browse files Browse the repository at this point in the history
  • Loading branch information
qgroulard authored and lmignon committed Jun 14, 2022
1 parent f54bd63 commit 384feda
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion pydantic/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from typing import Any

from odoo import models
from odoo import fields, models

from pydantic.utils import GetterDict

Expand Down Expand Up @@ -51,6 +51,18 @@ def get(self, key: Any, default: Any = None) -> Any:
res = getattr(self._obj, key, default)
if isinstance(self._obj, models.BaseModel) and key in self._obj._fields:
field = self._obj._fields[key]
if res is False and field.type != "boolean":
return None
if field.type == "date" and not res:
return None
if field.type == "datetime":
if not res:
return None
# Get the timestamp converted to the client's timezone.
# This call also add the tzinfo into the datetime object
return fields.Datetime.context_timestamp(self._obj, res)
if field.type == "many2one" and not res:
return None
if field.type in ["one2many", "many2many"]:
return list(res)
return res

0 comments on commit 384feda

Please sign in to comment.