from odoo import models, api


class EventCompassion(models.Model):

    _inherit = "crm.event.compassion"

    @api.model
    def create(self, vals):
        event = super().create(vals)
        if event.campaign_id:
            event.analytic_id.campaign_id = event.campaign_id
            event.origin_id.campaign_id = event.campaign_id
        return event

    @api.multi
    def write(self, vals):
        res = super().write(vals)
        for new_event in self:
            if new_event.campaign_id:
                new_event.analytic_id.campaign_id = new_event.campaign_id
                new_event.origin_id.campaign_id = new_event.campaign_id
        return res

from odoo import models, api


class EventCompassion(models.Model):

    _inherit = "crm.event.compassion"

    @api.model
    def create(self, vals):
        event = super().create(vals)
        if event.campaign_id:
            event.analytic_id.campaign_id = event.campaign_id
            event.origin_id.campaign_id = event.campaign_id
        return event

    @api.multi
    def write(self, vals):
        res = super().write(vals)
        for new_event in self:
            if new_event.campaign_id:
                if new_event.analytic_id:
                    new_event.analytic_id.campaign_id = new_event.campaign_id
                if new_event.origin_id:
                    new_event.origin_id.campaign_id = new_event.campaign_id
        return res

FIX bug in event creation
FIX bug in event creation

  from odoo import models, api
  
  
  class EventCompassion(models.Model):
  
      _inherit = "crm.event.compassion"
  
      @api.model
      def create(self, vals):
          event = super().create(vals)
          if event.campaign_id:
              event.analytic_id.campaign_id = event.campaign_id
              event.origin_id.campaign_id = event.campaign_id
          return event
  
      @api.multi
      def write(self, vals):
          res = super().write(vals)
          for new_event in self:
              if new_event.campaign_id:
+                 if new_event.analytic_id:
-                 new_event.analytic_id.campaign_id = new_event.campaign_id
+                     new_event.analytic_id.campaign_id = new_event.campaign_id
+                 if new_event.origin_id:
-                 new_event.origin_id.campaign_id = new_event.campaign_id
+                     new_event.origin_id.campaign_id = new_event.campaign_id
          return res
  
FIX bug in event creation
## Code Before:
from odoo import models, api


class EventCompassion(models.Model):

    _inherit = "crm.event.compassion"

    @api.model
    def create(self, vals):
        event = super().create(vals)
        if event.campaign_id:
            event.analytic_id.campaign_id = event.campaign_id
            event.origin_id.campaign_id = event.campaign_id
        return event

    @api.multi
    def write(self, vals):
        res = super().write(vals)
        for new_event in self:
            if new_event.campaign_id:
                new_event.analytic_id.campaign_id = new_event.campaign_id
                new_event.origin_id.campaign_id = new_event.campaign_id
        return res

## Instruction:
FIX bug in event creation
## Code After:
from odoo import models, api


class EventCompassion(models.Model):

    _inherit = "crm.event.compassion"

    @api.model
    def create(self, vals):
        event = super().create(vals)
        if event.campaign_id:
            event.analytic_id.campaign_id = event.campaign_id
            event.origin_id.campaign_id = event.campaign_id
        return event

    @api.multi
    def write(self, vals):
        res = super().write(vals)
        for new_event in self:
            if new_event.campaign_id:
                if new_event.analytic_id:
                    new_event.analytic_id.campaign_id = new_event.campaign_id
                if new_event.origin_id:
                    new_event.origin_id.campaign_id = new_event.campaign_id
        return res
