Odoo18-Base/addons/base_address_extended/models/res_city.py
2025-03-10 11:12:23 +07: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