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.

55 lines
1.9 KiB

10 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. # -*- coding: utf-8 -*-
  2. # Odoo, Open Source Management Solution
  3. # Copyright (C) 2014-2015 Grupo ESOC <www.grupoesoc.es>
  4. #
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU Affero General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU Affero General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU Affero General Public License
  16. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. from openerp import _, api, fields, models
  18. import logging
  19. _logger = logging.getLogger(__name__)
  20. class Partner(models.Model):
  21. """Partner with birth date in date format."""
  22. _inherit = "res.partner"
  23. # New birthdate field in date format
  24. birthdate_date = fields.Date("Birthdate")
  25. # Make the old Char field to reflect the new Date field
  26. birthdate = fields.Char(
  27. compute="_compute_birthdate",
  28. inverse="_inverse_birthdate",
  29. store=True)
  30. @api.multi
  31. @api.depends("birthdate_date")
  32. def _compute_birthdate(self):
  33. """Store a string of the new date in the old field."""
  34. for this in self:
  35. this.birthdate = this.birthdate_date
  36. @api.multi
  37. def _inverse_birthdate(self):
  38. """Convert the old Char date to the new Date format."""
  39. for this in self:
  40. try:
  41. this.birthdate_date = this.birthdate
  42. except ValueError:
  43. _logger.warn(
  44. _("Could not convert '{0.birthdate}' to date in "
  45. "res.partner {0.id} ({0.name}). Skipping.").format(this))