Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][l10n_fr_department] improve search res_partner by department #575

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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
Loading