From 6a500a006932f997da8aa6cd7ac06ffc2defa078 Mon Sep 17 00:00:00 2001 From: ecino Date: Wed, 7 Sep 2016 15:35:33 +0200 Subject: [PATCH] FIX birthdate date install Fix a bug where a typo would prevent to set all birthdate dates at installation of module partner_contact_birthdate --- partner_contact_birthdate/__init__.py | 1 + partner_contact_birthdate/__openerp__.py | 1 + .../data/res_partner.yml | 19 ------------------- partner_contact_birthdate/hooks.py | 10 ++++++++++ partner_contact_birthdate/models.py | 5 ----- 5 files changed, 12 insertions(+), 24 deletions(-) delete mode 100644 partner_contact_birthdate/data/res_partner.yml create mode 100644 partner_contact_birthdate/hooks.py diff --git a/partner_contact_birthdate/__init__.py b/partner_contact_birthdate/__init__.py index 3b3430c28..1b4d792c6 100644 --- a/partner_contact_birthdate/__init__.py +++ b/partner_contact_birthdate/__init__.py @@ -17,3 +17,4 @@ # along with this program. If not, see . from . import models +from .hooks import post_init_hook diff --git a/partner_contact_birthdate/__openerp__.py b/partner_contact_birthdate/__openerp__.py index d7758ddb2..b7fe767ce 100644 --- a/partner_contact_birthdate/__openerp__.py +++ b/partner_contact_birthdate/__openerp__.py @@ -28,4 +28,5 @@ "data": [ "views/res_partner.xml", ], + "post_init_hook": "post_init_hook", } diff --git a/partner_contact_birthdate/data/res_partner.yml b/partner_contact_birthdate/data/res_partner.yml deleted file mode 100644 index 2b3d5efe9..000000000 --- a/partner_contact_birthdate/data/res_partner.yml +++ /dev/null @@ -1,19 +0,0 @@ -# -*- coding: utf-8 -*- - -# Odoo, Open Source Management Solution -# Copyright (C) 2014-2015 Grupo ESOC -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . - -- !function {model: res.partner, name: _birthdate_install} diff --git a/partner_contact_birthdate/hooks.py b/partner_contact_birthdate/hooks.py new file mode 100644 index 000000000..f07477246 --- /dev/null +++ b/partner_contact_birthdate/hooks.py @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- + +from openerp import SUPERUSER_ID +from openerp.api import Environment + + +def post_init_hook(cr, pool): + env = Environment(cr, SUPERUSER_ID, {}) + env['res.partner'].search( + [('birthdate', "!=", False)])._birthdate_inverse() diff --git a/partner_contact_birthdate/models.py b/partner_contact_birthdate/models.py index 2686fed6d..880674ec1 100644 --- a/partner_contact_birthdate/models.py +++ b/partner_contact_birthdate/models.py @@ -51,8 +51,3 @@ class Partner(models.Model): _logger.warn( _("Could not convert '{0.birthdate}' to date in " "res.partner {0.id} ({0.name}). Skipping.").format(self)) - - @api.model - def _birthdate_install(self): - """Export all old birthdates to the new format.""" - self.search([('birthdate', "!=", False)])._inverse_birthdate()