From a1904aa6f62acbd3d8e7d4cc873692e20edb37fd Mon Sep 17 00:00:00 2001 From: Raphael Collet Date: Mon, 24 Jan 2022 13:19:16 +0000 Subject: [PATCH] [IMP] core: field index names The possible index names have been renamed "btree", "btree_not_null" (instead of "not null") and "trigram" (instead of "gin"). Task 2742526 Part-of: odoo/odoo#83274 --- addons/account/models/account_account.py | 2 +- addons/account/models/account_move.py | 20 ++++++------- addons/account_fleet/models/account_move.py | 2 +- addons/analytic/models/analytic_account.py | 4 +-- addons/crm/models/crm_lead.py | 4 +-- addons/crm_iap_mine/models/crm_lead.py | 2 +- addons/event/models/event_registration.py | 2 +- addons/hr/models/hr_job.py | 2 +- addons/hr_recruitment/models/calendar.py | 2 +- .../hr_recruitment/models/hr_recruitment.py | 2 +- addons/hr_timesheet/models/hr_timesheet.py | 2 +- .../l10n_ar_afip_responsibility_type.py | 2 +- addons/l10n_ar/models/res_partner.py | 2 +- addons/l10n_cl/models/res_partner.py | 2 +- addons/l10n_latam_base/models/res_partner.py | 2 +- .../models/account_move.py | 2 +- .../models/account_move_line.py | 2 +- addons/mail/models/mail_blacklist.py | 2 +- addons/mail/models/mail_message.py | 2 +- addons/mail/models/mail_shortcode.py | 2 +- addons/mass_mailing/models/mailing_trace.py | 6 ++-- .../mass_mailing_sms/models/mailing_trace.py | 4 +-- addons/mrp/models/mrp_production.py | 2 +- addons/mrp/models/stock_move.py | 4 +-- addons/point_of_sale/models/pos_order.py | 2 +- addons/pos_restaurant/models/pos_order.py | 2 +- addons/product/models/product.py | 2 +- addons/product/models/product_template.py | 2 +- addons/project/models/project.py | 6 ++-- addons/purchase/models/account_invoice.py | 2 +- addons/purchase/models/purchase.py | 2 +- addons/purchase_stock/models/purchase.py | 2 +- addons/purchase_stock/models/stock.py | 2 +- addons/repair/models/repair.py | 2 +- addons/sale/models/sale_order.py | 2 +- addons/sale_project/models/project.py | 4 +-- addons/sale_purchase/models/purchase_order.py | 2 +- addons/sale_stock/models/stock.py | 2 +- addons/sms/models/mail_notification.py | 2 +- addons/snailmail/models/mail_notification.py | 2 +- addons/stock/models/stock_lot.py | 2 +- addons/stock/models/stock_picking.py | 6 ++-- addons/stock/models/stock_quant.py | 4 +-- addons/stock_account/models/account_move.py | 2 +- addons/website/models/website_visitor.py | 2 +- .../website_crm_iap_reveal/models/crm_lead.py | 2 +- .../models/crm_reveal_view.py | 2 +- .../models/crm_lead.py | 2 +- .../models/res_partner.py | 2 +- .../website_event/models/website_visitor.py | 2 +- .../models/website_visitor.py | 2 +- addons/website_sale/models/website_visitor.py | 2 +- odoo/addons/base/models/ir_attachment.py | 2 +- odoo/fields.py | 17 +++++------ odoo/modules/registry.py | 28 ++++++++----------- odoo/tools/sql.py | 4 ++- 56 files changed, 98 insertions(+), 99 deletions(-) diff --git a/addons/account/models/account_account.py b/addons/account/models/account_account.py index 29b0a7bf72e..bb66ea601a6 100644 --- a/addons/account/models/account_account.py +++ b/addons/account/models/account_account.py @@ -55,7 +55,7 @@ class AccountAccount(models.Model): ('user_type_id', '=', data_unaffected_earnings.id)]) raise ValidationError(_('You cannot have more than one account with "Current Year Earnings" as type. (accounts: %s)', [a.code for a in account_unaffected_earnings])) - name = fields.Char(string="Account Name", required=True, index='gin', tracking=True) + name = fields.Char(string="Account Name", required=True, index='trigram', tracking=True) currency_id = fields.Many2one('res.currency', string='Account Currency', help="Forces all moves for this account to have this account currency.", tracking=True) code = fields.Char(size=64, required=True, index=True, tracking=True) diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index d3dbda2ec68..2e551cb99f0 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -220,10 +220,10 @@ class AccountMove(models.Model): partner_bank_id = fields.Many2one('res.partner.bank', string='Recipient Bank', help='Bank Account Number to which the invoice will be paid. A Company bank account if this is a Customer Invoice or Vendor Credit Note, otherwise a Partner bank account number.', check_company=True) - payment_reference = fields.Char(string='Payment Reference', index='gin', copy=False, + payment_reference = fields.Char(string='Payment Reference', index='trigram', copy=False, help="The payment reference to set on journal items.") payment_id = fields.Many2one( - index='not null', + index='btree_not_null', comodel_name='account.payment', string="Payment", copy=False, check_company=True) statement_line_id = fields.Many2one( @@ -3478,9 +3478,9 @@ class AccountMoveLine(models.Model): index=True, required=True, readonly=True, auto_join=True, ondelete="cascade", check_company=True, help="The move of this entry line.") - move_name = fields.Char(string='Number', related='move_id.name', store=True, index='gin') + move_name = fields.Char(string='Number', related='move_id.name', store=True, index='trigram') date = fields.Date(related='move_id.date', store=True, readonly=True, index=True, copy=False, group_operator='min') - ref = fields.Char(related='move_id.ref', store=True, copy=False, index='gin', readonly=True) + ref = fields.Char(related='move_id.ref', store=True, copy=False, index='trigram', readonly=True) parent_state = fields.Selection(related='move_id.state', store=True, readonly=True) journal_id = fields.Many2one(related='move_id.journal_id', store=True, index=True, copy=False) company_id = fields.Many2one(related='move_id.company_id', store=True, readonly=True) @@ -3532,15 +3532,15 @@ class AccountMoveLine(models.Model): # ==== Origin fields ==== reconcile_model_id = fields.Many2one('account.reconcile.model', string="Reconciliation Model", copy=False, readonly=True, check_company=True) - payment_id = fields.Many2one('account.payment', index="not null", store=True, + payment_id = fields.Many2one('account.payment', index='btree_not_null', store=True, string="Originator Payment", related='move_id.payment_id', help="The payment that created this entry") - statement_line_id = fields.Many2one('account.bank.statement.line', index="not null", store=True, + statement_line_id = fields.Many2one('account.bank.statement.line', index='btree_not_null', store=True, string="Originator Statement Line", related='move_id.statement_line_id', help="The statement line that created this entry") - statement_id = fields.Many2one(related='statement_line_id.statement_id', store=True, index="not null", copy=False, + statement_id = fields.Many2one(related='statement_line_id.statement_id', store=True, index='btree_not_null', copy=False, help="The bank statement used for bank reconciliation") # ==== Tax fields ==== @@ -3553,7 +3553,7 @@ class AccountMoveLine(models.Model): group_tax_id = fields.Many2one( comodel_name='account.tax', string="Originator Group of Taxes", - index="not null", + index='btree_not_null', help="The group of taxes that generated this tax line", ) tax_line_id = fields.Many2one('account.tax', string='Originator Tax', ondelete='restrict', store=True, @@ -3583,7 +3583,7 @@ class AccountMoveLine(models.Model): amount_residual_currency = fields.Monetary(string='Residual Amount in Currency', store=True, compute='_compute_amount_residual', help="The residual amount on a journal item expressed in its currency (possibly not the company currency).") - full_reconcile_id = fields.Many2one('account.full.reconcile', string="Matching", copy=False, index="not null", readonly=True) + full_reconcile_id = fields.Many2one('account.full.reconcile', string="Matching", copy=False, index='btree_not_null', readonly=True) matched_debit_ids = fields.One2many('account.partial.reconcile', 'credit_move_id', string='Matched Debits', help='Debit journal items that are matched with this journal item.', readonly=True) matched_credit_ids = fields.One2many('account.partial.reconcile', 'debit_move_id', string='Matched Credits', @@ -3593,7 +3593,7 @@ class AccountMoveLine(models.Model): # ==== Analytic fields ==== analytic_line_ids = fields.One2many('account.analytic.line', 'move_id', string='Analytic lines') analytic_account_id = fields.Many2one('account.analytic.account', string='Analytic Account', - index="not null", compute="_compute_analytic_account_id", store=True, readonly=False, check_company=True, copy=True) + index='btree_not_null', compute="_compute_analytic_account_id", store=True, readonly=False, check_company=True, copy=True) analytic_tag_ids = fields.Many2many('account.analytic.tag', string='Analytic Tags', compute="_compute_analytic_tag_ids", store=True, readonly=False, check_company=True, copy=True) diff --git a/addons/account_fleet/models/account_move.py b/addons/account_fleet/models/account_move.py index 8b2a5e42edc..ca5b68d363b 100644 --- a/addons/account_fleet/models/account_move.py +++ b/addons/account_fleet/models/account_move.py @@ -33,7 +33,7 @@ class AccountMove(models.Model): class AccountMoveLine(models.Model): _inherit = 'account.move.line' - vehicle_id = fields.Many2one('fleet.vehicle', string='Vehicle', index='not null') + vehicle_id = fields.Many2one('fleet.vehicle', string='Vehicle', index='btree_not_null') need_vehicle = fields.Boolean(compute='_compute_need_vehicle', help="Technical field to decide whether the vehicle_id field is editable") diff --git a/addons/analytic/models/analytic_account.py b/addons/analytic/models/analytic_account.py index 8cf83577b85..3b9bbefeb6c 100644 --- a/addons/analytic/models/analytic_account.py +++ b/addons/analytic/models/analytic_account.py @@ -25,7 +25,7 @@ class AccountAnalyticDistribution(models.Model): class AccountAnalyticTag(models.Model): _name = 'account.analytic.tag' _description = 'Analytic Tags' - name = fields.Char(string='Analytic Tag', index='gin', required=True) + name = fields.Char(string='Analytic Tag', index='trigram', required=True) color = fields.Integer('Color Index') active = fields.Boolean(default=True, help="Set active to false to hide the Analytic Tag without removing it.") active_analytic_distribution = fields.Boolean('Analytic Distribution') @@ -123,7 +123,7 @@ class AccountAnalyticAccount(models.Model): account.credit = data_credit.get(account.id, 0.0) account.balance = account.credit - account.debit - name = fields.Char(string='Analytic Account', index='gin', required=True, tracking=True) + name = fields.Char(string='Analytic Account', index='trigram', required=True, tracking=True) code = fields.Char(string='Reference', index='btree', tracking=True) active = fields.Boolean('Active', help="If the active field is set to False, it will allow you to hide the account without removing it.", default=True) diff --git a/addons/crm/models/crm_lead.py b/addons/crm/models/crm_lead.py index 6a71b880548..9bcd56bd1cd 100644 --- a/addons/crm/models/crm_lead.py +++ b/addons/crm/models/crm_lead.py @@ -101,7 +101,7 @@ class Lead(models.Model): # Description name = fields.Char( - 'Opportunity', index='gin', required=True, + 'Opportunity', index='trigram', required=True, compute='_compute_name', readonly=False, store=True) user_id = fields.Many2one( 'res.users', string='Salesperson', default=lambda self: self.env.user, @@ -180,7 +180,7 @@ class Lead(models.Model): function = fields.Char('Job Position', compute='_compute_function', readonly=False, store=True) title = fields.Many2one('res.partner.title', string='Title', compute='_compute_title', readonly=False, store=True) email_from = fields.Char( - 'Email', tracking=40, index='gin', + 'Email', tracking=40, index='trigram', compute='_compute_email_from', inverse='_inverse_email_from', readonly=False, store=True) phone = fields.Char( 'Phone', tracking=50, diff --git a/addons/crm_iap_mine/models/crm_lead.py b/addons/crm_iap_mine/models/crm_lead.py index ef6ef1bf19d..96361b11332 100644 --- a/addons/crm_iap_mine/models/crm_lead.py +++ b/addons/crm_iap_mine/models/crm_lead.py @@ -7,7 +7,7 @@ from odoo import fields, models class Lead(models.Model): _inherit = 'crm.lead' - lead_mining_request_id = fields.Many2one('crm.iap.lead.mining.request', string='Lead Mining Request', index="not null") + lead_mining_request_id = fields.Many2one('crm.iap.lead.mining.request', string='Lead Mining Request', index='btree_not_null') def _merge_get_fields(self): return super(Lead, self)._merge_get_fields() + ['lead_mining_request_id'] diff --git a/addons/event/models/event_registration.py b/addons/event/models/event_registration.py index 2422b80d60a..7a733869c82 100644 --- a/addons/event/models/event_registration.py +++ b/addons/event/models/event_registration.py @@ -29,7 +29,7 @@ class EventRegistration(models.Model): # attendee partner_id = fields.Many2one('res.partner', string='Booked by', tracking=1) name = fields.Char( - string='Attendee Name', index='gin', + string='Attendee Name', index='trigram', compute='_compute_name', readonly=False, store=True, tracking=10) email = fields.Char(string='Email', compute='_compute_email', readonly=False, store=True, tracking=11) phone = fields.Char(string='Phone', compute='_compute_phone', readonly=False, store=True, tracking=12) diff --git a/addons/hr/models/hr_job.py b/addons/hr/models/hr_job.py index 55b759ac035..5afc46c3dce 100644 --- a/addons/hr/models/hr_job.py +++ b/addons/hr/models/hr_job.py @@ -11,7 +11,7 @@ class Job(models.Model): _inherit = ['mail.thread'] _order = 'sequence' - name = fields.Char(string='Job Position', required=True, index='gin', translate=True) + name = fields.Char(string='Job Position', required=True, index='trigram', translate=True) sequence = fields.Integer(default=10) expected_employees = fields.Integer(compute='_compute_employees', string='Total Forecasted Employees', store=True, help='Expected number of employees for this job position after new recruitment.') diff --git a/addons/hr_recruitment/models/calendar.py b/addons/hr_recruitment/models/calendar.py index 6317cade2e7..bb14a5e152a 100644 --- a/addons/hr_recruitment/models/calendar.py +++ b/addons/hr_recruitment/models/calendar.py @@ -36,4 +36,4 @@ class CalendarEvent(models.Model): if event.applicant_id.id == applicant_id: event.is_highlighted = True - applicant_id = fields.Many2one('hr.applicant', string="Applicant", index='not null', ondelete='set null') + applicant_id = fields.Many2one('hr.applicant', string="Applicant", index='btree_not_null', ondelete='set null') diff --git a/addons/hr_recruitment/models/hr_recruitment.py b/addons/hr_recruitment/models/hr_recruitment.py index a8f23cb5960..ae3a479aeff 100644 --- a/addons/hr_recruitment/models/hr_recruitment.py +++ b/addons/hr_recruitment/models/hr_recruitment.py @@ -112,7 +112,7 @@ class Applicant(models.Model): _inherit = ['mail.thread.cc', 'mail.activity.mixin', 'utm.mixin'] _mailing_enabled = True - name = fields.Char("Subject / Application Name", required=True, help="Email subject for applications sent via email", index='gin') + name = fields.Char("Subject / Application Name", required=True, help="Email subject for applications sent via email", index='trigram') active = fields.Boolean("Active", default=True, help="If the active field is set to false, it will allow you to hide the case without removing it.") description = fields.Html("Description") email_from = fields.Char("Email", size=128, help="Applicant email", compute='_compute_partner_phone_email', diff --git a/addons/hr_timesheet/models/hr_timesheet.py b/addons/hr_timesheet/models/hr_timesheet.py index 062820befeb..61c05131fc7 100644 --- a/addons/hr_timesheet/models/hr_timesheet.py +++ b/addons/hr_timesheet/models/hr_timesheet.py @@ -40,7 +40,7 @@ class AccountAnalyticLine(models.Model): return [] task_id = fields.Many2one( - 'project.task', 'Task', index='not null', + 'project.task', 'Task', index='btree_not_null', compute='_compute_task_id', store=True, readonly=False, domain="[('company_id', '=', company_id), ('project_id.allow_timesheets', '=', True), ('project_id', '=?', project_id)]") project_id = fields.Many2one( diff --git a/addons/l10n_ar/models/l10n_ar_afip_responsibility_type.py b/addons/l10n_ar/models/l10n_ar_afip_responsibility_type.py index c99580ce879..843380ee89a 100644 --- a/addons/l10n_ar/models/l10n_ar_afip_responsibility_type.py +++ b/addons/l10n_ar/models/l10n_ar_afip_responsibility_type.py @@ -9,7 +9,7 @@ class L10nArAfipResponsibilityType(models.Model): _description = 'AFIP Responsibility Type' _order = 'sequence' - name = fields.Char(required=True, index='gin') + name = fields.Char(required=True, index='trigram') sequence = fields.Integer() code = fields.Char(required=True, index=True) active = fields.Boolean(default=True) diff --git a/addons/l10n_ar/models/res_partner.py b/addons/l10n_ar/models/res_partner.py index e15d2524eec..4ea0ca609da 100644 --- a/addons/l10n_ar/models/res_partner.py +++ b/addons/l10n_ar/models/res_partner.py @@ -24,7 +24,7 @@ class ResPartner(models.Model): [('multilateral', 'Multilateral'), ('local', 'Local'), ('exempt', 'Exempt')], 'Gross Income Type', help='Type of gross income: exempt, local, multilateral') l10n_ar_afip_responsibility_type_id = fields.Many2one( - 'l10n_ar.afip.responsibility.type', string='AFIP Responsibility Type', index='not null', help='Defined by AFIP to' + 'l10n_ar.afip.responsibility.type', string='AFIP Responsibility Type', index='btree_not_null', help='Defined by AFIP to' ' identify the type of responsibilities that a person or a legal entity could have and that impacts in the' ' type of operations and requirements they need.') l10n_ar_special_purchase_document_type_ids = fields.Many2many( diff --git a/addons/l10n_cl/models/res_partner.py b/addons/l10n_cl/models/res_partner.py index 4cda1e1f9b7..f9e657297fb 100644 --- a/addons/l10n_cl/models/res_partner.py +++ b/addons/l10n_cl/models/res_partner.py @@ -17,7 +17,7 @@ class ResPartner(models.Model): ] l10n_cl_sii_taxpayer_type = fields.Selection( - _sii_taxpayer_types, 'Taxpayer Type', index='not null', + _sii_taxpayer_types, 'Taxpayer Type', index='btree_not_null', help='1 - VAT Affected (1st Category) (Most of the cases)\n' '2 - Fees Receipt Issuer (Applies to suppliers who issue fees receipt)\n' '3 - End consumer (only receipts)\n' diff --git a/addons/l10n_latam_base/models/res_partner.py b/addons/l10n_latam_base/models/res_partner.py index ba81e80bdec..767c637af21 100644 --- a/addons/l10n_latam_base/models/res_partner.py +++ b/addons/l10n_latam_base/models/res_partner.py @@ -7,7 +7,7 @@ class ResPartner(models.Model): _inherit = 'res.partner' l10n_latam_identification_type_id = fields.Many2one('l10n_latam.identification.type', - string="Identification Type", index='not null', auto_join=True, + string="Identification Type", index='btree_not_null', auto_join=True, default=lambda self: self.env.ref('l10n_latam_base.it_vat', raise_if_not_found=False), help="The type of identification") vat = fields.Char(string='Identification Number', help="Identification Number for selected type") diff --git a/addons/l10n_latam_invoice_document/models/account_move.py b/addons/l10n_latam_invoice_document/models/account_move.py index 0b6f69383a8..4fc9326095e 100644 --- a/addons/l10n_latam_invoice_document/models/account_move.py +++ b/addons/l10n_latam_invoice_document/models/account_move.py @@ -43,7 +43,7 @@ class AccountMove(models.Model): l10n_latam_available_document_type_ids = fields.Many2many('l10n_latam.document.type', compute='_compute_l10n_latam_available_document_types') l10n_latam_document_type_id = fields.Many2one( - 'l10n_latam.document.type', string='Document Type', readonly=False, auto_join=True, index='not null', + 'l10n_latam.document.type', string='Document Type', readonly=False, auto_join=True, index='btree_not_null', states={'posted': [('readonly', True)]}, compute='_compute_l10n_latam_document_type', store=True) l10n_latam_document_number = fields.Char( compute='_compute_l10n_latam_document_number', inverse='_inverse_l10n_latam_document_number', diff --git a/addons/l10n_latam_invoice_document/models/account_move_line.py b/addons/l10n_latam_invoice_document/models/account_move_line.py index 82d3b89719d..f763866941b 100644 --- a/addons/l10n_latam_invoice_document/models/account_move_line.py +++ b/addons/l10n_latam_invoice_document/models/account_move_line.py @@ -16,4 +16,4 @@ class AccountMoveLine(models.Model): return super()._auto_init() l10n_latam_document_type_id = fields.Many2one( - related='move_id.l10n_latam_document_type_id', auto_join=True, store=True, index='not null') + related='move_id.l10n_latam_document_type_id', auto_join=True, store=True, index='btree_not_null') diff --git a/addons/mail/models/mail_blacklist.py b/addons/mail/models/mail_blacklist.py index 825e94fecd0..fdb3223ad53 100644 --- a/addons/mail/models/mail_blacklist.py +++ b/addons/mail/models/mail_blacklist.py @@ -12,7 +12,7 @@ class MailBlackList(models.Model): _description = 'Mail Blacklist' _rec_name = 'email' - email = fields.Char(string='Email Address', required=True, index='gin', help='This field is case insensitive.', + email = fields.Char(string='Email Address', required=True, index='trigram', help='This field is case insensitive.', tracking=True) active = fields.Boolean(default=True, tracking=True) diff --git a/addons/mail/models/mail_message.py b/addons/mail/models/mail_message.py index 275c2b84048..bc748045b83 100644 --- a/addons/mail/models/mail_message.py +++ b/addons/mail/models/mail_message.py @@ -96,7 +96,7 @@ class Message(models.Model): help='Attachments are linked to a document through model / res_id and to the message ' 'through this field.') parent_id = fields.Many2one( - 'mail.message', 'Parent Message', index="not null", ondelete='set null', + 'mail.message', 'Parent Message', index='btree_not_null', ondelete='set null', help="Initial thread message.") child_ids = fields.One2many('mail.message', 'parent_id', 'Child Messages') # related document diff --git a/addons/mail/models/mail_shortcode.py b/addons/mail/models/mail_shortcode.py index a84551d7fd6..86bbdfc9b08 100644 --- a/addons/mail/models/mail_shortcode.py +++ b/addons/mail/models/mail_shortcode.py @@ -13,7 +13,7 @@ class MailShortcode(models.Model): _name = 'mail.shortcode' _description = 'Canned Response / Shortcode' - source = fields.Char('Shortcut', required=True, index='gin', help="The shortcut which must be replaced in the Chat Messages") + source = fields.Char('Shortcut', required=True, index='trigram', help="The shortcut which must be replaced in the Chat Messages") substitution = fields.Text('Substitution', required=True, help="The escaped html code replacing the shortcut") description = fields.Char('Description') message_ids = fields.Many2one('mail.message', string="Messages", store=False) diff --git a/addons/mass_mailing/models/mailing_trace.py b/addons/mass_mailing/models/mailing_trace.py index 4cd70877e2a..18a242c9297 100644 --- a/addons/mass_mailing/models/mailing_trace.py +++ b/addons/mass_mailing/models/mailing_trace.py @@ -54,13 +54,13 @@ class MailingTrace(models.Model): trace_type = fields.Selection([('mail', 'Email')], string='Type', default='mail', required=True) display_name = fields.Char(compute='_compute_display_name') # mail data - mail_mail_id = fields.Many2one('mail.mail', string='Mail', index="not null") + mail_mail_id = fields.Many2one('mail.mail', string='Mail', index='btree_not_null') mail_mail_id_int = fields.Integer( string='Mail ID (tech)', help='ID of the related mail_mail. This field is an integer field because ' 'the related mail_mail can be deleted separately from its statistics. ' 'However the ID is needed for several action and controllers.', - index="not null", + index='btree_not_null', ) email = fields.Char(string="Email", help="Normalized email address") message_id = fields.Char(string='Message-ID', help="Technical field for the email Message-ID (RFC 2392)") @@ -74,7 +74,7 @@ class MailingTrace(models.Model): campaign_id = fields.Many2one( related='mass_mailing_id.campaign_id', string='Campaign', - store=True, readonly=True, index="not null") + store=True, readonly=True, index='btree_not_null') # Status sent_datetime = fields.Datetime('Sent On') open_datetime = fields.Datetime('Opened On') diff --git a/addons/mass_mailing_sms/models/mailing_trace.py b/addons/mass_mailing_sms/models/mailing_trace.py index 146f4b2f41b..f14f9b77ed0 100644 --- a/addons/mass_mailing_sms/models/mailing_trace.py +++ b/addons/mass_mailing_sms/models/mailing_trace.py @@ -17,13 +17,13 @@ class MailingTrace(models.Model): trace_type = fields.Selection(selection_add=[ ('sms', 'SMS') ], ondelete={'sms': 'set default'}) - sms_sms_id = fields.Many2one('sms.sms', string='SMS', index="not null", ondelete='set null') + sms_sms_id = fields.Many2one('sms.sms', string='SMS', index='btree_not_null', ondelete='set null') sms_sms_id_int = fields.Integer( string='SMS ID (tech)', help='ID of the related sms.sms. This field is an integer field because ' 'the related sms.sms can be deleted separately from its statistics. ' 'However the ID is needed for several action and controllers.', - index="not null", + index='btree_not_null', ) sms_number = fields.Char('Number') sms_code = fields.Char('Code') diff --git a/addons/mrp/models/mrp_production.py b/addons/mrp/models/mrp_production.py index 428e8ff5cba..7c2c042838a 100644 --- a/addons/mrp/models/mrp_production.py +++ b/addons/mrp/models/mrp_production.py @@ -228,7 +228,7 @@ class MrpProduction(models.Model): 'procurement.group', 'Procurement Group', copy=False) product_description_variants = fields.Char('Custom Description') - orderpoint_id = fields.Many2one('stock.warehouse.orderpoint', 'Orderpoint', copy=False) + orderpoint_id = fields.Many2one('stock.warehouse.orderpoint', 'Orderpoint', copy=False, index='btree_not_null') propagate_cancel = fields.Boolean( 'Propagate cancel and split', help='If checked, when the previous move of the move (which was generated by a next procurement) is cancelled or split, the move generated by this move will too') diff --git a/addons/mrp/models/stock_move.py b/addons/mrp/models/stock_move.py index 726b60fffd8..720f2196e49 100644 --- a/addons/mrp/models/stock_move.py +++ b/addons/mrp/models/stock_move.py @@ -108,9 +108,9 @@ class StockMove(models.Model): created_production_id = fields.Many2one('mrp.production', 'Created Production Order', check_company=True) production_id = fields.Many2one( - 'mrp.production', 'Production Order for finished products', check_company=True, index="not null") + 'mrp.production', 'Production Order for finished products', check_company=True, index='btree_not_null') raw_material_production_id = fields.Many2one( - 'mrp.production', 'Production Order for components', check_company=True, index="not null") + 'mrp.production', 'Production Order for components', check_company=True, index='btree_not_null') unbuild_id = fields.Many2one( 'mrp.unbuild', 'Disassembly Order', check_company=True) consume_unbuild_id = fields.Many2one( diff --git a/addons/point_of_sale/models/pos_order.py b/addons/point_of_sale/models/pos_order.py index 7ab9772dbed..8baa89b01c4 100644 --- a/addons/point_of_sale/models/pos_order.py +++ b/addons/point_of_sale/models/pos_order.py @@ -248,7 +248,7 @@ class PosOrder(models.Model): company_id = fields.Many2one('res.company', string='Company', required=True, readonly=True) pricelist_id = fields.Many2one('product.pricelist', string='Pricelist', required=True, states={ 'draft': [('readonly', False)]}, readonly=True) - partner_id = fields.Many2one('res.partner', string='Customer', change_default=True, index='not null', states={'draft': [('readonly', False)], 'paid': [('readonly', False)]}) + partner_id = fields.Many2one('res.partner', string='Customer', change_default=True, index='btree_not_null', states={'draft': [('readonly', False)], 'paid': [('readonly', False)]}) sequence_number = fields.Integer(string='Sequence Number', help='A session-unique sequence number for the order', default=1) session_id = fields.Many2one( diff --git a/addons/pos_restaurant/models/pos_order.py b/addons/pos_restaurant/models/pos_order.py index d5d03766583..83584ef3f34 100644 --- a/addons/pos_restaurant/models/pos_order.py +++ b/addons/pos_restaurant/models/pos_order.py @@ -18,7 +18,7 @@ class PosOrderLine(models.Model): class PosOrder(models.Model): _inherit = 'pos.order' - table_id = fields.Many2one('restaurant.table', string='Table', help='The table where this order was served', index='not null') + table_id = fields.Many2one('restaurant.table', string='Table', help='The table where this order was served', index='btree_not_null') customer_count = fields.Integer(string='Guests', help='The amount of customers that have been served by this order.') multiprint_resume = fields.Char() diff --git a/addons/product/models/product.py b/addons/product/models/product.py index 0c7b2ba5612..444825d94f0 100644 --- a/addons/product/models/product.py +++ b/addons/product/models/product.py @@ -19,7 +19,7 @@ class ProductCategory(models.Model): _rec_name = 'complete_name' _order = 'complete_name' - name = fields.Char('Name', index='gin', required=True) + name = fields.Char('Name', index='trigram', required=True) complete_name = fields.Char( 'Complete Name', compute='_compute_complete_name', recursive=True, store=True) diff --git a/addons/product/models/product_template.py b/addons/product/models/product_template.py index 636325fa999..946800ced90 100644 --- a/addons/product/models/product_template.py +++ b/addons/product/models/product_template.py @@ -34,7 +34,7 @@ class ProductTemplate(models.Model): category_ids = categories._search([], order=order, access_rights_uid=SUPERUSER_ID) return categories.browse(category_ids) - name = fields.Char('Name', index='gin', required=True, translate=True) + name = fields.Char('Name', index='trigram', required=True, translate=True) sequence = fields.Integer('Sequence', default=1, help='Gives the sequence order when displaying a product list') description = fields.Html( 'Description', translate=True) diff --git a/addons/project/models/project.py b/addons/project/models/project.py index 508e3b5b37a..99e9211d9d7 100644 --- a/addons/project/models/project.py +++ b/addons/project/models/project.py @@ -205,7 +205,7 @@ class Project(models.Model): def _read_group_stage_ids(self, stages, domain, order): return self.env['project.project.stage'].search([], order=order) - name = fields.Char("Name", index='gin', required=True, tracking=True, translate=True) + name = fields.Char("Name", index='trigram', required=True, tracking=True, translate=True) description = fields.Html() active = fields.Boolean(default=True, help="If the active field is set to False, it will allow you to hide the project without removing it.") @@ -913,7 +913,7 @@ class Task(models.Model): return stages.search(['|', ('id', 'in', stages.ids), ('user_id', '=', self.env.user.id)]) active = fields.Boolean(default=True) - name = fields.Char(string='Title', tracking=True, required=True, index='gin') + name = fields.Char(string='Title', tracking=True, required=True, index='trigram') description = fields.Html(string='Description') priority = fields.Selection([ ('0', 'Normal'), @@ -1002,7 +1002,7 @@ class Task(models.Model): child_text = fields.Char(compute="_compute_child_text") allow_subtasks = fields.Boolean(string="Allow Sub-tasks", related="project_id.allow_subtasks", readonly=True) subtask_count = fields.Integer("Sub-task Count", compute='_compute_subtask_count') - email_from = fields.Char(string='Email From', help="These people will receive email.", index='gin', + email_from = fields.Char(string='Email From', help="These people will receive email.", index='trigram', compute='_compute_email_from', recursive=True, store=True, readonly=False) project_privacy_visibility = fields.Selection(related='project_id.privacy_visibility', string="Project Visibility") # Computed field about working time elapsed between record creation and assignation/closing. diff --git a/addons/purchase/models/account_invoice.py b/addons/purchase/models/account_invoice.py index afe10e7942f..31fa9990e0a 100644 --- a/addons/purchase/models/account_invoice.py +++ b/addons/purchase/models/account_invoice.py @@ -132,7 +132,7 @@ class AccountMoveLine(models.Model): """ Override AccountInvoice_line to add the link to the purchase order line it is related to""" _inherit = 'account.move.line' - purchase_line_id = fields.Many2one('purchase.order.line', 'Purchase Order Line', ondelete='set null', index="not null") + purchase_line_id = fields.Many2one('purchase.order.line', 'Purchase Order Line', ondelete='set null', index='btree_not_null') purchase_order_id = fields.Many2one('purchase.order', 'Purchase Order', related='purchase_line_id.order_id', readonly=True) def _copy_data_extend_business_fields(self, values): diff --git a/addons/purchase/models/purchase.py b/addons/purchase/models/purchase.py index 1436e4c5f56..3d2dc6d67ca 100644 --- a/addons/purchase/models/purchase.py +++ b/addons/purchase/models/purchase.py @@ -73,7 +73,7 @@ class PurchaseOrder(models.Model): 'cancel': [('readonly', True)], } - name = fields.Char('Order Reference', required=True, index='gin', copy=False, default='New') + name = fields.Char('Order Reference', required=True, index='trigram', copy=False, default='New') priority = fields.Selection( [('0', 'Normal'), ('1', 'Urgent')], 'Priority', default='0', index=True) origin = fields.Char('Source Document', copy=False, diff --git a/addons/purchase_stock/models/purchase.py b/addons/purchase_stock/models/purchase.py index ccd84828b99..6ea932bf0cf 100644 --- a/addons/purchase_stock/models/purchase.py +++ b/addons/purchase_stock/models/purchase.py @@ -271,7 +271,7 @@ class PurchaseOrderLine(models.Model): qty_received_method = fields.Selection(selection_add=[('stock_moves', 'Stock Moves')]) move_ids = fields.One2many('stock.move', 'purchase_line_id', string='Reservation', readonly=True, copy=False) - orderpoint_id = fields.Many2one('stock.warehouse.orderpoint', 'Orderpoint', copy=False, index='not null') + orderpoint_id = fields.Many2one('stock.warehouse.orderpoint', 'Orderpoint', copy=False, index='btree_not_null') move_dest_ids = fields.One2many('stock.move', 'created_purchase_line_id', 'Downstream Moves') product_description_variants = fields.Char('Custom Description') propagate_cancel = fields.Boolean('Propagate cancellation', default=True) diff --git a/addons/purchase_stock/models/stock.py b/addons/purchase_stock/models/stock.py index 2d021dd2451..9093d91a402 100644 --- a/addons/purchase_stock/models/stock.py +++ b/addons/purchase_stock/models/stock.py @@ -18,7 +18,7 @@ class StockMove(models.Model): _inherit = 'stock.move' purchase_line_id = fields.Many2one('purchase.order.line', - 'Purchase Order Line', ondelete='set null', index='not null', readonly=True) + 'Purchase Order Line', ondelete='set null', index='btree_not_null', readonly=True) created_purchase_line_id = fields.Many2one('purchase.order.line', 'Created Purchase Order Line', ondelete='set null', readonly=True, copy=False) diff --git a/addons/repair/models/repair.py b/addons/repair/models/repair.py index 245685bd189..0a067f34e17 100644 --- a/addons/repair/models/repair.py +++ b/addons/repair/models/repair.py @@ -24,7 +24,7 @@ class Repair(models.Model): name = fields.Char( 'Repair Reference', - default='New', index='gin', + default='New', index='trigram', copy=False, required=True, readonly=True) description = fields.Char('Repair Description') diff --git a/addons/sale/models/sale_order.py b/addons/sale/models/sale_order.py index e2a146fdc7a..8b1c0855849 100644 --- a/addons/sale/models/sale_order.py +++ b/addons/sale/models/sale_order.py @@ -138,7 +138,7 @@ class SaleOrder(models.Model): name = fields.Char( string='Order Reference', required=True, copy=False, readonly=True, - states={'draft': [('readonly', False)]}, index='gin', default=lambda self: _('New')) + states={'draft': [('readonly', False)]}, index='trigram', default=lambda self: _('New')) origin = fields.Char(string='Source Document', help="Reference of the document that generated this sales order request.") client_order_ref = fields.Char(string='Customer Reference', copy=False) reference = fields.Char(string='Payment Ref.', copy=False, diff --git a/addons/sale_project/models/project.py b/addons/sale_project/models/project.py index 26b5e04dc87..6de2ed1c4c9 100644 --- a/addons/sale_project/models/project.py +++ b/addons/sale_project/models/project.py @@ -12,7 +12,7 @@ class Project(models.Model): sale_line_id = fields.Many2one( 'sale.order.line', 'Sales Order Item', copy=False, - compute="_compute_sale_line_id", store=True, readonly=False, index='not null', + compute="_compute_sale_line_id", store=True, readonly=False, index='btree_not_null', domain="[('is_service', '=', True), ('is_expense', '=', False), ('state', 'in', ['sale', 'done']), ('order_partner_id', '=?', partner_id), '|', ('company_id', '=', False), ('company_id', '=', company_id)]", help="Sales order item to which the project is linked. Link the timesheet entry to the sales order item defined on the project. " "Only applies on tasks without sale order item defined, and if the employee is not in the 'Employee/Sales Order Item Mapping' of the project.") @@ -141,7 +141,7 @@ class ProjectTask(models.Model): sale_order_id = fields.Many2one('sale.order', 'Sales Order', compute='_compute_sale_order_id', store=True, help="Sales order to which the task is linked.") sale_line_id = fields.Many2one( 'sale.order.line', 'Sales Order Item', - copy=False, tracking=True, index='not null', recursive=True, + copy=False, tracking=True, index='btree_not_null', recursive=True, compute='_compute_sale_line', store=True, readonly=False, domain="[('company_id', '=', company_id), ('is_service', '=', True), ('order_partner_id', 'child_of', commercial_partner_id), ('is_expense', '=', False), ('state', 'in', ['sale', 'done'])]", help="Sales Order Item to which the time spent on this task will be added, in order to be invoiced to your customer.") diff --git a/addons/sale_purchase/models/purchase_order.py b/addons/sale_purchase/models/purchase_order.py index 5b36cd500df..4f289d65e36 100644 --- a/addons/sale_purchase/models/purchase_order.py +++ b/addons/sale_purchase/models/purchase_order.py @@ -71,4 +71,4 @@ class PurchaseOrderLine(models.Model): _inherit = 'purchase.order.line' sale_order_id = fields.Many2one(related='sale_line_id.order_id', string="Sale Order", store=True, readonly=True) - sale_line_id = fields.Many2one('sale.order.line', string="Origin Sale Item", index='not null', copy=False) + sale_line_id = fields.Many2one('sale.order.line', string="Origin Sale Item", index='btree_not_null', copy=False) diff --git a/addons/sale_stock/models/stock.py b/addons/sale_stock/models/stock.py index bff9c1a691f..0a3c081ad02 100644 --- a/addons/sale_stock/models/stock.py +++ b/addons/sale_stock/models/stock.py @@ -14,7 +14,7 @@ class StockRoute(models.Model): class StockMove(models.Model): _inherit = "stock.move" - sale_line_id = fields.Many2one('sale.order.line', 'Sale Line', index="not null") + sale_line_id = fields.Many2one('sale.order.line', 'Sale Line', index='btree_not_null') @api.model def _prepare_merge_moves_distinct_fields(self): diff --git a/addons/sms/models/mail_notification.py b/addons/sms/models/mail_notification.py index 5b6ac6c6653..5fdfc33f477 100644 --- a/addons/sms/models/mail_notification.py +++ b/addons/sms/models/mail_notification.py @@ -10,7 +10,7 @@ class MailNotification(models.Model): notification_type = fields.Selection(selection_add=[ ('sms', 'SMS') ], ondelete={'sms': 'set default'}) - sms_id = fields.Many2one('sms.sms', string='SMS', index='not null', ondelete='set null') + sms_id = fields.Many2one('sms.sms', string='SMS', index='btree_not_null', ondelete='set null') sms_number = fields.Char('SMS Number') failure_type = fields.Selection(selection_add=[ ('sms_number_missing', 'Missing Number'), diff --git a/addons/snailmail/models/mail_notification.py b/addons/snailmail/models/mail_notification.py index cd9507c510f..c1046ebf6c5 100644 --- a/addons/snailmail/models/mail_notification.py +++ b/addons/snailmail/models/mail_notification.py @@ -7,7 +7,7 @@ class Notification(models.Model): _inherit = 'mail.notification' notification_type = fields.Selection(selection_add=[('snail', 'Snailmail')], ondelete={'snail': 'cascade'}) - letter_id = fields.Many2one('snailmail.letter', string="Snailmail Letter", index="not null", ondelete='cascade') + letter_id = fields.Many2one('snailmail.letter', string="Snailmail Letter", index='btree_not_null', ondelete='cascade') failure_type = fields.Selection(selection_add=[ ('sn_credit', "Snailmail Credit Error"), ('sn_trial', "Snailmail Trial Error"), diff --git a/addons/stock/models/stock_lot.py b/addons/stock/models/stock_lot.py index c2de4906099..b7da9a19d57 100644 --- a/addons/stock/models/stock_lot.py +++ b/addons/stock/models/stock_lot.py @@ -17,7 +17,7 @@ class StockLot(models.Model): name = fields.Char( 'Lot/Serial Number', default=lambda self: self.env['ir.sequence'].next_by_code('stock.lot.serial'), - required=True, help="Unique Lot/Serial Number", index='gin') + required=True, help="Unique Lot/Serial Number", index='trigram') ref = fields.Char('Internal Reference', help="Internal reference number in case it differs from the manufacturer's lot/serial number") product_id = fields.Many2one( 'product.product', 'Product', index=True, diff --git a/addons/stock/models/stock_picking.py b/addons/stock/models/stock_picking.py index 24941da3527..589792f7b2b 100644 --- a/addons/stock/models/stock_picking.py +++ b/addons/stock/models/stock_picking.py @@ -259,15 +259,15 @@ class Picking(models.Model): name = fields.Char( 'Reference', default='/', - copy=False, index='gin', readonly=True) + copy=False, index='trigram', readonly=True) origin = fields.Char( - 'Source Document', index='gin', + 'Source Document', index='trigram', states={'done': [('readonly', True)], 'cancel': [('readonly', True)]}, help="Reference of the document") note = fields.Html('Notes') backorder_id = fields.Many2one( 'stock.picking', 'Back Order of', - copy=False, index='not null', readonly=True, + copy=False, index='btree_not_null', readonly=True, check_company=True, help="If this shipment was split, then this field links to the shipment which contains the already processed part.") backorder_ids = fields.One2many('stock.picking', 'backorder_id', 'Back Orders') diff --git a/addons/stock/models/stock_quant.py b/addons/stock/models/stock_quant.py index 61bb330105c..817d5fb4456 100644 --- a/addons/stock/models/stock_quant.py +++ b/addons/stock/models/stock_quant.py @@ -1040,7 +1040,7 @@ class QuantPackage(models.Model): _order = 'name' name = fields.Char( - 'Package Reference', copy=False, index='gin', + 'Package Reference', copy=False, index='trigram', default=lambda self: self.env['ir.sequence'].next_by_code('stock.quant.package') or _('Unknown Pack')) quant_ids = fields.One2many('stock.quant', 'package_id', 'Bulk Content', readonly=True, domain=['|', ('quantity', '!=', 0), ('reserved_quantity', '!=', 0)]) @@ -1054,7 +1054,7 @@ class QuantPackage(models.Model): index=True, readonly=True, store=True) owner_id = fields.Many2one( 'res.partner', 'Owner', compute='_compute_package_info', search='_search_owner', - index='not null', readonly=True, compute_sudo=True) + index='btree_not_null', readonly=True, compute_sudo=True) package_use = fields.Selection([ ('disposable', 'Disposable Box'), ('reusable', 'Reusable Box'), diff --git a/addons/stock_account/models/account_move.py b/addons/stock_account/models/account_move.py index f0f3e88e110..eafebb7b535 100644 --- a/addons/stock_account/models/account_move.py +++ b/addons/stock_account/models/account_move.py @@ -6,7 +6,7 @@ from odoo import fields, models class AccountMove(models.Model): _inherit = 'account.move' - stock_move_id = fields.Many2one('stock.move', string='Stock Move', index='not null') + stock_move_id = fields.Many2one('stock.move', string='Stock Move', index='btree_not_null') stock_valuation_layer_ids = fields.One2many('stock.valuation.layer', 'account_move_id', string='Stock Valuation Layer') # ------------------------------------------------------------------------- diff --git a/addons/website/models/website_visitor.py b/addons/website/models/website_visitor.py index 616046a6518..400afd00a7f 100644 --- a/addons/website/models/website_visitor.py +++ b/addons/website/models/website_visitor.py @@ -34,7 +34,7 @@ class WebsiteVisitor(models.Model): access_token = fields.Char(required=True, default=lambda x: uuid.uuid4().hex, copy=False, groups='website.group_website_publisher') active = fields.Boolean('Active', default=True) website_id = fields.Many2one('website', "Website", readonly=True) - partner_id = fields.Many2one('res.partner', string="Contact", help="Partner of the last logged in user.", index="not null") + partner_id = fields.Many2one('res.partner', string="Contact", help="Partner of the last logged in user.", index='btree_not_null') partner_image = fields.Binary(related='partner_id.image_1920') # localisation and info diff --git a/addons/website_crm_iap_reveal/models/crm_lead.py b/addons/website_crm_iap_reveal/models/crm_lead.py index 1e8b044aaa1..074a651a14c 100644 --- a/addons/website_crm_iap_reveal/models/crm_lead.py +++ b/addons/website_crm_iap_reveal/models/crm_lead.py @@ -9,7 +9,7 @@ class Lead(models.Model): reveal_ip = fields.Char(string='IP Address') reveal_iap_credits = fields.Integer(string='IAP Credits') - reveal_rule_id = fields.Many2one('crm.reveal.rule', string='Lead Generation Rule', index='not null') + reveal_rule_id = fields.Many2one('crm.reveal.rule', string='Lead Generation Rule', index='btree_not_null') def _merge_get_fields(self): return super(Lead, self)._merge_get_fields() + ['reveal_ip', 'reveal_iap_credits', 'reveal_rule_id'] diff --git a/addons/website_crm_iap_reveal/models/crm_reveal_view.py b/addons/website_crm_iap_reveal/models/crm_reveal_view.py index b48b2fede02..b08f096ae33 100644 --- a/addons/website_crm_iap_reveal/models/crm_reveal_view.py +++ b/addons/website_crm_iap_reveal/models/crm_reveal_view.py @@ -13,7 +13,7 @@ class CRMRevealView(models.Model): _order = 'id desc' reveal_ip = fields.Char(string='IP Address') - reveal_rule_id = fields.Many2one('crm.reveal.rule', string='Lead Generation Rule', index='not null') + reveal_rule_id = fields.Many2one('crm.reveal.rule', string='Lead Generation Rule', index='btree_not_null') reveal_state = fields.Selection([('to_process', 'To Process'), ('not_found', 'Not Found')], default='to_process', string="State", index=True) create_date = fields.Datetime(index=True) diff --git a/addons/website_crm_partner_assign/models/crm_lead.py b/addons/website_crm_partner_assign/models/crm_lead.py index 51c4ac7d6ed..f5038e49a26 100644 --- a/addons/website_crm_partner_assign/models/crm_lead.py +++ b/addons/website_crm_partner_assign/models/crm_lead.py @@ -14,7 +14,7 @@ class CrmLead(models.Model): partner_latitude = fields.Float('Geo Latitude', digits=(10, 7)) partner_longitude = fields.Float('Geo Longitude', digits=(10, 7)) - partner_assigned_id = fields.Many2one('res.partner', 'Assigned Partner', tracking=True, domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]", help="Partner this case has been forwarded/assigned to.", index="not null") + partner_assigned_id = fields.Many2one('res.partner', 'Assigned Partner', tracking=True, domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]", help="Partner this case has been forwarded/assigned to.", index='btree_not_null') partner_declined_ids = fields.Many2many( 'res.partner', 'crm_lead_declined_partner', diff --git a/addons/website_crm_partner_assign/models/res_partner.py b/addons/website_crm_partner_assign/models/res_partner.py index 5d07a55bf40..47b076024bf 100644 --- a/addons/website_crm_partner_assign/models/res_partner.py +++ b/addons/website_crm_partner_assign/models/res_partner.py @@ -57,7 +57,7 @@ class ResPartner(models.Model): help="This should be a numerical value greater than 0 which will decide the contention for this partner to take this lead/opportunity.") grade_id = fields.Many2one('res.partner.grade', 'Partner Level', tracking=True) grade_sequence = fields.Integer(related='grade_id.sequence', readonly=True, store=True) - activation = fields.Many2one('res.partner.activation', 'Activation', index='not null', tracking=True) + activation = fields.Many2one('res.partner.activation', 'Activation', index='btree_not_null', tracking=True) date_partnership = fields.Date('Partnership Date') date_review = fields.Date('Latest Partner Review') date_review_next = fields.Date('Next Partner Review') diff --git a/addons/website_event/models/website_visitor.py b/addons/website_event/models/website_visitor.py index 2db2d7c606d..bbc0fec190a 100644 --- a/addons/website_event/models/website_visitor.py +++ b/addons/website_event/models/website_visitor.py @@ -9,7 +9,7 @@ class WebsiteVisitor(models.Model): _inherit = ['website.visitor'] parent_id = fields.Many2one( - 'website.visitor', string="Parent", ondelete='set null', index="not null", + 'website.visitor', string="Parent", ondelete='set null', index='btree_not_null', help="Main identity") event_registration_ids = fields.One2many( 'event.registration', 'visitor_id', string='Event Registrations', diff --git a/addons/website_livechat/models/website_visitor.py b/addons/website_livechat/models/website_visitor.py index 763e8344229..28b2587c8f7 100644 --- a/addons/website_livechat/models/website_visitor.py +++ b/addons/website_livechat/models/website_visitor.py @@ -12,7 +12,7 @@ from odoo.http import request class WebsiteVisitor(models.Model): _inherit = 'website.visitor' - livechat_operator_id = fields.Many2one('res.partner', compute='_compute_livechat_operator_id', store=True, string='Speaking with', index="not null") + livechat_operator_id = fields.Many2one('res.partner', compute='_compute_livechat_operator_id', store=True, string='Speaking with', index='btree_not_null') livechat_operator_name = fields.Char('Operator Name', related="livechat_operator_id.name") mail_channel_ids = fields.One2many('mail.channel', 'livechat_visitor_id', string="Visitor's livechat channels", readonly=True) diff --git a/addons/website_sale/models/website_visitor.py b/addons/website_sale/models/website_visitor.py index 13ebad3dfd9..37d7af38781 100644 --- a/addons/website_sale/models/website_visitor.py +++ b/addons/website_sale/models/website_visitor.py @@ -8,7 +8,7 @@ from odoo import fields, models, api class WebsiteTrack(models.Model): _inherit = 'website.track' - product_id = fields.Many2one('product.product', ondelete='cascade', readonly=True, index="not null") + product_id = fields.Many2one('product.product', ondelete='cascade', readonly=True, index='btree_not_null') class WebsiteVisitor(models.Model): diff --git a/odoo/addons/base/models/ir_attachment.py b/odoo/addons/base/models/ir_attachment.py index 0a95ac61aea..815d0781ee4 100644 --- a/odoo/addons/base/models/ir_attachment.py +++ b/odoo/addons/base/models/ir_attachment.py @@ -384,7 +384,7 @@ class IrAttachment(models.Model): type = fields.Selection([('url', 'URL'), ('binary', 'File')], string='Type', required=True, default='binary', change_default=True, help="You can either upload a file from your computer or copy/paste an internet link to your file.") - url = fields.Char('Url', index="not null", size=1024) + url = fields.Char('Url', index='btree_not_null', size=1024) public = fields.Boolean('Is public document') # for external access diff --git a/odoo/fields.py b/odoo/fields.py index 536d33e9314..ada910744e9 100644 --- a/odoo/fields.py +++ b/odoo/fields.py @@ -112,14 +112,15 @@ class Field(MetaField('DummyField', (object,), {})): :param bool required: whether the value of the field is required (default: ``False``) - :param bool index: whether the field is indexed in database. Note: no effect - on non-stored and virtual fields. (default: ``False``) Possible attributes: + :param str index: whether the field is indexed in database, and the kind of index. + Note: this has no effect on non-stored and virtual fields. + The possible values are: - * ``True``: auto-detect (currently set to btree) - * ``btree``: standard index, good for many2one - * ``not null``: btree without indexing NULL values (usefull when 90% of values are NULL) - * ``gin``: Generalized Inverted Indexes (GIN). Better for full-text search. - * ``False``: no index (default) + * ``"btree"`` or ``True``: standard index, good for many2one + * ``"btree_not_null"``: BTREE index without NULL values (useful when most + values are NULL, or when NULL is never searched for) + * ``"trigram"``: Generalized Inverted Index (GIN) with trigrams (good for full-text search) + * ``None`` or ``False``: no index (default) :param default: the default value for the field; this is either a static value, or a function taking a recordset and returning a value; use @@ -261,7 +262,7 @@ class Field(MetaField('DummyField', (object,), {})): comodel_name = None # name of the model of values (if relational) store = True # whether the field is stored in database - index = False # whether the field is indexed in database + index = None # how the field is indexed in database manual = False # whether the field is a custom field copy = True # whether the field is copied over by BaseModel.copy() _depends = None # collection of field dependencies diff --git a/odoo/modules/registry.py b/odoo/modules/registry.py index 3f4160f68e2..6eb5032734c 100644 --- a/odoo/modules/registry.py +++ b/odoo/modules/registry.py @@ -458,7 +458,7 @@ class Registry(Mapping): def check_indexes(self, cr, model_names): """ Create or drop column indexes for the given models. """ expected = [ - ("%s_%s_index" % (Model._table, field.name), Model, field.name, field) + (f"{Model._table}_{field.name}_index", Model._table, field.name, field.index) for model_name in model_names for Model in [self.models[model_name]] if Model._auto and not Model._abstract @@ -473,25 +473,21 @@ class Registry(Mapping): [tuple(row[0] for row in expected)]) existing = {row[0] for row in cr.fetchall()} - for indexname, model, columnname, field in expected: - tablename = model._table - index = field.index - assert index in ('btree', 'gin', 'not null', True, False) - if field.index and indexname not in existing: - where = '' + for indexname, tablename, columnname, index in expected: + assert index in ('btree', 'btree_not_null', 'trigram', True, False, None) + if index and indexname not in existing: method = 'btree' operator = '' - if index == 'not null': - where = ' WHERE "%s" IS NOT NULL' % columnname - if index == 'gin': - if trgm: - operator = 'gin_trgm_ops' - method = 'gin' - else: - method = "btree" + where = '' + if index == 'btree_not_null': + where = f'"{columnname}" IS NOT NULL' + elif index == 'trigram' and trgm: + method = 'gin' + operator = 'gin_trgm_ops' try: with cr.savepoint(flush=False): - sql.create_index(cr, indexname, tablename, ['"%s" %s' % (columnname, operator)], method, where) + expression = f'"{columnname}" {operator}' + sql.create_index(cr, indexname, tablename, [expression], method, where) except psycopg2.OperationalError: _schema.error("Unable to add index for %s", self) elif not index and indexname in existing: diff --git a/odoo/tools/sql.py b/odoo/tools/sql.py index 71209b5ff36..44e176668a1 100644 --- a/odoo/tools/sql.py +++ b/odoo/tools/sql.py @@ -247,7 +247,9 @@ def create_index(cr, indexname, tablename, expressions, method='btree', where='' if index_exists(cr, indexname): return args = ', '.join(expressions) - cr.execute('CREATE INDEX "{}" ON "{}" USING {} ({}) {}'.format(indexname, tablename, method, args, where)) + if where: + where = f' WHERE {where}' + cr.execute(f'CREATE INDEX "{indexname}" ON "{tablename}" USING {method} ({args}){where}') _schema.debug("Table %r: created index %r (%s)", tablename, indexname, args) def create_unique_index(cr, indexname, tablename, expressions):