Пример #1
0
    def _rebuild_case_from_transactions(case, detail, updated_xforms=None):
        transactions = get_case_transactions(case.case_id, updated_xforms=updated_xforms)
        strategy = SqlCaseUpdateStrategy(case)

        rebuild_transaction = CaseTransaction.rebuild_transaction(case, detail)
        strategy.rebuild_from_transactions(transactions, rebuild_transaction)
        return case
Пример #2
0
    def _rebuild_case_from_transactions(case, detail, updated_xforms=None):
        transactions = get_case_transactions(case.case_id, updated_xforms=updated_xforms)
        strategy = SqlCaseUpdateStrategy(case)

        rebuild_transaction = CaseTransaction.rebuild_transaction(case, detail)
        unarchived_form_id = None
        if detail.type == CaseTransaction.TYPE_REBUILD_FORM_ARCHIVED and not detail.archived:
            # we're rebuilding because a form was un-archived
            unarchived_form_id = detail.form_id
        strategy.rebuild_from_transactions(
            transactions, rebuild_transaction, unarchived_form_id=unarchived_form_id
        )
        return case
Пример #3
0
    def _rebuild_case_from_transactions(case, detail, updated_xforms=None):
        transactions = CaseAccessorSQL.get_case_transactions_by_case_id(
            case,
            updated_xforms=updated_xforms)
        strategy = SqlCaseUpdateStrategy(case)

        rebuild_transaction = CaseTransaction.rebuild_transaction(case, detail)
        if updated_xforms:
            rebuild_transaction.server_date = updated_xforms[0].edited_on
        unarchived_form_id = None
        if detail.type == CaseTransaction.TYPE_REBUILD_FORM_ARCHIVED and not detail.archived:
            # we're rebuilding because a form was un-archived
            unarchived_form_id = detail.form_id
        strategy.rebuild_from_transactions(
            transactions, rebuild_transaction, unarchived_form_id=unarchived_form_id
        )
        return case, rebuild_transaction
Пример #4
0
    def reconcile_transactions(self):
        transactions = self.case.transactions
        sorted_transactions = sorted(
            transactions,
            key=_transaction_sort_key_function(self.case)
        )
        if sorted_transactions:
            if not sorted_transactions[0].is_case_create:
                error = "Case {0} first transaction not create transaction: {1}"
                raise ReconciliationError(
                    error.format(self.case.case_id, sorted_transactions[0])
                )

        CaseAccessorSQL.fetch_case_transaction_forms(self.case, sorted_transactions)
        rebuild_detail = RebuildWithReason(reason="client_date_reconciliation")
        rebuild_transaction = CaseTransaction.rebuild_transaction(self.case, rebuild_detail)
        self.rebuild_from_transactions(sorted_transactions, rebuild_transaction)
    def test_ignores_before_rebuild_transaction(self):
        with freeze_time("2018-10-10"):
            case = self._create_case()

        with freeze_time("2018-10-11"):
            new_old_xform = self._create_form()
        with freeze_time("2018-10-08"):
            new_old_trans = self._create_case_transaction(case, new_old_xform)
        with freeze_time("2018-10-11"):
            case.track_create(new_old_trans)
            FormProcessorSQL.save_processed_models(ProcessedForms(new_old_xform, []), [case])

        self.assertFalse(case.check_transaction_order())

        with freeze_time("2018-10-13"):
            new_rebuild_xform = self._create_form()
            rebuild_detail = RebuildWithReason(reason="shadow's golden coin")
            rebuild_transaction = CaseTransaction.rebuild_transaction(case, rebuild_detail)
            case.track_create(rebuild_transaction)
            FormProcessorSQL.save_processed_models(ProcessedForms(new_rebuild_xform, []), [case])

        case = CaseAccessorSQL.get_case(case.case_id)
        update_strategy = SqlCaseUpdateStrategy(case)
        self.assertFalse(update_strategy.reconcile_transactions_if_necessary())