Skip to content

Commit

Permalink
feat: Add hidden products (#915)
Browse files Browse the repository at this point in the history
## Describe your changes

Fixes: #

## Checklist before requesting review

- [ ] Feature/fix PRs should add one atomic (as small as possible)
feature or fix.
- [ ] The code compiles and all the tests pass.
  • Loading branch information
didrikmunther authored Aug 15, 2023
1 parent ed7acdf commit d37d906
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 17 deletions.
2 changes: 1 addition & 1 deletion accounting/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Meta:
"unit_price",
"description",
"category",
"no_customer_removal",
"display_in_product_list",
"registration_section",
)
fields = read_only_fields + ("id",)
Expand Down
15 changes: 8 additions & 7 deletions accounting/migrations/0025_add_child_product_descriptoin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
),
),
]
33 changes: 33 additions & 0 deletions accounting/migrations/0026_rename_hidden_products_field.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# 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",
),
),
]
16 changes: 9 additions & 7 deletions accounting/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
]
),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
}
Expand Down Expand Up @@ -65,7 +65,7 @@ export const productSlice = createSlice({
initialState,
reducers: {
loadProducts: (state, action: PayloadAction<Product[]>) => {
state.records = action.payload
state.records = action.payload.filter(product => product.display_in_product_list)
},
loadProductMeta: (
state,
Expand Down
3 changes: 3 additions & 0 deletions register/api/registration/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -50,6 +51,7 @@ def submit(request):

return submit_cr(request, company, fair, contact, exhibitor)


# Todo: remove in prod
@csrf_exempt
def index(request):
Expand All @@ -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):
Expand Down

0 comments on commit d37d906

Please sign in to comment.