-
-
Notifications
You must be signed in to change notification settings - Fork 409
Add UPC support to product import, search, and duplicate scan flow #1468
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -5,6 +5,21 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||
| <DialogTitle>{{ $t("components.item.product_import.title") }}</DialogTitle> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| </DialogHeader> | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| <div | ||||||||||||||||||||||||||||||||||||||||||||||||||
| v-if="existingItems.length > 0" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| class="flex flex-col gap-2 rounded-md border border-amber-500/40 bg-amber-500/10 p-4 text-amber-700 dark:text-amber-300" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| role="alert" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||||||||||||||||||||||||
| <span class="text-sm font-medium"> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| Found {{ existingItems.length }} existing item(s) with UPC {{ barcode }}. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| </span> | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+14
to
+15
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Duplicate count may be underreported due fixed page size. The alert says “Found N existing item(s)”, but 🛠️ Proposed fix- const existingResult = await api.items.getAll({ q: barcode.trim(), page: 1, pageSize: 10 });
+ const existingResult = await api.items.getAll({ q: barcode.trim(), page: 1, pageSize: 100 });If you keep paging capped, adjust the text to indicate it is a partial list (e.g., “showing first N matches”). Also applies to: 228-231 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||
| <div class="flex flex-wrap gap-2"> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| <Button v-for="existing in existingItems" :key="existing.id" size="sm" variant="outline" @click="navigateToItem(existing.id)"> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| Open {{ existing.name }} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| </Button> | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+8
to
+19
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Localize the new duplicate-alert copy. The strings 🌐 Proposed fix- <span class="text-sm font-medium">
- Found {{ existingItems.length }} existing item(s) with UPC {{ barcode }}.
- </span>
+ <span class="text-sm font-medium">
+ {{ $t("components.item.product_import.duplicates_found", { count: existingItems.length, barcode }) }}
+ </span>
<div class="flex flex-wrap gap-2">
<Button v-for="existing in existingItems" :key="existing.id" size="sm" variant="outline" `@click`="navigateToItem(existing.id)">
- Open {{ existing.name }}
+ {{ $t("components.item.product_import.open_item", { name: existing.name }) }}
</Button>
</div>As per coding guidelines: " 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| <div | ||||||||||||||||||||||||||||||||||||||||||||||||||
| v-if="errorMessage" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| class="flex items-center gap-2 rounded-md border border-destructive bg-destructive/10 p-4 text-destructive" | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -112,7 +127,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||
| import { useI18n } from "vue-i18n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import { DialogID } from "@/components/ui/dialog-provider/utils"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import { Button } from "~/components/ui/button"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import type { BarcodeProduct } from "~~/lib/api/types/data-contracts"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import type { BarcodeProduct, EntitySummary } from "~~/lib/api/types/data-contracts"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import { useDialog } from "~/components/ui/dialog-provider"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import MdiAlertCircleOutline from "~icons/mdi/alert-circle-outline"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import MdiBarcode from "~icons/mdi/barcode"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -129,6 +144,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||
| const searching = ref(false); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| const barcode = ref<string>(""); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| const products = ref<BarcodeProduct[] | null>(null); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| const existingItems = ref<EntitySummary[]>([]); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| const selectedRow = ref(-1); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| const errorMessage = ref<string | null>(null); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -159,6 +175,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||
| selectedRow.value = -1; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| searching.value = false; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| errorMessage.value = null; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| existingItems.value = []; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| if (params?.barcode) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| // Reset if the barcode is different | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -196,6 +213,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| async function retrieveProductInfo(barcode: string) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| errorMessage.value = null; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| existingItems.value = []; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!barcode || barcode.trim().length === 0 || !/^[0-9]+$/.test(barcode)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| errorMessage.value = t("components.item.product_import.error_invalid_barcode"); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -207,6 +225,11 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||
| searching.value = true; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| const existingResult = await api.items.getAll({ q: barcode.trim(), page: 1, pageSize: 10 }); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!existingResult.error && existingResult.data?.items) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| existingItems.value = existingResult.data.items.filter(item => item.upc === barcode.trim()); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| const result = await api.products.searchFromBarcode(barcode.trim()); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if (result.error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| errorMessage.value = t("errors.api_failure") + result.error; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -226,6 +249,10 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| function navigateToItem(itemId: string) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| navigateTo(`/item/${itemId}`); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||||||||||||||||||||||||||||||||||||||||||||||||||
| function extractValue(data: Record<string, any>, value: string) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| const parts = value.split("."); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -419,6 +419,7 @@ | |
| parentId: null, | ||
| name: "", | ||
| quantity: 1, | ||
| upc: "", | ||
| description: "", | ||
| color: "", | ||
| tags: [] as string[], | ||
|
|
@@ -602,6 +603,7 @@ | |
| if (params?.product) { | ||
| form.name = params.product.item.name; | ||
| form.description = params.product.item.description; | ||
| form.upc = params.product.barcode; | ||
|
|
||
|
Comment on lines
603
to
607
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. UPC is dropped when creation goes through the template endpoint.
💡 Proposed fix (preserve UPC immediately)- if (templateData.value) {
+ if (templateData.value && !form.upc) {
const templateRequest = {
name: form.name,
description: form.description,
parentId: form.location.id as string,
tagIds: form.tags,
quantity: form.quantity,
};
const result = await api.templates.createItem(templateData.value.id, templateRequest);
error = result.error;
data = result.data;
} else {
// Normal item creation without template
const out: EntityCreate = {
parentId: form.parentId || form.location.id as string,
name: form.name,
quantity: form.quantity,
upc: form.upc,
description: form.description,
tagIds: form.tags,
entityTypeId: selectedEntityType.value?.id,
};Also applies to: 646-666 🤖 Prompt for AI Agents |
||
| if (params.product.imageURL) { | ||
| form.photos.push({ | ||
|
|
@@ -660,6 +662,7 @@ | |
| parentId: form.parentId || form.location.id as string, | ||
| name: form.name, | ||
| quantity: form.quantity, | ||
| upc: form.upc, | ||
| description: form.description, | ||
| tagIds: form.tags, | ||
| entityTypeId: selectedEntityType.value?.id, | ||
|
|
@@ -705,6 +708,7 @@ | |
|
|
||
| form.name = ""; | ||
| form.quantity = 1; | ||
| form.upc = ""; | ||
| form.description = ""; | ||
| form.color = ""; | ||
| form.photos = []; | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid unconditional ImportRef overwrite on update.
SetImportRef(data.UPC)always executes. If UPC is absent/empty from a caller, this clears existing data unexpectedly.✅ Proposed fix
🤖 Prompt for AI Agents