
from odoo import models, fields, api


class EndContractWizard(models.TransientModel):
    _inherit = 'end.contract.wizard'

    generate_communication = fields.Boolean(
        'Create depart communication')

    @api.multi
    def end_contract(self):
        self.ensure_one()
        child = self.child_id

        if self.generate_communication:
            exit_config = self.env.ref(
                'partner_communication_switzerland.'
                'lifecycle_child_unplanned_exit')
            self.contract_id.with_context(
                default_object_ids=child.id,
                default_auto_send=False).send_communication(exit_config)

        return super(EndContractWizard, self).end_contract()


from odoo import models, fields, api


class EndContractWizard(models.TransientModel):
    _inherit = 'end.contract.wizard'

    generate_communication = fields.Boolean(
        'Create depart communication')

    @api.multi
    def end_contract(self):
        self.ensure_one()
        if self.generate_communication:
            exit_config = self.env.ref(
                'partner_communication_switzerland.'
                'lifecycle_child_unplanned_exit')
            self.contract_id.with_context(
                default_object_ids=self.contract_id.id,
                default_auto_send=False).send_communication(exit_config)

        return super(EndContractWizard, self).end_contract()

FIX end contract depart letter generation
FIX end contract depart letter generation

  
  from odoo import models, fields, api
  
  
  class EndContractWizard(models.TransientModel):
      _inherit = 'end.contract.wizard'
  
      generate_communication = fields.Boolean(
          'Create depart communication')
  
      @api.multi
      def end_contract(self):
          self.ensure_one()
-         child = self.child_id
- 
          if self.generate_communication:
              exit_config = self.env.ref(
                  'partner_communication_switzerland.'
                  'lifecycle_child_unplanned_exit')
              self.contract_id.with_context(
-                 default_object_ids=child.id,
+                 default_object_ids=self.contract_id.id,
                  default_auto_send=False).send_communication(exit_config)
  
          return super(EndContractWizard, self).end_contract()
  
FIX end contract depart letter generation
## Code Before:

from odoo import models, fields, api


class EndContractWizard(models.TransientModel):
    _inherit = 'end.contract.wizard'

    generate_communication = fields.Boolean(
        'Create depart communication')

    @api.multi
    def end_contract(self):
        self.ensure_one()
        child = self.child_id

        if self.generate_communication:
            exit_config = self.env.ref(
                'partner_communication_switzerland.'
                'lifecycle_child_unplanned_exit')
            self.contract_id.with_context(
                default_object_ids=child.id,
                default_auto_send=False).send_communication(exit_config)

        return super(EndContractWizard, self).end_contract()

## Instruction:
FIX end contract depart letter generation
## Code After:

from odoo import models, fields, api


class EndContractWizard(models.TransientModel):
    _inherit = 'end.contract.wizard'

    generate_communication = fields.Boolean(
        'Create depart communication')

    @api.multi
    def end_contract(self):
        self.ensure_one()
        if self.generate_communication:
            exit_config = self.env.ref(
                'partner_communication_switzerland.'
                'lifecycle_child_unplanned_exit')
            self.contract_id.with_context(
                default_object_ids=self.contract_id.id,
                default_auto_send=False).send_communication(exit_config)

        return super(EndContractWizard, self).end_contract()
