feat refactorResponse login #refs 7827

This commit is contained in:
Sergio De la torre 2024-08-13 06:57:35 +02:00
parent c3eaea124e
commit bb44fbd56a
4 changed files with 62 additions and 79 deletions

View File

@ -130,13 +130,13 @@ interface SalixService {
fun getCollectionSalix(
): Call<List<CollectionVO>>
@GET("AddressShortages")
/*@GET("AddressShortages")
fun getAddressSalix(
@Query("filter") filter: String
): Call<List<AddressLoses>>
): Call<List<AddressLoses>>*/
@GET("AddressWastes")
fun getAddressSalixNew(
fun getAddress(
@Query("filter") filter: String
): Call<List<AddressLoses>>

View File

@ -195,40 +195,38 @@ class ItemCardFragment(
}
}
private fun getItemCard(itemFk: String) {
private fun getItemCard(itemValueFk: String) {
warehouseFk = mobileApplication.dataStoreApp.readDataStoreKey(WAREHOUSEFK) as Int
itemFk = itemValueFk
viewModel.getItemCard(itemFk.toLong(), warehouseFk!!)
this.itemFk = itemFk
}
override fun observeViewModel() {
with(viewModel) {
itemCard.observe(viewLifecycleOwner) {
loadResponseItemCard.observe(viewLifecycleOwner) { event ->
event.getContentIfNotHandled().notNull {
if (it.id != 0) {
binding.itemcardLayout.visibility = View.VISIBLE
setItemCard(it)
binding.mainToolbar.toolbarIcons.visibility = View.VISIBLE
} else {
binding.itemcardLayout.visibility = GONE
binding.mainToolbar.toolbarTitle.text = getString(R.string.itemCard)
ma.messageWithSound(
getString(R.string.itemNotFound),
isError = true,
isPlayed = false,
getString(R.string.noResults)
)
if (it.id != 0) {
binding.itemcardLayout.visibility = View.VISIBLE
setItemCard(it)
binding.mainToolbar.toolbarIcons.visibility = View.VISIBLE
} else {
binding.itemcardLayout.visibility = GONE
binding.mainToolbar.toolbarTitle.text = getString(R.string.itemCard)
ma.messageWithSound(
getString(R.string.itemNotFound),
isError = true,
isPlayed = false,
getString(R.string.noResults)
)
}
}
}
responseItemCard.observe(viewLifecycleOwner) {
getItemCard(itemInfoG!!.id.toString())
}
loadAddressLosesList.observe(viewLifecycleOwner) { event ->
event.getContentIfNotHandled().notNull {
@ -467,13 +465,13 @@ class ItemCardFragment(
item, customDialogInput.getValue().toInt()
)
customDialogInput.setValue("")
customDialogInput.dismiss()
ma.hideKeyboard(customDialogInput.getEditText())
customDialogInput.dismiss()
} catch (ex: Exception) {
if (item.action == "itemSaveStem") {
viewModel.updateStems(
itemFk = itemInfoG!!.id, value = null
itemFk = itemInfoG!!.id, value = null, warehouseFk!!
)
} else {
getString(R.string.errorInput).toast(requireContext())
@ -488,17 +486,19 @@ class ItemCardFragment(
}
"itemStockUpdateRemove" -> {
viewModel.getAddressNew()
viewModel.getAddress()
quantityToDiscard = value
}
"updateGrouping" -> viewModel.updateGrouping(
warehouseFk = warehouseFk!!,
itemFk = itemInfoG!!.id,
value = value,
"updateGrouping" -> {
viewModel.updateGrouping(
warehouseFk = warehouseFk!!,
itemFk = itemInfoG!!.id,
value = value,
)
}
"updatePacking" -> viewModel.updatePacking(
warehouseFk = warehouseFk!!,
itemFk = itemInfoG!!.id,
@ -507,11 +507,11 @@ class ItemCardFragment(
)
"itemSaveStem" -> viewModel.updateStems(
itemFk = itemInfoG!!.id, value = value
itemFk = itemInfoG!!.id, value = value, warehouseFk = warehouseFk!!
)
"item_saveReference" -> viewModel.updateReference(
itemFk = itemInfoG!!.id, value = value
itemFk = itemInfoG!!.id, value = value, warehouseFk = warehouseFk!!
)
}
@ -565,6 +565,7 @@ class ItemCardFragment(
false
)
customDialogList.setValue("")
ma.hideKeyboard(customDialogList.getEditText())
customDialogList.dismiss()
} catch (ex: Exception) {
@ -579,6 +580,7 @@ class ItemCardFragment(
itemFk = itemInfoG!!.id,
barCodeValue = code,
delete = delete,
warehouseFk = warehouseFk!!
)
}

View File

@ -25,20 +25,14 @@ import java.io.File
class ItemCardViewModel(var context: Context) : BaseViewModel(context) {
private val getItemFromBarcodeUseCase = GetItemFromBarcodeUseCase(salix)
private val getItemFromBarcodeUseCase = GetItemFromBarcodeUseCase(salix)
private val _itemCard by lazy { MutableLiveData<ItemCardVO>() }
val itemCard: LiveData<ItemCardVO>
get() = _itemCard
private val _responseItemCard by lazy { MutableLiveData<Any>() }
val responseItemCard: LiveData<Any>
get() = _responseItemCard
val loadResponseItemCard: LiveData<Event<Any>> =
_responseItemCard.map { Event(it) }
val loadResponseItemCard: LiveData<Event<ItemCardVO>> =
_itemCard.map { Event(it) }
private val _responseCode by lazy { MutableLiveData<Int?>() }
val responseCode: LiveData<Int?>
@ -52,18 +46,19 @@ class ItemCardViewModel(var context: Context) : BaseViewModel(context) {
val addressLosesList: LiveData<AddressLosesList>
get() = _addressLosesList
val loadAddressLosesList: LiveData<Event<AddressLosesList>> = _addressLosesList.map { Event(it) }
val loadAddressLosesList: LiveData<Event<AddressLosesList>> =
_addressLosesList.map { Event(it) }
fun getItemCard(
itemFk: Number,
warehouseFk: Int,
) {
//Tarea 6276
salix.getCard(barcode = itemFk, warehouseFk = warehouseFk)
.enqueue(object : SalixCallback<ItemCardVO>(context) {
override fun onSuccess(response: Response<ItemCardVO>) {
_itemCard.value = response.body() ?: ItemCardVO()
}
})
@ -99,7 +94,8 @@ class ItemCardViewModel(var context: Context) : BaseViewModel(context) {
).enqueue(object : SalixCallback<Any>(context) {
override fun onSuccess(response: Response<Any>) {
_responseItemCard.value = response.message()
getItemCard(itemFk,warehouseFk)
super.onSuccess(response)
}
})
}
@ -111,7 +107,8 @@ class ItemCardViewModel(var context: Context) : BaseViewModel(context) {
salix.updateGrouping(params = arrayListOf(warehouseFk, itemFk, value))
.enqueue(object : SalixCallback<Any>(context) {
override fun onSuccess(response: Response<Any>) {
_responseItemCard.value = response.message()
getItemCard(itemFk,warehouseFk)
super.onSuccess(response)
}
})
@ -124,48 +121,51 @@ class ItemCardViewModel(var context: Context) : BaseViewModel(context) {
salix.updatePacking(params = arrayListOf(warehouseFk, itemFk, value))
.enqueue(object : SalixCallback<Any>(context) {
override fun onSuccess(response: Response<Any>) {
_responseItemCard.value = response.message()
getItemCard(itemFk,warehouseFk)
super.onSuccess(response)
}
})
}
fun updateStems(
itemFk: Int, value: Int?
itemFk: Int, value: Int?,warehouseFk: Int
) {
salix.updateItem(itemFk, hashMapOf("stems" to value))
.enqueue(object : SalixCallback<Any>(context) {
override fun onSuccess(response: Response<Any>) {
_responseItemCard.value = response.message()
getItemCard(itemFk,warehouseFk)
super.onSuccess(response)
}
})
}
fun updateReference(
itemFk: Int, value: Int
itemFk: Int, value: Int, warehouseFk: Int
) {
salix.updateItem(itemFk, hashMapOf("comment" to value))
.enqueue(object : SalixCallback<Any>(context) {
override fun onSuccess(response: Response<Any>) {
_responseItemCard.value = response.message()
getItemCard(itemFk,warehouseFk)
super.onSuccess(response)
}
})
}
fun getIdFromCodeSalix(code: String) {
getItemFromBarcodeUseCase.execute (code)
getItemFromBarcodeUseCase.execute(code)
.enqueue(object : SalixCallback<Int?>(context) {
override fun onSuccess(response: Response<Int?>) {
_responseCode.value = response.body()
override fun onSuccess(response: Response<Int?>) {
_responseCode.value = response.body()
}
})
}
})
}
fun barcodesEditSalix(itemFk: Int, barCodeValue: String, delete: Boolean) {
fun barcodesEditSalix(itemFk: Int, barCodeValue: String, delete: Boolean,warehouseFk: Int) {
if (delete) {
salix.barcodesDelete(itemFk = itemFk, barcode = barCodeValue)
@ -177,8 +177,7 @@ class ItemCardViewModel(var context: Context) : BaseViewModel(context) {
}.enqueue(object : SalixCallback<Any>(context) {
override fun onSuccess(response: Response<Any>) {
_responseItemCard.value =
ResponseItemVO(isError = false, response = response.message()!!)
getItemCard(itemFk,warehouseFk)
}
})
}
@ -208,27 +207,11 @@ class ItemCardViewModel(var context: Context) : BaseViewModel(context) {
}
fun getAddress() {
salix.getAddressSalix("""{ "include": [ { "relation": "address", "scope": { "fields": { "nickname": true } } } ] }""")
salix.getAddress("""{"where":{"type":"internal"}, "include": [ { "relation": "address", "scope": { "fields": { "nickname": true } } } ] }""")
.enqueue(object : SalixCallback<List<AddressLoses>>(context) {
override fun onSuccess(response: Response<List<AddressLoses>>) {
_addressLosesList.value = response.body()?.let { AddressLosesList(it) }
}
/* override fun onError(t: Throwable) {
getAddressNew()
}*/
})
}
//Tarea 7622 retroCompatible, borrar getAddress y renombra getAddressNew a getAddress.
fun getAddressNew() {
salix.getAddressSalixNew("""{"where":{"type":"internal"}, "include": [ { "relation": "address", "scope": { "fields": { "nickname": true } } } ] }""")
.enqueue(object : SalixCallback<List<AddressLoses>>(context) {
override fun onSuccess(response: Response<List<AddressLoses>>) {
_addressLosesList.value = response.body()?.let { AddressLosesList(it) }
}
override fun onError(t: Throwable) {
getAddress()
}
})
}
}

View File

@ -33,9 +33,7 @@ class AddressLosesList(
data class AddressLoses(
val addressFk: Int = 0,
val address: Address? = null,
var isError: Boolean = false,
var errorMessage: String = ""
val address: Address? = null
)
data class Address(