
from odoo import fields, models


class AccountMoveLine(models.Model):
    _inherit = 'account.move.line'

    payment_mode_id = fields.Many2one(
        'account.payment.mode',
        string='Payment Mode',
        domain="[('company_id', '=', company_id)]",
        ondelete='restrict'
    )


from odoo import fields, models


class AccountMoveLine(models.Model):
    _inherit = 'account.move.line'

    payment_mode_id = fields.Many2one(
        'account.payment.mode',
        string='Payment Mode',
        domain="[('company_id', '=', company_id)]",
        ondelete='restrict',
        index=True,
    )

Add indexes on account payment models
Add indexes on account payment models

The fields where the indexes are added are used in searches in
account_payment_order, which becomes really slow when a database have
many lines.

  
  from odoo import fields, models
  
  
  class AccountMoveLine(models.Model):
      _inherit = 'account.move.line'
  
      payment_mode_id = fields.Many2one(
          'account.payment.mode',
          string='Payment Mode',
          domain="[('company_id', '=', company_id)]",
-         ondelete='restrict'
+         ondelete='restrict',
+         index=True,
      )
  
Add indexes on account payment models
## Code Before:

from odoo import fields, models


class AccountMoveLine(models.Model):
    _inherit = 'account.move.line'

    payment_mode_id = fields.Many2one(
        'account.payment.mode',
        string='Payment Mode',
        domain="[('company_id', '=', company_id)]",
        ondelete='restrict'
    )

## Instruction:
Add indexes on account payment models
## Code After:

from odoo import fields, models


class AccountMoveLine(models.Model):
    _inherit = 'account.move.line'

    payment_mode_id = fields.Many2one(
        'account.payment.mode',
        string='Payment Mode',
        domain="[('company_id', '=', company_id)]",
        ondelete='restrict',
        index=True,
    )
