from openerp import api, models


class SaleOrder(models.Model):
    _inherit = 'sale.order'

    @api.multi
    def action_button_confirm(self):
        project_obj = self.env['project.project']
        event_obj = self.env['event.event']
        res = super(SaleOrder, self).action_button_confirm()
        cond = [('analytic_account_id', '=', self.project_id.id)]
        project = project_obj.search(cond, limit=1)
        cond = [('project_id', '=', project.id)]
        events = event_obj.search(cond)
        for event in events:
            tickets = event.event_ticket_ids.filtered(
                lambda x: x.product_id.id ==
                self.env.ref('event_sale.product_product_event').id)
            tickets.unlink()
        return res

from openerp import api, models


class SaleOrder(models.Model):
    _inherit = 'sale.order'

    @api.multi
    def action_button_confirm(self):
        project_obj = self.env['project.project']
        event_obj = self.env['event.event']
        res = super(SaleOrder, self).action_button_confirm()
        for sale in self.filtered(lambda x: x.project_id):
            cond = [('analytic_account_id', '=', sale.project_id.id)]
            project = project_obj.search(cond, limit=1)
            cond = [('project_id', '=', project.id)]
            events = event_obj.search(cond)
            for event in events:
                tickets = event.event_ticket_ids.filtered(
                    lambda x: x.product_id.id ==
                    self.env.ref('event_sale.product_product_event').id)
                tickets.unlink()
        return res

Fix bug when in sales order lines there is a nonrecurring service.
[FIX] event_registration_analytic: Fix bug when in sales order lines there is a nonrecurring service.

  from openerp import api, models
  
  
  class SaleOrder(models.Model):
      _inherit = 'sale.order'
  
      @api.multi
      def action_button_confirm(self):
          project_obj = self.env['project.project']
          event_obj = self.env['event.event']
          res = super(SaleOrder, self).action_button_confirm()
+         for sale in self.filtered(lambda x: x.project_id):
-         cond = [('analytic_account_id', '=', self.project_id.id)]
+             cond = [('analytic_account_id', '=', sale.project_id.id)]
-         project = project_obj.search(cond, limit=1)
+             project = project_obj.search(cond, limit=1)
-         cond = [('project_id', '=', project.id)]
+             cond = [('project_id', '=', project.id)]
-         events = event_obj.search(cond)
+             events = event_obj.search(cond)
-         for event in events:
+             for event in events:
-             tickets = event.event_ticket_ids.filtered(
+                 tickets = event.event_ticket_ids.filtered(
-                 lambda x: x.product_id.id ==
+                     lambda x: x.product_id.id ==
-                 self.env.ref('event_sale.product_product_event').id)
+                     self.env.ref('event_sale.product_product_event').id)
-             tickets.unlink()
+                 tickets.unlink()
          return res
  
Fix bug when in sales order lines there is a nonrecurring service.
## Code Before:
from openerp import api, models


class SaleOrder(models.Model):
    _inherit = 'sale.order'

    @api.multi
    def action_button_confirm(self):
        project_obj = self.env['project.project']
        event_obj = self.env['event.event']
        res = super(SaleOrder, self).action_button_confirm()
        cond = [('analytic_account_id', '=', self.project_id.id)]
        project = project_obj.search(cond, limit=1)
        cond = [('project_id', '=', project.id)]
        events = event_obj.search(cond)
        for event in events:
            tickets = event.event_ticket_ids.filtered(
                lambda x: x.product_id.id ==
                self.env.ref('event_sale.product_product_event').id)
            tickets.unlink()
        return res

## Instruction:
Fix bug when in sales order lines there is a nonrecurring service.
## Code After:
from openerp import api, models


class SaleOrder(models.Model):
    _inherit = 'sale.order'

    @api.multi
    def action_button_confirm(self):
        project_obj = self.env['project.project']
        event_obj = self.env['event.event']
        res = super(SaleOrder, self).action_button_confirm()
        for sale in self.filtered(lambda x: x.project_id):
            cond = [('analytic_account_id', '=', sale.project_id.id)]
            project = project_obj.search(cond, limit=1)
            cond = [('project_id', '=', project.id)]
            events = event_obj.search(cond)
            for event in events:
                tickets = event.event_ticket_ids.filtered(
                    lambda x: x.product_id.id ==
                    self.env.ref('event_sale.product_product_event').id)
                tickets.unlink()
        return res
