You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.4 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2016 Nicolas Bessi, Camptocamp SA
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  4. from odoo import models, fields, api
  5. class BetterZip(models.Model):
  6. '''City/locations completion object'''
  7. _name = "res.better.zip"
  8. _description = __doc__
  9. _order = "name asc"
  10. _rec_name = "display_name"
  11. display_name = fields.Char('Name', compute='_get_display_name', store=True)
  12. name = fields.Char('ZIP')
  13. code = fields.Char('City Code', size=64,
  14. help="The official code for the city")
  15. city = fields.Char('City', required=True)
  16. state_id = fields.Many2one('res.country.state', 'State')
  17. country_id = fields.Many2one('res.country', 'Country')
  18. latitude = fields.Float()
  19. longitude = fields.Float()
  20. @api.one
  21. @api.depends(
  22. 'name',
  23. 'city',
  24. 'state_id',
  25. 'country_id',
  26. )
  27. def _get_display_name(self):
  28. if self.name:
  29. name = [self.name, self.city]
  30. else:
  31. name = [self.city]
  32. if self.state_id:
  33. name.append(self.state_id.name)
  34. if self.country_id:
  35. name.append(self.country_id.name)
  36. self.display_name = ", ".join(name)
  37. @api.onchange('state_id')
  38. def onchange_state_id(self):
  39. if self.state_id:
  40. self.country_id = self.state_id.country_id