Esempio n. 1
0
def close_supply_point_case(domain, supply_point_id):
    if supply_point_id:
        close_case(
            supply_point_id,
            domain,
            const.COMMTRACK_USERNAME,
            __name__ + ".close_supply_point_case",
        )
Esempio n. 2
0
def close_supply_point_case(location):
    supply_point_id = location.supply_point_id
    if supply_point_id:
        close_case(
            supply_point_id,
            location.domain,
            const.COMMTRACK_USERNAME,
            __name__ + ".close_supply_point_case",
        )
Esempio n. 3
0
 def test_patch_closed_case(self):
     from casexml.apps.case.cleanup import close_case
     self.submit_form(make_test_form("form-1", case_id="case-1"))
     close_case("case-1", self.domain_name, "system", "test")
     self.do_migration(case_diff="none")
     clear_local_domain_sql_backend_override(self.domain_name)
     with self.augmented_couch_case("case-1") as case:
         case.name = "Zena"
         case.save()
         self.do_case_diffs()
Esempio n. 4
0
 def test_patch_case_open_in_couch_closed_in_sql(self):
     from casexml.apps.case.cleanup import close_case
     self.submit_form(make_test_form("form-1", case_id="case-1"))
     close_case("case-1", self.domain_name, "system", "test")
     self.do_migration(case_diff="none")
     with self.augmented_couch_case("case-1") as case:
         case.closed = False
         case.closed_by = None
         case.closed_on = None
         case.save()
         self.do_case_diffs()
Esempio n. 5
0
    def _close_case_and_remove_users(self):
        """
        Closes linked supply point cases for a location and unassigns the users
        assigned to that location.

        Used by both archive and delete methods
        """
        sp = self.linked_supply_point()
        # sanity check that the supply point exists and is still open.
        # this is important because if you archive a child, then try
        # to archive the parent, we don't want to try to close again
        if sp and not sp.closed:
            close_case(sp.case_id, self.domain, COMMTRACK_USERNAME)

        _unassign_users_from_location(self.domain, self.location_id)
Esempio n. 6
0
    def _close_case_and_remove_users(self):
        """
        Closes linked supply point cases for a location and unassigns the users
        assigned to that location.

        Used by both archive and delete methods
        """
        sp = self.linked_supply_point()
        # sanity check that the supply point exists and is still open.
        # this is important because if you archive a child, then try
        # to archive the parent, we don't want to try to close again
        if sp and not sp.closed:
            close_case(sp.case_id, self.domain, COMMTRACK_USERNAME)

        _unassign_users_from_location(self.domain, self.location_id)
Esempio n. 7
0
    def _archive_single_location(self):
        """
        Archive a single location, caller is expected to handle
        archiving children as well.

        This is just used to prevent having to do recursive
        couch queries in `archive()`.
        """
        self.is_archived = True
        self.save()

        sp = self.linked_supply_point()
        # sanity check that the supply point exists and is still open.
        # this is important because if you archive a child, then try
        # to archive the parent, we don't want to try to close again
        if sp and not sp.closed:
            close_case(sp._id, self.domain, COMMTRACK_USERNAME)
Esempio n. 8
0
    def _archive_single_location(self):
        """
        Archive a single location, caller is expected to handle
        archiving children as well.

        This is just used to prevent having to do recursive
        couch queries in `archive()`.
        """
        self.is_archived = True
        self.save()

        sp = self.linked_supply_point()
        # sanity check that the supply point exists and is still open.
        # this is important because if you archive a child, then try
        # to archive the parent, we don't want to try to close again
        if sp and not sp.closed:
            close_case(sp._id, self.domain, COMMTRACK_USERNAME)

        _unassign_users_from_location(self.domain, self._id)
Esempio n. 9
0
def close_case_view(request, domain, case_id):
    case = get_document_or_404(CommCareCase, domain, case_id)
    if case.closed:
        messages.info(request, u'Case {} is already closed.'.format(case.name))
    else:
        form_id = close_case(case_id, domain, request.couch_user)
        msg = _(u'''Case {name} has been closed.
            <a href="javascript:document.getElementById('{html_form_id}').submit();">Undo</a>.
            You can also reopen the case in the future by archiving the last form in the case history.
            <form id="{html_form_id}" action="{url}" method="POST">
                <input type="hidden" name="closing_form" value="{xform_id}" />
            </form>
        '''.format(
            name=case.name,
            html_form_id='undo-close-case',
            xform_id=form_id,
            url=reverse('undo_close_case', args=[domain, case_id]),
        ))
        messages.success(request, mark_safe(msg), extra_tags='html')
    return HttpResponseRedirect(reverse('case_details', args=[domain, case_id]))
Esempio n. 10
0
    rebuild_case(case_id)
    messages.success(request,
                     _(u'Case %s was rebuilt from its forms.' % case.name))
    return HttpResponseRedirect(reverse('case_details', args=[domain,
                                                              case_id]))


@require_case_view_permission
@require_permission(Permissions.edit_data)
@require_POST
def close_case_view(request, domain, case_id):
    case = _get_case_or_404(domain, case_id)
    if case.closed:
        messages.info(request, u'Case {} is already closed.'.format(case.name))
    else:
        form_id = close_case(case_id, domain, request.couch_user)
        msg = _(u'''Case {name} has been closed.
            <a href="javascript:document.getElementById('{html_form_id}').submit();">Undo</a>.
            You can also reopen the case in the future by archiving the last form in the case history.
            <form id="{html_form_id}" action="{url}" method="POST">
                <input type="hidden" name="closing_form" value="{xform_id}" />
            </form>
        '''.format(
            name=case.name,
            html_form_id='undo-close-case',
            xform_id=form_id,
            url=reverse('undo_close_case', args=[domain, case_id]),
        ))
        messages.success(request, mark_safe(msg), extra_tags='html')
    return HttpResponseRedirect(reverse('case_details', args=[domain,
                                                              case_id]))
Esempio n. 11
0
def _make_location_admininstrative(location):
    supply_point_id = location.supply_point_id
    if supply_point_id:
        close_case(supply_point_id, location.domain, const.COMMTRACK_USERNAME)
    location.supply_point_id = None  # this will be saved soon anyways
Esempio n. 12
0
def _make_location_admininstrative(location):
    supply_point_id = location.supply_point_id
    if supply_point_id:
        close_case(supply_point_id, location.domain, const.COMMTRACK_USERNAME)
    location.supply_point_id = None  # this will be saved soon anyways