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.

57 lines
2.2 KiB

  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # Author Nicolas Bessi. Copyright Camptocamp SA
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. ##############################################################################
  20. from openerp.osv.orm import Model, fields
  21. class BetterZip(Model):
  22. " Zip/NPA object"
  23. _name = "res.better.zip"
  24. _description = __doc__
  25. _order = "priority"
  26. _columns = {'priority': fields.integer('Priority'),
  27. 'name': fields.char('ZIP', required=True),
  28. 'city': fields.char('City', required=True),
  29. 'state_id': fields.many2one('res.country.state', 'State'),
  30. 'country_id': fields.many2one('res.country', 'Country'),
  31. }
  32. _defaults = {'priority': 100}
  33. def name_get(self, cursor, uid, ids, context=None):
  34. res = []
  35. for bzip in self.browse(cursor, uid, ids):
  36. res.append((bzip.id, u"%s %s" % (bzip.name, bzip.city)))
  37. return res
  38. class Partner(Model):
  39. _inherit = "res.partner"
  40. _columns = {'zip_id': fields.many2one('res.better.zip', 'ZIP/PN')}
  41. def onchange_zip_id(self, cursor, uid, ids, zip_id, context=None):
  42. if not zip_id:
  43. return {}
  44. if isinstance(zip_id, list):
  45. zip_id = zip_id[0]
  46. bzip = self.pool['res.better.zip'].browse(cursor, uid, zip_id, context=context)
  47. return {'value': {'zip': bzip.name, 'city': bzip.city,
  48. 'country_id': bzip.country_id.id, 'state_id': bzip.state_id.id}}