refs #6440: errorNaturPhotos

This commit is contained in:
Sergio De la torre 2024-02-09 11:03:29 +01:00
parent 18dd98cf7d
commit a9814013cb
2 changed files with 47 additions and 16 deletions

View File

@ -34,6 +34,10 @@ class ItemCardViewModel(var context: Context) : BaseViewModel(context) {
val response: LiveData<ResponseItemVO>
get() = _response
private val _responseCode by lazy { MutableLiveData<ResponseItemVO>() }
val responseCode: LiveData<ResponseItemVO>
get() = _responseCode
private val _itemspackinglist by lazy { MutableLiveData<ItemPackingTypeList>() }
val itemspackinglist: LiveData<ItemPackingTypeList>
get() = _itemspackinglist
@ -221,6 +225,23 @@ class ItemCardViewModel(var context: Context) : BaseViewModel(context) {
})
}
fun getIdFromCodeSalix(code: String) {
salix.barcodes_toitem(code)
.enqueue(object : SalixCallback<String?>(context) {
override fun onSuccess(response: Response<String?>) {
_responseCode.value =
ResponseItemVO(
isError = false,
response = if (response.body() == null) "" else {
response!!.body().toString()
}
)
}
})
}
fun barcodesEdit(
itemFk: Int,
value: String,

View File

@ -39,7 +39,7 @@ class PhotosFragment(
private val PICK_IMAGE_REQUEST = 1
private val REQUEST_IMAGE_CAPTURE = 2
private val imageUri: Uri? = null
private var originalItem: Number = 0
private var originalItem: String = ""
override fun getLayoutId(): Int = R.layout.fragment_photos
@ -108,20 +108,17 @@ class PhotosFragment(
binding.editItemFk.setOnEditorActionListener { _, actionId, _ ->
if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0 || actionId == 5) {
if (!binding.editItemFk.text.toString().isEmpty()) {
originalItem = itemScanValue(
binding.editItemFk.text.toString(),
"buy",
"more"
).toString().toLong()
try {
viewModel.getItemCard(
originalItem, mobileApplication.dataStoreApp.readDataStoreKey(WAREHOUSEFK)
)
originalItem = itemScanValue(
binding.editItemFk.text.toString(),
"buy",
"more"
).toString()
} catch (Ex: Exception) {
ma.messageWithSound(Ex.message.toString(), true, true)
viewModel.getIdFromCodeSalix(originalItem)
} catch (ex: Exception) {
ma.messageWithSound(ex.message.toString(), true, true)
}
}
binding.editItemFk.setText("")
@ -177,9 +174,22 @@ class PhotosFragment(
}
}
responseCode.observe(viewLifecycleOwner) {
if (it.response.isNotBlank()) {
viewModel.getItemCard(
it.response.toLong(),
mobileApplication.dataStoreApp.readDataStoreKey(WAREHOUSEFK)
)
} else {
ma.messageWithSound(
getString(R.string.itemScanetNotFound),
true,
false,
getString(R.string.noResults)
)
}
}
}
}
private fun upLoadPhoto() {
@ -191,7 +201,7 @@ class PhotosFragment(
if (drawable is BitmapDrawable) {
val bitmap = drawable.bitmap
viewModel.uploadPhoto(
itemFK = originalItem,
itemFK = originalItem.toLong(),
urlImage = saveBitmapAsTempFile(requireContext(), bitmap)
)
}