Skip to content
Snippets Groups Projects
Commit 44ffb5832bc9 authored by Vincent Hatakeyama's avatar Vincent Hatakeyama
Browse files

:pencil: avoid legacy converters in tests, add warnings on deprecation, include the...

:pencil: avoid legacy converters in tests, add warnings on deprecation, include the functionnality of FirstKeyField in KeyField
parent 052e08f55c94
No related branches found
Tags 13.0.2.0.0
1 merge request!19📝 avoid legacy converters in tests, add warnings on deprecation, include the...
...@@ -13,6 +13,8 @@ ...@@ -13,6 +13,8 @@
Add the switch converter and fix it and its tests. Add the switch converter and fix it and its tests.
Include the functionnality of FirstKeyField in KeyField directly, marking it as deprecated.
1.2.1 1.2.1
===== =====
......
import warnings
from typing import Any, Dict, Optional from typing import Any, Dict, Optional
from odoo import models from odoo import models
...@@ -6,6 +7,8 @@ ...@@ -6,6 +7,8 @@
class KeyField(Converter): class KeyField(Converter):
def __init__(self, field_name: str, model_name: str): def __init__(
self, field_name: str, model_name: str, limit_lookup: bool = False
):
self.field_name = field_name self.field_name = field_name
self.model_name = model_name self.model_name = model_name
...@@ -10,6 +13,6 @@ ...@@ -10,6 +13,6 @@
self.field_name = field_name self.field_name = field_name
self.model_name = model_name self.model_name = model_name
self.lookup_limit = None # used by FirstKeyField self.lookup_limit = 1 if limit_lookup else None
def odoo_to_message( def odoo_to_message(
self, instance: models.Model, ctx: Optional[Dict] = None self, instance: models.Model, ctx: Optional[Dict] = None
...@@ -30,5 +33,8 @@ ...@@ -30,5 +33,8 @@
class FirstKeyField(KeyField): class FirstKeyField(KeyField):
"""Same as KeyField but allow dupes when looking the Odoo record up.""" """Same as KeyField but allow dupes when looking the Odoo record up.
.. deprecated:: 2.0.0
Use :class:`KeyField` instead, setting the limit_lookup value to True.
"""
...@@ -34,4 +40,7 @@ ...@@ -34,4 +40,7 @@
def __init__(self, *args, **kwargs): def __init__(self, field_name: str, model_name: str):
super().__init__(*args, **kwargs) warnings.warn(
self.lookup_limit = 1 "Use KeyField with limit_lookup=True instead of FirstKeyField",
DeprecationWarning,
)
super().__init__(field_name, model_name, True)
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
.. deprecated:: 1.0 .. deprecated:: 1.0
Use the other converter instead, kept for ease of porting. Use the other converter instead, kept for ease of porting.
""" """
import warnings
from typing import Any, Dict, Optional from typing import Any, Dict, Optional
from odoo import api, models from odoo import api, models
...@@ -11,6 +12,8 @@ ...@@ -11,6 +12,8 @@
from .model import Model from .model import Model
from .models.ir_model_data import _XREF_IMD_MODULE from .models.ir_model_data import _XREF_IMD_MODULE
warnings.warn("legacy converters are deprecated", DeprecationWarning)
class Many2oneConverter(Field): class Many2oneConverter(Field):
"""Converts many2one xref.""" """Converts many2one xref."""
......
import logging import logging
import warnings
from typing import Any, Callable, Dict, Optional, Union from typing import Any, Callable, Dict, Optional, Union
from odoo import api, models from odoo import api, models
...@@ -239,5 +240,8 @@ ...@@ -239,5 +240,8 @@
.. deprecated:: 1.2.0 .. deprecated:: 1.2.0
Use :func:`relation` instead, that uses PEP8 defined function case. Use :func:`relation` instead, that uses PEP8 defined function case.
""" """
_logger.warning("Deprecated function Relation, use relation instead") warnings.warn(
"Deprecated function Relation, use relation instead",
DeprecationWarning,
)
return relation(path, converter) return relation(path, converter)
...@@ -22,5 +22,5 @@ ...@@ -22,5 +22,5 @@
from ..base import Skip from ..base import Skip
from ..field import Field from ..field import Field
from ..legacy import Many2oneConverter, Many2oneFieldValueConverter from ..keyfield import KeyField
from ..model import Model from ..model import Model
...@@ -26,4 +26,5 @@ ...@@ -26,4 +26,5 @@
from ..model import Model from ..model import Model
from ..relation import RelationToOne
from ..xref import Xref from ..xref import Xref
...@@ -109,8 +110,7 @@ ...@@ -109,8 +110,7 @@
"test-type", "test-type",
{ {
"id": Xref(), "id": Xref(),
# TODO fix "country_code": RelationToOne(
"country_code": Many2oneFieldValueConverter( "country_id", None, KeyField("code", "res.country")
"country_id", "res.country", "code"
), ),
"name": Field("name"), "name": Field("name"),
...@@ -115,6 +115,5 @@ ...@@ -115,6 +115,5 @@
), ),
"name": Field("name"), "name": Field("name"),
# TODO fix "partner_id": RelationToOne("partner_id", None, Xref()),
"partner_id": Many2oneConverter("partner_id"),
}, },
) )
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment