# HG changeset patch
# User Vincent Hatakeyama <vincent.hatakeyama@xcg-consulting.fr>
# Date 1655385335 -7200
#      Thu Jun 16 15:15:35 2022 +0200
# Branch 13.0
# Node ID 44ffb5832bc99f3fcea330128d5fddd50752f4c0
# Parent  052e08f55c942fe332612a2078b699c7ae174d68
📝 avoid legacy converters in tests, add warnings on deprecation, include the functionnality of FirstKeyField in KeyField

diff --git a/NEWS.rst b/NEWS.rst
--- a/NEWS.rst
+++ b/NEWS.rst
@@ -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
 =====
 
diff --git a/keyfield.py b/keyfield.py
--- a/keyfield.py
+++ b/keyfield.py
@@ -1,3 +1,4 @@
+import warnings
 from typing import Any, Dict, Optional
 
 from odoo import models
@@ -6,10 +7,12 @@
 
 
 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
-        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,8 +33,14 @@
 
 
 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.
+    """
 
-    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)
diff --git a/legacy.py b/legacy.py
--- a/legacy.py
+++ b/legacy.py
@@ -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."""
diff --git a/relation.py b/relation.py
--- a/relation.py
+++ b/relation.py
@@ -1,4 +1,5 @@
 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)
diff --git a/tests/test_converters.py b/tests/test_converters.py
--- a/tests/test_converters.py
+++ b/tests/test_converters.py
@@ -22,8 +22,9 @@
 
 from ..base import Skip
 from ..field import Field
-from ..legacy import Many2oneConverter, Many2oneFieldValueConverter
+from ..keyfield import KeyField
 from ..model import Model
+from ..relation import RelationToOne
 from ..xref import Xref
 
 
@@ -109,12 +110,10 @@
             "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"),
-                # TODO fix
-                "partner_id": Many2oneConverter("partner_id"),
+                "partner_id": RelationToOne("partner_id", None, Xref()),
             },
         )