Begin adding Purchase Method to item purchase details

This commit is contained in:
Katos
2024-07-12 22:44:29 +01:00
committed by GitHub
parent 625730f37c
commit da78f13513
11 changed files with 32 additions and 11 deletions

View File

@@ -2145,6 +2145,9 @@
"purchaseFrom": { "purchaseFrom": {
"type": "string" "type": "string"
}, },
"purchaseFrom": {
"type": "string"
},
"purchasePrice": { "purchasePrice": {
"type": "string", "type": "string",
"example": "0" "example": "0"

View File

@@ -170,6 +170,8 @@ definitions:
x-omitempty: true x-omitempty: true
purchaseFrom: purchaseFrom:
type: string type: string
purchaseMethod:
type: string
purchasePrice: purchasePrice:
example: "0" example: "0"
type: string type: string

View File

@@ -202,9 +202,10 @@ func (s *IOSheet) ReadItems(ctx context.Context, items []repo.ItemOut, GID uuid.
Insured: item.Insured, Insured: item.Insured,
Archived: item.Archived, Archived: item.Archived,
PurchasePrice: item.PurchasePrice, PurchasePrice: item.PurchasePrice,
PurchaseFrom: item.PurchaseFrom, PurchaseMethod: item.PurchaseMethod,
PurchaseTime: item.PurchaseTime, PurchaseFrom: item.PurchaseFrom,
PurchaseTime: item.PurchaseTime,
Manufacturer: item.Manufacturer, Manufacturer: item.Manufacturer,
ModelNumber: item.ModelNumber, ModelNumber: item.ModelNumber,

View File

@@ -298,6 +298,7 @@ func (svc *ItemService) CsvImport(ctx context.Context, GID uuid.UUID, data io.Re
Archived: row.Archived, Archived: row.Archived,
PurchasePrice: row.PurchasePrice, PurchasePrice: row.PurchasePrice,
PurchaseFrom: row.PurchaseMethod,
PurchaseFrom: row.PurchaseFrom, PurchaseFrom: row.PurchaseFrom,
PurchaseTime: row.PurchaseTime, PurchaseTime: row.PurchaseTime,

View File

@@ -76,6 +76,8 @@ func (Item) Fields() []ent.Field {
// ------------------------------------ // ------------------------------------
// item purchase // item purchase
field.String("purchase_method").
Optional(),
field.Time("purchase_time"). field.Time("purchase_time").
Optional(), Optional(),
field.String("purchase_from"). field.String("purchase_from").

View File

@@ -17,7 +17,7 @@ CREATE INDEX `documenttoken_token` ON `document_tokens` (`token`);
-- create "groups" table -- 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 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 "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" to table: "items"
CREATE INDEX `item_name` ON `items` (`name`); CREATE INDEX `item_name` ON `items` (`name`);
-- create index "item_manufacturer" to table: "items" -- create index "item_manufacturer" to table: "items"

View File

@@ -91,9 +91,10 @@ type (
WarrantyDetails string `json:"warrantyDetails"` WarrantyDetails string `json:"warrantyDetails"`
// Purchase // Purchase
PurchaseTime types.Date `json:"purchaseTime"` PurchaseMethod string `json:"purchaseMethod"`
PurchaseFrom string `json:"purchaseFrom"` PurchaseTime types.Date `json:"purchaseTime"`
PurchasePrice float64 `json:"purchasePrice,string"` PurchaseFrom string `json:"purchaseFrom"`
PurchasePrice float64 `json:"purchasePrice,string"`
// Sold // Sold
SoldTime types.Date `json:"soldTime"` SoldTime types.Date `json:"soldTime"`
@@ -147,8 +148,9 @@ type (
WarrantyDetails string `json:"warrantyDetails"` WarrantyDetails string `json:"warrantyDetails"`
// Purchase // Purchase
PurchaseTime types.Date `json:"purchaseTime"` PurchaseMethod string `json:"purchaseMethod"`
PurchaseFrom string `json:"purchaseFrom"` PurchaseTime types.Date `json:"purchaseTime"`
PurchaseFrom string `json:"purchaseFrom"`
// Sold // Sold
SoldTime types.Date `json:"soldTime"` SoldTime types.Date `json:"soldTime"`
@@ -261,8 +263,9 @@ func mapItemOut(item *ent.Item) ItemOut {
Manufacturer: item.Manufacturer, Manufacturer: item.Manufacturer,
// Purchase // Purchase
PurchaseTime: types.DateFromTime(item.PurchaseTime), PurchaseMethod: item.PurchaseMethod
PurchaseFrom: item.PurchaseFrom, PurchaseTime: types.DateFromTime(item.PurchaseTime),
PurchaseFrom: item.PurchaseFrom,
// Sold // Sold
SoldTime: types.DateFromTime(item.SoldTime), SoldTime: types.DateFromTime(item.SoldTime),
@@ -594,6 +597,7 @@ func (e *ItemsRepository) UpdateByGroup(ctx context.Context, GID uuid.UUID, data
SetManufacturer(data.Manufacturer). SetManufacturer(data.Manufacturer).
SetArchived(data.Archived). SetArchived(data.Archived).
SetPurchaseTime(data.PurchaseTime.Time()). SetPurchaseTime(data.PurchaseTime.Time()).
SetPurchaseMethod(data.PurchaseMethod).
SetPurchaseFrom(data.PurchaseFrom). SetPurchaseFrom(data.PurchaseFrom).
SetPurchasePrice(data.PurchasePrice). SetPurchasePrice(data.PurchasePrice).
SetSoldTime(data.SoldTime.Time()). SetSoldTime(data.SoldTime.Time()).

View File

@@ -236,6 +236,7 @@ func TestItemsRepository_Update(t *testing.T) {
ModelNumber: fk.Str(10), ModelNumber: fk.Str(10),
Manufacturer: fk.Str(10), Manufacturer: fk.Str(10),
PurchaseTime: types.DateFromTime(time.Now()), PurchaseTime: types.DateFromTime(time.Now()),
PurchaseMethod: fk.Str(10),
PurchaseFrom: fk.Str(10), PurchaseFrom: fk.Str(10),
PurchasePrice: 300.99, PurchasePrice: 300.99,
SoldTime: types.DateFromTime(time.Now()), SoldTime: types.DateFromTime(time.Now()),
@@ -262,6 +263,7 @@ func TestItemsRepository_Update(t *testing.T) {
assert.Equal(t, updateData.Manufacturer, got.Manufacturer) assert.Equal(t, updateData.Manufacturer, got.Manufacturer)
// assert.Equal(t, updateData.PurchaseTime, got.PurchaseTime) // assert.Equal(t, updateData.PurchaseTime, got.PurchaseTime)
assert.Equal(t, updateData.PurchaseFrom, got.PurchaseFrom) assert.Equal(t, updateData.PurchaseFrom, got.PurchaseFrom)
assert.Equal(t, updateData.PurchaseMethod, got.PurchaseMethod)
assert.InDelta(t, updateData.PurchasePrice, got.PurchasePrice, 0.01) assert.InDelta(t, updateData.PurchasePrice, got.PurchasePrice, 0.01)
// assert.Equal(t, updateData.SoldTime, got.SoldTime) // assert.Equal(t, updateData.SoldTime, got.SoldTime)
assert.Equal(t, updateData.SoldTo, got.SoldTo) assert.Equal(t, updateData.SoldTo, got.SoldTo)

View File

@@ -2140,6 +2140,9 @@
"x-nullable": true, "x-nullable": true,
"x-omitempty": true "x-omitempty": true
}, },
"purchaseMethod": {
"type": "string"
},
"purchaseFrom": { "purchaseFrom": {
"type": "string" "type": "string"
}, },

View File

@@ -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.model_number | String | Model of the item |
| HB.manufacturer | String | Manufacturer of the item | | HB.manufacturer | String | Manufacturer of the item |
| HB.notes | String (1000) | General notes about the product | | 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_from | String | Name of the place the item was purchased from |
| HB.purchase_price | Float64 | | | HB.purchase_price | Float64 | |
| HB.purchase_time | Date | Date the item was purchased | | HB.purchase_time | Date | Date the item was purchased |

View File

@@ -16,6 +16,7 @@ type ImportObj = {
[`HB.manufacturer`]: string; [`HB.manufacturer`]: string;
[`HB.notes`]: string; [`HB.notes`]: string;
[`HB.purchase_price`]: number; [`HB.purchase_price`]: number;
[`HB.purchase_method`]: string;
[`HB.purchase_from`]: string; [`HB.purchase_from`]: string;
[`HB.purchase_time`]: string; [`HB.purchase_time`]: string;
[`HB.lifetime_warranty`]: boolean; [`HB.lifetime_warranty`]: boolean;
@@ -62,6 +63,7 @@ function importFileGenerator(entries: number): ImportObj[] {
[`HB.manufacturer`]: faker.string.alphanumeric(5), [`HB.manufacturer`]: faker.string.alphanumeric(5),
[`HB.notes`]: "", [`HB.notes`]: "",
[`HB.purchase_from`]: faker.person.fullName(), [`HB.purchase_from`]: faker.person.fullName(),
[`HB.purchase_method`]: faker.string.alphanumeric(5),
[`HB.purchase_price`]: faker.number.int(100), [`HB.purchase_price`]: faker.number.int(100),
[`HB.purchase_time`]: faker.date.past().toDateString(), [`HB.purchase_time`]: faker.date.past().toDateString(),
[`HB.lifetime_warranty`]: half > i, [`HB.lifetime_warranty`]: half > i,