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.

45 lines
1.3 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. @api.one
  19. @api.depends(
  20. 'name',
  21. 'city',
  22. 'state_id',
  23. 'country_id',
  24. )
  25. def _get_display_name(self):
  26. if self.name:
  27. name = [self.name, self.city]
  28. else:
  29. name = [self.city]
  30. if self.state_id:
  31. name.append(self.state_id.name)
  32. if self.country_id:
  33. name.append(self.country_id.name)
  34. self.display_name = ", ".join(name)
  35. @api.onchange('state_id')
  36. def onchange_state_id(self):
  37. if self.state_id:
  38. self.country_id = self.state_id.country_id