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(
|
||||
type: FieldType,
|
||||
parentId: String?,
|
||||
familyId: String?,
|
||||
name: String,
|
||||
commonName: String?,
|
||||
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."
|
||||
return
|
||||
}
|
||||
if (type.familyRequired && familyId == null) {
|
||||
error = "Elegí una familia técnica o la opción Otro / no catalogado."
|
||||
return
|
||||
}
|
||||
launchBusy {
|
||||
val request = CreateFieldInventoryRequest(
|
||||
typeId = type.id,
|
||||
parentId = parentId,
|
||||
familyId = familyId,
|
||||
name = name.trim(),
|
||||
commonName = commonName?.trim()?.takeIf { it.isNotBlank() },
|
||||
attributes = attributes,
|
||||
@@ -175,11 +181,38 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
|
||||
deviceCapturedAt = Instant.now().toString(),
|
||||
)
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
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(
|
||||
file: File,
|
||||
latitude: Double,
|
||||
|
||||
Reference in New Issue
Block a user