diff --git a/l10n_fr_department/model/res_country_department.py b/l10n_fr_department/model/res_country_department.py
index b124b8502..d363a1720 100644
--- a/l10n_fr_department/model/res_country_department.py
+++ b/l10n_fr_department/model/res_country_department.py
@@ -5,6 +5,7 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import api, fields, models
+import re
class ResCountryDepartment(models.Model):
@@ -48,3 +49,24 @@ def name_get(self):
dname = "{} ({})".format(rec.name, rec.code)
res.append((rec.id, dname))
return res
+
+ @api.model
+ def _name_search(self, name, args=None, operator='ilike', limit=100, name_get_uid=None):
+ args = args or []
+
+ if name:
+ # Be sure name_search is symetric to name_get
+ match = re.match(r'^(.*)\s\((.*)\)$', name)
+ if match:
+ dpt_name = match.group(1)
+ dpt_code = match.group(2)
+ args += [('code', operator, dpt_code),('name', operator, dpt_name)]
+ else:
+ #Search on code and name
+ if operator in ('not ilike', '!='):
+ bool_operator = '&' #for negative comparators, use AND
+ else:
+ bool_operator = '|' #for positive comparators, use OR
+ args += [bool_operator,('code',operator,name),('name',operator,name)]
+
+ return self._search(args, limit=limit, access_rights_uid=name_get_uid)
diff --git a/l10n_fr_department/view/res_partner.xml b/l10n_fr_department/view/res_partner.xml
index dcce6569b..92728511d 100644
--- a/l10n_fr_department/view/res_partner.xml
+++ b/l10n_fr_department/view/res_partner.xml
@@ -11,6 +11,7 @@
+