From 305ff7a31eadca1a72c6eee2262f790aa1e93e30 Mon Sep 17 00:00:00 2001 From: Raphael Collet Date: Thu, 11 Aug 2016 10:06:13 +0200 Subject: [PATCH] [MIG] complete migration of special methods like `init` --- .../decimal_precision/models/decimal_precision.py | 3 ++- .../models/hr_timesheet_sheet.py | 5 +++-- .../report/hr_timesheet_attendance_report.py | 7 ++++--- addons/mail/models/mail_channel.py | 9 +++++---- addons/mail/models/mail_message.py | 9 +++++---- addons/project_issue/report/project_issue_report.py | 9 +++++---- addons/stock/models/stock_move.py | 9 +++++---- .../report/report_event_registrations_questions.py | 9 +++++---- addons/website_form/models/models.py | 13 +++++++------ addons/website_forum/models/forum.py | 7 ++++--- 10 files changed, 45 insertions(+), 35 deletions(-) diff --git a/addons/decimal_precision/models/decimal_precision.py b/addons/decimal_precision/models/decimal_precision.py index 8484f22b0ba..8ac6589bc8a 100644 --- a/addons/decimal_precision/models/decimal_precision.py +++ b/addons/decimal_precision/models/decimal_precision.py @@ -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() diff --git a/addons/hr_timesheet_attendance/models/hr_timesheet_sheet.py b/addons/hr_timesheet_attendance/models/hr_timesheet_sheet.py index 7a9da24eb10..653f19d8ce0 100644 --- a/addons/hr_timesheet_attendance/models/hr_timesheet_sheet.py +++ b/addons/hr_timesheet_attendance/models/hr_timesheet_sheet.py @@ -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, diff --git a/addons/hr_timesheet_attendance/report/hr_timesheet_attendance_report.py b/addons/hr_timesheet_attendance/report/hr_timesheet_attendance_report.py index 9cf1eab8949..582926ab89a 100644 --- a/addons/hr_timesheet_attendance/report/hr_timesheet_attendance_report.py +++ b/addons/hr_timesheet_attendance/report/hr_timesheet_attendance_report.py @@ -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, diff --git a/addons/mail/models/mail_channel.py b/addons/mail/models/mail_channel.py index 7cde2211fcc..94582dcf2a1 100644 --- a/addons/mail/models/mail_channel.py +++ b/addons/mail/models/mail_channel.py @@ -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 diff --git a/addons/mail/models/mail_message.py b/addons/mail/models/mail_message.py index 170bcbba864..cc3bc3d886b 100644 --- a/addons/mail/models/mail_message.py +++ b/addons/mail/models/mail_message.py @@ -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): diff --git a/addons/project_issue/report/project_issue_report.py b/addons/project_issue/report/project_issue_report.py index 18939b43397..2fd80ed6485 100644 --- a/addons/project_issue/report/project_issue_report.py +++ b/addons/project_issue/report/project_issue_report.py @@ -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, diff --git a/addons/stock/models/stock_move.py b/addons/stock/models/stock_move.py index 9722e98635d..880f79bf5bd 100644 --- a/addons/stock/models/stock_move.py +++ b/addons/stock/models/stock_move.py @@ -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): diff --git a/addons/website_event_questions/report/report_event_registrations_questions.py b/addons/website_event_questions/report/report_event_registrations_questions.py index 90c0e9e1350..0cf362bbf0d 100644 --- a/addons/website_event_questions/report/report_event_registrations_questions.py +++ b/addons/website_event_questions/report/report_event_registrations_questions.py @@ -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, diff --git a/addons/website_form/models/models.py b/addons/website_form/models/models.py index 1f3ec5d374d..54425b383bc 100644 --- a/addons/website_form/models/models.py +++ b/addons/website_form/models/models.py @@ -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): diff --git a/addons/website_forum/models/forum.py b/addons/website_forum/models/forum.py index 1f6013df78c..34d6e6ae083 100644 --- a/addons/website_forum/models/forum.py +++ b/addons/website_forum/models/forum.py @@ -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):