~homeworkprod/byceps

c6b428b85f1f55355008cc2d99dd87b0f6d5bf83 — Jochen Kupperschmidt a month ago 47c7313
Turn `find_article_number_sequence` into `get_article_number_sequence`

Raises an exception if ID is not found.
M byceps/blueprints/admin/shop/article/views.py => byceps/blueprints/admin/shop/article/views.py +2 -4
@@ 208,13 208,11 @@ def create(shop_id):
        return create_form(shop_id, form)

    article_number_sequence = (
        article_sequence_service.find_article_number_sequence(
        article_sequence_service.get_article_number_sequence(
            article_number_sequence_id
        )
    )
    if (article_number_sequence is None) or (
        article_number_sequence.shop_id != shop.id
    ):
    if article_number_sequence.shop_id != shop.id:
        flash_error(gettext('No valid article number sequence was specified.'))
        return create_form(shop_id, form)


M byceps/services/shop/article/sequence_service.py => byceps/services/shop/article/sequence_service.py +4 -6
@@ 55,18 55,16 @@ def delete_article_number_sequence(
    db.session.commit()


def find_article_number_sequence(
def get_article_number_sequence(
    sequence_id: ArticleNumberSequenceID,
) -> Optional[ArticleNumberSequence]:
    """Return the article number sequence, or `None` if the sequence ID
    is unknown.
    """
) -> ArticleNumberSequence:
    """Return the article number sequence, or raise an exception."""
    sequence = DbArticleNumberSequence.query \
        .filter_by(id=sequence_id) \
        .one_or_none()

    if sequence is None:
        return None
        raise ValueError(f'Unknown article number sequence ID "{sequence_id}"')

    return _db_entity_to_article_number_sequence(sequence)