Completamento inventario WMS

This commit is contained in:
Giuseppe Scorrano 2022-11-22 17:42:24 +01:00
parent 1512cb7de9
commit f967514f97
8 changed files with 83 additions and 30 deletions

View File

@ -78,6 +78,7 @@
android:name=".gest.inventario.picking.PickingInventarioActivity"
android:label="@string/activity_picking_inventario_title"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustNothing"
android:theme="@style/Light"/>
<meta-data

View File

@ -20,7 +20,8 @@ public interface InventarioDao extends EntityDaoInterface<InventarioRoomDTO> {
@Query("SELECT * FROM " + InventarioRoomDTO.TABLE_NAME +
" WHERE ((:toBeSync = 1 AND " + BaseSyncDTO.Columns.COLUMN_REMOTE_SYNC_DATE + " IS NULL) OR (:toBeSync = 0))")
" WHERE ((:toBeSync = 1 AND " + BaseSyncDTO.Columns.COLUMN_REMOTE_SYNC_DATE + " IS NULL) OR (:toBeSync = 0))" +
" ORDER BY " + InventarioRoomDTO.Columns.DATA_INVENTARIO + " DESC")
Flowable<List<InventarioRoomDTO>> selectAllFlowable(boolean toBeSync);
}

View File

@ -57,7 +57,7 @@ public class InventarioRESTConsumer extends _BaseRESTConsumer {
var request = new InsertInventarioRequestDTO()
.setMtbInvent(inventarioToInsert);
var inventarioRESTConsumerService = RESTBuilder.getService(InventarioRESTConsumerService.class);
var inventarioRESTConsumerService = RESTBuilder.getService(InventarioRESTConsumerService.class, 120);
inventarioRESTConsumerService
.insert(inventarioToInsert.getIdInventario(), request)
.enqueue(new Callback<>() {

View File

@ -43,33 +43,21 @@ public class PermissionsHelper {
activity.setOnRequestPermissionsResult((requestCode, permissions, grantResults) -> {
switch (requestCode) {
case 1: {
if (requestCode == 1) {
boolean allGranted = Stream.of(grantResults).allMatch(x -> x == PackageManager.PERMISSION_GRANTED);
// If request is cancelled, the result arrays are empty.
if (grantResults.size() > 0 && allGranted) {
onPermissionsConfirmed.run();
} else {
boolean anyPermDeny = shouldShowRequestPermissionRationale( activity, permissions );
boolean anyPermDeny = shouldShowRequestPermissionRationale(activity, permissions);
onPermissionsDenied.run(anyPermDeny);
}
return;
}
// other 'case' lines to check for other
// permissions this app might request
}
});
ActivityCompat.requestPermissions(activity, permissionArray,1);
}
private static boolean shouldShowRequestPermissionRationale(AppCompatActivity activity, String[] permissions) {

View File

@ -0,0 +1,18 @@
package it.integry.integrywmsnative.core.utility;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.Observer;
public class UtilityLiveData {
public static <T> void observeOnce(final LiveData<T> liveData, final Observer<T> observer) {
liveData.observeForever(new Observer<T>() {
@Override
public void onChanged(T t) {
liveData.removeObserver(this);
observer.onChanged(t);
}
});
}
}

View File

@ -64,7 +64,8 @@ public class ElencoInventariViewModel {
var matchedInventory = getInventarioList().getValue()
.stream()
.filter(x -> Objects.equals(x.getIdInventario(), inventoryId) && UtilityString.equalsIgnoreCase(x.getZona(), zone))
.filter(x -> Objects.equals(x.getIdInventario(), inventoryId) && UtilityString.equalsIgnoreCase(x.getZona(), zone) &&
!x.isSyncronized())
.findFirst()
.orElse(null);

View File

@ -14,6 +14,7 @@ import com.ravikoradiya.liveadapter.Type;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import javax.inject.Inject;
@ -89,19 +90,23 @@ public class PickingInventarioActivity extends BaseActivity implements PickingIn
.inject(this);
mViewModel.setListener(this);
mBindings.setViewmodel(mViewModel);
initToolbar();
initBarcodeReader();
}
@Override
protected void onStart() {
super.onStart();
mViewModel.init(
DataCache.retrieveItem(getIntent().getStringExtra(KEY_INVENTARIO)),
DataCache.retrieveItem(getIntent().getStringExtra(KEY_INVENTARIO_ARTS)));
mBindings.setViewmodel(mViewModel);
initToolbar();
initRecyclerView();
initBarcodeReader();
}
@Override
public boolean onSupportNavigateUp() {
onBackPressed();
@ -127,6 +132,8 @@ public class PickingInventarioActivity extends BaseActivity implements PickingIn
});
var itemType = new Type<InventarioRowRoomDTO, ActivityPickingInventarioListItemBinding>(R.layout.activity_picking_inventario__list_item, BR.item);
itemType.areItemSame((oldItem, newItem) -> Objects.equals(oldItem.getId(), newItem.getId()));
itemType.areContentsTheSame((oldItem, newItem) -> Objects.equals(oldItem.getId(), newItem.getId()));
itemType.onClick(x -> {
new BottomSheetInventarioRowActionsView(x.getBinding().getItem())
.setListener(new BottomSheetInventarioRowActionsView.Listener() {

View File

@ -2,12 +2,14 @@ package it.integry.integrywmsnative.gest.inventario.picking;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;
import it.integry.barcode_base_android_library.model.BarcodeScanDTO;
@ -26,11 +28,12 @@ import it.integry.integrywmsnative.core.rest.model.inventario.InventarioArtDTO;
import it.integry.integrywmsnative.core.utility.UtilityBarcode;
import it.integry.integrywmsnative.core.utility.UtilityBigDecimal;
import it.integry.integrywmsnative.core.utility.UtilityDate;
import it.integry.integrywmsnative.core.utility.UtilityLiveData;
import it.integry.integrywmsnative.gest.spedizione.exceptions.InvalidPesoKGException;
import it.integry.integrywmsnative.gest.spedizione.model.PickedQuantityDTO;
import it.integry.integrywmsnative.gest.spedizione.model.PickingObjectDTO;
public class PickingInventarioViewModel {
public class PickingInventarioViewModel extends ViewModel {
private final InventarioRepository inventarioRepository;
@ -50,9 +53,38 @@ public class PickingInventarioViewModel {
}
public void init(InventarioRoomDTO inventarioRoomDTO, List<InventarioArtDTO> inventarioArts) {
this.sendOnLoadingStarted();
this.currentInventario.postValue(inventarioRoomDTO);
this.currentInventarioRows = inventarioRowRepository.retrieve(inventarioRoomDTO.getId());
this.availableInventarioArts = inventarioArts == null ? new ArrayList<>() : inventarioArts;
UtilityLiveData.observeOnce(this.currentInventarioRows, data -> {
this.sendOnLoadingEnded();
});
this.sendOnLoadingEnded();
}
private void generateRandomItems() {
for (int i = 0; i < 500; i++) {
Random r = new Random();
int randomIndex = r.nextInt(availableInventarioArts.size());
var item = getAvailableArts().get(randomIndex);
var itemMtbAart = item.toMtbAart();
var fakePickingObjectDto = new PickingObjectDTO()
.setMtbAart(itemMtbAart);
var qta = BigDecimal.valueOf(r.nextInt(50));
var numCnf = UtilityBigDecimal.multiply(qta, itemMtbAart.getQtaCnf());
saveNewRow(fakePickingObjectDto, qta, itemMtbAart.getQtaCnf(), numCnf, null, null);
}
}
public LiveData<InventarioRoomDTO> getCurrentInventario() {
@ -95,8 +127,13 @@ public class PickingInventarioViewModel {
public void exportAll(Runnable onComplete) {
this.sendOnLoadingStarted();
currentInventario.getValue().setInventarioRowList(this.currentInventarioRows.getValue());
this.inventarioRepository.export(currentInventario.getValue(), onComplete, this::sendError);
this.inventarioRepository.export(currentInventario.getValue(), () -> {
this.sendOnLoadingEnded();
onComplete.run();
}, this::sendError);
}