F3.1 Android: clasificar y conciliar altas de campo
This commit is contained in:
@@ -150,6 +150,7 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
|
|||||||
fun createFieldAsset(
|
fun createFieldAsset(
|
||||||
type: FieldType,
|
type: FieldType,
|
||||||
parentId: String?,
|
parentId: String?,
|
||||||
|
familyId: String?,
|
||||||
name: String,
|
name: String,
|
||||||
commonName: String?,
|
commonName: String?,
|
||||||
attributes: Map<String, Any?>,
|
attributes: Map<String, Any?>,
|
||||||
@@ -162,10 +163,15 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
|
|||||||
error = "La inspección debe estar en curso para dar de alta Inventario."
|
error = "La inspección debe estar en curso para dar de alta Inventario."
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if (type.familyRequired && familyId == null) {
|
||||||
|
error = "Elegí una familia técnica o la opción Otro / no catalogado."
|
||||||
|
return
|
||||||
|
}
|
||||||
launchBusy {
|
launchBusy {
|
||||||
val request = CreateFieldInventoryRequest(
|
val request = CreateFieldInventoryRequest(
|
||||||
typeId = type.id,
|
typeId = type.id,
|
||||||
parentId = parentId,
|
parentId = parentId,
|
||||||
|
familyId = familyId,
|
||||||
name = name.trim(),
|
name = name.trim(),
|
||||||
commonName = commonName?.trim()?.takeIf { it.isNotBlank() },
|
commonName = commonName?.trim()?.takeIf { it.isNotBlank() },
|
||||||
attributes = attributes,
|
attributes = attributes,
|
||||||
@@ -175,11 +181,38 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
|
|||||||
deviceCapturedAt = Instant.now().toString(),
|
deviceCapturedAt = Instant.now().toString(),
|
||||||
)
|
)
|
||||||
selectedFieldAsset = repository.createFieldAsset(visitId, request)
|
selectedFieldAsset = repository.createFieldAsset(visitId, request)
|
||||||
notice = "Inventario creado con GPS. Falta la fotografía obligatoria."
|
notice = "Inventario creado con GPS. Falta la fotografía obligatoria. Si ya existía, podés fusionarlo antes de continuar."
|
||||||
inventory = repository.fieldInventory(visitId, null, null).data
|
inventory = repository.fieldInventory(visitId, null, null).data
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun mergeCreatedFieldAsset(canonicalAssetId: String, reason: String) {
|
||||||
|
val visitId = visit?.id ?: return
|
||||||
|
val source = selectedFieldAsset?.asset ?: return
|
||||||
|
if (canonicalAssetId.isBlank()) {
|
||||||
|
error = "Elegí el registro existente que se conservará."
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (reason.trim().length < 8) {
|
||||||
|
error = "Explicá brevemente por qué se trata de un duplicado."
|
||||||
|
return
|
||||||
|
}
|
||||||
|
launchBusy {
|
||||||
|
val result = repository.mergeFieldAsset(
|
||||||
|
visitId = visitId,
|
||||||
|
assetId = source.id,
|
||||||
|
canonicalAssetId = canonicalAssetId,
|
||||||
|
reason = reason,
|
||||||
|
)
|
||||||
|
selectedFieldAsset = repository.selectFieldAsset(visitId, result.canonical.id)
|
||||||
|
notice = "Fusión registrada. Se conserva ${result.canonical.code} y la historia de ${result.source.code} permanece trazable."
|
||||||
|
inventory = repository.fieldInventory(visitId, null, null).data
|
||||||
|
if (selectedFieldAsset?.capture?.readyForFinding == true) {
|
||||||
|
loadFindingOptionsInternal(visitId, result.canonical.id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun uploadFieldPhoto(
|
fun uploadFieldPhoto(
|
||||||
file: File,
|
file: File,
|
||||||
latitude: Double,
|
latitude: Double,
|
||||||
|
|||||||
Reference in New Issue
Block a user