fix(wizard): store material name cleanly instead of brand+category+specs
Adding a new item wrote the material name as 'brand + category + specs' (e.g. 'پارس لوله لوله PE100 سایز ۱۶'), while specs were also stored correctly in EAV attributes. The wizard then tried to recover the base name by stripping brand and specs out of that string, but never stripped the injected category — so the spec stayed baked into the cached material name and the مشخصه appeared as part of the material name on later visits. - api.ts / WizardPage / EditModal: build name from the material itself only (brand goes to brand_ids, specs to attributes) - materialBaseName: strip category too, never strip a part that would empty the name, and reject a spec-only result; legacy rows whose name cannot be disentangled fall back to the stored name rather than a guess - WizardPage: match existing materials on category+brand so legacy rows are still reused instead of duplicated
This commit is contained in:
@@ -128,7 +128,7 @@ export function WizardPage() {
|
||||
const rememberMaterial = (rec: MaterialRec) => {
|
||||
void addMaterial.mutateAsync({
|
||||
id: nextId("m", materials),
|
||||
name: [rec.brand, rec.category, ...rec.specs].filter(Boolean).join(" ") || "کالای جدید",
|
||||
name: (rec.category || rec.brand || rec.specs.join(" ") || "").trim() || "کالای جدید",
|
||||
topic: rec.topic,
|
||||
category: rec.category,
|
||||
brand: rec.brand,
|
||||
@@ -243,7 +243,7 @@ export function WizardPage() {
|
||||
const total = it.total;
|
||||
if (!cat && !brand && qty == null && price == null) continue;
|
||||
|
||||
const wantName = [brand, cat, ...specs].filter(Boolean).join(" ") || "کالای جدید";
|
||||
const wantName = (cat || brand || specs.join(" ") || "").trim() || "کالای جدید";
|
||||
let material = materials.find((m) => normalize(m.name) === normalize(wantName));
|
||||
if (!material) {
|
||||
material = materials.find(
|
||||
@@ -253,6 +253,13 @@ export function WizardPage() {
|
||||
specsKey(m.specs) === specsKey(specs),
|
||||
);
|
||||
}
|
||||
// رکوردهای قدیمی name را به شکل «برند + دسته + مشخصه» ذخیره کردهاند؛
|
||||
// تطبیق دوم بر اساس category/brand/specs انجام میشود تا آنها هم پیدا شوند.
|
||||
if (!material && cat) {
|
||||
material = materials.find(
|
||||
(m) => normalize(m.category) === normalize(cat) && normalize(m.brand) === normalize(brand),
|
||||
);
|
||||
}
|
||||
let materialId: string;
|
||||
if (material) {
|
||||
materialId = material.id;
|
||||
|
||||
Reference in New Issue
Block a user