
from openerp.osv import orm


class project_compassion(orm.Model):
    _inherit = 'compassion.project'

    def suspend_project(self, cr, uid, project_id,
                        start, context=None):
        """ When a project is suspended, We update all contracts of
        sponsored children in the project, so that we don't create invoices
        during the period of suspension.
        """
        project = self.browse(cr, uid, project_id, context)
        contract_obj = self.pool.get('recurring.contract')
        contract_ids = contract_obj.search(
            cr, uid, [('child_code', 'like', project.code),
                      ('state', 'in', ('active', 'waiting'))], context=context)
        # For now, suspend the contract for 3 months
        contract_obj.suspend_contract(cr, uid, contract_ids, start, 3, context)
        return True


from openerp.osv import orm


class project_compassion(orm.Model):
    _inherit = 'compassion.project'

    def suspend_project(self, cr, uid, project_id,
                        start, context=None):
        """ When a project is suspended, We update all contracts of
        sponsored children in the project, so that we don't create invoices
        during the period of suspension.
        We also remove the children on internet.
        """
        project = self.browse(cr, uid, project_id, context)
        contract_obj = self.pool.get('recurring.contract')
        contract_ids = contract_obj.search(cr, uid, [
            ('child_code', 'like', project.code),
            ('state', 'in', ('active', 'waiting'))], context=context)
        # For now, suspend the contract for 3 months
        contract_obj.suspend_contract(cr, uid, contract_ids, start, 3,
                                      context)

        # Children to remove from internet
        child_obj = self.pool.get('compassion.child')
        child_ids = child_obj.search(cr, uid, [
            ('code', 'like', project.code),
            ('state', '=', 'I')], context=context)
        if child_ids:
            child_obj.child_remove_from_typo3(cr, uid, child_ids, context)
        return True

Remove children of a suspended project from internet.
Remove children of a suspended project from internet.

  
  from openerp.osv import orm
  
  
  class project_compassion(orm.Model):
      _inherit = 'compassion.project'
  
      def suspend_project(self, cr, uid, project_id,
                          start, context=None):
          """ When a project is suspended, We update all contracts of
          sponsored children in the project, so that we don't create invoices
          during the period of suspension.
+         We also remove the children on internet.
          """
          project = self.browse(cr, uid, project_id, context)
          contract_obj = self.pool.get('recurring.contract')
-         contract_ids = contract_obj.search(
+         contract_ids = contract_obj.search(cr, uid, [
-             cr, uid, [('child_code', 'like', project.code),
+             ('child_code', 'like', project.code),
-                       ('state', 'in', ('active', 'waiting'))], context=context)
+             ('state', 'in', ('active', 'waiting'))], context=context)
          # For now, suspend the contract for 3 months
-         contract_obj.suspend_contract(cr, uid, contract_ids, start, 3, context)
+         contract_obj.suspend_contract(cr, uid, contract_ids, start, 3,
+                                       context)
+ 
+         # Children to remove from internet
+         child_obj = self.pool.get('compassion.child')
+         child_ids = child_obj.search(cr, uid, [
+             ('code', 'like', project.code),
+             ('state', '=', 'I')], context=context)
+         if child_ids:
+             child_obj.child_remove_from_typo3(cr, uid, child_ids, context)
          return True
  
Remove children of a suspended project from internet.
## Code Before:

from openerp.osv import orm


class project_compassion(orm.Model):
    _inherit = 'compassion.project'

    def suspend_project(self, cr, uid, project_id,
                        start, context=None):
        """ When a project is suspended, We update all contracts of
        sponsored children in the project, so that we don't create invoices
        during the period of suspension.
        """
        project = self.browse(cr, uid, project_id, context)
        contract_obj = self.pool.get('recurring.contract')
        contract_ids = contract_obj.search(
            cr, uid, [('child_code', 'like', project.code),
                      ('state', 'in', ('active', 'waiting'))], context=context)
        # For now, suspend the contract for 3 months
        contract_obj.suspend_contract(cr, uid, contract_ids, start, 3, context)
        return True

## Instruction:
Remove children of a suspended project from internet.
## Code After:

from openerp.osv import orm


class project_compassion(orm.Model):
    _inherit = 'compassion.project'

    def suspend_project(self, cr, uid, project_id,
                        start, context=None):
        """ When a project is suspended, We update all contracts of
        sponsored children in the project, so that we don't create invoices
        during the period of suspension.
        We also remove the children on internet.
        """
        project = self.browse(cr, uid, project_id, context)
        contract_obj = self.pool.get('recurring.contract')
        contract_ids = contract_obj.search(cr, uid, [
            ('child_code', 'like', project.code),
            ('state', 'in', ('active', 'waiting'))], context=context)
        # For now, suspend the contract for 3 months
        contract_obj.suspend_contract(cr, uid, contract_ids, start, 3,
                                      context)

        # Children to remove from internet
        child_obj = self.pool.get('compassion.child')
        child_ids = child_obj.search(cr, uid, [
            ('code', 'like', project.code),
            ('state', '=', 'I')], context=context)
        if child_ids:
            child_obj.child_remove_from_typo3(cr, uid, child_ids, context)
        return True
