~homeworkprod/byceps

47c731357a9102dedf9c3e66eccf084fb4fddf66 — Jochen Kupperschmidt a month ago 533662e
Turn `find_order_number_sequence` into `get_order_number_sequence`

Raises an exception if ID is not found.
M byceps/blueprints/admin/shop/storefront/views.py => byceps/blueprints/admin/shop/storefront/views.py +3 -5
@@ 69,7 69,7 @@ def view(storefront_id):

    brand = brand_service.get_brand(shop.brand_id)

    order_number_sequence = order_sequence_service.find_order_number_sequence(
    order_number_sequence = order_sequence_service.get_order_number_sequence(
        storefront.order_number_sequence_id
    )
    order_number_prefix = order_number_sequence.prefix


@@ 141,12 141,10 @@ def create(shop_id):
        flash_error(gettext('No valid order number sequence was specified.'))
        return create_form(shop_id, form)

    order_number_sequence = order_sequence_service.find_order_number_sequence(
    order_number_sequence = order_sequence_service.get_order_number_sequence(
        order_number_sequence_id
    )
    if (order_number_sequence is None) or (
        order_number_sequence.shop_id != shop.id
    ):
    if order_number_sequence.shop_id != shop.id:
        flash_error(gettext('No valid order number sequence was specified.'))
        return create_form(shop_id, form)


M byceps/services/shop/order/sequence_service.py => byceps/services/shop/order/sequence_service.py +4 -6
@@ 53,18 53,16 @@ def delete_order_number_sequence(sequence_id: OrderNumberSequenceID) -> None:
    db.session.commit()


def find_order_number_sequence(
def get_order_number_sequence(
    sequence_id: OrderNumberSequenceID,
) -> Optional[OrderNumberSequence]:
    """Return the order number sequence, or `None` if the sequence ID
    is unknown.
    """
) -> OrderNumberSequence:
    """Return the order number sequence, or raise an exception."""
    sequence = DbOrderNumberSequence.query \
        .filter_by(id=sequence_id) \
        .one_or_none()

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

    return _db_entity_to_order_number_sequence(sequence)


M byceps/services/shop/order/service.py => byceps/services/shop/order/service.py +1 -1
@@ 58,7 58,7 @@ def place_order(

    orderer_user = user_service.get_user(orderer.user_id)

    order_number_sequence = sequence_service.find_order_number_sequence(
    order_number_sequence = sequence_service.get_order_number_sequence(
        storefront.order_number_sequence_id
    )
    order_number = sequence_service.generate_order_number(