-
-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[16.0][l10n_fr_department] improve search res_partner by department
- Loading branch information
1 parent
0302bdc
commit baaf16d
Showing
2 changed files
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ | |
# @author Alexis de Lattre ([email protected]) | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
import re | ||
|
||
from odoo import api, fields, models | ||
|
||
|
||
|
@@ -48,3 +50,30 @@ 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) | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters