
from openerp import models, fields, api


class ResPartner(models.Model):
    _inherit = 'res.partner'

    registrations = fields.One2many(
        string="Event registrations",
        comodel_name='event.registration', inverse_name="partner_id")
    registration_count = fields.Integer(
        string='Event registrations number', compute='_count_registration',
        store=True)
    attended_registration_count = fields.Integer(
        string='Event attended registrations number',
        compute='_count_attended_registration', store=True)

    @api.one
    @api.depends('registrations')
    def _count_registration(self):
        self.registration_count = len(self.registrations)

    @api.one
    @api.depends('registrations')
    def _count_attended_registration(self):
        self.attended_registration_count = len(self.registrations.filtered(
            lambda x: x.state == 'done'))


from openerp import models, fields, api


class ResPartner(models.Model):
    _inherit = 'res.partner'

    registrations = fields.One2many(
        string="Event registrations",
        comodel_name='event.registration', inverse_name="partner_id")
    registration_count = fields.Integer(
        string='Event registrations number', compute='_count_registration',
        store=True)
    attended_registration_count = fields.Integer(
        string='Event attended registrations number',
        compute='_count_registration', store=True)

    @api.one
    @api.depends('registrations')
    def _count_registration(self):
        self.registration_count = len(self.registrations)
        self.attended_registration_count = len(self.registrations.filtered(
            lambda x: x.state == 'done'))

Use only one method to recalculate event counters
Use only one method to recalculate event counters

  
  from openerp import models, fields, api
  
  
  class ResPartner(models.Model):
      _inherit = 'res.partner'
  
      registrations = fields.One2many(
          string="Event registrations",
          comodel_name='event.registration', inverse_name="partner_id")
      registration_count = fields.Integer(
          string='Event registrations number', compute='_count_registration',
          store=True)
      attended_registration_count = fields.Integer(
          string='Event attended registrations number',
-         compute='_count_attended_registration', store=True)
+         compute='_count_registration', store=True)
  
      @api.one
      @api.depends('registrations')
      def _count_registration(self):
          self.registration_count = len(self.registrations)
- 
-     @api.one
-     @api.depends('registrations')
-     def _count_attended_registration(self):
          self.attended_registration_count = len(self.registrations.filtered(
              lambda x: x.state == 'done'))
  
Use only one method to recalculate event counters
## Code Before:

from openerp import models, fields, api


class ResPartner(models.Model):
    _inherit = 'res.partner'

    registrations = fields.One2many(
        string="Event registrations",
        comodel_name='event.registration', inverse_name="partner_id")
    registration_count = fields.Integer(
        string='Event registrations number', compute='_count_registration',
        store=True)
    attended_registration_count = fields.Integer(
        string='Event attended registrations number',
        compute='_count_attended_registration', store=True)

    @api.one
    @api.depends('registrations')
    def _count_registration(self):
        self.registration_count = len(self.registrations)

    @api.one
    @api.depends('registrations')
    def _count_attended_registration(self):
        self.attended_registration_count = len(self.registrations.filtered(
            lambda x: x.state == 'done'))

## Instruction:
Use only one method to recalculate event counters
## Code After:

from openerp import models, fields, api


class ResPartner(models.Model):
    _inherit = 'res.partner'

    registrations = fields.One2many(
        string="Event registrations",
        comodel_name='event.registration', inverse_name="partner_id")
    registration_count = fields.Integer(
        string='Event registrations number', compute='_count_registration',
        store=True)
    attended_registration_count = fields.Integer(
        string='Event attended registrations number',
        compute='_count_registration', store=True)

    @api.one
    @api.depends('registrations')
    def _count_registration(self):
        self.registration_count = len(self.registrations)
        self.attended_registration_count = len(self.registrations.filtered(
            lambda x: x.state == 'done'))
