
from odoo import models, api, fields


class CNABReturnMoveCode(models.Model):
    """
        CNAB return code, each Bank can has a list of Codes
    """
    _name = 'cnab.return.move.code'
    _description = 'CNAB Return Move Code'

    name = fields.Char(string='Name')
    code = fields.Char(string='Code')
    bank_id = fields.Many2one(
        string='Bank', comodel_name='res.bank'
    )
    payment_method_id = fields.Many2one(
        'account.payment.method', string='Payment Method'
    )
    # Fields used to create domain
    bank_code_bc = fields.Char(
        related='bank_id.code_bc',
    )
    payment_method_code = fields.Char(related='payment_method_id.code')

    @api.multi
    def name_get(self):
        result = []
        for record in self:
            result.append((
                record.id,  '%s - %s' % (
                    record.code, record.name)
            ))
        return result


from odoo import models, api, fields


class CNABReturnMoveCode(models.Model):
    """
        CNAB return code, each Bank can has a list of Codes
    """
    _name = 'cnab.return.move.code'
    _description = 'CNAB Return Move Code'

    name = fields.Char(
        string='Name',
        index=True,
    )
    code = fields.Char(
        string='Code',
        index=True,
    )
    bank_id = fields.Many2one(
        string='Bank',
        comodel_name='res.bank',
        index=True,
    )
    payment_method_id = fields.Many2one(
        comodel_name='account.payment.method',
        string='Payment Method',
        index=True,
    )
    # Fields used to create domain
    bank_code_bc = fields.Char(
        related='bank_id.code_bc',
        store=True,
    )
    payment_method_code = fields.Char(
        related='payment_method_id.code',
        store=True,
    )

    @api.multi
    def name_get(self):
        result = []
        for record in self:
            result.append((
                record.id,  '%s - %s' % (
                    record.code, record.name)
            ))
        return result

Index and code improve cnab.return.move.code
[REF] Index and code improve cnab.return.move.code

Signed-off-by: Luis Felipe Mileo <c9a5b4d335634d99740001a1172b3e56e4fc5aa8@kmee.com.br>

  
  from odoo import models, api, fields
  
  
  class CNABReturnMoveCode(models.Model):
      """
          CNAB return code, each Bank can has a list of Codes
      """
      _name = 'cnab.return.move.code'
      _description = 'CNAB Return Move Code'
  
-     name = fields.Char(string='Name')
+     name = fields.Char(
+         string='Name',
+         index=True,
+     )
-     code = fields.Char(string='Code')
+     code = fields.Char(
+         string='Code',
+         index=True,
+     )
      bank_id = fields.Many2one(
+         string='Bank',
-         string='Bank', comodel_name='res.bank'
+         comodel_name='res.bank',
+         index=True,
      )
      payment_method_id = fields.Many2one(
-         'account.payment.method', string='Payment Method'
+         comodel_name='account.payment.method',
+         string='Payment Method',
+         index=True,
      )
      # Fields used to create domain
      bank_code_bc = fields.Char(
          related='bank_id.code_bc',
+         store=True,
      )
-     payment_method_code = fields.Char(related='payment_method_id.code')
+     payment_method_code = fields.Char(
+         related='payment_method_id.code',
+         store=True,
+     )
  
      @api.multi
      def name_get(self):
          result = []
          for record in self:
              result.append((
                  record.id,  '%s - %s' % (
                      record.code, record.name)
              ))
          return result
  
Index and code improve cnab.return.move.code
## Code Before:

from odoo import models, api, fields


class CNABReturnMoveCode(models.Model):
    """
        CNAB return code, each Bank can has a list of Codes
    """
    _name = 'cnab.return.move.code'
    _description = 'CNAB Return Move Code'

    name = fields.Char(string='Name')
    code = fields.Char(string='Code')
    bank_id = fields.Many2one(
        string='Bank', comodel_name='res.bank'
    )
    payment_method_id = fields.Many2one(
        'account.payment.method', string='Payment Method'
    )
    # Fields used to create domain
    bank_code_bc = fields.Char(
        related='bank_id.code_bc',
    )
    payment_method_code = fields.Char(related='payment_method_id.code')

    @api.multi
    def name_get(self):
        result = []
        for record in self:
            result.append((
                record.id,  '%s - %s' % (
                    record.code, record.name)
            ))
        return result

## Instruction:
Index and code improve cnab.return.move.code
## Code After:

from odoo import models, api, fields


class CNABReturnMoveCode(models.Model):
    """
        CNAB return code, each Bank can has a list of Codes
    """
    _name = 'cnab.return.move.code'
    _description = 'CNAB Return Move Code'

    name = fields.Char(
        string='Name',
        index=True,
    )
    code = fields.Char(
        string='Code',
        index=True,
    )
    bank_id = fields.Many2one(
        string='Bank',
        comodel_name='res.bank',
        index=True,
    )
    payment_method_id = fields.Many2one(
        comodel_name='account.payment.method',
        string='Payment Method',
        index=True,
    )
    # Fields used to create domain
    bank_code_bc = fields.Char(
        related='bank_id.code_bc',
        store=True,
    )
    payment_method_code = fields.Char(
        related='payment_method_id.code',
        store=True,
    )

    @api.multi
    def name_get(self):
        result = []
        for record in self:
            result.append((
                record.id,  '%s - %s' % (
                    record.code, record.name)
            ))
        return result
