Files
odoo_source/addons/base_address_extended/models/res_city.py
T
william 3155c3e425 [IMP] core,*: add helper for name_search
Most of the extensions of `_name_get` are very similar and only want to
search for the given string in multiple fields.
A lot of extensions also don't take into account the negative operators.
Some implementations were also really outdated and needlessly
complicated.

closes odoo/odoo#86588

Related: odoo/enterprise#25608
Signed-off-by: Raphael Collet <rco@odoo.com>
2022-04-06 18:37:39 +02:00

24 lines
843 B
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, fields, models
from odoo.osv import expression
class City(models.Model):
_name = 'res.city'
_description = 'City'
_order = 'name'
_rec_names_search = ['name', 'zipcode']
name = fields.Char("Name", required=True, translate=True)
zipcode = fields.Char("Zip")
country_id = fields.Many2one(comodel_name='res.country', string='Country', required=True)
state_id = fields.Many2one(comodel_name='res.country.state', string='State', domain="[('country_id', '=', country_id)]")
def name_get(self):
res = []
for city in self:
name = city.name if not city.zipcode else '%s (%s)' % (city.name, city.zipcode)
res.append((city.id, name))
return res