Skip to content
Snippets Groups Projects
Commit 44ffb583 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 052e08f5
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 @@
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
=====
......
import warnings
from typing import Any, Dict, Optional
from odoo import models
......@@ -6,6 +7,8 @@
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.model_name = model_name
......@@ -10,6 +13,6 @@
self.field_name = field_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(
self, instance: models.Model, ctx: Optional[Dict] = None
......@@ -30,5 +33,8 @@
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 @@
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.lookup_limit = 1
def __init__(self, field_name: str, model_name: str):
warnings.warn(
"Use KeyField with limit_lookup=True instead of FirstKeyField",
DeprecationWarning,
)
super().__init__(field_name, model_name, True)
......@@ -2,6 +2,7 @@
.. deprecated:: 1.0
Use the other converter instead, kept for ease of porting.
"""
import warnings
from typing import Any, Dict, Optional
from odoo import api, models
......@@ -11,6 +12,8 @@
from .model import Model
from .models.ir_model_data import _XREF_IMD_MODULE
warnings.warn("legacy converters are deprecated", DeprecationWarning)
class Many2oneConverter(Field):
"""Converts many2one xref."""
......
import logging
import warnings
from typing import Any, Callable, Dict, Optional, Union
from odoo import api, models
......@@ -239,5 +240,8 @@
.. deprecated:: 1.2.0
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)
......@@ -22,5 +22,5 @@
from ..base import Skip
from ..field import Field
from ..legacy import Many2oneConverter, Many2oneFieldValueConverter
from ..keyfield import KeyField
from ..model import Model
......@@ -26,4 +26,5 @@
from ..model import Model
from ..relation import RelationToOne
from ..xref import Xref
......@@ -109,8 +110,7 @@
"test-type",
{
"id": Xref(),
# TODO fix
"country_code": Many2oneFieldValueConverter(
"country_id", "res.country", "code"
"country_code": RelationToOne(
"country_id", None, KeyField("code", "res.country")
),
"name": Field("name"),
......@@ -115,6 +115,5 @@
),
"name": Field("name"),
# TODO fix
"partner_id": Many2oneConverter("partner_id"),
"partner_id": RelationToOne("partner_id", None, Xref()),
},
)
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