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.

43 lines
1.3 KiB

9 years ago
  1. # -*- coding: utf-8 -*-
  2. # Copyright (C) 2014-2015 Grupo ESOC <www.grupoesoc.es>
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from openerp import _, api, fields, models
  5. import logging
  6. _logger = logging.getLogger(__name__)
  7. class Partner(models.Model):
  8. """Partner with birth date in date format."""
  9. _inherit = "res.partner"
  10. # New birthdate field in date format
  11. birthdate_date = fields.Date("Birthdate")
  12. # Make the old Char field to reflect the new Date field
  13. birthdate = fields.Char(
  14. compute="_birthdate_compute",
  15. inverse="_birthdate_inverse",
  16. store=True)
  17. @api.one
  18. @api.depends("birthdate_date")
  19. def _birthdate_compute(self):
  20. """Store a string of the new date in the old field."""
  21. self.birthdate = self.birthdate_date
  22. @api.one
  23. def _birthdate_inverse(self):
  24. """Convert the old Char date to the new Date format."""
  25. try:
  26. self.birthdate_date = self.birthdate
  27. except ValueError:
  28. _logger.warn(
  29. _("Could not convert '{0.birthdate}' to date in "
  30. "res.partner {0.id} ({0.name}). Skipping.").format(self))
  31. @api.model
  32. def _birthdate_install(self):
  33. """Export all old birthdates to the new format."""
  34. self.search([('birthdate', "!=", False)])._inverse_birthdate()