[FIX] *: add indexes
Deleting a partner may take a long time because odoo has to check an entire table to find few records or no records at all that reference the partner and set it to null. So we are adding an index btree not null to speed up the deletion of partners. closes odoo/odoo#160184 Task-id: 3759406 Related: odoo/enterprise#59932 Signed-off-by: Pierre Masereel (pim) <pim@odoo.com>
This commit is contained in:
@@ -39,7 +39,7 @@ class Applicant(models.Model):
|
||||
inverse='_inverse_partner_email', store=True, index='trigram')
|
||||
email_normalized = fields.Char(index='trigram') # inherited via mail.thread.blacklist
|
||||
probability = fields.Float("Probability")
|
||||
partner_id = fields.Many2one('res.partner', "Contact", copy=False)
|
||||
partner_id = fields.Many2one('res.partner', "Contact", copy=False, index='btree_not_null')
|
||||
create_date = fields.Datetime("Applied on", readonly=True)
|
||||
stage_id = fields.Many2one('hr.recruitment.stage', 'Stage', ondelete='restrict', tracking=True,
|
||||
compute='_compute_stage', store=True, readonly=False,
|
||||
|
||||
@@ -22,7 +22,7 @@ class DiscussChannel(models.Model):
|
||||
duration = fields.Float('Duration', compute='_compute_duration', help='Duration of the session in hours')
|
||||
livechat_active = fields.Boolean('Is livechat ongoing?', help='Livechat session is active until visitor leaves the conversation.')
|
||||
livechat_channel_id = fields.Many2one('im_livechat.channel', 'Channel')
|
||||
livechat_operator_id = fields.Many2one('res.partner', string='Operator')
|
||||
livechat_operator_id = fields.Many2one('res.partner', string='Operator', index='btree_not_null')
|
||||
chatbot_current_step_id = fields.Many2one('chatbot.script.step', string='Chatbot Current Step')
|
||||
chatbot_message_ids = fields.One2many('chatbot.message', 'discuss_channel_id', string='Chatbot Messages')
|
||||
country_id = fields.Many2one('res.country', string="Country", help="Country of the visitor of the channel")
|
||||
|
||||
@@ -9,7 +9,8 @@ class Rating(models.Model):
|
||||
# Adding information for comment a rating message
|
||||
publisher_comment = fields.Text("Publisher comment")
|
||||
publisher_id = fields.Many2one('res.partner', 'Commented by',
|
||||
ondelete='set null', readonly=True)
|
||||
ondelete='set null', readonly=True,
|
||||
index='btree_not_null')
|
||||
publisher_datetime = fields.Datetime("Commented on", readonly=True)
|
||||
|
||||
@api.model_create_multi
|
||||
|
||||
@@ -63,7 +63,7 @@ class PurchaseOrderLine(models.Model):
|
||||
qty_to_invoice = fields.Float(compute='_compute_qty_invoiced', string='To Invoice Quantity', store=True, readonly=True,
|
||||
digits='Product Unit of Measure')
|
||||
|
||||
partner_id = fields.Many2one('res.partner', related='order_id.partner_id', string='Partner', readonly=True, store=True)
|
||||
partner_id = fields.Many2one('res.partner', related='order_id.partner_id', string='Partner', readonly=True, store=True, index='btree_not_null')
|
||||
currency_id = fields.Many2one(related='order_id.currency_id', store=True, string='Currency', readonly=True)
|
||||
date_order = fields.Datetime(related='order_id.date_order', string='Order Date', readonly=True)
|
||||
date_approve = fields.Datetime(related="order_id.date_approve", string='Confirmation Date', readonly=True)
|
||||
|
||||
@@ -139,13 +139,15 @@ class SaleOrder(models.Model):
|
||||
string="Invoice Address",
|
||||
compute='_compute_partner_invoice_id',
|
||||
store=True, readonly=False, required=True, precompute=True,
|
||||
domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]")
|
||||
domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]",
|
||||
index='btree_not_null')
|
||||
partner_shipping_id = fields.Many2one(
|
||||
comodel_name='res.partner',
|
||||
string="Delivery Address",
|
||||
compute='_compute_partner_shipping_id',
|
||||
store=True, readonly=False, required=True, precompute=True,
|
||||
domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]",)
|
||||
domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]",
|
||||
index='btree_not_null')
|
||||
|
||||
fiscal_position_id = fields.Many2one(
|
||||
comodel_name='account.fiscal.position',
|
||||
|
||||
@@ -82,7 +82,8 @@ class StockMove(models.Model):
|
||||
partner_id = fields.Many2one(
|
||||
'res.partner', 'Destination Address ',
|
||||
help="Optional address where goods are to be delivered, specifically used for allotment",
|
||||
compute='_compute_partner_id', store=True, readonly=False)
|
||||
compute='_compute_partner_id', store=True, readonly=False,
|
||||
index='btree_not_null')
|
||||
move_dest_ids = fields.Many2many(
|
||||
'stock.move', 'stock_move_move_rel', 'move_orig_id', 'move_dest_id', 'Destination Moves',
|
||||
copy=False,
|
||||
@@ -147,7 +148,8 @@ class StockMove(models.Model):
|
||||
readonly=True, help='Quantity in stock that can still be reserved for this move')
|
||||
# used to depict a restriction on the ownership of quants to consider when marking this move as 'done'
|
||||
restrict_partner_id = fields.Many2one(
|
||||
'res.partner', 'Owner ', check_company=True)
|
||||
'res.partner', 'Owner ', check_company=True,
|
||||
index='btree_not_null')
|
||||
route_ids = fields.Many2many(
|
||||
'stock.route', 'stock_route_move', 'move_id', 'route_id', 'Destination route', help="Preferred route")
|
||||
warehouse_id = fields.Many2one('stock.warehouse', 'Warehouse', help="the warehouse to consider for the route selection on the next procurement (if any).")
|
||||
|
||||
@@ -56,7 +56,7 @@ class StockMoveLine(models.Model):
|
||||
date = fields.Datetime('Date', default=fields.Datetime.now, required=True)
|
||||
owner_id = fields.Many2one(
|
||||
'res.partner', 'From Owner',
|
||||
check_company=True,
|
||||
check_company=True, index='btree_not_null',
|
||||
help="When validating the transfer, the products will be taken from this owner.")
|
||||
location_id = fields.Many2one(
|
||||
'stock.location', 'From', domain="[('usage', '!=', 'view')]", check_company=True, required=True,
|
||||
|
||||
@@ -464,7 +464,7 @@ class Picking(models.Model):
|
||||
hide_picking_type = fields.Boolean(compute='_compute_hide_picking_type')
|
||||
partner_id = fields.Many2one(
|
||||
'res.partner', 'Contact',
|
||||
check_company=True)
|
||||
check_company=True, index='btree_not_null')
|
||||
company_id = fields.Many2one(
|
||||
'res.company', string='Company', related='picking_type_id.company_id',
|
||||
readonly=True, store=True, index=True)
|
||||
@@ -488,7 +488,7 @@ class Picking(models.Model):
|
||||
help='Technical Field used to decide whether the button "Allocation" should be displayed.')
|
||||
owner_id = fields.Many2one(
|
||||
'res.partner', 'Assign Owner',
|
||||
check_company=True,
|
||||
check_company=True, index='btree_not_null',
|
||||
help="When validating the transfer, the products will be assigned to this owner.")
|
||||
printed = fields.Boolean('Printed', copy=False)
|
||||
signature = fields.Image('Signature', help='Signature', copy=False, attachment=True)
|
||||
|
||||
@@ -73,7 +73,8 @@ class StockQuant(models.Model):
|
||||
help='The package containing this quant', ondelete='restrict', check_company=True, index=True)
|
||||
owner_id = fields.Many2one(
|
||||
'res.partner', 'Owner',
|
||||
help='This is the owner of the quant', check_company=True)
|
||||
help='This is the owner of the quant', check_company=True,
|
||||
index='btree_not_null')
|
||||
quantity = fields.Float(
|
||||
'Quantity',
|
||||
help='Quantity of products in this quant, in the default unit of measure of the product',
|
||||
|
||||
@@ -168,7 +168,7 @@ class BlogPost(models.Model):
|
||||
'''
|
||||
name = fields.Char('Title', required=True, translate=True, default='')
|
||||
subtitle = fields.Char('Sub Title', translate=True)
|
||||
author_id = fields.Many2one('res.partner', 'Author', default=lambda self: self.env.user.partner_id)
|
||||
author_id = fields.Many2one('res.partner', 'Author', default=lambda self: self.env.user.partner_id, index='btree_not_null')
|
||||
author_avatar = fields.Binary(related='author_id.image_128', string="Avatar", readonly=False)
|
||||
author_name = fields.Char(related='author_id.display_name', string="Author Name", readonly=False, store=True)
|
||||
active = fields.Boolean('Active', default=True)
|
||||
|
||||
Reference in New Issue
Block a user