
from openupgradelib import openupgrade


@openupgrade.migrate(use_env=True)
def migrate(env, version):
    if not version:
        return

    cr = env.cr
    # Remove end reason on active sponsorships
    cr.execute("""
        UPDATE recurring_contract
        SET end_reason = NULL
        WHERE STATE NOT IN
        ('terminated', 'cancelled');
    """)


from openupgradelib import openupgrade


@openupgrade.migrate(use_env=True)
def migrate(env, version):
    if not version:
        return

    cr = env.cr
    # Remove end reason on active sponsorships
    cr.execute("""
        UPDATE recurring_contract
        SET end_reason = NULL
        WHERE STATE NOT IN
        ('terminated', 'cancelled');
    """)
    # Remove waiting_welcome state of non sponsorship contracts
    # or old contracts
    cr.execute("""
            UPDATE recurring_contract
            SET sds_state = 'active'
            WHERE sds_state = 'waiting_welcome'
            AND (type not in ('S', 'SC')
                 OR sds_state_date < current_date - INTERVAL '15 days');
        """)

FIX only sponsorships can go through waiting_welcome state
FIX only sponsorships can go through waiting_welcome state

  
  from openupgradelib import openupgrade
  
  
  @openupgrade.migrate(use_env=True)
  def migrate(env, version):
      if not version:
          return
  
      cr = env.cr
      # Remove end reason on active sponsorships
      cr.execute("""
          UPDATE recurring_contract
          SET end_reason = NULL
          WHERE STATE NOT IN
          ('terminated', 'cancelled');
      """)
+     # Remove waiting_welcome state of non sponsorship contracts
+     # or old contracts
+     cr.execute("""
+             UPDATE recurring_contract
+             SET sds_state = 'active'
+             WHERE sds_state = 'waiting_welcome'
+             AND (type not in ('S', 'SC')
+                  OR sds_state_date < current_date - INTERVAL '15 days');
+         """)
  
FIX only sponsorships can go through waiting_welcome state
## Code Before:

from openupgradelib import openupgrade


@openupgrade.migrate(use_env=True)
def migrate(env, version):
    if not version:
        return

    cr = env.cr
    # Remove end reason on active sponsorships
    cr.execute("""
        UPDATE recurring_contract
        SET end_reason = NULL
        WHERE STATE NOT IN
        ('terminated', 'cancelled');
    """)

## Instruction:
FIX only sponsorships can go through waiting_welcome state
## Code After:

from openupgradelib import openupgrade


@openupgrade.migrate(use_env=True)
def migrate(env, version):
    if not version:
        return

    cr = env.cr
    # Remove end reason on active sponsorships
    cr.execute("""
        UPDATE recurring_contract
        SET end_reason = NULL
        WHERE STATE NOT IN
        ('terminated', 'cancelled');
    """)
    # Remove waiting_welcome state of non sponsorship contracts
    # or old contracts
    cr.execute("""
            UPDATE recurring_contract
            SET sds_state = 'active'
            WHERE sds_state = 'waiting_welcome'
            AND (type not in ('S', 'SC')
                 OR sds_state_date < current_date - INTERVAL '15 days');
        """)
