@@ -0,0 +1,2938 @@
+# -*- encoding: utf-8 -*-%0A##############################################################################%0A#%0A#    OpenERP, Open Source Management Solution%0A#    This module copyright (C) 2010 - 2014 Savoir-faire Linux%0A#    (%3Chttp://www.savoirfairelinux.com%3E).%0A#%0A#    This program is free software: you can redistribute it and/or modify%0A#    it under the terms of the GNU Affero General Public License as%0A#    published by the Free Software Foundation, either version 3 of the%0A#    License, or (at your option) any later version.%0A#%0A#    This program is distributed in the hope that it will be useful,%0A#    but WITHOUT ANY WARRANTY; without even the implied warranty of%0A#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the%0A#    GNU Affero General Public License for more details.%0A#%0A#    You should have received a copy of the GNU Affero General Public License%0A#    along with this program.  If not, see %3Chttp://www.gnu.org/licenses/%3E.%0A#%0A##############################################################################%0A%0A# This module provides simple tools for OpenUpgrade migration, specific for%0A# the 7.0 -%3E 8.0 migration. It is kept in later editions to keep all the API%0A# docs in the latest release.%0A%0A%0Adef get_last_post_for_model(cr, uid, ids, model_pool):%0A    %22%22%22%0A    Given a set of ids and a model pool, return a dict of each object ids with%0A    their latest message date as a value.%0A    To be called in post-migration scripts%0A    :param cr: database cursor%0A    :param uid: user id, assumed to be openerp.SUPERUSER_ID%0A    :param ids: ids of the model in question to retrieve ids%0A    :param model_pool: orm model pool, assumed to be from pool.get()%0A    :return: a dict with ids as keys and with dates as values%0A    %22%22%22%0A    if type(ids) is not list:%0A        ids = %5Bids%5D%0A    res = %7B%7D%0A    for obj in model_pool.browse(cr, uid, ids):%0A        message_ids = obj.message_ids%0A        if message_ids:%0A            res%5Bobj.id%5D = sorted(%0A                message_ids, key=lambda x: x.date, reverse=True)%5B0%5D.date%0A        else:%0A            res%5Bobj.id%5D = False%0A    return res%0A%0A%0Adef set_message_last_post(cr, uid, pool, models):%0A    %22%22%22%0A    Given a list of models, set their 'message_last_post' fields to an%0A    estimated last post datetime.%0A    To be called in post-migration scripts%0A    :param cr: database cursor%0A    :param uid: user id, assumed to be openerp.SUPERUSER_ID%0A    :param pool: orm pool, assumed to be openerp.pooler.get_pool(cr.dbname)%0A    :param models: a list of model names for which 'message_last_post' needs to%0A    be filled%0A    :return:%0A    %22%22%22%0A    if type(models) is not list:%0A        models = %5Bmodels%5D%0A    for model in models:%0A        model_pool = pool%5Bmodel%5D%0A        obj_ids = model_pool.search(cr, uid, %5B%5D, context=%7B'active_test': False%7D)%0A        last_posts = get_last_post_for_model(cr, uid, obj_ids, model_pool)%0A        for i in obj_ids:%0A            model_pool.write(cr, uid, i, %7B'message_last_post': last_posts%5Bi%5D%7D)%0A

Add OpenUpgrade specific functions for message_last_post fields