[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
This commit is contained in:
Raphael Collet
2022-01-28 14:10:01 +00:00
parent 5a573c6f18
commit a1904aa6f6
56 changed files with 98 additions and 99 deletions
+1 -1
View File
@@ -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)
+10 -10
View File
@@ -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)
+1 -1
View File
@@ -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")
+2 -2
View File
@@ -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)
+2 -2
View File
@@ -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,
+1 -1
View File
@@ -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']
+1 -1
View File
@@ -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)
+1 -1
View File
@@ -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.')
+1 -1
View File
@@ -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')
@@ -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',
+1 -1
View File
@@ -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(
@@ -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)
+1 -1
View File
@@ -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(
+1 -1
View File
@@ -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'
+1 -1
View File
@@ -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")
@@ -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',
@@ -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')
+1 -1
View File
@@ -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)
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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)
+3 -3
View File
@@ -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')
@@ -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')
+1 -1
View File
@@ -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')
+2 -2
View File
@@ -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(
+1 -1
View File
@@ -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(
+1 -1
View File
@@ -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()
+1 -1
View File
@@ -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)
+1 -1
View File
@@ -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)
+3 -3
View File
@@ -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.
+1 -1
View File
@@ -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):
+1 -1
View File
@@ -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,
+1 -1
View File
@@ -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)
+1 -1
View File
@@ -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)
+1 -1
View File
@@ -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')
+1 -1
View File
@@ -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,
+2 -2
View File
@@ -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.")
@@ -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)
+1 -1
View File
@@ -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):
+1 -1
View File
@@ -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'),
+1 -1
View File
@@ -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"),
+1 -1
View File
@@ -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,
+3 -3
View File
@@ -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')
+2 -2
View File
@@ -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'),
+1 -1
View File
@@ -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')
# -------------------------------------------------------------------------
+1 -1
View File
@@ -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
@@ -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']
@@ -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)
@@ -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',
@@ -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')
@@ -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',
@@ -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)
@@ -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):
+1 -1
View File
@@ -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
+9 -8
View File
@@ -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
+12 -16
View File
@@ -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:
+3 -1
View File
@@ -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):