From afda26f4c36dc06df6984ce8c4aced612e9d5eda Mon Sep 17 00:00:00 2001 From: Didrik Munther Date: Tue, 15 Aug 2023 12:06:55 +0200 Subject: [PATCH 1/2] Add hidden products --- accounting/api.py | 2 +- .../0026_rename_hidden_products_field.py | 27 +++++++++++++++++++ accounting/models.py | 16 ++++++----- .../src/store/products/products_slice.ts | 4 +-- 4 files changed, 39 insertions(+), 10 deletions(-) create mode 100644 accounting/migrations/0026_rename_hidden_products_field.py diff --git a/accounting/api.py b/accounting/api.py index 059acc0e1..24b214cd4 100644 --- a/accounting/api.py +++ b/accounting/api.py @@ -35,7 +35,7 @@ class Meta: "unit_price", "description", "category", - "no_customer_removal", + "display_in_product_list", "registration_section", ) fields = read_only_fields + ("id",) diff --git a/accounting/migrations/0026_rename_hidden_products_field.py b/accounting/migrations/0026_rename_hidden_products_field.py new file mode 100644 index 000000000..ec6a00253 --- /dev/null +++ b/accounting/migrations/0026_rename_hidden_products_field.py @@ -0,0 +1,27 @@ +# Generated by Django 2.2.24 on 2023-08-15 12:00 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('accounting', '0025_add_child_product_descriptoin'), + ] + + operations = [ + migrations.RemoveField( + model_name='product', + name='no_customer_removal', + ), + migrations.AddField( + model_name='product', + name='display_in_product_list', + field=models.BooleanField(default=True, help_text='This product will not be shown to the customer unless a salesperson has added it, or it was ordered with a package Only a salesperson can add and remove it. Used among other things to be a child product to a package product.'), + ), + migrations.AlterField( + model_name='product', + name='child_products', + field=models.ManyToManyField(blank=True, help_text='This product will automatically add these products when added. Recommended (but not neccessary) is to toggle the "Display in product list" to false on the child products in order to make the package automatically add packages which can only be removed by a salesperson. This feature was used in 2023 when selling gold, silver, and bronze packages.', to='accounting.ChildProduct'), + ), + ] diff --git a/accounting/models.py b/accounting/models.py index 5d2e81100..049543958 100644 --- a/accounting/models.py +++ b/accounting/models.py @@ -78,20 +78,22 @@ class Product(models.Model): help_text=" ".join( [ "This product will automatically add these products when added.", - 'Recommended (but not neccessary) is to toggle the "No customer removal" on', - "the child products in order to make the package automatically add packages ", + 'Recommended (but not neccessary) is to toggle the "Display in product list" to false on', + "the child products in order to make the package automatically add packages", "which can only be removed by a salesperson.", "This feature was used in 2023 when selling gold, silver, and bronze packages.", ] ), ) - no_customer_removal = models.BooleanField( - default=False, + + display_in_product_list = models.BooleanField( + default=True, help_text=" ".join( [ - "This product will be unable to be removed by the customer." - "Only a salesperson can remove it.", - "Used in order to be a child product to a package product.", + "This product will not be shown to the customer unless a salesperson has added it,", + "or it was ordered with a package", + "Only a salesperson can add and remove it.", + "Used among other things to be a child product to a package product.", ] ), ) diff --git a/apps/complete_registration/src/store/products/products_slice.ts b/apps/complete_registration/src/store/products/products_slice.ts index 4dad17143..2aedbd8f5 100644 --- a/apps/complete_registration/src/store/products/products_slice.ts +++ b/apps/complete_registration/src/store/products/products_slice.ts @@ -25,7 +25,7 @@ export interface Product { unit_price: number description: string category: Category | null - no_customer_removal: boolean + display_in_product_list: boolean registration_section: RegistrationSection | null child_products: ChildProduct[] } @@ -65,7 +65,7 @@ export const productSlice = createSlice({ initialState, reducers: { loadProducts: (state, action: PayloadAction) => { - state.records = action.payload + state.records = action.payload.filter(product => product.display_in_product_list) }, loadProductMeta: ( state, From 3178f9b602f7ed7d8a56e068d2e2cd473c26672a Mon Sep 17 00:00:00 2001 From: Didrik Munther Date: Tue, 15 Aug 2023 12:08:53 +0200 Subject: [PATCH 2/2] Reformat code --- .../0025_add_child_product_descriptoin.py | 15 ++++++----- .../0026_rename_hidden_products_field.py | 26 ++++++++++++------- accounting/models.py | 2 +- register/api/registration/__init__.py | 3 +++ 4 files changed, 28 insertions(+), 18 deletions(-) diff --git a/accounting/migrations/0025_add_child_product_descriptoin.py b/accounting/migrations/0025_add_child_product_descriptoin.py index ef34a71ba..2317e81e5 100644 --- a/accounting/migrations/0025_add_child_product_descriptoin.py +++ b/accounting/migrations/0025_add_child_product_descriptoin.py @@ -5,20 +5,21 @@ class Migration(migrations.Migration): - dependencies = [ - ('accounting', '0024_add_child_product_model'), + ("accounting", "0024_add_child_product_model"), ] operations = [ migrations.AddField( - model_name='childproduct', - name='description', + model_name="childproduct", + name="description", field=models.TextField(blank=True, null=True), ), migrations.AlterField( - model_name='product', - name='revenue', - field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='accounting.Revenue'), + model_name="product", + name="revenue", + field=models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, to="accounting.Revenue" + ), ), ] diff --git a/accounting/migrations/0026_rename_hidden_products_field.py b/accounting/migrations/0026_rename_hidden_products_field.py index ec6a00253..a1459e404 100644 --- a/accounting/migrations/0026_rename_hidden_products_field.py +++ b/accounting/migrations/0026_rename_hidden_products_field.py @@ -4,24 +4,30 @@ class Migration(migrations.Migration): - dependencies = [ - ('accounting', '0025_add_child_product_descriptoin'), + ("accounting", "0025_add_child_product_descriptoin"), ] operations = [ migrations.RemoveField( - model_name='product', - name='no_customer_removal', + model_name="product", + name="no_customer_removal", ), migrations.AddField( - model_name='product', - name='display_in_product_list', - field=models.BooleanField(default=True, help_text='This product will not be shown to the customer unless a salesperson has added it, or it was ordered with a package Only a salesperson can add and remove it. Used among other things to be a child product to a package product.'), + model_name="product", + name="display_in_product_list", + field=models.BooleanField( + default=True, + help_text="This product will not be shown to the customer unless a salesperson has added it, or it was ordered with a package Only a salesperson can add and remove it. Used among other things to be a child product to a package product.", + ), ), migrations.AlterField( - model_name='product', - name='child_products', - field=models.ManyToManyField(blank=True, help_text='This product will automatically add these products when added. Recommended (but not neccessary) is to toggle the "Display in product list" to false on the child products in order to make the package automatically add packages which can only be removed by a salesperson. This feature was used in 2023 when selling gold, silver, and bronze packages.', to='accounting.ChildProduct'), + model_name="product", + name="child_products", + field=models.ManyToManyField( + blank=True, + help_text='This product will automatically add these products when added. Recommended (but not neccessary) is to toggle the "Display in product list" to false on the child products in order to make the package automatically add packages which can only be removed by a salesperson. This feature was used in 2023 when selling gold, silver, and bronze packages.', + to="accounting.ChildProduct", + ), ), ] diff --git a/accounting/models.py b/accounting/models.py index 049543958..bf8a8eaae 100644 --- a/accounting/models.py +++ b/accounting/models.py @@ -85,7 +85,7 @@ class Product(models.Model): ] ), ) - + display_in_product_list = models.BooleanField( default=True, help_text=" ".join( diff --git a/register/api/registration/__init__.py b/register/api/registration/__init__.py index eb2c64a17..2b8c4c40f 100644 --- a/register/api/registration/__init__.py +++ b/register/api/registration/__init__.py @@ -29,6 +29,7 @@ def render_company(request, company, contact, exhibitor): else: return status.INVALID_REGISTRATION_PERIOD + # Todo: remove in prod @csrf_exempt def submit(request): @@ -50,6 +51,7 @@ def submit(request): return submit_cr(request, company, fair, contact, exhibitor) + # Todo: remove in prod @csrf_exempt def index(request): @@ -69,6 +71,7 @@ def index(request): return render_company(request, company, contact, exhibitor) + # Todo: remove in prod @csrf_exempt def get_company(request, company_pk):