feat: refs #7763 rename

This commit is contained in:
Sergio De la torre 2024-09-18 10:37:51 +02:00
parent 98ecb8e365
commit 251cdd32ee
3 changed files with 71 additions and 101 deletions

View File

@ -12,7 +12,6 @@ import android.view.View.VISIBLE
import android.view.inputmethod.EditorInfo import android.view.inputmethod.EditorInfo
import android.widget.ImageView import android.widget.ImageView
import android.widget.Toast import android.widget.Toast
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import es.verdnatura.R import es.verdnatura.R
import es.verdnatura.databinding.FragmentUbicadorBinding import es.verdnatura.databinding.FragmentUbicadorBinding
@ -40,7 +39,6 @@ import es.verdnatura.presentation.view.feature.articulo.model.BarcodeVO
import es.verdnatura.presentation.view.feature.pasillero.model.PasillerosItemVO import es.verdnatura.presentation.view.feature.pasillero.model.PasillerosItemVO
import es.verdnatura.presentation.view.feature.ubicador.adapter.UbicadorAdapterNew import es.verdnatura.presentation.view.feature.ubicador.adapter.UbicadorAdapterNew
import es.verdnatura.presentation.view.feature.ubicador.model.ItemUbicador import es.verdnatura.presentation.view.feature.ubicador.model.ItemUbicador
import kotlinx.coroutines.launch
@Suppress("UNUSED_ANONYMOUS_PARAMETER") @Suppress("UNUSED_ANONYMOUS_PARAMETER")
class UbicadorFragmentNew : BaseFragment<FragmentUbicadorBinding, UbicadorViewModel>( class UbicadorFragmentNew : BaseFragment<FragmentUbicadorBinding, UbicadorViewModel>(
@ -760,7 +758,8 @@ class UbicadorFragmentNew : BaseFragment<FragmentUbicadorBinding, UbicadorViewMo
.setItemValue(itemUbicador.item.toString()) .setItemValue(itemUbicador.item.toString())
.setPackingValue(itemUbicador.packing.toString()) .setPackingValue(itemUbicador.packing.toString())
.setVisibleValue(itemUbicador.visible.toString()) .setVisibleValue(itemUbicador.visible.toString())
.setEtiquetaValue((itemUbicador.visible / (itemUbicador.packing ?: 0)).toString()) //.setEtiquetaValue((itemUbicador.visible / (itemUbicador.packing ?: 0)).toString())
.setEtiquetaValue(itemUbicador.stickers.toString())
.setUnits( .setUnits(
if (itemUbicador.stickers != 0) { if (itemUbicador.stickers != 0) {
(itemUbicador.visible % itemUbicador.stickers).toString() (itemUbicador.visible % itemUbicador.stickers).toString()
@ -1051,28 +1050,29 @@ class UbicadorFragmentNew : BaseFragment<FragmentUbicadorBinding, UbicadorViewMo
} }
customDialogConfirm.show() customDialogConfirm.show()
}//Tarea 7763 }//Tarea 7763
/*.setOkButtonThree(getString(R.string.rename)) { /*
customDialogInput.setTitle(getString(R.string.itemNew)) .setOkButtonThree(getString(R.string.rename)) {
.setDescription(getString(R.string.scanItem)).setValue("") customDialogInput.setTitle(getString(R.string.itemNew))
.setOkButton(getString(R.string.rename)) { .setDescription(getString(R.string.scanItem)).setValue("")
.setOkButton(getString(R.string.rename)) {
actionRename(item, customDialogInput.getValue()) actionRename(item, customDialogInput.getValue())
}.setKoButton(getString(R.string.cancel)) { }.setKoButton(getString(R.string.cancel)) {
customDialogInput.dismiss() customDialogInput.dismiss()
customDialogTwoButtons.dismiss() customDialogTwoButtons.dismiss()
}.show() }.show()
customDialogInput.getEditText().setOnEditorActionListener { _, actionId, _ -> customDialogInput.getEditText().setOnEditorActionListener { _, actionId, _ ->
if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0 || actionId == 5) { if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0 || actionId == 5) {
actionRename(item, customDialogInput.getValue())
return@setOnEditorActionListener true
}
false
}
customDialogInput.getEditText().requestFocus()
}*/
actionRename(item, customDialogInput.getValue())
return@setOnEditorActionListener true
}
false
}
customDialogInput.getEditText().requestFocus()
}
*/
customDialogTwoButtons.setKoButton(getString(R.string.cancel)) { customDialogTwoButtons.setKoButton(getString(R.string.cancel)) {
customDialogTwoButtons.dismiss() customDialogTwoButtons.dismiss()
} }
@ -1098,19 +1098,13 @@ class UbicadorFragmentNew : BaseFragment<FragmentUbicadorBinding, UbicadorViewMo
} }
private fun renameItem(item: ItemUbicador, barCode: Long) { private fun renameItem(item: ItemUbicador, barCode: Long) {
viewLifecycleOwner.lifecycleScope.launch { try {
try { viewModel.getInfoFromBuy(item.id, buyFk = barCode)
viewModel.rename( } catch (ex: Exception) {
item = item, ma.messageWithSound(ex.message.toString(), isError = true, isPlayed = true)
barCode = barCode,
warehouse = mobileApplication.dataStoreApp.readDataStoreKey(WAREHOUSEFK)
)
} catch (ex: Exception) {
ma.messageWithSound(ex.message.toString(), isError = true, isPlayed = true)
}
} }
} }
private fun customDialogTransferAction(item: ItemUbicador) { private fun customDialogTransferAction(item: ItemUbicador) {

View File

@ -5,8 +5,6 @@ import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.map import androidx.lifecycle.map
import com.google.gson.JsonObject import com.google.gson.JsonObject
import com.google.gson.JsonParser
import com.google.gson.JsonPrimitive
import es.verdnatura.domain.SalixCallback import es.verdnatura.domain.SalixCallback
import es.verdnatura.domain.formatWithQuotes import es.verdnatura.domain.formatWithQuotes
import es.verdnatura.domain.userCases.GetItemFromBarcodeUseCase import es.verdnatura.domain.userCases.GetItemFromBarcodeUseCase
@ -16,9 +14,9 @@ import es.verdnatura.presentation.base.nameofFunction
import es.verdnatura.presentation.common.Event import es.verdnatura.presentation.common.Event
import es.verdnatura.presentation.common.ItemShelvingSalix import es.verdnatura.presentation.common.ItemShelvingSalix
import es.verdnatura.presentation.common.ResponseHasOlder import es.verdnatura.presentation.common.ResponseHasOlder
import es.verdnatura.presentation.common.ResponseItemVO
import es.verdnatura.presentation.view.feature.claim.fragment.reubication.model.Reubication import es.verdnatura.presentation.view.feature.claim.fragment.reubication.model.Reubication
import es.verdnatura.presentation.view.feature.claim.fragment.reubication.model.ReubicationList import es.verdnatura.presentation.view.feature.claim.fragment.reubication.model.ReubicationList
import es.verdnatura.presentation.view.feature.ubicador.model.ItemBuy
import es.verdnatura.presentation.view.feature.ubicador.model.ItemShelvingNewer import es.verdnatura.presentation.view.feature.ubicador.model.ItemShelvingNewer
import es.verdnatura.presentation.view.feature.ubicador.model.ItemShelvingNewerList import es.verdnatura.presentation.view.feature.ubicador.model.ItemShelvingNewerList
import es.verdnatura.presentation.view.feature.ubicador.model.ItemUbicador import es.verdnatura.presentation.view.feature.ubicador.model.ItemUbicador
@ -34,10 +32,6 @@ class UbicadorViewModel(val context: Context) : BaseViewModel(context) {
private val _shelvingList by lazy { MutableLiveData<ItemUbicadorListVO>() } private val _shelvingList by lazy { MutableLiveData<ItemUbicadorListVO>() }
private val _response by lazy { MutableLiveData<ResponseItemVO>() }
val response: LiveData<ResponseItemVO>
get() = _response
private val _responseUbicator by lazy { MutableLiveData<Boolean>() } private val _responseUbicator by lazy { MutableLiveData<Boolean>() }
val responseUbicator: LiveData<Boolean> val responseUbicator: LiveData<Boolean>
get() = _responseUbicator get() = _responseUbicator
@ -151,7 +145,6 @@ class UbicadorViewModel(val context: Context) : BaseViewModel(context) {
packing: Int?, packing: Int?,
warehouse: Int, warehouse: Int,
grouping: Int?, grouping: Int?,
createdRename: String? = null
) { ) {
salix.itemShelvingAdd( salix.itemShelvingAdd(
arrayListOf( arrayListOf(
@ -166,18 +159,6 @@ class UbicadorViewModel(val context: Context) : BaseViewModel(context) {
).enqueue(object : SalixCallback<Any>(context) { ).enqueue(object : SalixCallback<Any>(context) {
override fun onResponse(call: Call<Any>, response: Response<Any>) { override fun onResponse(call: Call<Any>, response: Response<Any>) {
if (!createdRename.isNullOrBlank() && response.body() != null) {
val jsonArray = JsonParser().parse(response.body().toString()).asJsonArray
val jsonObject = jsonArray.get(0).asJsonObject
itemShelvingUpdateCreated(
itemShelvingFk = (jsonObject.get("LAST_INSERT_ID()") as JsonPrimitive).asInt,
created = createdRename
)
} else {
_responseUbicator.value =
true
}
_responseUbicator.value = _responseUbicator.value =
true true
super.onResponse(call, response) super.onResponse(call, response)
@ -207,32 +188,16 @@ class UbicadorViewModel(val context: Context) : BaseViewModel(context) {
}) })
} }
fun rename( fun getInfoFromBuy(
item: ItemUbicador, barCode: Long, warehouse: Int itemShelvingFk: Number, buyFk: Number
) { ) {
salix.itemShelvingUpdate( salix.getInfoFromBuyId(
params = ItemShelvingSalix( id = buyFk,
visible = 0, ).enqueue(object : SalixCallback<ItemBuy?>(context) {
packing = item.packing, override fun onSuccess(response: Response<ItemBuy?>) {
grouping = item.grouping, itemShelvingUpdateFromBuy(itemShelvingFk, response.body().let { it as ItemBuy })
available = item.available
),
id = item.id,
).enqueue(object : SalixCallback<ItemUbicador?>(context) {
override fun onSuccess(response: Response<ItemUbicador?>) {
itemShelvingAdd(
shelving = response.body()!!.shelvingFk!!,
item = barCode,
quantity = item.visible,
packing = null,
warehouse = warehouse,
grouping = null,
createdRename = response.body()!!.created
)
} }
}) })
} }
@ -278,16 +243,18 @@ class UbicadorViewModel(val context: Context) : BaseViewModel(context) {
} }
fun itemShelvingMerge( fun itemShelvingMerge(
vShelf: Int, vShelvingFk: String vShelf: Int, shelvingFk: String
) { ) {
salix.itemShelvingsUpdate( salix.itemShelvingsUpdate(
where = JsonObject().apply { addProperty("id", vShelf) }, where = JsonObject().apply { addProperty("id", vShelf) },
params = hashMapOf("shelvingFk" to vShelvingFk) params = hashMapOf("shelvingFk" to shelvingFk)
).enqueue(object : SalixCallback<Any>(context) { ).enqueue(object : SalixCallback<Any>(context) {
override fun onSuccess(response: Response<Any>) { override fun onSuccess(response: Response<Any>) {
_response.value = ResponseItemVO(isError = false, response = response.message()!!)
super.onSuccess(response) super.onSuccess(response)
itemShelvingAlternative(
shelvingFk = shelvingFk,
)
} }
}) })
} }
@ -308,20 +275,26 @@ class UbicadorViewModel(val context: Context) : BaseViewModel(context) {
}) })
} }
fun itemShelvingUpdateCreated( fun itemShelvingUpdateFromBuy(
itemShelvingFk: Int, created: String itemShelvingFk: Number, itemBuy: ItemBuy
) { ) {
salix.itemShelvingsUpdate( salix.itemShelvingsUpdate(
where = JsonObject().apply { addProperty("id", itemShelvingFk) }, where = JsonObject().apply { addProperty("id", itemShelvingFk) },
params = hashMapOf("created" to created) JsonObject().apply {
).enqueue(object : SalixCallback<Any>(context) { addProperty("itemFk", itemBuy.itemFk)
addProperty("buyFk", itemBuy.id)
addProperty("grouping", itemBuy.grouping)
addProperty("packing", itemBuy.packing)
addProperty("packagingFk", itemBuy.packagingFk)
})
.enqueue(object : SalixCallback<Any>(context) {
override fun onSuccess(response: Response<Any>) { override fun onSuccess(response: Response<Any>) {
_response.value = ResponseItemVO(isError = false, response = response.message()!!) _responseUbicator.value = true
super.onSuccess(response) super.onSuccess(response)
} }
}) })
} }
fun shelvingLogAdd( fun shelvingLogAdd(
@ -364,7 +337,7 @@ class UbicadorViewModel(val context: Context) : BaseViewModel(context) {
).enqueue(object : SalixCallback<Any>(context) { ).enqueue(object : SalixCallback<Any>(context) {
override fun onSuccess(response: Response<Any>) { override fun onSuccess(response: Response<Any>) {
_response.value = ResponseItemVO(isError = false, response = response.message()) _responseUbicator.value = true
super.onSuccess(response) super.onSuccess(response)
} }
}) })
@ -397,7 +370,7 @@ class UbicadorViewModel(val context: Context) : BaseViewModel(context) {
).enqueue(object : SalixCallback<Any>(context) { ).enqueue(object : SalixCallback<Any>(context) {
override fun onSuccess(response: Response<Any>) { override fun onSuccess(response: Response<Any>) {
_response.value = ResponseItemVO(isError = false, response = response.message()) _responseUbicator.value = true
super.onSuccess(response) super.onSuccess(response)
} }
}) })
@ -457,15 +430,10 @@ class UbicadorViewModel(val context: Context) : BaseViewModel(context) {
salix.upsertItem(MakeMultiSalix(shelvingFk, items, warehouseFk)) salix.upsertItem(MakeMultiSalix(shelvingFk, items, warehouseFk))
.enqueue(object : SalixCallback<Any>(context) { .enqueue(object : SalixCallback<Any>(context) {
override fun onError(t: Throwable) {
super.onError(t)
_response.value =
ResponseItemVO(isError = true, response = t.message.toString())
}
override fun onSuccess(response: Response<Any>) { override fun onSuccess(response: Response<Any>) {
super.onSuccess(response) super.onSuccess(response)
_response.value = ResponseItemVO(isError = false, response = response.message()) _responseUbicator.value = true
} }
}) })

View File

@ -29,7 +29,7 @@ class ItemUbicador(
var grouping: Int? = null, var grouping: Int? = null,
var available: Int? = null, var available: Int? = null,
var code: String? = "", var code: String? = "",
var created:String? = null, var created: String? = null,
var shelvingFk: String? = null, var shelvingFk: String? = null,
var id: Int = 0, var id: Int = 0,
var priority: Int = 0, var priority: Int = 0,
@ -39,7 +39,7 @@ class ItemUbicador(
var isNew: Boolean = false, var isNew: Boolean = false,
var isChecked: Int? = null, var isChecked: Int? = null,
var url: String = "", var url: String = "",
var units:Int = 0 var units: Int = 0
) )
class ItemEscanerVO( class ItemEscanerVO(
@ -49,18 +49,26 @@ class ItemEscanerVO(
class ItemUbicadorListVO( class ItemUbicadorListVO(
var list: List<ItemUbicadorVO> = listOf() var list: List<ItemUbicadorVO> = listOf()
) )
class ItemUbicadorListNew( class ItemUbicadorListNew(
var list: List<ItemUbicador> = listOf() var list: List<ItemUbicador> = listOf()
) )
class ItemShelvingNewerList( class ItemShelvingNewerList(
var list: List<ItemShelvingNewer> = listOf(), var list: List<ItemShelvingNewer> = listOf(),
var originalParking:String, var originalParking: String,
var originalShelvingFk:String var originalShelvingFk: String
) )
data class ItemShelvingNewer( data class ItemShelvingNewer(
var itemFk: Int, var itemFk: Int,
var shelvingFk : String, var shelvingFk: String,
)
data class ItemBuy(
val id: Number,
val itemFk: Number,
val grouping: Int?,
val packing: Int,
val packagingFk: String?
) )