Exemplo n.º 1
0
def cancel_batch_finalization(batch_id=None):
    batch = DocumentBatchDbObject.query.filter_by(id=batch_id, _owner=current_user, deleted=False).first()
    if not batch:
        raise errors.BatchNotFound()
    if batch.status != BatchStatusEnum.BS_BEING_FINALISED:
        return {"result": True}

    try:
        BatchManager.cancel_batch_finalization(batch, current_app.config, current_app.logger)
    except Exception:
        current_app.logger.exception(u"Failed to cancel batch finalization.")
        return {"result": False}

    return {"result": True}
Exemplo n.º 2
0
def batch_update(batch_id=None, batch=None):
    with current_app.model_cache_context:
        current_batch_db_object = DocumentBatchDbObject.query.filter_by(
            id=batch_id, _owner=current_user, deleted=False).first()
        if not current_batch_db_object:
            raise errors.BatchNotFound()

        if current_batch_db_object.status == BatchStatusEnum.BS_BEING_FINALISED:
            current_app.logger.debug(
                u"Updating batch during finalization - cancelling finalization"
            )

            try:
                BatchManager.cancel_batch_finalization(current_batch_db_object,
                                                       current_app.config,
                                                       current_app.logger)
            except Exception:
                current_app.logger.exception(
                    u"Failed to cancel batch finalisation")
                DocumentBatchDbObject.query.filter_by(
                    id=batch_id,
                    status=BatchStatusEnum.BS_BEING_FINALISED).update(
                        {'status': BatchStatusEnum.BS_EDITED})
                sqldb.session.commit()
                raise errors.DocumentBatchUpdateError()

        manager = BatchManager.init(current_batch_db_object)

        batch_type = current_batch_db_object.batch_type
        batch['batch_type'] = batch_type
        if 'metadata' in batch:
            batch['_metadata'] = batch['metadata']

        new_batch = DocumentBatch.parse_raw_value(batch, api_data=True)

        new_batch_api_data = manager.update_batch(batch_id, new_batch,
                                                  current_user.id,
                                                  current_app.config,
                                                  current_app.logger)

        DocumentBatchDbObject.query.filter_by(id=batch_id).update(
            {'last_change_dt': datetime.utcnow()})
        sqldb.session.commit()
        if batch_type == DocumentBatchTypeEnum.DBT_NEW_LLC:
            schedule_notification_email(batch_id)
        return new_batch_api_data
Exemplo n.º 3
0
def batch_update(batch_id=None, batch=None):
    with current_app.model_cache_context:
        current_batch_db_object = DocumentBatchDbObject.query.filter_by(id=batch_id, _owner=current_user,
                                                                        deleted=False).first()
        if not current_batch_db_object:
            raise errors.BatchNotFound()

        if current_batch_db_object.status == BatchStatusEnum.BS_BEING_FINALISED:
            current_app.logger.debug(u"Updating batch during finalization - cancelling finalization")

            try:
                BatchManager.cancel_batch_finalization(current_batch_db_object,
                                                       current_app.config, current_app.logger)
            except Exception:
                current_app.logger.exception(u"Failed to cancel batch finalisation")
                DocumentBatchDbObject.query.filter_by(id=batch_id, status=BatchStatusEnum.BS_BEING_FINALISED).update(
                    {'status': BatchStatusEnum.BS_EDITED})
                sqldb.session.commit()
                raise errors.DocumentBatchUpdateError()

        manager = BatchManager.init(current_batch_db_object)

        batch_type = current_batch_db_object.batch_type
        batch['batch_type'] = batch_type
        if 'metadata' in batch:
            batch['_metadata'] = batch['metadata']

        new_batch = DocumentBatch.parse_raw_value(batch, api_data=True)

        new_batch_api_data = manager.update_batch(batch_id, new_batch, current_user.id,
                                                  current_app.config, current_app.logger)

        DocumentBatchDbObject.query.filter_by(id=batch_id).update({'last_change_dt': datetime.utcnow()})
        sqldb.session.commit()
        if batch_type == DocumentBatchTypeEnum.DBT_NEW_LLC:
            schedule_notification_email(batch_id)
        return new_batch_api_data