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 01f0889
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
22 changes: 22 additions & 0 deletions l10n_fr_department/model/res_country_department.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
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 01f0889

Please sign in to comment.