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.

62 lines
2.1 KiB

  1. # -*- coding: utf-8 -*-
  2. #
  3. #
  4. # Author: Nicolas Bessi. Copyright Camptocamp SA
  5. # Contributor: Pedro Manuel Baeza <pedro.baeza@serviciosbaeza.com>
  6. # Ignacio Ibeas <ignacio@acysos.com>
  7. # Alejandro Santana <alejandrosantana@anubia.es>
  8. #
  9. # This program is free software: you can redistribute it and/or modify
  10. # it under the terms of the GNU Affero General Public License as
  11. # published by the Free Software Foundation, either version 3 of the
  12. # License, or (at your option) any later version.
  13. #
  14. # This program is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. # GNU Affero General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU Affero General Public License
  20. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. #
  22. from openerp import models, fields, api
  23. class BetterZip(models.Model):
  24. '''City/locations completion object'''
  25. _name = "res.better.zip"
  26. _description = __doc__
  27. _order = "name asc"
  28. _rec_name = "display_name"
  29. display_name = fields.Char('Name', compute='_get_display_name', store=True)
  30. name = fields.Char('ZIP')
  31. code = fields.Char('City Code', size=64,
  32. help="The official code for the city")
  33. city = fields.Char('City', required=True)
  34. state_id = fields.Many2one('res.country.state', 'State')
  35. country_id = fields.Many2one('res.country', 'Country')
  36. @api.one
  37. @api.depends(
  38. 'name',
  39. 'city',
  40. 'state_id',
  41. 'country_id',
  42. )
  43. def _get_display_name(self):
  44. if self.name:
  45. name = [self.name, self.city]
  46. else:
  47. name = [self.city]
  48. if self.state_id:
  49. name.append(self.state_id.name)
  50. if self.country_id:
  51. name.append(self.country_id.name)
  52. self.display_name = ", ".join(name)
  53. @api.onchange('state_id')
  54. def onchange_state_id(self):
  55. if self.state_id:
  56. self.country_id = self.state_id.country_id