diff --git a/apps/dashboard/src/forms/fr_accounting/components/DiscountCard.tsx b/apps/dashboard/src/forms/fr_accounting/components/DiscountCard.tsx index 0e238dc2..01da08c8 100644 --- a/apps/dashboard/src/forms/fr_accounting/components/DiscountCard.tsx +++ b/apps/dashboard/src/forms/fr_accounting/components/DiscountCard.tsx @@ -1,7 +1,11 @@ import { Product } from "@/shared/hooks/api/useDashboard" import { formatCurrency } from "@/utils/format_currency" -export function DiscountCard({ product }: { product: Product }) { +export function DiscountCard({ + product +}: { + product: Omit +}) { return (
diff --git a/apps/dashboard/src/forms/fr_accounting/components/ProductOrderingCard.tsx b/apps/dashboard/src/forms/fr_accounting/components/ProductOrderingCard.tsx index 4df33136..99b0b0d6 100644 --- a/apps/dashboard/src/forms/fr_accounting/components/ProductOrderingCard.tsx +++ b/apps/dashboard/src/forms/fr_accounting/components/ProductOrderingCard.tsx @@ -26,7 +26,11 @@ import { cn } from "@/utils/cx" import { formatCurrency } from "@/utils/format_currency" import { cx } from "class-variance-authority" -export function ProductOrderingCard({ product }: { product: Product }) { +export function ProductOrderingCard({ + product +}: { + product: Omit +}) { const { updateCache } = useDashboard() const { data: orders } = useOrders() const { data: products } = useProducts() diff --git a/apps/dashboard/src/forms/fr_accounting/product.page.tsx b/apps/dashboard/src/forms/fr_accounting/product.page.tsx index ca7079ad..86ace54f 100644 --- a/apps/dashboard/src/forms/fr_accounting/product.page.tsx +++ b/apps/dashboard/src/forms/fr_accounting/product.page.tsx @@ -2,6 +2,7 @@ import { belongsToSection } from "@/forms/fr_accounting/accounting_utilities" import { DiscountCard } from "@/forms/fr_accounting/components/DiscountCard" import { ProductOrderingCard } from "@/forms/fr_accounting/components/ProductOrderingCard" import { Category, Product } from "@/shared/hooks/api/useDashboard" +import { useOrders } from "@/shared/hooks/api/useOrders" import { useProducts } from "@/shared/hooks/api/useProducts" import { RegistrationSection } from "@/shared/vars" import React, { useMemo } from "react" @@ -9,21 +10,47 @@ import { FormWrapper } from "../FormWrapper" export function ProductFormPage({ section }: { section: RegistrationSection }) { const { data: allProducts } = useProducts() + const { data: orders } = useOrders() + + const selectedPackage = orders.find( + order => + order.product.registration_section?.name === + RegistrationSection.Packages + ) const products = useMemo( - () => - allProducts.filter( + () => [ + ...allProducts.filter( product => belongsToSection(product, section) && product.display_in_product_list ), - [allProducts, section] + ...(selectedPackage?.product.specific_products + .filter( + specificProduct => + specificProduct.specific_product.registration_section != + null && + specificProduct.specific_product.registration_section + .name === section + ) + .map(specificProduct => specificProduct.specific_product) ?? []) + ], + [allProducts, section, selectedPackage?.product.specific_products] ) const categorizedProducts = useMemo( () => Object.entries( products.reduce< - Record + Record< + string, + { + category?: Category + products: Omit< + Product, + "child_products" | "specific_products" + >[] + } + > >( // Split products into categories (total, current) => { diff --git a/apps/dashboard/src/shared/hooks/api/useDashboard.tsx b/apps/dashboard/src/shared/hooks/api/useDashboard.tsx index 9687b986..39b7d263 100644 --- a/apps/dashboard/src/shared/hooks/api/useDashboard.tsx +++ b/apps/dashboard/src/shared/hooks/api/useDashboard.tsx @@ -1,4 +1,4 @@ -import { HOST } from "@/shared/vars" +import { HOST, RegistrationSection } from "@/shared/vars" import { useQuery, useQueryClient } from "@tanstack/react-query" import { useNavigate, useParams } from "@tanstack/react-router" @@ -93,9 +93,9 @@ export interface Category { allow_multiple_purchases: boolean } -export interface RegistrationSection { +export interface ProductRegistrationSection { id: string - name: string + name: RegistrationSection description: string hide_from_registration: boolean } @@ -114,7 +114,7 @@ export interface Product { description: string category: Category | null display_in_product_list: boolean - registration_section: RegistrationSection | null + registration_section: ProductRegistrationSection | null child_products: ChildProduct[] specific_products: Array<{ unit_price: number diff --git a/dashboard/api/registration/response.py b/dashboard/api/registration/response.py index a9a5bca4..3655f45f 100644 --- a/dashboard/api/registration/response.py +++ b/dashboard/api/registration/response.py @@ -51,8 +51,16 @@ def order_is_allowed(fair, company): package = orders.filter(product__category__name="Package").first() if package is None: + print("No package") return False + # for order in orders: + # parent_products = order.product.specificproduct_set.all() + + # if parent_products.count() > 0 and not package in parent_products: + # print(order.product, parent_products, "Parent not in package") + # return False + return True