From 1eb78f01df6d3cc5b61689d2835c1a67e52e9677 Mon Sep 17 00:00:00 2001 From: pdsccode Date: Sat, 30 Dec 2023 07:29:27 +0100 Subject: [PATCH 01/15] Added pricing field for single spool --- client/public/locales/en/common.json | 2 ++ client/src/pages/spools/create.tsx | 15 ++++++++++++++- client/src/pages/spools/edit.tsx | 14 ++++++++++++++ client/src/pages/spools/list.tsx | 9 +++++++++ client/src/pages/spools/model.tsx | 1 + client/src/pages/spools/show.tsx | 2 ++ spoolman/api/v1/models.py | 5 +++++ spoolman/api/v1/spool.py | 6 ++++++ spoolman/database/models.py | 1 + spoolman/database/spool.py | 1 + 10 files changed, 55 insertions(+), 1 deletion(-) diff --git a/client/public/locales/en/common.json b/client/public/locales/en/common.json index 7dfceed..fd26c6f 100644 --- a/client/public/locales/en/common.json +++ b/client/public/locales/en/common.json @@ -134,6 +134,7 @@ "id": "ID", "filament_name": "Filament", "filament": "Filament", + "price": "Price", "material": "Material", "weight_to_use": "Weight", "used_weight": "Used Weight", @@ -150,6 +151,7 @@ "archived": "Archived" }, "fields_help": { + "price": "Price of a full spool in the system configured currency.", "weight_to_use": "Select what weight value to enter. Measured weight is only available if the spool weight is set for the selected filament.", "used_weight": "How much filament has been used from the spool. A new spool should have 0g used.", "remaining_weight": "How much filament is left on the spool. For a new spool this should match the spool weight.", diff --git a/client/src/pages/spools/create.tsx b/client/src/pages/spools/create.tsx index f9c41f7..d33d6ff 100644 --- a/client/src/pages/spools/create.tsx +++ b/client/src/pages/spools/create.tsx @@ -201,7 +201,20 @@ export const SpoolCreate: React.FC - + + + diff --git a/client/src/pages/spools/edit.tsx b/client/src/pages/spools/edit.tsx index 1bbce4b..86b84ce 100644 --- a/client/src/pages/spools/edit.tsx +++ b/client/src/pages/spools/edit.tsx @@ -181,6 +181,20 @@ export const SpoolEdit: React.FC = () => { }} /> + + + diff --git a/client/src/pages/spools/list.tsx b/client/src/pages/spools/list.tsx index cc17f38..770ec17 100644 --- a/client/src/pages/spools/list.tsx +++ b/client/src/pages/spools/list.tsx @@ -73,6 +73,7 @@ const allColumns: (keyof ISpoolCollapsed & string)[] = [ "id", "combined_name", "filament.material", + "price", "used_weight", "remaining_weight", "used_length", @@ -312,6 +313,14 @@ export const SpoolList: React.FC = () => { filterValueQuery: useSpoolmanMaterials(), width: 120, }), + SortedColumn({ + id: "price", + i18ncat: "spool", + actions, + dataSource, + tableState, + width: 80, + }), NumberColumn({ id: "used_weight", i18ncat: "spool", diff --git a/client/src/pages/spools/model.tsx b/client/src/pages/spools/model.tsx index 7dd64d2..f365d03 100644 --- a/client/src/pages/spools/model.tsx +++ b/client/src/pages/spools/model.tsx @@ -6,6 +6,7 @@ export interface ISpool { first_used?: string; last_used?: string; filament: IFilament; + price?: number; remaining_weight?: number; used_weight: number; remaining_length?: number; diff --git a/client/src/pages/spools/show.tsx b/client/src/pages/spools/show.tsx index 2765310..bae1b39 100644 --- a/client/src/pages/spools/show.tsx +++ b/client/src/pages/spools/show.tsx @@ -58,6 +58,8 @@ export const SpoolShow: React.FC = () => { {t("spool.fields.filament")} + {t("spool.fields.price")} + {t("spool.fields.registered")} Date: Sat, 30 Dec 2023 08:30:17 +0100 Subject: [PATCH 02/15] Resolved indentation error --- spoolman/api/v1/spool.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spoolman/api/v1/spool.py b/spoolman/api/v1/spool.py index 6c41933..35ec5ea 100644 --- a/spoolman/api/v1/spool.py +++ b/spoolman/api/v1/spool.py @@ -34,7 +34,7 @@ class SpoolParameters(BaseModel): first_used: Optional[datetime] = Field(description="First logged occurence of spool usage.") last_used: Optional[datetime] = Field(description="Last logged occurence of spool usage.") filament_id: int = Field(description="The ID of the filament type of this spool.") - price: Optional[float] = Field( + price: Optional[float] = Field( ge=0, description="The price of this filament in the system configured currency.", example=20.0, From df45a47b99b15550fadf8aa4d2faeaba3b218f0c Mon Sep 17 00:00:00 2001 From: pdsccode Date: Sat, 30 Dec 2023 08:44:54 +0100 Subject: [PATCH 03/15] Added db migration for spool prices --- ...30_0839-b82cd9e2aa6f_added_spool_prices.py | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 migrations/versions/2023_12_30_0839-b82cd9e2aa6f_added_spool_prices.py diff --git a/migrations/versions/2023_12_30_0839-b82cd9e2aa6f_added_spool_prices.py b/migrations/versions/2023_12_30_0839-b82cd9e2aa6f_added_spool_prices.py new file mode 100644 index 0000000..5b23030 --- /dev/null +++ b/migrations/versions/2023_12_30_0839-b82cd9e2aa6f_added_spool_prices.py @@ -0,0 +1,28 @@ +"""Added spool prices. + +Revision ID: b82cd9e2aa6f +Revises: 92793c8a937c +Create Date: 2023-12-30 08:39:48.430846 +""" +import sqlalchemy as sa +from alembic import op + +# revision identifiers, used by Alembic. +revision = 'b82cd9e2aa6f' +down_revision = '92793c8a937c' +branch_labels = None +depends_on = None + + +def upgrade() -> None: + """Perform the upgrade.""" + # ### commands auto generated by Alembic - please adjust! ### + op.add_column('spool', sa.Column('price', sa.Float(), nullable=True)) + # ### end Alembic commands ### + + +def downgrade() -> None: + """Perform the downgrade.""" + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column('spool', 'price') + # ### end Alembic commands ### From d18d21d8fd279c99b46496f2ee1ac9c735c69326 Mon Sep 17 00:00:00 2001 From: pdsccode Date: Sat, 30 Dec 2023 09:18:37 +0100 Subject: [PATCH 04/15] Fixed db access to spool price field --- spoolman/database/spool.py | 1 + 1 file changed, 1 insertion(+) diff --git a/spoolman/database/spool.py b/spoolman/database/spool.py index 390a99d..dc29d32 100644 --- a/spoolman/database/spool.py +++ b/spoolman/database/spool.py @@ -64,6 +64,7 @@ async def create( filament=filament_item, registered=datetime.utcnow().replace(microsecond=0), used_weight=used_weight, + price=price, first_used=first_used, last_used=last_used, location=location, From f659284bed66f85fc9ef6ae8cbfa2e9b44f1b22e Mon Sep 17 00:00:00 2001 From: pdsccode Date: Sat, 30 Dec 2023 09:28:08 +0100 Subject: [PATCH 05/15] Fixed api missing spool price return --- spoolman/api/v1/models.py | 1 + 1 file changed, 1 insertion(+) diff --git a/spoolman/api/v1/models.py b/spoolman/api/v1/models.py index 2043c7b..6870194 100644 --- a/spoolman/api/v1/models.py +++ b/spoolman/api/v1/models.py @@ -202,6 +202,7 @@ class Spool(BaseModel): first_used=item.first_used, last_used=item.last_used, filament=filament, + price=item.price used_weight=item.used_weight, used_length=used_length, remaining_weight=remaining_weight, From 50ac3985197377d6b1a8de4e95d02c79b55e2ea8 Mon Sep 17 00:00:00 2001 From: pdsccode Date: Sat, 30 Dec 2023 09:29:26 +0100 Subject: [PATCH 06/15] Fixed missing comma in api model spool price --- spoolman/api/v1/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spoolman/api/v1/models.py b/spoolman/api/v1/models.py index 6870194..0be5a14 100644 --- a/spoolman/api/v1/models.py +++ b/spoolman/api/v1/models.py @@ -202,7 +202,7 @@ class Spool(BaseModel): first_used=item.first_used, last_used=item.last_used, filament=filament, - price=item.price + price=item.price, used_weight=item.used_weight, used_length=used_length, remaining_weight=remaining_weight, From 577ed1e680063b7a685fa3fa3d620c44d29a1790 Mon Sep 17 00:00:00 2001 From: pdsccode Date: Sat, 6 Jan 2024 21:42:09 +0100 Subject: [PATCH 07/15] Changed to show filament price if no spool price set and added tests --- client/src/pages/spools/list.tsx | 3 +++ tests_integration/tests/spool/test_add.py | 12 +++++++++++ tests_integration/tests/spool/test_get.py | 2 ++ tests_integration/tests/spool/test_update.py | 21 ++++++++++++++++++++ 4 files changed, 38 insertions(+) diff --git a/client/src/pages/spools/list.tsx b/client/src/pages/spools/list.tsx index 770ec17..714a6f8 100644 --- a/client/src/pages/spools/list.tsx +++ b/client/src/pages/spools/list.tsx @@ -52,6 +52,9 @@ function collapseSpool(element: ISpool): ISpoolCollapsed { } else { filament_name = element.filament.name ?? element.filament.id.toString(); } + if (!element.price){ + element.price = element.filament.price; + } return { ...element, combined_name: filament_name, diff --git a/tests_integration/tests/spool/test_add.py b/tests_integration/tests/spool/test_add.py index f5ae7fd..817a74d 100644 --- a/tests_integration/tests/spool/test_add.py +++ b/tests_integration/tests/spool/test_add.py @@ -185,3 +185,15 @@ def test_add_spool_both_used_and_remaining_weight(random_filament: dict[str, Any }, ) assert result.status_code == 400 # Cannot set both used and remaining weight + +def test_add_spool_price(random_filament: dict[str, Any]): + """Test adding a spool to the database.""" + # Execute + result = httpx.post( + f"{URL}/api/v1/spool", + json={ + "filament_id": random_filament["id"], + "price": 25, + }, + ) + assert result.status_code == 400 # Cannot set price \ No newline at end of file diff --git a/tests_integration/tests/spool/test_get.py b/tests_integration/tests/spool/test_get.py index acb8345..fa4e0f4 100644 --- a/tests_integration/tests/spool/test_get.py +++ b/tests_integration/tests/spool/test_get.py @@ -16,6 +16,7 @@ def test_get_spool(random_filament: dict[str, Any]): location = "The Pantry" lot_nr = "123456789" comment = "abcdefghåäö" + price = 25 archived = True result = httpx.post( f"{URL}/api/v1/spool", @@ -27,6 +28,7 @@ def test_get_spool(random_filament: dict[str, Any]): "location": location, "lot_nr": lot_nr, "comment": comment, + "price": price, "archived": archived, }, ) diff --git a/tests_integration/tests/spool/test_update.py b/tests_integration/tests/spool/test_update.py index c1d3be3..6ce69d8 100644 --- a/tests_integration/tests/spool/test_update.py +++ b/tests_integration/tests/spool/test_update.py @@ -99,6 +99,27 @@ def test_update_spool_both_used_and_remaining_weight(random_filament: dict[str, # Clean up httpx.delete(f"{URL}/api/v1/spool/{spool['id']}").raise_for_status() +def test_update_spool_price(random_filament: dict[str, Any]): + """Test updating a spool in the database.""" + # Setup + result = httpx.post( + f"{URL}/api/v1/spool", + json={"filament_id": random_filament["id"]}, + ) + result.raise_for_status() + spool = result.json() + + # Execute + result = httpx.patch( + f"{URL}/api/v1/spool/{spool['id']}", + json={ + "price": 750, + }, + ) + assert result.status_code == 400 # Cannot update both used and remaining weight + + # Clean up + httpx.delete(f"{URL}/api/v1/spool/{spool['id']}").raise_for_status() def test_update_spool_not_found(random_filament: dict[str, Any]): """Test updating a spool that does not exist.""" From a3be98263247a79c6e382b6231505557ec7dbd14 Mon Sep 17 00:00:00 2001 From: pdsccode Date: Sat, 6 Jan 2024 23:04:53 +0100 Subject: [PATCH 08/15] Fixing test update spool issue --- tests_integration/tests/spool/test_update.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tests_integration/tests/spool/test_update.py b/tests_integration/tests/spool/test_update.py index 6ce69d8..d7dc258 100644 --- a/tests_integration/tests/spool/test_update.py +++ b/tests_integration/tests/spool/test_update.py @@ -104,19 +104,28 @@ def test_update_spool_price(random_filament: dict[str, Any]): # Setup result = httpx.post( f"{URL}/api/v1/spool", - json={"filament_id": random_filament["id"]}, + json={ + "filament_id": random_filament["id"], + "price": 50, + }, ) result.raise_for_status() spool = result.json() # Execute + price = 25 + last_used = "2023-01-02T12:00:00+02:00" result = httpx.patch( f"{URL}/api/v1/spool/{spool['id']}", json={ - "price": 750, + "price": price, }, ) - assert result.status_code == 400 # Cannot update both used and remaining weight + result.raise_for_status() + + # Verify + spool = result.json() + assert spool["price"] == 25 # Clean up httpx.delete(f"{URL}/api/v1/spool/{spool['id']}").raise_for_status() From 2377b6cf38fa6a034008769ba1489fabbe13d609 Mon Sep 17 00:00:00 2001 From: Sebastian <42718020+pdsccode@users.noreply.github.com> Date: Sat, 6 Jan 2024 23:17:43 +0100 Subject: [PATCH 09/15] Update ci.yml Adding workflow_dispatch: to enable manual test runs --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d1419cd..465c71b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,7 +9,7 @@ on: pull_request: branches: - master - + workflow_dispatch: env: REGISTRY: ghcr.io IMAGE_NAME: donkie/spoolman From f9b438503490641e0fb60c6b049c162d078cda04 Mon Sep 17 00:00:00 2001 From: pdsccode Date: Sat, 6 Jan 2024 23:27:11 +0100 Subject: [PATCH 10/15] Revert "Update ci.yml" This reverts commit 2377b6cf38fa6a034008769ba1489fabbe13d609. --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 465c71b..d1419cd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,7 +9,7 @@ on: pull_request: branches: - master - workflow_dispatch: + env: REGISTRY: ghcr.io IMAGE_NAME: donkie/spoolman From 44b20fb360ad1b7a321dd20f6ba79ace86413e14 Mon Sep 17 00:00:00 2001 From: pdsccode Date: Sun, 7 Jan 2024 13:25:05 +0100 Subject: [PATCH 11/15] Fixed code formatting --- .pre-commit-config.yaml | 2 +- .../2023_12_30_0839-b82cd9e2aa6f_added_spool_prices.py | 8 ++++---- tests_integration/tests/spool/test_add.py | 3 ++- tests_integration/tests/spool/test_update.py | 3 ++- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 628d25f..a7d5009 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,5 +1,5 @@ default_language_version: - python: python3.9 + python: python3 repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.4.0 diff --git a/migrations/versions/2023_12_30_0839-b82cd9e2aa6f_added_spool_prices.py b/migrations/versions/2023_12_30_0839-b82cd9e2aa6f_added_spool_prices.py index 5b23030..b0f7820 100644 --- a/migrations/versions/2023_12_30_0839-b82cd9e2aa6f_added_spool_prices.py +++ b/migrations/versions/2023_12_30_0839-b82cd9e2aa6f_added_spool_prices.py @@ -8,8 +8,8 @@ import sqlalchemy as sa from alembic import op # revision identifiers, used by Alembic. -revision = 'b82cd9e2aa6f' -down_revision = '92793c8a937c' +revision = "b82cd9e2aa6f" +down_revision = "92793c8a937c" branch_labels = None depends_on = None @@ -17,12 +17,12 @@ depends_on = None def upgrade() -> None: """Perform the upgrade.""" # ### commands auto generated by Alembic - please adjust! ### - op.add_column('spool', sa.Column('price', sa.Float(), nullable=True)) + op.add_column("spool", sa.Column("price", sa.Float(), nullable=True)) # ### end Alembic commands ### def downgrade() -> None: """Perform the downgrade.""" # ### commands auto generated by Alembic - please adjust! ### - op.drop_column('spool', 'price') + op.drop_column("spool", "price") # ### end Alembic commands ### diff --git a/tests_integration/tests/spool/test_add.py b/tests_integration/tests/spool/test_add.py index 817a74d..256913f 100644 --- a/tests_integration/tests/spool/test_add.py +++ b/tests_integration/tests/spool/test_add.py @@ -186,6 +186,7 @@ def test_add_spool_both_used_and_remaining_weight(random_filament: dict[str, Any ) assert result.status_code == 400 # Cannot set both used and remaining weight + def test_add_spool_price(random_filament: dict[str, Any]): """Test adding a spool to the database.""" # Execute @@ -196,4 +197,4 @@ def test_add_spool_price(random_filament: dict[str, Any]): "price": 25, }, ) - assert result.status_code == 400 # Cannot set price \ No newline at end of file + assert result.status_code == 400 # Cannot set price diff --git a/tests_integration/tests/spool/test_update.py b/tests_integration/tests/spool/test_update.py index d7dc258..6075d6e 100644 --- a/tests_integration/tests/spool/test_update.py +++ b/tests_integration/tests/spool/test_update.py @@ -99,6 +99,7 @@ def test_update_spool_both_used_and_remaining_weight(random_filament: dict[str, # Clean up httpx.delete(f"{URL}/api/v1/spool/{spool['id']}").raise_for_status() + def test_update_spool_price(random_filament: dict[str, Any]): """Test updating a spool in the database.""" # Setup @@ -114,7 +115,6 @@ def test_update_spool_price(random_filament: dict[str, Any]): # Execute price = 25 - last_used = "2023-01-02T12:00:00+02:00" result = httpx.patch( f"{URL}/api/v1/spool/{spool['id']}", json={ @@ -130,6 +130,7 @@ def test_update_spool_price(random_filament: dict[str, Any]): # Clean up httpx.delete(f"{URL}/api/v1/spool/{spool['id']}").raise_for_status() + def test_update_spool_not_found(random_filament: dict[str, Any]): """Test updating a spool that does not exist.""" # Execute From f13c61b9e9acc033a10d2e8e074e7e2c85d3b07f Mon Sep 17 00:00:00 2001 From: pdsccode Date: Sun, 7 Jan 2024 13:44:04 +0100 Subject: [PATCH 12/15] Fixed test error that asserts 404 on create --- tests_integration/tests/spool/test_add.py | 57 +++++++++++++++++++++-- 1 file changed, 54 insertions(+), 3 deletions(-) diff --git a/tests_integration/tests/spool/test_add.py b/tests_integration/tests/spool/test_add.py index 256913f..d3e63ce 100644 --- a/tests_integration/tests/spool/test_add.py +++ b/tests_integration/tests/spool/test_add.py @@ -187,14 +187,65 @@ def test_add_spool_both_used_and_remaining_weight(random_filament: dict[str, Any assert result.status_code == 400 # Cannot set both used and remaining weight -def test_add_spool_price(random_filament: dict[str, Any]): +def test_add_spool_with_price(random_filament: dict[str, Any]): """Test adding a spool to the database.""" # Execute + remaining_weight = 750 + location = "The Pantry" + lot_nr = "123456789" + comment = "abcdefghåäö" + archived = True + price = 25 result = httpx.post( f"{URL}/api/v1/spool", json={ + "first_used": "2023-01-02T12:00:00+01:00", + "last_used": "2023-01-02T11:00:00Z", "filament_id": random_filament["id"], - "price": 25, + "remaining_weight": remaining_weight, + "location": location, + "lot_nr": lot_nr, + "comment": comment, + "archived": archived, + "price": price, }, ) - assert result.status_code == 400 # Cannot set price + result.raise_for_status() + + # Verify + used_weight = random_filament["weight"] - remaining_weight + used_length = length_from_weight( + weight=used_weight, + density=random_filament["density"], + diameter=random_filament["diameter"], + ) + remaining_length = length_from_weight( + weight=remaining_weight, + density=random_filament["density"], + diameter=random_filament["diameter"], + ) + + spool = result.json() + assert spool == { + "id": spool["id"], + "registered": spool["registered"], + "first_used": "2023-01-02T11:00:00Z", + "last_used": "2023-01-02T11:00:00Z", + "filament": random_filament, + "remaining_weight": pytest.approx(remaining_weight), + "used_weight": pytest.approx(used_weight), + "remaining_length": pytest.approx(remaining_length), + "used_length": pytest.approx(used_length), + "location": location, + "lot_nr": lot_nr, + "comment": comment, + "archived": archived, + "price": price, + } + + # Verify that registered happened almost now (within 1 minute) + diff = abs((datetime.now(tz=timezone.utc) - datetime.fromisoformat(spool["registered"])).total_seconds()) + assert diff < 60 + + # Clean up + httpx.delete(f"{URL}/api/v1/spool/{spool['id']}").raise_for_status() From 05dfb611cfaace43a9cbe6761959c6af8e36c78c Mon Sep 17 00:00:00 2001 From: pdsccode Date: Sun, 7 Jan 2024 14:17:59 +0100 Subject: [PATCH 13/15] Revert "Fixed test error that asserts 404 on create" This reverts commit f13c61b9e9acc033a10d2e8e074e7e2c85d3b07f. --- tests_integration/tests/spool/test_add.py | 57 ++--------------------- 1 file changed, 3 insertions(+), 54 deletions(-) diff --git a/tests_integration/tests/spool/test_add.py b/tests_integration/tests/spool/test_add.py index d3e63ce..256913f 100644 --- a/tests_integration/tests/spool/test_add.py +++ b/tests_integration/tests/spool/test_add.py @@ -187,65 +187,14 @@ def test_add_spool_both_used_and_remaining_weight(random_filament: dict[str, Any assert result.status_code == 400 # Cannot set both used and remaining weight -def test_add_spool_with_price(random_filament: dict[str, Any]): +def test_add_spool_price(random_filament: dict[str, Any]): """Test adding a spool to the database.""" # Execute - remaining_weight = 750 - location = "The Pantry" - lot_nr = "123456789" - comment = "abcdefghåäö" - archived = True - price = 25 result = httpx.post( f"{URL}/api/v1/spool", json={ - "first_used": "2023-01-02T12:00:00+01:00", - "last_used": "2023-01-02T11:00:00Z", "filament_id": random_filament["id"], - "remaining_weight": remaining_weight, - "location": location, - "lot_nr": lot_nr, - "comment": comment, - "archived": archived, - "price": price, + "price": 25, }, ) - result.raise_for_status() - - # Verify - used_weight = random_filament["weight"] - remaining_weight - used_length = length_from_weight( - weight=used_weight, - density=random_filament["density"], - diameter=random_filament["diameter"], - ) - remaining_length = length_from_weight( - weight=remaining_weight, - density=random_filament["density"], - diameter=random_filament["diameter"], - ) - - spool = result.json() - assert spool == { - "id": spool["id"], - "registered": spool["registered"], - "first_used": "2023-01-02T11:00:00Z", - "last_used": "2023-01-02T11:00:00Z", - "filament": random_filament, - "remaining_weight": pytest.approx(remaining_weight), - "used_weight": pytest.approx(used_weight), - "remaining_length": pytest.approx(remaining_length), - "used_length": pytest.approx(used_length), - "location": location, - "lot_nr": lot_nr, - "comment": comment, - "archived": archived, - "price": price, - } - - # Verify that registered happened almost now (within 1 minute) - diff = abs((datetime.now(tz=timezone.utc) - datetime.fromisoformat(spool["registered"])).total_seconds()) - assert diff < 60 - - # Clean up - httpx.delete(f"{URL}/api/v1/spool/{spool['id']}").raise_for_status() + assert result.status_code == 400 # Cannot set price From 28a70d5190e5b2c3a435899f82a8b1b23f77c660 Mon Sep 17 00:00:00 2001 From: pdsccode Date: Sun, 7 Jan 2024 14:24:14 +0100 Subject: [PATCH 14/15] Merged spool price testing into existing test methods --- tests_integration/tests/spool/test_add.py | 16 ++------- tests_integration/tests/spool/test_update.py | 34 ++------------------ 2 files changed, 6 insertions(+), 44 deletions(-) diff --git a/tests_integration/tests/spool/test_add.py b/tests_integration/tests/spool/test_add.py index 256913f..fa64f48 100644 --- a/tests_integration/tests/spool/test_add.py +++ b/tests_integration/tests/spool/test_add.py @@ -19,6 +19,7 @@ def test_add_spool_remaining_weight(random_filament: dict[str, Any]): lot_nr = "123456789" comment = "abcdefghåäö" archived = True + price = 25 result = httpx.post( f"{URL}/api/v1/spool", json={ @@ -30,6 +31,7 @@ def test_add_spool_remaining_weight(random_filament: dict[str, Any]): "lot_nr": lot_nr, "comment": comment, "archived": archived, + "price": price, }, ) result.raise_for_status() @@ -62,6 +64,7 @@ def test_add_spool_remaining_weight(random_filament: dict[str, Any]): "lot_nr": lot_nr, "comment": comment, "archived": archived, + "price": price, } # Verify that registered happened almost now (within 1 minute) @@ -185,16 +188,3 @@ def test_add_spool_both_used_and_remaining_weight(random_filament: dict[str, Any }, ) assert result.status_code == 400 # Cannot set both used and remaining weight - - -def test_add_spool_price(random_filament: dict[str, Any]): - """Test adding a spool to the database.""" - # Execute - result = httpx.post( - f"{URL}/api/v1/spool", - json={ - "filament_id": random_filament["id"], - "price": 25, - }, - ) - assert result.status_code == 400 # Cannot set price diff --git a/tests_integration/tests/spool/test_update.py b/tests_integration/tests/spool/test_update.py index 6075d6e..feaad44 100644 --- a/tests_integration/tests/spool/test_update.py +++ b/tests_integration/tests/spool/test_update.py @@ -33,6 +33,7 @@ def test_update_spool(random_filament: dict[str, Any]): lot_nr = "987654321" comment = "abcdefghåäö" archived = True + price = 25 result = httpx.patch( f"{URL}/api/v1/spool/{spool['id']}", json={ @@ -43,6 +44,7 @@ def test_update_spool(random_filament: dict[str, Any]): "lot_nr": lot_nr, "comment": comment, "archived": archived, + "price": price, }, ) result.raise_for_status() @@ -71,6 +73,7 @@ def test_update_spool(random_filament: dict[str, Any]): assert spool["lot_nr"] == lot_nr assert spool["comment"] == comment assert spool["archived"] == archived + assert spool["price"] == price # Clean up httpx.delete(f"{URL}/api/v1/spool/{spool['id']}").raise_for_status() @@ -100,37 +103,6 @@ def test_update_spool_both_used_and_remaining_weight(random_filament: dict[str, httpx.delete(f"{URL}/api/v1/spool/{spool['id']}").raise_for_status() -def test_update_spool_price(random_filament: dict[str, Any]): - """Test updating a spool in the database.""" - # Setup - result = httpx.post( - f"{URL}/api/v1/spool", - json={ - "filament_id": random_filament["id"], - "price": 50, - }, - ) - result.raise_for_status() - spool = result.json() - - # Execute - price = 25 - result = httpx.patch( - f"{URL}/api/v1/spool/{spool['id']}", - json={ - "price": price, - }, - ) - result.raise_for_status() - - # Verify - spool = result.json() - assert spool["price"] == 25 - - # Clean up - httpx.delete(f"{URL}/api/v1/spool/{spool['id']}").raise_for_status() - - def test_update_spool_not_found(random_filament: dict[str, Any]): """Test updating a spool that does not exist.""" # Execute From 1ec1e05c40544164dc3e8917f344a7291467d787 Mon Sep 17 00:00:00 2001 From: pdsccode Date: Wed, 10 Jan 2024 19:22:26 +0100 Subject: [PATCH 15/15] Reverted changes to .pre-commit-config.yaml, changed en locales to reflect default and added filament price as default to spools/show.tsx --- .pre-commit-config.yaml | 2 +- client/public/locales/en/common.json | 2 +- client/src/pages/spools/show.tsx | 11 ++++++++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a7d5009..628d25f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,5 +1,5 @@ default_language_version: - python: python3 + python: python3.9 repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.4.0 diff --git a/client/public/locales/en/common.json b/client/public/locales/en/common.json index fd26c6f..23e3f97 100644 --- a/client/public/locales/en/common.json +++ b/client/public/locales/en/common.json @@ -151,7 +151,7 @@ "archived": "Archived" }, "fields_help": { - "price": "Price of a full spool in the system configured currency.", + "price": "Price of a full spool in the system configured currency. If not set, the price of the filament will be assumed instead.", "weight_to_use": "Select what weight value to enter. Measured weight is only available if the spool weight is set for the selected filament.", "used_weight": "How much filament has been used from the spool. A new spool should have 0g used.", "remaining_weight": "How much filament is left on the spool. For a new spool this should match the spool weight.", diff --git a/client/src/pages/spools/show.tsx b/client/src/pages/spools/show.tsx index bae1b39..f068b00 100644 --- a/client/src/pages/spools/show.tsx +++ b/client/src/pages/spools/show.tsx @@ -23,6 +23,15 @@ export const SpoolShow: React.FC = () => { const record = data?.data; + const spoolPrice = (item: ISpool) => { + let spoolPrice = ""; + if (!item.price){ + spoolPrice = `${item.filament.price}`; + return spoolPrice; + } + return item.price; + } + const formatFilament = (item: IFilament) => { let vendorPrefix = ""; if (item.vendor) { @@ -59,7 +68,7 @@ export const SpoolShow: React.FC = () => { {t("spool.fields.filament")} {t("spool.fields.price")} - + {t("spool.fields.registered")}