Skip to content

Commit

Permalink
shipment view prototyping
Browse files Browse the repository at this point in the history
  • Loading branch information
teosarca committed Aug 23, 2019
1 parent 2ea3e8d commit 676890a
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 57 deletions.
Expand Up @@ -52,16 +52,16 @@

public class ShipmentCandidateRow implements IViewRow, WebuiASIEditingInfoAware
{
@ViewColumn(seqNo = 10, widgetType = DocumentFieldWidgetType.Text, captionKey = "C_OrderSO_ID")
private final String salesOrderDocumentNo;
@ViewColumn(seqNo = 10, widgetType = DocumentFieldWidgetType.Lookup, captionKey = "C_OrderSO_ID")
private final LookupValue salesOrder;

@ViewColumn(seqNo = 20, widgetType = DocumentFieldWidgetType.Lookup, captionKey = "C_BPartner_Customer_ID")
private final LookupValue customer;

@ViewColumn(seqNo = 30, widgetType = DocumentFieldWidgetType.Lookup, captionKey = "M_Warehouse_ID")
private final LookupValue warehouse;

@ViewColumn(seqNo = 40, widgetType = DocumentFieldWidgetType.Text, captionKey = "M_Product_ID")
@ViewColumn(seqNo = 40, widgetType = DocumentFieldWidgetType.Lookup, captionKey = "M_Product_ID")
private final LookupValue product;

@ViewColumn(seqNo = 50, widgetType = DocumentFieldWidgetType.ZonedDateTime, captionKey = "PreparationDate")
Expand All @@ -71,9 +71,9 @@ public class ShipmentCandidateRow implements IViewRow, WebuiASIEditingInfoAware
@ViewColumn(seqNo = 60, widgetType = DocumentFieldWidgetType.Quantity, fieldName = FIELD_qtyToDeliver, captionKey = "QtyToDeliver", editor = ViewEditorRenderMode.ALWAYS)
private final BigDecimal qtyToDeliver;

public static final String FIELD_asiId = "asiId";
@ViewColumn(seqNo = 70, widgetType = DocumentFieldWidgetType.ProductAttributes, fieldName = FIELD_asiId, captionKey = "M_AttributeSetInstance_ID", editor = ViewEditorRenderMode.ALWAYS)
private final AttributeSetInstanceId asiId;
public static final String FIELD_asi = "asi";
@ViewColumn(seqNo = 70, widgetType = DocumentFieldWidgetType.ProductAttributes, fieldName = FIELD_asi, captionKey = "M_AttributeSetInstance_ID", editor = ViewEditorRenderMode.ALWAYS)
private final LookupValue asi;

private final ShipmentScheduleId shipmentScheduleId;
private final DocumentId rowId;
Expand All @@ -84,23 +84,23 @@ public class ShipmentCandidateRow implements IViewRow, WebuiASIEditingInfoAware
@Builder(toBuilder = true)
private ShipmentCandidateRow(
@NonNull final ShipmentScheduleId shipmentScheduleId,
@Nullable final String salesOrderDocumentNo,
@Nullable final LookupValue salesOrder,
@NonNull final LookupValue customer,
@NonNull final LookupValue warehouse,
@NonNull final LookupValue product,
@NonNull final ZonedDateTime preparationDate,
@NonNull final Quantity qtyToDeliverInitial,
@NonNull final BigDecimal qtyToDeliver,
@NonNull final AttributeSetInstanceId asiId)
@NonNull final LookupValue asi)
{
this.salesOrderDocumentNo = salesOrderDocumentNo;
this.salesOrder = salesOrder;
this.customer = customer;
this.warehouse = warehouse;
this.product = product;
this.preparationDate = preparationDate;
this.qtyToDeliverInitial = qtyToDeliverInitial;
this.qtyToDeliver = qtyToDeliver;
this.asiId = asiId;
this.asi = asi;

this.shipmentScheduleId = shipmentScheduleId;
rowId = DocumentId.of(shipmentScheduleId);
Expand Down Expand Up @@ -148,9 +148,9 @@ public ShipmentCandidateRow withChanges(@NonNull final ShipmentCandidateRowUserC
{
builder.qtyToDeliver(userChanges.getQtyToDeliver());
}
else if (userChanges.getAsiId() != null)
else if (userChanges.getAsi() != null)
{
builder.asiId(userChanges.getAsiId());
builder.asi(userChanges.getAsi());
}

return builder.build();
Expand Down
Expand Up @@ -4,8 +4,7 @@

import javax.annotation.Nullable;

import org.adempiere.mm.attributes.AttributeSetInstanceId;

import de.metas.ui.web.window.datatypes.LookupValue;
import lombok.Builder;
import lombok.Value;

Expand Down Expand Up @@ -39,5 +38,5 @@ public class ShipmentCandidateRowUserChangeRequest
BigDecimal qtyToDeliver;

@Nullable
AttributeSetInstanceId asiId;
LookupValue asi;
}
Expand Up @@ -5,7 +5,6 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.UnaryOperator;

import org.adempiere.mm.attributes.AttributeSetInstanceId;
import org.adempiere.util.lang.impl.TableRecordReferenceSet;

import com.google.common.collect.ImmutableList;
Expand Down Expand Up @@ -105,9 +104,9 @@ private static ShipmentCandidateRowUserChangeRequest toUserChangeRequest(@NonNul
{
builder.qtyToDeliver(fieldChangeRequest.getValueAsBigDecimal());
}
else if (ShipmentCandidateRow.FIELD_asiId.equals(fieldName))
else if (ShipmentCandidateRow.FIELD_asi.equals(fieldName))
{
builder.asiId(fieldChangeRequest.getValueAsId(AttributeSetInstanceId::ofRepoIdOrNone));
builder.asi(fieldChangeRequest.getValueAsIntegerLookupValue());
}
}

Expand Down
Expand Up @@ -6,30 +6,26 @@

import org.adempiere.mm.attributes.AttributeSetInstanceId;
import org.adempiere.warehouse.WarehouseId;
import org.adempiere.warehouse.api.IWarehouseDAO;
import org.compiere.model.I_C_BPartner;
import org.compiere.model.I_C_Order;
import org.compiere.util.TimeUtil;
import org.compiere.model.I_M_AttributeSetInstance;
import org.compiere.model.I_M_Product;
import org.compiere.model.I_M_Warehouse;

import com.google.common.collect.ImmutableList;

import de.metas.bpartner.BPartnerId;
import de.metas.bpartner.service.IBPartnerDAO;
import de.metas.i18n.ITranslatableString;
import de.metas.i18n.TranslatableStrings;
import de.metas.inoutcandidate.api.IShipmentScheduleBL;
import de.metas.inoutcandidate.api.IShipmentScheduleEffectiveBL;
import de.metas.inoutcandidate.api.IShipmentSchedulePA;
import de.metas.inoutcandidate.api.ShipmentScheduleId;
import de.metas.inoutcandidate.model.I_M_ShipmentSchedule;
import de.metas.order.IOrderDAO;
import de.metas.order.OrderId;
import de.metas.product.IProductBL;
import de.metas.product.ProductId;
import de.metas.quantity.Quantity;
import de.metas.ui.web.window.datatypes.LookupValue;
import de.metas.ui.web.window.datatypes.LookupValue.IntegerLookupValue;
import de.metas.ui.web.window.model.lookup.LookupDataSource;
import de.metas.ui.web.window.model.lookup.LookupDataSourceFactory;
import de.metas.util.Check;
import de.metas.util.Services;
import lombok.Builder;
import lombok.NonNull;

Expand Down Expand Up @@ -57,26 +53,32 @@

final class ShipmentCandidateRowsRepository
{
private final IShipmentScheduleEffectiveBL shipmentScheduleEffectiveBL = Services.get(IShipmentScheduleEffectiveBL.class);
private final IShipmentScheduleBL shipmentScheduleBL;
private final IShipmentSchedulePA shipmentSchedulesRepo = Services.get(IShipmentSchedulePA.class);
private final IOrderDAO salesOrdersRepo = Services.get(IOrderDAO.class);
private final IBPartnerDAO bpartnersRepo = Services.get(IBPartnerDAO.class);
private final IWarehouseDAO warehousesRepo = Services.get(IWarehouseDAO.class);
private final IProductBL productsService = Services.get(IProductBL.class);

private final LookupDataSource salesOrdersLookup;
private final LookupDataSource customersLookup;
private final LookupDataSource warehousesLookup;
private final LookupDataSource productsLookup;
private final LookupDataSource asiLookup;

@Builder
private ShipmentCandidateRowsRepository(
@NonNull final IShipmentScheduleBL shipmentScheduleBL)
{
this.shipmentScheduleBL = shipmentScheduleBL;

salesOrdersLookup = LookupDataSourceFactory.instance.searchInTableLookup(I_C_Order.Table_Name);
customersLookup = LookupDataSourceFactory.instance.searchInTableLookup(I_C_BPartner.Table_Name);
warehousesLookup = LookupDataSourceFactory.instance.searchInTableLookup(I_M_Warehouse.Table_Name);
productsLookup = LookupDataSourceFactory.instance.searchInTableLookup(I_M_Product.Table_Name);
asiLookup = LookupDataSourceFactory.instance.searchInTableLookup(I_M_AttributeSetInstance.Table_Name);
}

public ShipmentCandidateRows getByShipmentScheduleIds(final Set<ShipmentScheduleId> shipmentScheduleIds)
{
Check.assumeNotEmpty(shipmentScheduleIds, "shipmentScheduleIds is not empty");

final Collection<I_M_ShipmentSchedule> records = shipmentSchedulesRepo.getByIdsOutOfTrx(shipmentScheduleIds).values();
final Collection<I_M_ShipmentSchedule> records = shipmentScheduleBL.getByIdsOutOfTrx(shipmentScheduleIds).values();
final ImmutableList<ShipmentCandidateRow> rows = records
.stream()
.map(this::toShipmentCandidateRow)
Expand All @@ -90,60 +92,57 @@ public ShipmentCandidateRows getByShipmentScheduleIds(final Set<ShipmentSchedule
private ShipmentCandidateRow toShipmentCandidateRow(@NonNull final I_M_ShipmentSchedule record)
{
final Quantity qtyToDeliver = extractQtyToDeliver(record);
final AttributeSetInstanceId asiId = AttributeSetInstanceId.ofRepoIdOrNone(record.getM_AttributeSetInstance_ID());

return ShipmentCandidateRow.builder()
.shipmentScheduleId(ShipmentScheduleId.ofRepoId(record.getM_ShipmentSchedule_ID()))
.salesOrderDocumentNo(extractSalesOrderDocumentNo(record))
.salesOrder(extractSalesOrder(record))
.customer(extractCustomer(record))
.warehouse(extractWarehouse(record))
.product(extractProduct(record))
.preparationDate(extractPreparationTime(record))
.qtyToDeliverInitial(qtyToDeliver)
.qtyToDeliver(qtyToDeliver.getAsBigDecimal())
.asiId(asiId)
.asi(extractASI(record))
.build();
}

private String extractSalesOrderDocumentNo(@NonNull final I_M_ShipmentSchedule record)
private LookupValue extractSalesOrder(@NonNull final I_M_ShipmentSchedule record)
{
final OrderId salesOrderId = OrderId.ofRepoIdOrNull(record.getC_Order_ID());
if (salesOrderId == null)
{
return null;
}

final I_C_Order salesOrder = salesOrdersRepo.getById(salesOrderId);
return salesOrder.getDocumentNo();
return salesOrderId != null
? salesOrdersLookup.findById(salesOrderId)
: null;
}

private LookupValue extractCustomer(@NonNull final I_M_ShipmentSchedule record)
{
final BPartnerId customerId = shipmentScheduleEffectiveBL.getBPartnerId(record);

final ITranslatableString customerName = TranslatableStrings.anyLanguage(bpartnersRepo.getBPartnerNameById(customerId));
return IntegerLookupValue.of(customerId, customerName);
final BPartnerId customerId = shipmentScheduleBL.getBPartnerId(record);
return customersLookup.findById(customerId);
}

private LookupValue extractWarehouse(@NonNull final I_M_ShipmentSchedule record)
{
final WarehouseId warehouseId = shipmentScheduleEffectiveBL.getWarehouseId(record);

final ITranslatableString warehouseName = TranslatableStrings.anyLanguage(warehousesRepo.getWarehouseName(warehouseId));
return IntegerLookupValue.of(warehouseId, warehouseName);
final WarehouseId warehouseId = shipmentScheduleBL.getWarehouseId(record);
return warehousesLookup.findById(warehouseId);
}

private LookupValue extractProduct(@NonNull final I_M_ShipmentSchedule record)
{
final ProductId productId = ProductId.ofRepoId(record.getM_Product_ID());
return productsLookup.findById(productId);
}

final ITranslatableString productName = TranslatableStrings.anyLanguage(productsService.getProductValueAndName(productId));
return IntegerLookupValue.of(productId, productName);
private LookupValue extractASI(@NonNull final I_M_ShipmentSchedule record)
{
final AttributeSetInstanceId asiId = AttributeSetInstanceId.ofRepoIdOrNone(record.getM_AttributeSetInstance_ID());
return asiId.isRegular()
? asiLookup.findById(asiId)
: IntegerLookupValue.of(asiId.getRepoId(), "");
}

private ZonedDateTime extractPreparationTime(@NonNull final I_M_ShipmentSchedule record)
{
return TimeUtil.asZonedDateTime(shipmentScheduleEffectiveBL.getPreparationDate(record));
return shipmentScheduleBL.getPreparationDate(record);
}

private Quantity extractQtyToDeliver(@NonNull final I_M_ShipmentSchedule record)
Expand Down

0 comments on commit 676890a

Please sign in to comment.