From 49e4f187cf54459dd07cec0642767aeb70ff297c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Wed, 4 Apr 2012 14:33:40 +0200 Subject: [PATCH] [IMP] publisher_warranty: updated code based on res.log, now using mail.message if exists. bzr revid: tde@openerp.com-20120404123340-b12w4jwf7nclo38u --- .../publisher_warranty/publisher_warranty.py | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/openerp/addons/base/publisher_warranty/publisher_warranty.py b/openerp/addons/base/publisher_warranty/publisher_warranty.py index d6c1304a9ca..2fa47f150f3 100644 --- a/openerp/addons/base/publisher_warranty/publisher_warranty.py +++ b/openerp/addons/base/publisher_warranty/publisher_warranty.py @@ -187,22 +187,21 @@ class publisher_warranty_contract(osv.osv): limit_date = (datetime.datetime.now() - _PREVIOUS_LOG_CHECK).strftime(misc.DEFAULT_SERVER_DATETIME_FORMAT) - # TODO: must be updated with OpenChatter ? - #for message in result["messages"]: - #ids = self.pool.get("res.log").search(cr, uid, [("res_model", "=", "publisher_warranty.contract"), - #("create_date", ">=", limit_date), - #("name", "=", message)]) - #if ids: - #continue - #self.pool.get('res.log').create(cr, uid, - #{ - #'name': message, - #'res_model': "publisher_warranty.contract", - #"read": True, - #"user_id": False, - #}, - #context=context - #) + + # old behavior based on res.log; now on mail.message, that is not necessarily installed + mail_message_obj = self.pool.get('mail.message') + if mail_message_obj: + for message in result["messages"]: + ids = mail_message_obj.search(cr, uid, [("model", "=", "publisher_warranty.contract"), + ("create_date", ">=", limit_date), + ("body_text", "=", message)]) + if ids: + continue + mail_message_obj.create(cr, uid, { + 'name': message, + 'model': "publisher_warranty.contract", + 'user_id': False, + }, context=context) except Exception: if cron_mode: return False # we don't want to see any stack trace in cron @@ -216,12 +215,13 @@ class publisher_warranty_contract(osv.osv): @return: A list of html messages with ids, can be False or empty. @rtype: list of tuples(int,string) """ - ids = [] - #ids = self.pool.get('res.log').search(cr, uid, [("res_model", "=", "publisher_warranty.contract")] - #, order="create_date desc", limit=limit) + if not self.pool.get('mail.message'): + return [] + ids = self.pool.get('mail.message').search(cr, uid, [("model", "=", "publisher_warranty.contract")] + , order="create_date desc", limit=limit, context=context) if not ids: return [] - messages = [(x.id, x.name) for x in self.pool.get('res.log').browse(cr, uid, ids, context=context)] + messages = [(x.id, x.name) for x in self.pool.get('mail.message').browse(cr, uid, ids, context=context)] return messages _columns = {