From fceab8c1820528d95343b246d897a96b4416a4a6 Mon Sep 17 00:00:00 2001 From: Sergio De la torre Date: Tue, 24 Sep 2024 10:24:42 +0200 Subject: [PATCH] feat: boxPickingPrepared refs #7855 --- .../feature/boxPicking/BoxPickingFragment.kt | 120 +++++++++++------- .../feature/boxPicking/BoxPickingViewModel.kt | 46 +++++-- 2 files changed, 108 insertions(+), 58 deletions(-) diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/boxPicking/BoxPickingFragment.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/boxPicking/BoxPickingFragment.kt index 8b9e2faf..0d94833f 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/boxPicking/BoxPickingFragment.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/boxPicking/BoxPickingFragment.kt @@ -5,15 +5,18 @@ import android.view.inputmethod.EditorInfo import es.verdnatura.R import es.verdnatura.databinding.FragmentGeneralBlackBinding import es.verdnatura.presentation.base.BaseFragment -import es.verdnatura.presentation.common.ExpeditionPrintOut import es.verdnatura.presentation.common.OnCollectionSelectedListener import es.verdnatura.presentation.view.component.CustomDialogInput +import es.verdnatura.presentation.view.feature.delivery.model.ExpeditionSalix +import es.verdnatura.presentation.view.feature.delivery.model.Expeditions +import es.verdnatura.presentation.view.feature.delivery.viewmodels.DeliveryViewModel class BoxPickingFragment(var title: String) : - BaseFragment(BoxPickingViewModel::class) { + BaseFragment(DeliveryViewModel::class) { private var onCollectionSelectedListener: OnCollectionSelectedListener? = null private var isBoxScanned: Boolean = false private lateinit var customDialogInput: CustomDialogInput + private var codeStateId: Number = 0 override fun getLayoutId(): Int = R.layout.fragment_general_black companion object { @@ -25,6 +28,7 @@ class BoxPickingFragment(var title: String) : binding.mainToolbar.toolbarTitle.text = title setEvents() customDialogInput = CustomDialogInput(requireContext()) + viewModel.getExpeditionStateId("CHECKED") super.init() } @@ -40,11 +44,20 @@ class BoxPickingFragment(var title: String) : if (!binding.scanInput.text.isNullOrEmpty()) { try { - showScanBarcode(binding.scanInput.text.toString().toLong()) - }catch (ex:Exception){ - ma.messageWithSound(message =getString(R.string.itemNotValid), isError = true, isPlayed = true, isToasted = false) - } + viewModel.findExpedition( + expedition = binding.scanInput.text.toString().toLong(), + expeditionStateId = codeStateId + ) + + } catch (ex: Exception) { + ma.messageWithSound( + message = getString(R.string.itemNotValid), + isError = true, + isPlayed = true, + isToasted = false + ) + } } binding.scanInput.setText("") @@ -61,10 +74,19 @@ class BoxPickingFragment(var title: String) : customDialogInput.setTitle(getString(R.string.scanItem)) .setOkButton(getString(R.string.accept)) { if (customDialogInput.getValue().isNotEmpty()) { - viewModel.isBoxPickingInPrintOut( - expeditionFk = expeditionFk, - customDialogInput.getValue() + + viewModel.expeditionStateAddSalix( + expeditions = Expeditions( + arrayListOf( + ExpeditionSalix( + expeditionFk = expeditionFk, + stateCode = "CHECKED", + isScanned = 1 + ) + ) + ) ) + } customDialogInput.dismiss() } @@ -76,15 +98,12 @@ class BoxPickingFragment(var title: String) : }.setValue("").show() - - customDialogInput.getEditText().setOnEditorActionListener { _, actionId, _ -> if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0) { if (customDialogInput.getValue().isNotEmpty()) { - viewModel.isBoxPickingInPrintOut( - expeditionFk = expeditionFk, - customDialogInput.getValue() + viewModel.findExpedition( + expedition = expeditionFk, expeditionStateId = expeditionFk ) } customDialogInput.dismiss() @@ -101,50 +120,55 @@ class BoxPickingFragment(var title: String) : override fun observeViewModel() { with(viewModel) { - /*isBoxPickingInPrintOut.observe(viewLifecycleOwner) { + responseExpeditionStateId.observe(viewLifecycleOwner) { + codeStateId = it + } + responseFindExpeditionId.observe(viewLifecycleOwner) { + if (it != 0) { + showScanBarcode(it.toLong()) + } else { + ma.messageWithSound( + getString( + R.string.errorBoxPicking + ), isError = true, isPlayed = true, isToasted = true + ) + } + responseStateAdd.observe(viewLifecycleOwner) { + if (it) { + customDialogInput.dismiss() + binding.scanInput.requestFocus() + } + } + //Tarea 7751 + isBoxPickingInPrintOut.observe(viewLifecycleOwner) { + if (it.isChecked) { + ma.messageWithSound( + message = getString(R.string.errorBoxPicking), + isError = true, + isPlayed = true, + isToasted = false + + ) + } else { + + } + binding.scanInput.requestFocus() + } + responseCode.observe(viewLifecycleOwner) { ma.messageWithSound( message = getString(R.string.errorInput), - isError = !it, + isError = true, isPlayed = true, isToasted = null ) - binding.scanInput.requestFocus() - - }*/ - //Tarea 7751 - isBoxPickingInPrintOut.observe(viewLifecycleOwner) { - - if (it.isChecked){ - ma.messageWithSound( - message = getString(R.string.errorBoxPicking), - isError = true, - isPlayed = true, - isToasted = false - - ) - }else{ - viewModel.updateExpeditionPrint(it.expeditionFk, expeditionPrintOut = ExpeditionPrintOut(it.expeditionFk,it.itemFk, true)) - - } - binding.scanInput.requestFocus() - - } - responseCode.observe(viewLifecycleOwner) { - - ma.messageWithSound( - message = getString(R.string.errorInput), - isError = true, - isPlayed = true, - isToasted = null - - ) - binding.scanInput.requestFocus() + binding.scanInput.requestFocus() + } } } + } - } diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/boxPicking/BoxPickingViewModel.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/boxPicking/BoxPickingViewModel.kt index 49afcaea..fc0a39ee 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/boxPicking/BoxPickingViewModel.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/boxPicking/BoxPickingViewModel.kt @@ -12,8 +12,11 @@ import retrofit2.Response class BoxPickingViewModel(val context: Context) : BaseViewModel(context) { private val getItemFromBarcodeUseCase = GetItemFromBarcodeUseCase(salix) + /*private val _isBoxPickingInPrintOut by lazy { MutableLiveData() } val isBoxPickingInPrintOut: LiveData = _isBoxPickingInPrintOut*/ + private val _responseFindExpeditionId by lazy { MutableLiveData() } + val responseFindExpeditionId: LiveData = _responseFindExpeditionId //Tarea 7751 private val _isBoxPickingInPrintOut by lazy { MutableLiveData() } @@ -28,16 +31,16 @@ class BoxPickingViewModel(val context: Context) : BaseViewModel(context) { salix.isBoxPickingInPrintOut( filter = """{"where":{"expeditionFk":$expeditionFk,"itemFk":$itemFk}}""" - /* ).enqueue(object : SalixCallback(context) { + /* ).enqueue(object : SalixCallback(context) { - override fun onSuccess(response: Response) { - _isBoxPickingInPrintOut.value = true - } - override fun onError(t: Throwable) { - _isBoxPickingInPrintOut.value = false - } + override fun onSuccess(response: Response) { + _isBoxPickingInPrintOut.value = true + } + override fun onError(t: Throwable) { + _isBoxPickingInPrintOut.value = false + } - })*/ + })*/ //Tarea 7751 //isChecked ).enqueue(object : SalixCallback(context) { @@ -45,8 +48,9 @@ class BoxPickingViewModel(val context: Context) : BaseViewModel(context) { override fun onSuccess(response: Response) { _isBoxPickingInPrintOut.value = response.body() } + override fun onError(t: Throwable) { - _isBoxPickingInPrintOut.value = ExpeditionPrintOut(0,0,false) + _isBoxPickingInPrintOut.value = ExpeditionPrintOut(0, 0, false) } }) @@ -70,8 +74,30 @@ class BoxPickingViewModel(val context: Context) : BaseViewModel(context) { } }) } + + fun findExpedition(expedition: Number, expeditionStateId: Number) { + salix.findExpedition( + filter = """{"where": + { + "expeditionFk":$expedition, + "typeFk":$expeditionStateId + } + }""".trimMargin() + ).enqueue(object : SalixCallback(context) { + override fun onSuccess(response: Response) { + _responseFindExpeditionId.value = 0 + + } + + override fun onError(t: Throwable) { + _responseFindExpeditionId.value = expedition + } + + }) + } + fun updateExpeditionPrint(expeditionFk: Long, expeditionPrintOut: ExpeditionPrintOut) { - salix.update(expeditionFk, expeditionPrintOut) + salix.update(expeditionFk, expeditionPrintOut) .enqueue(object : SalixCallback(context) { })