[MIG] complete migration of special methods like init

This commit is contained in:
Raphael Collet
2016-08-11 12:09:57 +02:00
parent 9fb53a5055
commit 305ff7a31e
10 changed files with 45 additions and 35 deletions
@@ -20,7 +20,8 @@ class DecimalPrecision(models.Model):
res = self.env.cr.fetchone()
return res[0] if res else 2
def clear_cache(self, cr):
@api.model_cr
def clear_cache(self):
""" Deprecated, use `clear_caches` instead. """
self.clear_caches()
@@ -104,8 +104,9 @@ class hr_timesheet_sheet_sheet_day(models.Model):
'hr_timesheet_sheet.sheet': ['attendances_ids', 'timesheet_ids'],
}
def init(self, cr):
cr.execute("""create or replace view %s as
@api.model_cr
def init(self):
self._cr.execute("""create or replace view %s as
SELECT
id,
name,
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import fields, models
from odoo import api, fields, models
class TimesheetAttendance(models.Model):
@@ -14,8 +14,9 @@ class TimesheetAttendance(models.Model):
total_attendance = fields.Float()
total_difference = fields.Float()
def init(self, cr):
cr.execute("""CREATE OR REPLACE VIEW %s AS (
@api.model_cr
def init(self):
self._cr.execute("""CREATE OR REPLACE VIEW %s AS (
SELECT
max(id) AS id,
t.user_id,
+5 -4
View File
@@ -219,10 +219,11 @@ class Channel(models.Model):
message = super(Channel, self.with_context(mail_create_nosubscribe=True)).message_post(body=body, subject=subject, message_type=message_type, subtype=subtype, parent_id=parent_id, attachments=attachments, content_subtype=content_subtype, **kwargs)
return message
def init(self, cr):
cr.execute('SELECT indexname FROM pg_indexes WHERE indexname = %s', ('mail_channel_partner_seen_message_id_idx',))
if not cr.fetchone():
cr.execute('CREATE INDEX mail_channel_partner_seen_message_id_idx ON mail_channel_partner (channel_id,partner_id,seen_message_id)')
@api.model_cr
def init(self):
self._cr.execute('SELECT indexname FROM pg_indexes WHERE indexname = %s', ('mail_channel_partner_seen_message_id_idx',))
if not self._cr.fetchone():
self._cr.execute('CREATE INDEX mail_channel_partner_seen_message_id_idx ON mail_channel_partner (channel_id,partner_id,seen_message_id)')
#------------------------------------------------------
# Instant Messaging API
+5 -4
View File
@@ -409,10 +409,11 @@ class Message(models.Model):
# mail_message internals
#------------------------------------------------------
def init(self, cr):
cr.execute("""SELECT indexname FROM pg_indexes WHERE indexname = 'mail_message_model_res_id_idx'""")
if not cr.fetchone():
cr.execute("""CREATE INDEX mail_message_model_res_id_idx ON mail_message (model, res_id)""")
@api.model_cr
def init(self):
self._cr.execute("""SELECT indexname FROM pg_indexes WHERE indexname = 'mail_message_model_res_id_idx'""")
if not self._cr.fetchone():
self._cr.execute("""CREATE INDEX mail_message_model_res_id_idx ON mail_message (model, res_id)""")
@api.model
def _find_allowed_model_wise(self, doc_model, doc_dict):
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import fields, models, tools
from odoo import api, fields, models, tools
class ProjectIssueReport(models.Model):
@@ -29,9 +29,10 @@ class ProjectIssueReport(models.Model):
task_id = fields.Many2one('project.task', 'Task')
email = fields.Integer('# Emails', readonly=True)
def init(self, cr):
tools.drop_view_if_exists(cr, 'project_issue_report')
cr.execute("""
@api.model_cr
def init(self):
tools.drop_view_if_exists(self._cr, 'project_issue_report')
self._cr.execute("""
CREATE OR REPLACE VIEW project_issue_report AS (
SELECT
c.id as id,
+5 -4
View File
@@ -225,10 +225,11 @@ class StockMove(models.Model):
if any(move.product_id.uom_id.category_id.id != move.product_uom.category_id.id for move in self):
raise UserError(_('You try to move a product using a UoM that is not compatible with the UoM of the product moved. Please use an UoM in the same UoM category.'))
def init(self, cr):
cr.execute('SELECT indexname FROM pg_indexes WHERE indexname = %s', ('stock_move_product_location_index',))
if not cr.fetchone():
cr.execute('CREATE INDEX stock_move_product_location_index ON stock_move (product_id, location_id, location_dest_id, company_id, state)')
@api.model_cr
def init(self):
self._cr.execute('SELECT indexname FROM pg_indexes WHERE indexname = %s', ('stock_move_product_location_index',))
if not self._cr.fetchone():
self._cr.execute('CREATE INDEX stock_move_product_location_index ON stock_move (product_id, location_id, location_dest_id, company_id, state)')
@api.multi
def name_get(self):
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import fields, models, tools
from odoo import api, fields, models, tools
class ReportEventRegistrationQuestions(models.Model):
@@ -13,10 +13,11 @@ class ReportEventRegistrationQuestions(models.Model):
answer_id = fields.Many2one(comodel_name='event.answer', string='Answer')
event_id = fields.Many2one(comodel_name='event.event', string='Event')
def init(self, cr):
@api.model_cr
def init(self):
""" Event Question main report """
tools.drop_view_if_exists(cr, 'event_question_report')
cr.execute(""" CREATE VIEW event_question_report AS (
tools.drop_view_if_exists(self._cr, 'event_question_report')
self._cr.execute(""" CREATE VIEW event_question_report AS (
SELECT
att_answer.id as id,
att_answer.event_registration_id as attendee_id,
+7 -6
View File
@@ -71,18 +71,19 @@ class website_form_model_fields(models.Model):
_name = 'ir.model.fields'
_inherit = 'ir.model.fields'
def init(self, cr):
@api.model_cr
def init(self):
# set all existing unset website_form_blacklisted fields to ``true``
# (so that we can use it as a whitelist rather than a blacklist)
cr.execute('UPDATE ir_model_fields'
' SET website_form_blacklisted=true'
' WHERE website_form_blacklisted IS NULL')
self._cr.execute('UPDATE ir_model_fields'
' SET website_form_blacklisted=true'
' WHERE website_form_blacklisted IS NULL')
# add an SQL-level default value on website_form_blacklisted to that
# pure-SQL ir.model.field creations (e.g. in _field_create) generate
# the right default value for a whitelist (aka fields should be
# blacklisted by default)
cr.execute('ALTER TABLE ir_model_fields '
' ALTER COLUMN website_form_blacklisted SET DEFAULT true')
self._cr.execute('ALTER TABLE ir_model_fields '
' ALTER COLUMN website_form_blacklisted SET DEFAULT true')
@api.model
def formbuilder_whitelist(self, model, fields):
+4 -3
View File
@@ -26,13 +26,14 @@ class Forum(models.Model):
_description = 'Forum'
_inherit = ['mail.thread', 'website.seo.metadata']
def init(self, cr):
@api.model_cr
def init(self):
""" Add forum uuid for user email validation.
TDE TODO: move me somewhere else, auto_init ? """
forum_uuids = self.pool['ir.config_parameter'].search(cr, SUPERUSER_ID, [('key', '=', 'website_forum.uuid')])
forum_uuids = self.env['ir.config_parameter'].search([('key', '=', 'website_forum.uuid')])
if not forum_uuids:
self.pool['ir.config_parameter'].set_param(cr, SUPERUSER_ID, 'website_forum.uuid', str(uuid.uuid4()), ['base.group_system'])
forum_uuids.set_param('website_forum.uuid', str(uuid.uuid4()), ['base.group_system'])
@api.model
def _get_default_faq(self):