Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Begin adding Purchase Method to item purchase details #124

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions backend/app/api/static/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -2145,6 +2145,9 @@
"purchaseFrom": {
"type": "string"
},
"purchaseFrom": {
"type": "string"
},
"purchasePrice": {
"type": "string",
"example": "0"
Expand Down
2 changes: 2 additions & 0 deletions backend/app/api/static/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ definitions:
x-omitempty: true
purchaseFrom:
type: string
purchaseMethod:
type: string
purchasePrice:
example: "0"
type: string
Expand Down
7 changes: 4 additions & 3 deletions backend/internal/core/services/reporting/io_sheet.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,10 @@ func (s *IOSheet) ReadItems(ctx context.Context, items []repo.ItemOut, GID uuid.
Insured: item.Insured,
Archived: item.Archived,

PurchasePrice: item.PurchasePrice,
PurchaseFrom: item.PurchaseFrom,
PurchaseTime: item.PurchaseTime,
PurchasePrice: item.PurchasePrice,
PurchaseMethod: item.PurchaseMethod,
PurchaseFrom: item.PurchaseFrom,
PurchaseTime: item.PurchaseTime,

Manufacturer: item.Manufacturer,
ModelNumber: item.ModelNumber,
Expand Down
1 change: 1 addition & 0 deletions backend/internal/core/services/service_items.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ func (svc *ItemService) CsvImport(ctx context.Context, GID uuid.UUID, data io.Re
Archived: row.Archived,

PurchasePrice: row.PurchasePrice,
PurchaseFrom: row.PurchaseMethod,
PurchaseFrom: row.PurchaseFrom,
PurchaseTime: row.PurchaseTime,

Expand Down
2 changes: 2 additions & 0 deletions backend/internal/data/ent/schema/item.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ func (Item) Fields() []ent.Field {

// ------------------------------------
// item purchase
field.String("purchase_method").
Optional(),
field.Time("purchase_time").
Optional(),
field.String("purchase_from").
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ CREATE INDEX `documenttoken_token` ON `document_tokens` (`token`);
-- create "groups" table
CREATE TABLE `groups` (`id` uuid NOT NULL, `created_at` datetime NOT NULL, `updated_at` datetime NOT NULL, `name` text NOT NULL, `currency` text NOT NULL DEFAULT 'usd', PRIMARY KEY (`id`));
-- create "items" table
CREATE TABLE `items` (`id` uuid NOT NULL, `created_at` datetime NOT NULL, `updated_at` datetime NOT NULL, `name` text NOT NULL, `description` text NULL, `import_ref` text NULL, `notes` text NULL, `quantity` integer NOT NULL DEFAULT 1, `insured` bool NOT NULL DEFAULT false, `serial_number` text NULL, `model_number` text NULL, `manufacturer` text NULL, `lifetime_warranty` bool NOT NULL DEFAULT false, `warranty_expires` datetime NULL, `warranty_details` text NULL, `purchase_time` datetime NULL, `purchase_from` text NULL, `purchase_price` real NOT NULL DEFAULT 0, `sold_time` datetime NULL, `sold_to` text NULL, `sold_price` real NOT NULL DEFAULT 0, `sold_notes` text NULL, `group_items` uuid NOT NULL, `location_items` uuid NULL, PRIMARY KEY (`id`), CONSTRAINT `items_groups_items` FOREIGN KEY (`group_items`) REFERENCES `groups` (`id`) ON DELETE CASCADE, CONSTRAINT `items_locations_items` FOREIGN KEY (`location_items`) REFERENCES `locations` (`id`) ON DELETE CASCADE);
CREATE TABLE `items` (`id` uuid NOT NULL, `created_at` datetime NOT NULL, `updated_at` datetime NOT NULL, `name` text NOT NULL, `description` text NULL, `import_ref` text NULL, `notes` text NULL, `quantity` integer NOT NULL DEFAULT 1, `insured` bool NOT NULL DEFAULT false, `serial_number` text NULL, `model_number` text NULL, `manufacturer` text NULL, `lifetime_warranty` bool NOT NULL DEFAULT false, `warranty_expires` datetime NULL, `warranty_details` text NULL, `purchase_method` text NULL, `purchase_time` datetime NULL, `purchase_from` text NULL, `purchase_price` real NOT NULL DEFAULT 0, `sold_time` datetime NULL, `sold_to` text NULL, `sold_price` real NOT NULL DEFAULT 0, `sold_notes` text NULL, `group_items` uuid NOT NULL, `location_items` uuid NULL, PRIMARY KEY (`id`), CONSTRAINT `items_groups_items` FOREIGN KEY (`group_items`) REFERENCES `groups` (`id`) ON DELETE CASCADE, CONSTRAINT `items_locations_items` FOREIGN KEY (`location_items`) REFERENCES `locations` (`id`) ON DELETE CASCADE);
-- create index "item_name" to table: "items"
CREATE INDEX `item_name` ON `items` (`name`);
-- create index "item_manufacturer" to table: "items"
Expand Down
18 changes: 11 additions & 7 deletions backend/internal/data/repo/repo_items.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,10 @@ type (
WarrantyDetails string `json:"warrantyDetails"`

// Purchase
PurchaseTime types.Date `json:"purchaseTime"`
PurchaseFrom string `json:"purchaseFrom"`
PurchasePrice float64 `json:"purchasePrice,string"`
PurchaseMethod string `json:"purchaseMethod"`
PurchaseTime types.Date `json:"purchaseTime"`
PurchaseFrom string `json:"purchaseFrom"`
PurchasePrice float64 `json:"purchasePrice,string"`

// Sold
SoldTime types.Date `json:"soldTime"`
Expand Down Expand Up @@ -147,8 +148,9 @@ type (
WarrantyDetails string `json:"warrantyDetails"`

// Purchase
PurchaseTime types.Date `json:"purchaseTime"`
PurchaseFrom string `json:"purchaseFrom"`
PurchaseMethod string `json:"purchaseMethod"`
PurchaseTime types.Date `json:"purchaseTime"`
PurchaseFrom string `json:"purchaseFrom"`

// Sold
SoldTime types.Date `json:"soldTime"`
Expand Down Expand Up @@ -261,8 +263,9 @@ func mapItemOut(item *ent.Item) ItemOut {
Manufacturer: item.Manufacturer,

// Purchase
PurchaseTime: types.DateFromTime(item.PurchaseTime),
PurchaseFrom: item.PurchaseFrom,
PurchaseMethod: item.PurchaseMethod
PurchaseTime: types.DateFromTime(item.PurchaseTime),
PurchaseFrom: item.PurchaseFrom,

// Sold
SoldTime: types.DateFromTime(item.SoldTime),
Expand Down Expand Up @@ -594,6 +597,7 @@ func (e *ItemsRepository) UpdateByGroup(ctx context.Context, GID uuid.UUID, data
SetManufacturer(data.Manufacturer).
SetArchived(data.Archived).
SetPurchaseTime(data.PurchaseTime.Time()).
SetPurchaseMethod(data.PurchaseMethod).
SetPurchaseFrom(data.PurchaseFrom).
SetPurchasePrice(data.PurchasePrice).
SetSoldTime(data.SoldTime.Time()).
Expand Down
2 changes: 2 additions & 0 deletions backend/internal/data/repo/repo_items_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ func TestItemsRepository_Update(t *testing.T) {
ModelNumber: fk.Str(10),
Manufacturer: fk.Str(10),
PurchaseTime: types.DateFromTime(time.Now()),
PurchaseMethod: fk.Str(10),
PurchaseFrom: fk.Str(10),
PurchasePrice: 300.99,
SoldTime: types.DateFromTime(time.Now()),
Expand All @@ -262,6 +263,7 @@ func TestItemsRepository_Update(t *testing.T) {
assert.Equal(t, updateData.Manufacturer, got.Manufacturer)
// assert.Equal(t, updateData.PurchaseTime, got.PurchaseTime)
assert.Equal(t, updateData.PurchaseFrom, got.PurchaseFrom)
assert.Equal(t, updateData.PurchaseMethod, got.PurchaseMethod)
assert.InDelta(t, updateData.PurchasePrice, got.PurchasePrice, 0.01)
// assert.Equal(t, updateData.SoldTime, got.SoldTime)
assert.Equal(t, updateData.SoldTo, got.SoldTo)
Expand Down
3 changes: 3 additions & 0 deletions docs/docs/api/openapi-2.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -2140,6 +2140,9 @@
"x-nullable": true,
"x-omitempty": true
},
"purchaseMethod": {
"type": "string"
},
"purchaseFrom": {
"type": "string"
},
Expand Down
1 change: 1 addition & 0 deletions docs/en/import-csv.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Specifying import refs also allows you to update existing items via the CSV impo
| HB.model_number | String | Model of the item |
| HB.manufacturer | String | Manufacturer of the item |
| HB.notes | String (1000) | General notes about the product |
| HB.purchase_method | String | Method of how the item was purchased |
| HB.purchase_from | String | Name of the place the item was purchased from |
| HB.purchase_price | Float64 | |
| HB.purchase_time | Date | Date the item was purchased |
Expand Down
2 changes: 2 additions & 0 deletions frontend/lib/api/__test__/user/stats.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type ImportObj = {
[`HB.manufacturer`]: string;
[`HB.notes`]: string;
[`HB.purchase_price`]: number;
[`HB.purchase_method`]: string;
[`HB.purchase_from`]: string;
[`HB.purchase_time`]: string;
[`HB.lifetime_warranty`]: boolean;
Expand Down Expand Up @@ -62,6 +63,7 @@ function importFileGenerator(entries: number): ImportObj[] {
[`HB.manufacturer`]: faker.string.alphanumeric(5),
[`HB.notes`]: "",
[`HB.purchase_from`]: faker.person.fullName(),
[`HB.purchase_method`]: faker.string.alphanumeric(5),
[`HB.purchase_price`]: faker.number.int(100),
[`HB.purchase_time`]: faker.date.past().toDateString(),
[`HB.lifetime_warranty`]: half > i,
Expand Down
Loading