Skip to content

Commit

Permalink
[16.0][l10n_fr_department] improve search res_partner by department
Browse files Browse the repository at this point in the history
  • Loading branch information
clementthomas committed Oct 17, 2024
1 parent 0302bdc commit baaf16d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
29 changes: 29 additions & 0 deletions l10n_fr_department/model/res_country_department.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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 []

Check warning on line 58 in l10n_fr_department/model/res_country_department.py

View check run for this annotation

Codecov / codecov/patch

l10n_fr_department/model/res_country_department.py#L58

Added line #L58 was not covered by tests

if name:
# Be sure name_search is symetric to name_get
match = re.match(r"^(.*)\s\((.*)\)$", name)

Check warning on line 62 in l10n_fr_department/model/res_country_department.py

View check run for this annotation

Codecov / codecov/patch

l10n_fr_department/model/res_country_department.py#L62

Added line #L62 was not covered by tests
if match:
dpt_name = match.group(1)
dpt_code = match.group(2)
args += [("code", operator, dpt_code), ("name", operator, dpt_name)]

Check warning on line 66 in l10n_fr_department/model/res_country_department.py

View check run for this annotation

Codecov / codecov/patch

l10n_fr_department/model/res_country_department.py#L64-L66

Added lines #L64 - L66 were not covered by tests
else:
# Search on code and name
if operator in ("not ilike", "!="):
bool_operator = "&" # for negative comparators, use AND

Check warning on line 70 in l10n_fr_department/model/res_country_department.py

View check run for this annotation

Codecov / codecov/patch

l10n_fr_department/model/res_country_department.py#L70

Added line #L70 was not covered by tests
else:
bool_operator = "|" # for positive comparators, use OR
args += [

Check warning on line 73 in l10n_fr_department/model/res_country_department.py

View check run for this annotation

Codecov / codecov/patch

l10n_fr_department/model/res_country_department.py#L72-L73

Added lines #L72 - L73 were not covered by tests
bool_operator,
("code", operator, name),
("name", operator, name),
]

return self._search(args, limit=limit, access_rights_uid=name_get_uid)

Check warning on line 79 in l10n_fr_department/model/res_country_department.py

View check run for this annotation

Codecov / codecov/patch

l10n_fr_department/model/res_country_department.py#L79

Added line #L79 was not covered by tests
1 change: 1 addition & 0 deletions l10n_fr_department/view/res_partner.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<field name="inherit_id" ref="base.view_res_partner_filter" />
<field name="arch" type="xml">
<filter name="group_country" position="before">
<field name="country_department_id" />
<filter
name="country_department_groupby"
string="Department"
Expand Down

0 comments on commit baaf16d

Please sign in to comment.