from odoo import api, models, fields, _
from odoo.exceptions import UserError


class ExportMailchimpWizard(models.TransientModel):
    _inherit = "partner.export.mailchimp"

    @api.multi
    def get_mailing_contact_id(self, partner_id, force_create=False):
        # Avoid exporting opt_out partner
        if force_create:
            partner = self.env["res.partner"].browse(partner_id)
            if partner.opt_out:
                return False
        # Push the partner_id in mailing_contact creation
        return super(
            ExportMailchimpWizard, self.with_context(default_partner_id=partner_id)
        ).get_mailing_contact_id(partner_id, force_create)

from odoo import api, models, fields, _
from odoo.exceptions import UserError


class ExportMailchimpWizard(models.TransientModel):
    _inherit = "partner.export.mailchimp"

    @api.multi
    def get_mailing_contact_id(self, partner_id, force_create=False):
        # Avoid exporting opt_out partner
        if force_create and partner_id.opt_out:
            return False
        # Push the partner_id in mailing_contact creation
        return super(
            ExportMailchimpWizard, self.with_context(default_partner_id=partner_id)
        ).get_mailing_contact_id(partner_id, force_create)

FIX opt_out prevention for mailchimp export
FIX opt_out prevention for mailchimp export

  from odoo import api, models, fields, _
  from odoo.exceptions import UserError
  
  
  class ExportMailchimpWizard(models.TransientModel):
      _inherit = "partner.export.mailchimp"
  
      @api.multi
      def get_mailing_contact_id(self, partner_id, force_create=False):
          # Avoid exporting opt_out partner
+         if force_create and partner_id.opt_out:
-         if force_create:
-             partner = self.env["res.partner"].browse(partner_id)
-             if partner.opt_out:
-                 return False
+             return False
          # Push the partner_id in mailing_contact creation
          return super(
              ExportMailchimpWizard, self.with_context(default_partner_id=partner_id)
          ).get_mailing_contact_id(partner_id, force_create)
  
FIX opt_out prevention for mailchimp export
## Code Before:
from odoo import api, models, fields, _
from odoo.exceptions import UserError


class ExportMailchimpWizard(models.TransientModel):
    _inherit = "partner.export.mailchimp"

    @api.multi
    def get_mailing_contact_id(self, partner_id, force_create=False):
        # Avoid exporting opt_out partner
        if force_create:
            partner = self.env["res.partner"].browse(partner_id)
            if partner.opt_out:
                return False
        # Push the partner_id in mailing_contact creation
        return super(
            ExportMailchimpWizard, self.with_context(default_partner_id=partner_id)
        ).get_mailing_contact_id(partner_id, force_create)

## Instruction:
FIX opt_out prevention for mailchimp export
## Code After:
from odoo import api, models, fields, _
from odoo.exceptions import UserError


class ExportMailchimpWizard(models.TransientModel):
    _inherit = "partner.export.mailchimp"

    @api.multi
    def get_mailing_contact_id(self, partner_id, force_create=False):
        # Avoid exporting opt_out partner
        if force_create and partner_id.opt_out:
            return False
        # Push the partner_id in mailing_contact creation
        return super(
            ExportMailchimpWizard, self.with_context(default_partner_id=partner_id)
        ).get_mailing_contact_id(partner_id, force_create)
