registrasion/controllers/invoice.py
def _generate_from_cart(cls, cart):
        ''' Generates an invoice for the given cart. '''

        cart.refresh_from_db()

        # Generate the line items from the cart.

        product_items = commerce.ProductItem.objects.filter(cart=cart)
        product_items = product_items.select_related(
            "product",
            "product__category",
        )
        product_items = product_items.order_by(
            "product__category__order", "product__order"
        )

        if len(product_items) == 0:
            raise ValidationError("Your cart is empty.")

        discount_items = commerce.DiscountItem.objects.filter(cart=cart)
        discount_items = discount_items.select_related(
            "discount",
            "product",
            "product__category",
        )

        def format_product(product):
            return "%s - %s" % (product.category.name, product.name)

        def format_discount(discount, product):
            description = discount.description
            return "%s (%s)" % (description, format_product(product))

        line_items = []

        for item in product_items:
            product = item.product
            line_item = commerce.LineItem(
                description=format_product(product),
                quantity=item.quantity,
                price=product.price,
                product=product,
            )
            line_items.append(line_item)
        for item in discount_items:
            line_item = commerce.LineItem(
                description=format_discount(item.discount, item.product),
                quantity=item.quantity,
                price=cls.resolve_discount_value(item) * -1,
                product=item.product,
            )
            line_items.append(line_item)

        # Generate the invoice

        min_due_time = cart.reservation_duration + cart.time_last_updated

        return cls._generate(cart.user, cart, min_due_time, line_items)
def _generate_from_cart(cls, cart):
        ''' Generates an invoice for the given cart. '''

        cart.refresh_from_db()

        # Generate the line items from the cart.

        product_items = commerce.ProductItem.objects.filter(cart=cart)
        product_items = product_items.select_related(
            "product",
            "product__category",
        )
        product_items = product_items.order_by(
            "product__category__order", "product__order"
        )

        if len(product_items) == 0:
            raise ValidationError("Your cart is empty.")

        discount_items = commerce.DiscountItem.objects.filter(cart=cart)
        discount_items = discount_items.select_related(
            "discount",
            "product",
            "product__category",
        )

        def format_product(product):
            return "%s - %s" % (product.category.name, product.name)

        def format_discount(discount, product):
            description = discount.description
            return "%s (%s)" % (description, format_product(product))

        line_items = []

        for item in product_items:
            product = item.product
            line_item = commerce.LineItem(
                description=format_product(product),
                quantity=item.quantity,
                price=product.price,
                product=product,
            )
            line_items.append(line_item)
        for item in discount_items:
            line_item = commerce.LineItem(
                description=format_discount(item.discount, item.product),
                quantity=item.quantity,
                price=cls.resolve_discount_value(item) * -1,
                product=item.product,
            )
            line_items.append(line_item)

        # Generate the invoice

        min_due_time = cart.reservation_duration + cart.time_last_updated

        return cls._generate(cart.user, cart, min_due_time, line_items)
Generates an invoice for the given cart.