res_city.py 843 B

123456789101112131415161718192021222324
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. from odoo import api, fields, models
  4. from odoo.osv import expression
  5. class City(models.Model):
  6. _name = 'res.city'
  7. _description = 'City'
  8. _order = 'name'
  9. _rec_names_search = ['name', 'zipcode']
  10. name = fields.Char("Name", required=True, translate=True)
  11. zipcode = fields.Char("Zip")
  12. country_id = fields.Many2one(comodel_name='res.country', string='Country', required=True)
  13. state_id = fields.Many2one(comodel_name='res.country.state', string='State', domain="[('country_id', '=', country_id)]")
  14. def name_get(self):
  15. res = []
  16. for city in self:
  17. name = city.name if not city.zipcode else '%s (%s)' % (city.name, city.zipcode)
  18. res.append((city.id, name))
  19. return res