feat refactorResponse login #refs 7827
This commit is contained in:
parent
c3eaea124e
commit
bb44fbd56a
|
@ -130,13 +130,13 @@ interface SalixService {
|
||||||
fun getCollectionSalix(
|
fun getCollectionSalix(
|
||||||
): Call<List<CollectionVO>>
|
): Call<List<CollectionVO>>
|
||||||
|
|
||||||
@GET("AddressShortages")
|
/*@GET("AddressShortages")
|
||||||
fun getAddressSalix(
|
fun getAddressSalix(
|
||||||
@Query("filter") filter: String
|
@Query("filter") filter: String
|
||||||
): Call<List<AddressLoses>>
|
): Call<List<AddressLoses>>*/
|
||||||
|
|
||||||
@GET("AddressWastes")
|
@GET("AddressWastes")
|
||||||
fun getAddressSalixNew(
|
fun getAddress(
|
||||||
@Query("filter") filter: String
|
@Query("filter") filter: String
|
||||||
): Call<List<AddressLoses>>
|
): Call<List<AddressLoses>>
|
||||||
|
|
||||||
|
|
|
@ -195,40 +195,38 @@ class ItemCardFragment(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getItemCard(itemFk: String) {
|
private fun getItemCard(itemValueFk: String) {
|
||||||
|
|
||||||
warehouseFk = mobileApplication.dataStoreApp.readDataStoreKey(WAREHOUSEFK) as Int
|
warehouseFk = mobileApplication.dataStoreApp.readDataStoreKey(WAREHOUSEFK) as Int
|
||||||
|
itemFk = itemValueFk
|
||||||
|
|
||||||
viewModel.getItemCard(itemFk.toLong(), warehouseFk!!)
|
viewModel.getItemCard(itemFk.toLong(), warehouseFk!!)
|
||||||
this.itemFk = itemFk
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun observeViewModel() {
|
override fun observeViewModel() {
|
||||||
with(viewModel) {
|
with(viewModel) {
|
||||||
itemCard.observe(viewLifecycleOwner) {
|
loadResponseItemCard.observe(viewLifecycleOwner) { event ->
|
||||||
|
event.getContentIfNotHandled().notNull {
|
||||||
|
|
||||||
if (it.id != 0) {
|
if (it.id != 0) {
|
||||||
binding.itemcardLayout.visibility = View.VISIBLE
|
binding.itemcardLayout.visibility = View.VISIBLE
|
||||||
setItemCard(it)
|
setItemCard(it)
|
||||||
binding.mainToolbar.toolbarIcons.visibility = View.VISIBLE
|
binding.mainToolbar.toolbarIcons.visibility = View.VISIBLE
|
||||||
} else {
|
} else {
|
||||||
binding.itemcardLayout.visibility = GONE
|
binding.itemcardLayout.visibility = GONE
|
||||||
binding.mainToolbar.toolbarTitle.text = getString(R.string.itemCard)
|
binding.mainToolbar.toolbarTitle.text = getString(R.string.itemCard)
|
||||||
ma.messageWithSound(
|
ma.messageWithSound(
|
||||||
getString(R.string.itemNotFound),
|
getString(R.string.itemNotFound),
|
||||||
isError = true,
|
isError = true,
|
||||||
isPlayed = false,
|
isPlayed = false,
|
||||||
getString(R.string.noResults)
|
getString(R.string.noResults)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
responseItemCard.observe(viewLifecycleOwner) {
|
|
||||||
getItemCard(itemInfoG!!.id.toString())
|
|
||||||
}
|
|
||||||
|
|
||||||
loadAddressLosesList.observe(viewLifecycleOwner) { event ->
|
loadAddressLosesList.observe(viewLifecycleOwner) { event ->
|
||||||
event.getContentIfNotHandled().notNull {
|
event.getContentIfNotHandled().notNull {
|
||||||
|
|
||||||
|
@ -467,13 +465,13 @@ class ItemCardFragment(
|
||||||
item, customDialogInput.getValue().toInt()
|
item, customDialogInput.getValue().toInt()
|
||||||
)
|
)
|
||||||
customDialogInput.setValue("")
|
customDialogInput.setValue("")
|
||||||
customDialogInput.dismiss()
|
|
||||||
ma.hideKeyboard(customDialogInput.getEditText())
|
ma.hideKeyboard(customDialogInput.getEditText())
|
||||||
|
customDialogInput.dismiss()
|
||||||
} catch (ex: Exception) {
|
} catch (ex: Exception) {
|
||||||
|
|
||||||
if (item.action == "itemSaveStem") {
|
if (item.action == "itemSaveStem") {
|
||||||
viewModel.updateStems(
|
viewModel.updateStems(
|
||||||
itemFk = itemInfoG!!.id, value = null
|
itemFk = itemInfoG!!.id, value = null, warehouseFk!!
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
getString(R.string.errorInput).toast(requireContext())
|
getString(R.string.errorInput).toast(requireContext())
|
||||||
|
@ -488,17 +486,19 @@ class ItemCardFragment(
|
||||||
}
|
}
|
||||||
|
|
||||||
"itemStockUpdateRemove" -> {
|
"itemStockUpdateRemove" -> {
|
||||||
viewModel.getAddressNew()
|
viewModel.getAddress()
|
||||||
quantityToDiscard = value
|
quantityToDiscard = value
|
||||||
}
|
}
|
||||||
|
|
||||||
"updateGrouping" -> viewModel.updateGrouping(
|
"updateGrouping" -> {
|
||||||
warehouseFk = warehouseFk!!,
|
viewModel.updateGrouping(
|
||||||
itemFk = itemInfoG!!.id,
|
warehouseFk = warehouseFk!!,
|
||||||
value = value,
|
itemFk = itemInfoG!!.id,
|
||||||
|
value = value,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
"updatePacking" -> viewModel.updatePacking(
|
"updatePacking" -> viewModel.updatePacking(
|
||||||
warehouseFk = warehouseFk!!,
|
warehouseFk = warehouseFk!!,
|
||||||
itemFk = itemInfoG!!.id,
|
itemFk = itemInfoG!!.id,
|
||||||
|
@ -507,11 +507,11 @@ class ItemCardFragment(
|
||||||
)
|
)
|
||||||
|
|
||||||
"itemSaveStem" -> viewModel.updateStems(
|
"itemSaveStem" -> viewModel.updateStems(
|
||||||
itemFk = itemInfoG!!.id, value = value
|
itemFk = itemInfoG!!.id, value = value, warehouseFk = warehouseFk!!
|
||||||
)
|
)
|
||||||
|
|
||||||
"item_saveReference" -> viewModel.updateReference(
|
"item_saveReference" -> viewModel.updateReference(
|
||||||
itemFk = itemInfoG!!.id, value = value
|
itemFk = itemInfoG!!.id, value = value, warehouseFk = warehouseFk!!
|
||||||
)
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -565,6 +565,7 @@ class ItemCardFragment(
|
||||||
false
|
false
|
||||||
)
|
)
|
||||||
customDialogList.setValue("")
|
customDialogList.setValue("")
|
||||||
|
ma.hideKeyboard(customDialogList.getEditText())
|
||||||
customDialogList.dismiss()
|
customDialogList.dismiss()
|
||||||
|
|
||||||
} catch (ex: Exception) {
|
} catch (ex: Exception) {
|
||||||
|
@ -579,6 +580,7 @@ class ItemCardFragment(
|
||||||
itemFk = itemInfoG!!.id,
|
itemFk = itemInfoG!!.id,
|
||||||
barCodeValue = code,
|
barCodeValue = code,
|
||||||
delete = delete,
|
delete = delete,
|
||||||
|
warehouseFk = warehouseFk!!
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,20 +25,14 @@ import java.io.File
|
||||||
|
|
||||||
class ItemCardViewModel(var context: Context) : BaseViewModel(context) {
|
class ItemCardViewModel(var context: Context) : BaseViewModel(context) {
|
||||||
|
|
||||||
private val getItemFromBarcodeUseCase = GetItemFromBarcodeUseCase(salix)
|
private val getItemFromBarcodeUseCase = GetItemFromBarcodeUseCase(salix)
|
||||||
|
|
||||||
private val _itemCard by lazy { MutableLiveData<ItemCardVO>() }
|
private val _itemCard by lazy { MutableLiveData<ItemCardVO>() }
|
||||||
val itemCard: LiveData<ItemCardVO>
|
val itemCard: LiveData<ItemCardVO>
|
||||||
get() = _itemCard
|
get() = _itemCard
|
||||||
|
|
||||||
private val _responseItemCard by lazy { MutableLiveData<Any>() }
|
val loadResponseItemCard: LiveData<Event<ItemCardVO>> =
|
||||||
val responseItemCard: LiveData<Any>
|
_itemCard.map { Event(it) }
|
||||||
get() = _responseItemCard
|
|
||||||
|
|
||||||
val loadResponseItemCard: LiveData<Event<Any>> =
|
|
||||||
_responseItemCard.map { Event(it) }
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private val _responseCode by lazy { MutableLiveData<Int?>() }
|
private val _responseCode by lazy { MutableLiveData<Int?>() }
|
||||||
val responseCode: LiveData<Int?>
|
val responseCode: LiveData<Int?>
|
||||||
|
@ -52,18 +46,19 @@ class ItemCardViewModel(var context: Context) : BaseViewModel(context) {
|
||||||
val addressLosesList: LiveData<AddressLosesList>
|
val addressLosesList: LiveData<AddressLosesList>
|
||||||
get() = _addressLosesList
|
get() = _addressLosesList
|
||||||
|
|
||||||
val loadAddressLosesList: LiveData<Event<AddressLosesList>> = _addressLosesList.map { Event(it) }
|
val loadAddressLosesList: LiveData<Event<AddressLosesList>> =
|
||||||
|
_addressLosesList.map { Event(it) }
|
||||||
|
|
||||||
fun getItemCard(
|
fun getItemCard(
|
||||||
itemFk: Number,
|
itemFk: Number,
|
||||||
warehouseFk: Int,
|
warehouseFk: Int,
|
||||||
) {
|
) {
|
||||||
//Tarea 6276
|
|
||||||
salix.getCard(barcode = itemFk, warehouseFk = warehouseFk)
|
salix.getCard(barcode = itemFk, warehouseFk = warehouseFk)
|
||||||
.enqueue(object : SalixCallback<ItemCardVO>(context) {
|
.enqueue(object : SalixCallback<ItemCardVO>(context) {
|
||||||
|
|
||||||
override fun onSuccess(response: Response<ItemCardVO>) {
|
override fun onSuccess(response: Response<ItemCardVO>) {
|
||||||
_itemCard.value = response.body() ?: ItemCardVO()
|
_itemCard.value = response.body() ?: ItemCardVO()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
|
@ -99,7 +94,8 @@ class ItemCardViewModel(var 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>) {
|
||||||
_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))
|
salix.updateGrouping(params = arrayListOf(warehouseFk, itemFk, value))
|
||||||
.enqueue(object : SalixCallback<Any>(context) {
|
.enqueue(object : SalixCallback<Any>(context) {
|
||||||
override fun onSuccess(response: Response<Any>) {
|
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))
|
salix.updatePacking(params = arrayListOf(warehouseFk, itemFk, value))
|
||||||
.enqueue(object : SalixCallback<Any>(context) {
|
.enqueue(object : SalixCallback<Any>(context) {
|
||||||
override fun onSuccess(response: Response<Any>) {
|
override fun onSuccess(response: Response<Any>) {
|
||||||
_responseItemCard.value = response.message()
|
getItemCard(itemFk,warehouseFk)
|
||||||
|
super.onSuccess(response)
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateStems(
|
fun updateStems(
|
||||||
itemFk: Int, value: Int?
|
itemFk: Int, value: Int?,warehouseFk: Int
|
||||||
) {
|
) {
|
||||||
salix.updateItem(itemFk, hashMapOf("stems" to value))
|
salix.updateItem(itemFk, hashMapOf("stems" to value))
|
||||||
.enqueue(object : SalixCallback<Any>(context) {
|
.enqueue(object : SalixCallback<Any>(context) {
|
||||||
|
|
||||||
override fun onSuccess(response: Response<Any>) {
|
override fun onSuccess(response: Response<Any>) {
|
||||||
_responseItemCard.value = response.message()
|
getItemCard(itemFk,warehouseFk)
|
||||||
|
super.onSuccess(response)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateReference(
|
fun updateReference(
|
||||||
itemFk: Int, value: Int
|
itemFk: Int, value: Int, warehouseFk: Int
|
||||||
) {
|
) {
|
||||||
salix.updateItem(itemFk, hashMapOf("comment" to value))
|
salix.updateItem(itemFk, hashMapOf("comment" to value))
|
||||||
.enqueue(object : SalixCallback<Any>(context) {
|
.enqueue(object : SalixCallback<Any>(context) {
|
||||||
|
|
||||||
override fun onSuccess(response: Response<Any>) {
|
override fun onSuccess(response: Response<Any>) {
|
||||||
_responseItemCard.value = response.message()
|
getItemCard(itemFk,warehouseFk)
|
||||||
|
super.onSuccess(response)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getIdFromCodeSalix(code: String) {
|
fun getIdFromCodeSalix(code: String) {
|
||||||
getItemFromBarcodeUseCase.execute (code)
|
getItemFromBarcodeUseCase.execute(code)
|
||||||
.enqueue(object : SalixCallback<Int?>(context) {
|
.enqueue(object : SalixCallback<Int?>(context) {
|
||||||
|
|
||||||
override fun onSuccess(response: Response<Int?>) {
|
override fun onSuccess(response: Response<Int?>) {
|
||||||
_responseCode.value = response.body()
|
_responseCode.value = response.body()
|
||||||
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fun barcodesEditSalix(itemFk: Int, barCodeValue: String, delete: Boolean) {
|
fun barcodesEditSalix(itemFk: Int, barCodeValue: String, delete: Boolean,warehouseFk: Int) {
|
||||||
|
|
||||||
if (delete) {
|
if (delete) {
|
||||||
salix.barcodesDelete(itemFk = itemFk, barcode = barCodeValue)
|
salix.barcodesDelete(itemFk = itemFk, barcode = barCodeValue)
|
||||||
|
@ -177,8 +177,7 @@ class ItemCardViewModel(var 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>) {
|
||||||
_responseItemCard.value =
|
getItemCard(itemFk,warehouseFk)
|
||||||
ResponseItemVO(isError = false, response = response.message()!!)
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -208,27 +207,11 @@ class ItemCardViewModel(var context: Context) : BaseViewModel(context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getAddress() {
|
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) {
|
.enqueue(object : SalixCallback<List<AddressLoses>>(context) {
|
||||||
override fun onSuccess(response: Response<List<AddressLoses>>) {
|
override fun onSuccess(response: Response<List<AddressLoses>>) {
|
||||||
_addressLosesList.value = response.body()?.let { AddressLosesList(it) }
|
_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()
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,9 +33,7 @@ class AddressLosesList(
|
||||||
|
|
||||||
data class AddressLoses(
|
data class AddressLoses(
|
||||||
val addressFk: Int = 0,
|
val addressFk: Int = 0,
|
||||||
val address: Address? = null,
|
val address: Address? = null
|
||||||
var isError: Boolean = false,
|
|
||||||
var errorMessage: String = ""
|
|
||||||
)
|
)
|
||||||
|
|
||||||
data class Address(
|
data class Address(
|
||||||
|
|
Loading…
Reference in New Issue