feat: gérer les constructeurs multiples
This commit is contained in:
@@ -98,10 +98,10 @@
|
||||
<span class="label-text">Constructeur</span>
|
||||
</label>
|
||||
<ConstructeurSelect
|
||||
v-model="editionForm.constructeurId"
|
||||
v-model="editionForm.constructeurIds"
|
||||
class="w-full"
|
||||
:disabled="saving"
|
||||
placeholder="Rechercher un constructeur..."
|
||||
placeholder="Rechercher un ou plusieurs constructeurs..."
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
@@ -404,6 +404,7 @@ import { useApi } from '~/composables/useApi'
|
||||
import { useToast } from '~/composables/useToast'
|
||||
import { useDocuments } from '~/composables/useDocuments'
|
||||
import { formatStructurePreview, normalizeStructureForEditor } from '~/shared/modelUtils'
|
||||
import { uniqueConstructeurIds } from '~/shared/constructeurUtils'
|
||||
import type { ComponentModelStructure } from '~/shared/types/inventory'
|
||||
import type { ModelType } from '~/services/modelTypes'
|
||||
import { getFileIcon } from '~/utils/fileIcons'
|
||||
@@ -448,7 +449,7 @@ const selectedTypeId = ref<string>('')
|
||||
const editionForm = reactive({
|
||||
name: '' as string,
|
||||
reference: '' as string,
|
||||
constructeurId: null as string | null,
|
||||
constructeurIds: [] as string[],
|
||||
prix: '' as string,
|
||||
})
|
||||
|
||||
@@ -651,7 +652,11 @@ watch(
|
||||
|
||||
editionForm.name = currentComponent.name || ''
|
||||
editionForm.reference = currentComponent.reference || ''
|
||||
editionForm.constructeurId = currentComponent.constructeur?.id || currentComponent.constructeurId || null
|
||||
editionForm.constructeurIds = uniqueConstructeurIds(
|
||||
currentComponent,
|
||||
Array.isArray(currentComponent.constructeurs) ? currentComponent.constructeurs : [],
|
||||
currentComponent.constructeur ? [currentComponent.constructeur] : [],
|
||||
)
|
||||
editionForm.prix = currentComponent.prix !== null && currentComponent.prix !== undefined ? String(currentComponent.prix) : ''
|
||||
|
||||
customFieldInputs.value = buildCustomFieldInputs(
|
||||
@@ -691,7 +696,7 @@ const submitEdition = async () => {
|
||||
|
||||
const reference = editionForm.reference.trim()
|
||||
payload.reference = reference ? reference : null
|
||||
payload.constructeurId = editionForm.constructeurId || null
|
||||
payload.constructeurIds = uniqueConstructeurIds(editionForm.constructeurIds)
|
||||
|
||||
if (rawPrice) {
|
||||
const parsed = Number(rawPrice)
|
||||
|
||||
@@ -71,10 +71,10 @@
|
||||
<span class="label-text">Constructeur</span>
|
||||
</label>
|
||||
<ConstructeurSelect
|
||||
v-model="creationForm.constructeurId"
|
||||
v-model="creationForm.constructeurIds"
|
||||
class="w-full"
|
||||
:disabled="submitting || !selectedType"
|
||||
placeholder="Rechercher un constructeur..."
|
||||
placeholder="Rechercher un ou plusieurs constructeurs..."
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
@@ -339,6 +339,7 @@ import { useToast } from '~/composables/useToast'
|
||||
import { useCustomFields } from '~/composables/useCustomFields'
|
||||
import { useDocuments } from '~/composables/useDocuments'
|
||||
import { formatStructurePreview, normalizeStructureForEditor } from '~/shared/modelUtils'
|
||||
import { uniqueConstructeurIds } from '~/shared/constructeurUtils'
|
||||
import type {
|
||||
ComponentModelPiece,
|
||||
ComponentModelStructure,
|
||||
@@ -376,7 +377,7 @@ const submitting = ref(false)
|
||||
const creationForm = reactive({
|
||||
name: '' as string,
|
||||
reference: '' as string,
|
||||
constructeurId: null as string | null,
|
||||
constructeurIds: [] as string[],
|
||||
prix: '' as string,
|
||||
})
|
||||
const lastSuggestedName = ref('')
|
||||
@@ -737,7 +738,7 @@ const resolveSubcomponentLabel = (node: Record<string, any>) => {
|
||||
const clearCreationForm = () => {
|
||||
creationForm.name = ''
|
||||
creationForm.reference = ''
|
||||
creationForm.constructeurId = null
|
||||
creationForm.constructeurIds = []
|
||||
creationForm.prix = ''
|
||||
lastSuggestedName.value = ''
|
||||
structureAssignments.value = null
|
||||
@@ -758,8 +759,8 @@ const submitCreation = async () => {
|
||||
payload.reference = reference
|
||||
}
|
||||
|
||||
if (creationForm.constructeurId) {
|
||||
payload.constructeurId = creationForm.constructeurId
|
||||
if (creationForm.constructeurIds.length) {
|
||||
payload.constructeurIds = uniqueConstructeurIds(creationForm.constructeurIds)
|
||||
}
|
||||
|
||||
const rawPrice = typeof creationForm.prix === 'string'
|
||||
|
||||
@@ -143,19 +143,27 @@
|
||||
v-if="isEditMode"
|
||||
class="w-full"
|
||||
:key="machine.value?.id"
|
||||
:model-value="machineConstructeurId"
|
||||
placeholder="Rechercher un constructeur..."
|
||||
:model-value="machineConstructeurIds"
|
||||
placeholder="Rechercher un ou plusieurs constructeurs..."
|
||||
@update:modelValue="handleMachineConstructeurChange"
|
||||
/>
|
||||
<div v-else class="input input-bordered bg-base-200">
|
||||
<div class="flex flex-col">
|
||||
<span class="font-medium">
|
||||
{{ machineConstructeurDisplay?.name || machineConstructeurContact }}
|
||||
</span>
|
||||
<span v-if="machineConstructeurContact" class="text-xs text-gray-500">
|
||||
{{ machineConstructeurContact }}
|
||||
</span>
|
||||
<div v-if="machineConstructeursDisplay.length" class="space-y-1">
|
||||
<div
|
||||
v-for="constructeur in machineConstructeursDisplay"
|
||||
:key="constructeur.id"
|
||||
class="flex flex-col"
|
||||
>
|
||||
<span class="font-medium">{{ constructeur.name }}</span>
|
||||
<span
|
||||
v-if="formatConstructeurContactSummary(constructeur)"
|
||||
class="text-xs text-gray-500"
|
||||
>
|
||||
{{ formatConstructeurContactSummary(constructeur) }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<span v-else class="font-medium">Non défini</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -542,6 +550,11 @@ import { useToast } from '~/composables/useToast'
|
||||
import { useDocuments } from '~/composables/useDocuments'
|
||||
import { getFileIcon } from '~/utils/fileIcons'
|
||||
import { sanitizeDefinitionOverrides, normalizeStructureForEditor } from '~/shared/modelUtils'
|
||||
import {
|
||||
resolveConstructeurs,
|
||||
uniqueConstructeurIds,
|
||||
formatConstructeurContact as formatConstructeurContactSummary,
|
||||
} from '~/shared/constructeurUtils'
|
||||
import { canPreviewDocument, isImageDocument, isPdfDocument } from '~/utils/documentPreview'
|
||||
import ComponentHierarchy from '~/components/ComponentHierarchy.vue'
|
||||
import DocumentUpload from '~/components/DocumentUpload.vue'
|
||||
@@ -606,26 +619,36 @@ const { constructeurs, loadConstructeurs } = useConstructeurs()
|
||||
// Champs de la machine
|
||||
const machineName = ref('')
|
||||
const machineReference = ref('')
|
||||
const machineConstructeurId = ref(null)
|
||||
const machineConstructeurDisplay = computed(() => {
|
||||
const id = machineConstructeurId.value || machine.value?.constructeur?.id || machine.value?.constructeurId
|
||||
if (!id) return machine.value?.constructeur || null
|
||||
return constructeurs.value.find(item => item.id === id) || machine.value?.constructeur || null
|
||||
const machineConstructeurIds = ref([])
|
||||
const machineConstructeurId = computed({
|
||||
get: () => machineConstructeurIds.value[0] || null,
|
||||
set: (value) => {
|
||||
machineConstructeurIds.value = value ? [value] : []
|
||||
},
|
||||
})
|
||||
const machineConstructeurContact = computed(() => {
|
||||
const constructeur = machineConstructeurDisplay.value
|
||||
if (!constructeur) {
|
||||
return ''
|
||||
}
|
||||
return [constructeur.email, constructeur.phone].filter(Boolean).join(' • ')
|
||||
})
|
||||
const hasMachineConstructeur = computed(() => {
|
||||
const constructeur = machineConstructeurDisplay.value
|
||||
if (!constructeur) {
|
||||
return false
|
||||
}
|
||||
return Boolean(constructeur.name || machineConstructeurContact.value)
|
||||
const machineConstructeursDisplay = computed(() => {
|
||||
const ids = uniqueConstructeurIds(
|
||||
machineConstructeurIds.value,
|
||||
machine.value?.constructeurIds,
|
||||
machine.value?.constructeurs,
|
||||
machine.value?.constructeur,
|
||||
)
|
||||
return resolveConstructeurs(
|
||||
ids,
|
||||
Array.isArray(machine.value?.constructeurs) ? machine.value?.constructeurs : [],
|
||||
machine.value?.constructeur ? [machine.value.constructeur] : [],
|
||||
constructeurs.value,
|
||||
)
|
||||
})
|
||||
const machineConstructeurContact = computed(() =>
|
||||
machineConstructeursDisplay.value
|
||||
.map((constructeur) => formatConstructeurContactSummary(constructeur))
|
||||
.filter(Boolean)
|
||||
.join(' • '),
|
||||
)
|
||||
const hasMachineConstructeur = computed(
|
||||
() => machineConstructeursDisplay.value.length > 0,
|
||||
)
|
||||
|
||||
const machineDocumentFiles = ref([])
|
||||
const machineDocumentsUploading = ref(false)
|
||||
@@ -826,7 +849,8 @@ const createComponentSelectionEntry = (requirement, source = null) => {
|
||||
|| requirement?.typeComposant?.name
|
||||
|| '',
|
||||
reference: source?.reference || '',
|
||||
constructeurId: source?.constructeurId || source?.constructeur?.id || null,
|
||||
constructeurIds: [],
|
||||
constructeurId: null,
|
||||
prix:
|
||||
source?.prix
|
||||
?? source?.price
|
||||
@@ -834,6 +858,16 @@ const createComponentSelectionEntry = (requirement, source = null) => {
|
||||
},
|
||||
}
|
||||
|
||||
const definitionConstructeurIds = uniqueConstructeurIds(
|
||||
link?.overrides?.constructeurIds,
|
||||
link?.overrides?.constructeurId,
|
||||
source?.constructeurIds,
|
||||
source?.constructeurId,
|
||||
source?.constructeur,
|
||||
)
|
||||
entry.definition.constructeurIds = definitionConstructeurIds
|
||||
entry.definition.constructeurId = definitionConstructeurIds[0] || null
|
||||
|
||||
if (link?.overrides && isPlainObject(link.overrides)) {
|
||||
entry.definition = {
|
||||
...entry.definition,
|
||||
@@ -841,6 +875,14 @@ const createComponentSelectionEntry = (requirement, source = null) => {
|
||||
}
|
||||
}
|
||||
|
||||
const finalizedConstructeurIds = uniqueConstructeurIds(
|
||||
entry.definition.constructeurIds,
|
||||
entry.definition.constructeurId,
|
||||
entry.definition.constructeur,
|
||||
)
|
||||
entry.definition.constructeurIds = finalizedConstructeurIds
|
||||
entry.definition.constructeurId = finalizedConstructeurIds[0] || null
|
||||
|
||||
return entry
|
||||
}
|
||||
|
||||
@@ -887,7 +929,8 @@ const createPieceSelectionEntry = (requirement, source = null) => {
|
||||
|| requirement?.typePiece?.name
|
||||
|| '',
|
||||
reference: source?.reference || '',
|
||||
constructeurId: source?.constructeurId || source?.constructeur?.id || null,
|
||||
constructeurIds: [],
|
||||
constructeurId: null,
|
||||
prix:
|
||||
source?.prix
|
||||
?? source?.price
|
||||
@@ -895,6 +938,16 @@ const createPieceSelectionEntry = (requirement, source = null) => {
|
||||
},
|
||||
}
|
||||
|
||||
const definitionConstructeurIds = uniqueConstructeurIds(
|
||||
link?.overrides?.constructeurIds,
|
||||
link?.overrides?.constructeurId,
|
||||
source?.constructeurIds,
|
||||
source?.constructeurId,
|
||||
source?.constructeur,
|
||||
)
|
||||
entry.definition.constructeurIds = definitionConstructeurIds
|
||||
entry.definition.constructeurId = definitionConstructeurIds[0] || null
|
||||
|
||||
if (link?.overrides && isPlainObject(link.overrides)) {
|
||||
entry.definition = {
|
||||
...entry.definition,
|
||||
@@ -902,6 +955,14 @@ const createPieceSelectionEntry = (requirement, source = null) => {
|
||||
}
|
||||
}
|
||||
|
||||
const finalizedConstructeurIds = uniqueConstructeurIds(
|
||||
entry.definition.constructeurIds,
|
||||
entry.definition.constructeurId,
|
||||
entry.definition.constructeur,
|
||||
)
|
||||
entry.definition.constructeurIds = finalizedConstructeurIds
|
||||
entry.definition.constructeurId = finalizedConstructeurIds[0] || null
|
||||
|
||||
return entry
|
||||
}
|
||||
|
||||
@@ -945,7 +1006,9 @@ const setComponentRequirementConstructeur = (requirementId, index, value) => {
|
||||
const entries = getComponentRequirementEntries(requirementId)
|
||||
const entry = entries[index]
|
||||
if (!entry) return
|
||||
entry.definition.constructeurId = value || null
|
||||
const ids = uniqueConstructeurIds(value)
|
||||
entry.definition.constructeurIds = ids
|
||||
entry.definition.constructeurId = ids[0] || null
|
||||
}
|
||||
|
||||
const addPieceSelectionEntry = (requirement) => {
|
||||
@@ -976,7 +1039,9 @@ const setPieceRequirementConstructeur = (requirementId, index, value) => {
|
||||
const entries = getPieceRequirementEntries(requirementId)
|
||||
const entry = entries[index]
|
||||
if (!entry) return
|
||||
entry.definition.constructeurId = value || null
|
||||
const ids = uniqueConstructeurIds(value)
|
||||
entry.definition.constructeurIds = ids
|
||||
entry.definition.constructeurId = ids[0] || null
|
||||
}
|
||||
|
||||
const collectPiecesForSkeleton = () => {
|
||||
@@ -1298,7 +1363,7 @@ const saveSkeletonConfiguration = async () => {
|
||||
}
|
||||
|
||||
const handleMachineConstructeurChange = async (value) => {
|
||||
machineConstructeurId.value = value
|
||||
machineConstructeurIds.value = uniqueConstructeurIds(value)
|
||||
await updateMachineInfo()
|
||||
}
|
||||
|
||||
@@ -1332,7 +1397,11 @@ const initMachineFields = () => {
|
||||
if (machine.value) {
|
||||
machineName.value = machine.value.name || ''
|
||||
machineReference.value = machine.value.reference || ''
|
||||
machineConstructeurId.value = machine.value.constructeurId || machine.value.constructeur?.id || null
|
||||
machineConstructeurIds.value = uniqueConstructeurIds(
|
||||
machine.value.constructeurIds,
|
||||
machine.value.constructeurs,
|
||||
machine.value.constructeur,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1393,6 +1462,27 @@ const flattenComponents = (list = []) => {
|
||||
|
||||
const flattenedComponents = computed(() => flattenComponents(components.value))
|
||||
|
||||
const collectConstructeurs = (...sources) => {
|
||||
const ids = uniqueConstructeurIds(...sources)
|
||||
if (!ids.length) {
|
||||
return []
|
||||
}
|
||||
|
||||
const pools = sources
|
||||
.flatMap((source) => {
|
||||
if (Array.isArray(source)) {
|
||||
return [source]
|
||||
}
|
||||
if (source && typeof source === 'object' && source.id) {
|
||||
return [[source]]
|
||||
}
|
||||
return []
|
||||
})
|
||||
.filter(Boolean)
|
||||
|
||||
return resolveConstructeurs(ids, ...pools)
|
||||
}
|
||||
|
||||
const componentRequirementGroups = computed(() => {
|
||||
const requirements = machine.value?.typeMachine?.componentRequirements || []
|
||||
if (!requirements.length) return []
|
||||
@@ -1430,14 +1520,22 @@ const pieceRequirementGroups = computed(() => {
|
||||
|
||||
// Pièces rattachées à la machine directement
|
||||
machinePieces.value.forEach((piece) => {
|
||||
collected.push({ ...piece, parentComponentName: null })
|
||||
collected.push({
|
||||
...piece,
|
||||
constructeurs: piece.constructeurs || [],
|
||||
parentComponentName: null,
|
||||
})
|
||||
})
|
||||
|
||||
// Pièces rattachées aux composants
|
||||
flattenedComponents.value.forEach((component) => {
|
||||
if (component.pieces && component.pieces.length) {
|
||||
component.pieces.forEach((piece) => {
|
||||
collected.push({ ...piece, parentComponentName: component.name })
|
||||
collected.push({
|
||||
...piece,
|
||||
constructeurs: piece.constructeurs || [],
|
||||
parentComponentName: component.name,
|
||||
})
|
||||
})
|
||||
}
|
||||
})
|
||||
@@ -2230,12 +2328,34 @@ const transformCustomFields = (pieces) => {
|
||||
),
|
||||
)
|
||||
|
||||
const constructeurIds = uniqueConstructeurIds(
|
||||
piece.constructeurIds,
|
||||
piece.constructeurId,
|
||||
piece.constructeur,
|
||||
piece.originalPiece?.constructeurIds,
|
||||
piece.originalPiece?.constructeurId,
|
||||
piece.originalPiece?.constructeur,
|
||||
)
|
||||
|
||||
const constructeursList = resolveConstructeurs(
|
||||
constructeurIds,
|
||||
Array.isArray(piece.constructeurs) ? piece.constructeurs : [],
|
||||
piece.constructeur ? [piece.constructeur] : [],
|
||||
Array.isArray(piece.originalPiece?.constructeurs)
|
||||
? piece.originalPiece?.constructeurs
|
||||
: [],
|
||||
piece.originalPiece?.constructeur ? [piece.originalPiece.constructeur] : [],
|
||||
constructeurs.value,
|
||||
)
|
||||
|
||||
return {
|
||||
...piece,
|
||||
customFields,
|
||||
documents: piece.documents || [],
|
||||
constructeur: piece.constructeur || null,
|
||||
constructeurId: piece.constructeurId || piece.constructeur?.id || null,
|
||||
constructeurs: constructeursList,
|
||||
constructeur: constructeursList[0] || piece.constructeur || null,
|
||||
constructeurIds,
|
||||
constructeurId: constructeurIds[0] || null,
|
||||
typePieceId: piece.typePieceId
|
||||
|| piece.typeMachinePieceRequirement?.typePieceId
|
||||
|| piece.typePiece?.id
|
||||
@@ -2307,14 +2427,34 @@ const transformComponentCustomFields = (componentsData) => {
|
||||
? transformComponentCustomFields(component.sousComposants)
|
||||
: []
|
||||
|
||||
const constructeurIds = uniqueConstructeurIds(
|
||||
component.constructeurIds,
|
||||
component.constructeurId,
|
||||
component.constructeur,
|
||||
actualComponent?.constructeurIds,
|
||||
actualComponent?.constructeurId,
|
||||
actualComponent?.constructeur,
|
||||
)
|
||||
|
||||
const constructeursList = resolveConstructeurs(
|
||||
constructeurIds,
|
||||
Array.isArray(component.constructeurs) ? component.constructeurs : [],
|
||||
component.constructeur ? [component.constructeur] : [],
|
||||
Array.isArray(actualComponent?.constructeurs) ? actualComponent.constructeurs : [],
|
||||
actualComponent?.constructeur ? [actualComponent.constructeur] : [],
|
||||
constructeurs.value,
|
||||
)
|
||||
|
||||
return {
|
||||
...component,
|
||||
customFields,
|
||||
pieces,
|
||||
subComponents,
|
||||
documents: component.documents || [],
|
||||
constructeur: component.constructeur || null,
|
||||
constructeurId: component.constructeurId || component.constructeur?.id || null,
|
||||
constructeurs: constructeursList,
|
||||
constructeur: constructeursList[0] || component.constructeur || null,
|
||||
constructeurIds,
|
||||
constructeurId: constructeurIds[0] || null,
|
||||
typeComposantId: component.typeComposantId
|
||||
|| component.typeMachineComponentRequirement?.typeComposantId
|
||||
|| component.typeComposant?.id
|
||||
@@ -2354,13 +2494,27 @@ const syncMachineCustomFields = () => {
|
||||
|
||||
function mergePieceLists(existing = [], updates = []) {
|
||||
if (!existing.length) {
|
||||
return updates
|
||||
return updates.map(piece => ({
|
||||
...piece,
|
||||
constructeurs: piece.constructeurs || [],
|
||||
}))
|
||||
}
|
||||
if (!updates.length) {
|
||||
return existing
|
||||
return existing.map(piece => ({
|
||||
...piece,
|
||||
constructeurs: piece.constructeurs || [],
|
||||
}))
|
||||
}
|
||||
|
||||
const updateMap = new Map(updates.map(piece => [piece.id, piece]))
|
||||
const updateMap = new Map(
|
||||
updates.map(piece => [
|
||||
piece.id,
|
||||
{
|
||||
...piece,
|
||||
constructeurs: piece.constructeurs || [],
|
||||
},
|
||||
]),
|
||||
)
|
||||
const merged = existing.map(piece => {
|
||||
const update = updateMap.get(piece.id)
|
||||
if (!update) {
|
||||
@@ -2384,17 +2538,43 @@ function mergePieceLists(existing = [], updates = []) {
|
||||
|
||||
function mergeComponentTrees(existing = [], updates = []) {
|
||||
if (!existing.length) {
|
||||
return updates
|
||||
return updates.map(component => ({
|
||||
...component,
|
||||
constructeurs: component.constructeurs || [],
|
||||
pieces: (component.pieces || []).map(piece => ({
|
||||
...piece,
|
||||
constructeurs: piece.constructeurs || [],
|
||||
})),
|
||||
subComponents: mergeComponentTrees([], component.subComponents || []),
|
||||
}))
|
||||
}
|
||||
if (!updates.length) {
|
||||
return existing
|
||||
}
|
||||
|
||||
const updateMap = new Map(updates.map(component => [component.id, component]))
|
||||
const updateMap = new Map(
|
||||
updates.map(component => [
|
||||
component.id,
|
||||
{
|
||||
...component,
|
||||
constructeurs: component.constructeurs || [],
|
||||
pieces: (component.pieces || []).map(piece => ({
|
||||
...piece,
|
||||
constructeurs: piece.constructeurs || [],
|
||||
})),
|
||||
subComponents: mergeComponentTrees([], component.subComponents || []),
|
||||
},
|
||||
]),
|
||||
)
|
||||
const merged = existing.map(component => {
|
||||
const update = updateMap.get(component.id)
|
||||
if (!update) {
|
||||
return component
|
||||
return {
|
||||
...component,
|
||||
constructeurs: component.constructeurs || [],
|
||||
pieces: mergePieceLists(component.pieces || [], []),
|
||||
subComponents: mergeComponentTrees(component.subComponents || [], []),
|
||||
}
|
||||
}
|
||||
return {
|
||||
...component,
|
||||
@@ -2529,7 +2709,23 @@ const buildMachineHierarchyFromLinks = (componentLinks = [], pieceLinks = []) =>
|
||||
skeletonOnly: !pieceId,
|
||||
}
|
||||
|
||||
return basePiece
|
||||
const constructeurs = collectConstructeurs(
|
||||
appliedPiece.constructeurs,
|
||||
appliedPiece.constructeur,
|
||||
appliedPiece.constructeurIds,
|
||||
appliedPiece.constructeurId,
|
||||
originalPiece?.constructeurs,
|
||||
originalPiece?.constructeur,
|
||||
originalPiece?.constructeurIds,
|
||||
originalPiece?.constructeurId,
|
||||
)
|
||||
|
||||
return {
|
||||
...basePiece,
|
||||
constructeurs,
|
||||
constructeur: constructeurs[0] || basePiece.constructeur || null,
|
||||
constructeurId: constructeurs[0]?.id || basePiece.constructeurId || null,
|
||||
}
|
||||
}
|
||||
|
||||
const createComponentNode = (link) => {
|
||||
@@ -2653,7 +2849,23 @@ const buildMachineHierarchyFromLinks = (componentLinks = [], pieceLinks = []) =>
|
||||
skeletonOnly: !composantId,
|
||||
}
|
||||
|
||||
return baseComponent
|
||||
const constructeurs = collectConstructeurs(
|
||||
appliedComponent.constructeurs,
|
||||
appliedComponent.constructeur,
|
||||
appliedComponent.constructeurIds,
|
||||
appliedComponent.constructeurId,
|
||||
originalComponent?.constructeurs,
|
||||
originalComponent?.constructeur,
|
||||
originalComponent?.constructeurIds,
|
||||
originalComponent?.constructeurId,
|
||||
)
|
||||
|
||||
return {
|
||||
...baseComponent,
|
||||
constructeurs,
|
||||
constructeur: constructeurs[0] || baseComponent.constructeur || null,
|
||||
constructeurId: constructeurs[0]?.id || baseComponent.constructeurId || null,
|
||||
}
|
||||
}
|
||||
|
||||
const rootComponents = (Array.isArray(componentLinks) ? componentLinks : [])
|
||||
@@ -2792,7 +3004,7 @@ const updateMachineInfo = async () => {
|
||||
const result = await updateMachineApi(machine.value.id, {
|
||||
name: machineName.value,
|
||||
reference: machineReference.value,
|
||||
constructeurId: machineConstructeurId.value || null
|
||||
constructeurIds: machineConstructeurIds.value
|
||||
})
|
||||
if (result.success) {
|
||||
const machinePayload = result.data?.machine && typeof result.data.machine === 'object'
|
||||
@@ -2806,7 +3018,11 @@ const updateMachineInfo = async () => {
|
||||
documents: machinePayload.documents || machine.value.documents || [],
|
||||
customFieldValues: machinePayload.customFieldValues || machine.value.customFieldValues || [],
|
||||
}
|
||||
machineConstructeurId.value = machine.value.constructeurId || machine.value.constructeur?.id || null
|
||||
machineConstructeurIds.value = uniqueConstructeurIds(
|
||||
machine.value.constructeurIds,
|
||||
machine.value.constructeurs,
|
||||
machine.value.constructeur,
|
||||
)
|
||||
|
||||
const linksApplied = applyMachineLinks(result.data)
|
||||
if (linksApplied && machine.value) {
|
||||
@@ -2823,10 +3039,15 @@ const updateMachineInfo = async () => {
|
||||
const updateComponent = async (updatedComponent) => {
|
||||
try {
|
||||
const prixValue = updatedComponent.prix
|
||||
const constructeurIds = uniqueConstructeurIds(
|
||||
updatedComponent.constructeurIds,
|
||||
updatedComponent.constructeurId,
|
||||
updatedComponent.constructeur,
|
||||
)
|
||||
const result = await updateComposantApi(updatedComponent.id, {
|
||||
name: updatedComponent.name,
|
||||
reference: updatedComponent.reference,
|
||||
constructeurId: updatedComponent.constructeurId || updatedComponent.constructeur?.id || null,
|
||||
constructeurIds,
|
||||
prix: prixValue && prixValue !== '' ? parseFloat(prixValue) : null,
|
||||
})
|
||||
if (result.success) {
|
||||
@@ -2840,10 +3061,15 @@ const updateComponent = async (updatedComponent) => {
|
||||
|
||||
const updatePieceFromComponent = async (updatedPiece) => {
|
||||
try {
|
||||
const constructeurIds = uniqueConstructeurIds(
|
||||
updatedPiece.constructeurIds,
|
||||
updatedPiece.constructeurId,
|
||||
updatedPiece.constructeur,
|
||||
)
|
||||
const result = await updatePieceApi(updatedPiece.id, {
|
||||
name: updatedPiece.name,
|
||||
reference: updatedPiece.reference,
|
||||
constructeurId: updatedPiece.constructeurId || updatedPiece.constructeur?.id || null,
|
||||
constructeurIds,
|
||||
prix: updatedPiece.prix && updatedPiece.prix !== '' ? parseFloat(updatedPiece.prix) : null,
|
||||
})
|
||||
if (result.success) {
|
||||
@@ -2870,10 +3096,15 @@ const updatePieceFromComponent = async (updatedPiece) => {
|
||||
|
||||
const updatePieceInfo = async (updatedPiece) => {
|
||||
try {
|
||||
const constructeurIds = uniqueConstructeurIds(
|
||||
updatedPiece.constructeurIds,
|
||||
updatedPiece.constructeurId,
|
||||
updatedPiece.constructeur,
|
||||
)
|
||||
const result = await updatePieceApi(updatedPiece.id, {
|
||||
name: updatedPiece.name,
|
||||
reference: updatedPiece.reference,
|
||||
constructeurId: updatedPiece.constructeurId || updatedPiece.constructeur?.id || null,
|
||||
constructeurIds,
|
||||
prix: updatedPiece.prix && updatedPiece.prix !== '' ? parseFloat(updatedPiece.prix) : null,
|
||||
})
|
||||
if (result.success) {
|
||||
|
||||
@@ -98,10 +98,10 @@
|
||||
<span class="label-text">Constructeur</span>
|
||||
</label>
|
||||
<ConstructeurSelect
|
||||
v-model="editionForm.constructeurId"
|
||||
v-model="editionForm.constructeurIds"
|
||||
class="w-full"
|
||||
:disabled="saving"
|
||||
placeholder="Rechercher un constructeur..."
|
||||
placeholder="Rechercher un ou plusieurs constructeurs..."
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
@@ -365,6 +365,7 @@ import { useDocuments } from '~/composables/useDocuments'
|
||||
import { getFileIcon } from '~/utils/fileIcons'
|
||||
import { canPreviewDocument, isImageDocument, isPdfDocument } from '~/utils/documentPreview'
|
||||
import { formatPieceStructurePreview } from '~/shared/modelUtils'
|
||||
import { uniqueConstructeurIds } from '~/shared/constructeurUtils'
|
||||
import type { PieceModelStructure } from '~/shared/types/inventory'
|
||||
import type { ModelType } from '~/services/modelTypes'
|
||||
|
||||
@@ -407,7 +408,7 @@ const selectedTypeId = ref<string>('')
|
||||
const editionForm = reactive({
|
||||
name: '' as string,
|
||||
reference: '' as string,
|
||||
constructeurId: null as string | null,
|
||||
constructeurIds: [] as string[],
|
||||
prix: '' as string,
|
||||
})
|
||||
|
||||
@@ -602,7 +603,11 @@ watch(
|
||||
|
||||
editionForm.name = currentPiece.name || ''
|
||||
editionForm.reference = currentPiece.reference || ''
|
||||
editionForm.constructeurId = currentPiece.constructeur?.id || currentPiece.constructeurId || null
|
||||
editionForm.constructeurIds = uniqueConstructeurIds(
|
||||
currentPiece,
|
||||
Array.isArray(currentPiece.constructeurs) ? currentPiece.constructeurs : [],
|
||||
currentPiece.constructeur ? [currentPiece.constructeur] : [],
|
||||
)
|
||||
editionForm.prix = currentPiece.prix !== null && currentPiece.prix !== undefined ? String(currentPiece.prix) : ''
|
||||
|
||||
customFieldInputs.value = buildCustomFieldInputs(
|
||||
@@ -642,7 +647,7 @@ const submitEdition = async () => {
|
||||
|
||||
const reference = editionForm.reference.trim()
|
||||
payload.reference = reference ? reference : null
|
||||
payload.constructeurId = editionForm.constructeurId || null
|
||||
payload.constructeurIds = uniqueConstructeurIds(editionForm.constructeurIds)
|
||||
|
||||
if (rawPrice) {
|
||||
const parsed = Number(rawPrice)
|
||||
|
||||
@@ -260,6 +260,7 @@ import { useToast } from '~/composables/useToast'
|
||||
import { useCustomFields } from '~/composables/useCustomFields'
|
||||
import { useDocuments } from '~/composables/useDocuments'
|
||||
import { formatPieceStructurePreview } from '~/shared/modelUtils'
|
||||
import { uniqueConstructeurIds } from '~/shared/constructeurUtils'
|
||||
import type { PieceModelStructure } from '~/shared/types/inventory'
|
||||
import type { ModelType } from '~/services/modelTypes'
|
||||
|
||||
@@ -283,7 +284,7 @@ const submitting = ref(false)
|
||||
const creationForm = reactive({
|
||||
name: '' as string,
|
||||
reference: '' as string,
|
||||
constructeurId: null as string | null,
|
||||
constructeurIds: [] as string[],
|
||||
prix: '' as string,
|
||||
})
|
||||
|
||||
@@ -381,7 +382,7 @@ const getStructureCustomFields = (structure: PieceModelStructure | null) => Arra
|
||||
const clearCreationForm = () => {
|
||||
creationForm.name = ''
|
||||
creationForm.reference = ''
|
||||
creationForm.constructeurId = null
|
||||
creationForm.constructeurIds = []
|
||||
creationForm.prix = ''
|
||||
lastSuggestedName.value = ''
|
||||
}
|
||||
@@ -401,8 +402,8 @@ const submitCreation = async () => {
|
||||
payload.reference = reference
|
||||
}
|
||||
|
||||
if (creationForm.constructeurId) {
|
||||
payload.constructeurId = creationForm.constructeurId
|
||||
if (creationForm.constructeurIds.length) {
|
||||
payload.constructeurIds = uniqueConstructeurIds(creationForm.constructeurIds)
|
||||
}
|
||||
|
||||
const rawPrice = typeof creationForm.prix === 'string'
|
||||
|
||||
Reference in New Issue
Block a user