Merge remote-tracking branch 'origin/master'

This commit is contained in:
M_Kececi
2026-04-04 19:04:59 +03:00
parent 6467017470
commit b1a3bbd3c5
5 changed files with 110 additions and 9 deletions

View File

@@ -895,18 +895,19 @@ async function saveCdItemDraft () {
function buildAttributeRowsFromLookup (list) {
const grouped = new Map()
for (const it of (list || [])) {
const typeCode = Number(it?.attribute_type_code || 0)
const typeCode = Number(it?.attribute_type_code || it?.AttributeTypeCode || 0)
if (!typeCode) continue
if (!grouped.has(typeCode)) {
grouped.set(typeCode, {
typeCode,
typeDesc: String(it?.attribute_type_description || '').trim() || String(typeCode),
typeDesc: String(it?.attribute_type_description || it?.AttributeTypeDescription || '').trim() || String(typeCode),
options: []
})
}
const g = grouped.get(typeCode)
const code = String(it?.attribute_code || '').trim()
const desc = String(it?.attribute_description || '').trim()
const code = String(it?.attribute_code || it?.AttributeCode || '').trim()
const desc = String(it?.attribute_description || it?.AttributeDescription || '').trim()
if (!code) continue
g.options.push({
value: code,
label: `${code} - ${desc || code}`
@@ -963,7 +964,7 @@ function mergeAttributeDraftWithLookupOptions (draftRows, lookupRows) {
const allOptions = baseAllOptions.length ? baseAllOptions : draftAllOptions
if (selectedCode && !allOptions.some(opt => String(opt?.value || '').trim() === selectedCode)) {
allOptions.unshift({ value: selectedCode, label: `${selectedCode} - (Secili)` })
allOptions.unshift({ value: selectedCode, label: selectedCode })
}
return {
@@ -982,14 +983,24 @@ async function openAttributeDialog (itemCode) {
if (!code) return
attributeTargetCode.value = code
const existingDraft = store.getProductAttributeDraft(code)
const modeInfo = store.classifyItemCode(code)
const fetched = await store.fetchProductAttributes(1)
const fromLookup = buildAttributeRowsFromLookup(fetched)
console.info('[OrderProductionUpdate] openAttributeDialog lookup', {
code,
mode: modeInfo.mode,
fetchedCount: Array.isArray(fetched) ? fetched.length : 0,
rowCount: fromLookup.length
})
if (!fromLookup.length) {
$q.notify({ type: 'negative', message: 'Urun ozellikleri listesi alinamadi. Lutfen daha sonra tekrar deneyin.' })
return
}
const modeInfo = store.classifyItemCode(code)
const dbCurrent = await store.fetchProductItemAttributes(code, 1, true)
console.info('[OrderProductionUpdate] openAttributeDialog dbCurrent', {
code,
dbCurrentCount: Array.isArray(dbCurrent) ? dbCurrent.length : 0
})
const dbMap = new Map(
(dbCurrent || []).map(x => [
@@ -1004,7 +1015,7 @@ async function openAttributeDialog (itemCode) {
? [...row.AllOptions]
: (Array.isArray(row.Options) ? [...row.Options] : [])
if (currentCode && !currentOptions.some(opt => String(opt?.value || '').trim() === currentCode)) {
currentOptions.unshift({ value: currentCode, label: `${currentCode} - (Mevcut)` })
currentOptions.unshift({ value: currentCode, label: currentCode })
}
return {
...row,
@@ -1019,6 +1030,18 @@ async function openAttributeDialog (itemCode) {
attributeRows.value = useDraft
? JSON.parse(JSON.stringify(mergeAttributeDraftWithLookupOptions(existingDraft, baseRows)))
: JSON.parse(JSON.stringify(baseRows))
console.info('[OrderProductionUpdate] openAttributeDialog rowsPrepared', {
code,
mode: modeInfo.mode,
useDraft,
rowCount: Array.isArray(attributeRows.value) ? attributeRows.value.length : 0,
optionCounts: (attributeRows.value || []).map(r => ({
type: Number(r?.AttributeTypeCodeNumber || 0),
options: Array.isArray(r?.Options) ? r.Options.length : 0,
allOptions: Array.isArray(r?.AllOptions) ? r.AllOptions.length : 0,
selected: String(r?.AttributeCode || '').trim()
}))
})
for (const row of (attributeRows.value || [])) {
if (!Array.isArray(row.AllOptions)) {
row.AllOptions = Array.isArray(row.Options) ? [...row.Options] : []
@@ -1046,6 +1069,14 @@ function saveAttributeDraft () {
}
}
store.setProductAttributeDraft(code, JSON.parse(JSON.stringify(attributeRows.value || [])))
console.info('[OrderProductionUpdate] saveAttributeDraft', {
code,
rowCount: (attributeRows.value || []).length,
selected: (attributeRows.value || []).map(r => ({
type: Number(r?.AttributeTypeCodeNumber || 0),
code: String(r?.AttributeCode || '').trim()
}))
})
attributeDialogOpen.value = false
$q.notify({ type: 'positive', message: 'Urun ozellikleri taslagi kaydedildi.' })
}
@@ -1062,6 +1093,11 @@ async function collectProductAttributesFromSelectedRows (selectedRows) {
const modeInfo = store.classifyItemCode(code)
let rows = store.getProductAttributeDraft(code)
let dbMap = new Map()
console.info('[OrderProductionUpdate] collectProductAttributes start', {
code,
mode: modeInfo.mode,
draftRowCount: Array.isArray(rows) ? rows.length : 0
})
if (modeInfo.mode === 'existing') {
const dbCurrent = await store.fetchProductItemAttributes(code, 1, true)
@@ -1077,13 +1113,18 @@ async function collectProductAttributesFromSelectedRows (selectedRows) {
if (!Array.isArray(rows) || !rows.length) {
const lookup = await store.fetchProductAttributes(1)
const baseRows = buildAttributeRowsFromLookup(lookup)
console.info('[OrderProductionUpdate] collectProductAttributes existing refetch', {
code,
lookupCount: Array.isArray(lookup) ? lookup.length : 0,
baseRowCount: baseRows.length
})
rows = baseRows.map(row => {
const currentCode = dbMap.get(Number(row.AttributeTypeCodeNumber || 0)) || ''
const currentOptions = Array.isArray(row.AllOptions)
? [...row.AllOptions]
: (Array.isArray(row.Options) ? [...row.Options] : [])
if (currentCode && !currentOptions.some(opt => String(opt?.value || '').trim() === currentCode)) {
currentOptions.unshift({ value: currentCode, label: `${currentCode} - (Mevcut)` })
currentOptions.unshift({ value: currentCode, label: currentCode })
}
return {
...row,
@@ -1109,6 +1150,12 @@ async function collectProductAttributesFromSelectedRows (selectedRows) {
...row,
AttributeCode: dbMap.get(Number(row.AttributeTypeCodeNumber || 0)) || ''
}))
console.info('[OrderProductionUpdate] collectProductAttributes new init', {
code,
lookupCount: Array.isArray(lookup) ? lookup.length : 0,
baseRowCount: baseRows.length,
dbCurrentCount: Array.isArray(dbCurrent) ? dbCurrent.length : 0
})
store.setProductAttributeDraft(code, JSON.parse(JSON.stringify(rows)))
}
@@ -1143,6 +1190,17 @@ async function collectProductAttributesFromSelectedRows (selectedRows) {
AttributeCode: attributeCode
})
}
console.info('[OrderProductionUpdate] collectProductAttributes done', {
code,
mode: modeInfo.mode,
outCount: out.filter(x => x.ItemCode === code).length,
rowCount: rows.length,
optionCounts: rows.map(r => ({
type: Number(r?.AttributeTypeCodeNumber || 0),
options: Array.isArray(r?.Options) ? r.Options.length : 0,
allOptions: Array.isArray(r?.AllOptions) ? r.AllOptions.length : 0
}))
})
}
return { errMsg: '', productAttributes: out }
}