Search in sources :

Example 11 with BPartnerId

use of de.metas.bpartner.BPartnerId in project metasfresh-webui-api by metasfresh.

the class PurchaseRowId method fromJson.

/**
 * NOTE: keep in sync with {@link #createDocumentId()}
 */
private static final PurchaseRowId fromJson(@NonNull final String json, @Nullable final DocumentId documentId) {
    final List<String> parts = PARTS_SPLITTER.splitToList(json);
    final int partsCount = parts.size();
    if (// we expect at least the type and purchaseDemandId to be encoded in the json string
    partsCount < 2) {
        throw new AdempiereException("Invalid format: " + json);
    }
    try {
        final PurchaseRowType type = PurchaseRowType.ofCode(parts.get(0));
        final PurchaseDemandId purchaseDemandId = PurchaseDemandId.ofId(Integer.parseInt(parts.get(1)));
        if (type == PurchaseRowType.GROUP) {
            return new PurchaseRowId(purchaseDemandId, documentId);
        }
        final BPartnerId vendorId = BPartnerId.ofRepoId(Integer.parseInt(parts.get(2)));
        if (type == PurchaseRowType.LINE) {
            final boolean readonly = decodeReadonly(parts.get(3));
            return new PurchaseRowId(purchaseDemandId, vendorId, readonly, documentId);
        }
        final Type availabilityType = Type.valueOf(parts.get(3));
        final String availabilityDistinguisher = parts.get(4);
        if (type == PurchaseRowType.AVAILABILITY_DETAIL) {
            return new PurchaseRowId(purchaseDemandId, vendorId, availabilityType, availabilityDistinguisher, documentId);
        }
        // 
        throw new AdempiereException("Type " + type + " is not supported");
    } catch (final Exception ex) {
        throw new AdempiereException("Cannot convert '" + json + "' to " + PurchaseRowId.class, ex);
    }
}
Also used : Type(de.metas.purchasecandidate.availability.AvailabilityResult.Type) AdempiereException(org.adempiere.exceptions.AdempiereException) ToString(lombok.ToString) PurchaseDemandId(de.metas.purchasecandidate.PurchaseDemandId) BPartnerId(de.metas.bpartner.BPartnerId) AdempiereException(org.adempiere.exceptions.AdempiereException)

Example 12 with BPartnerId

use of de.metas.bpartner.BPartnerId in project metasfresh-webui-api by metasfresh.

the class PackingInfoProcessParams method getM_HU_PI_Item_Products.

/**
 * @return a list of PI item products that match the selected CU's product and partner, sorted by name.
 */
public LookupValuesList getM_HU_PI_Item_Products() {
    final I_M_HU_LUTU_Configuration defaultLUTUConfig = getDefaultLUTUConfig();
    final ProductId productId = ProductId.ofRepoId(defaultLUTUConfig.getM_Product_ID());
    final BPartnerId bpartnerId = ILUTUConfigurationFactory.extractBPartnerIdOrNull(defaultLUTUConfig);
    final boolean includeVirtualItem = !enforcePhysicalTU;
    final LookupValuesList huPIItemProducts = WEBUI_ProcessHelper.retrieveHUPIItemProducts(Env.getCtx(), productId, bpartnerId, includeVirtualItem);
    return huPIItemProducts;
}
Also used : I_M_HU_LUTU_Configuration(de.metas.handlingunits.model.I_M_HU_LUTU_Configuration) LookupValuesList(de.metas.ui.web.window.datatypes.LookupValuesList) HUPIItemProductId(de.metas.handlingunits.HUPIItemProductId) ProductId(de.metas.product.ProductId) BPartnerId(de.metas.bpartner.BPartnerId)

Example 13 with BPartnerId

use of de.metas.bpartner.BPartnerId in project metasfresh-webui-api by metasfresh.

the class PackingInfoProcessParams method insertPhysicalFallbackTU.

private void insertPhysicalFallbackTU(@NonNull final I_M_HU_LUTU_Configuration defaultLUTUConfig) {
    final BPartnerId bpartnerId = ILUTUConfigurationFactory.extractBPartnerIdOrNull(defaultLUTUConfig);
    final ProductId productId = ProductId.ofRepoId(defaultLUTUConfig.getM_Product_ID());
    final List<I_M_HU_PI_Item_Product> availableHUPIItemProductRecords = WEBUI_ProcessHelper.retrieveHUPIItemProductRecords(Env.getCtx(), productId, bpartnerId, // includeVirtualItem == false
    false);
    Check.errorIf(availableHUPIItemProductRecords.isEmpty(), "There is no non-virtual M_HU_PI_Item_Product value for the given product and bPartner; product={}; bPartner={}", productId, bpartnerId);
    final I_M_HU_PI_Item_Product pip = availableHUPIItemProductRecords.get(0);
    defaultLUTUConfig.setM_HU_PI_Item_Product_ID(pip.getM_HU_PI_Item_Product_ID());
    defaultLUTUConfig.setM_TU_HU_PI_ID(pip.getM_HU_PI_Item().getM_HU_PI_Version().getM_HU_PI_ID());
    defaultLUTUConfig.setQtyCU(pip.getQty());
    final List<I_M_HU_PI_Item> luPIItems = getAvailableLuPIItems(pip, bpartnerId);
    if (luPIItems.isEmpty()) {
        defaultLUTUConfig.setM_LU_HU_PI_Item(null);
        defaultLUTUConfig.setM_LU_HU_PI(null);
    } else {
        final I_M_HU_PI_Item luPiItem = luPIItems.get(0);
        defaultLUTUConfig.setM_LU_HU_PI_Item(luPiItem);
        defaultLUTUConfig.setQtyTU(luPiItem.getQty());
        defaultLUTUConfig.setM_LU_HU_PI_ID(luPiItem.getM_HU_PI_Version().getM_HU_PI_ID());
    }
}
Also used : I_M_HU_PI_Item(de.metas.handlingunits.model.I_M_HU_PI_Item) I_M_HU_PI_Item_Product(de.metas.handlingunits.model.I_M_HU_PI_Item_Product) HUPIItemProductId(de.metas.handlingunits.HUPIItemProductId) ProductId(de.metas.product.ProductId) BPartnerId(de.metas.bpartner.BPartnerId)

Example 14 with BPartnerId

use of de.metas.bpartner.BPartnerId in project metasfresh-webui-api by metasfresh.

the class WEBUI_M_HU_CreateReceipt_Base method rejectIfSecurPharmAttributesAreNotOK.

private ProcessPreconditionsResolution rejectIfSecurPharmAttributesAreNotOK(final HUEditorRow document) {
    // 
    // OK if this is not a Pharma product
    final HUEditorRowAttributes attributes = document.getAttributes();
    if (!attributes.hasAttribute(AttributeConstants.ATTR_SecurPharmScannedStatus)) {
        return ProcessPreconditionsResolution.accept();
    }
    // NOK if SecurPharm connection is not configured and we deal with a pharma product
    if (!securPharmService.hasConfig()) {
        return ProcessPreconditionsResolution.reject("SecurPharm not configured");
    }
    // 
    // NOK if not scanned and vendor != manufacturer
    final BPartnerId vendorId = document.getBPartnerId();
    final BPartnerId manufacturerId = productRepository.getById(document.getProductId()).getManufacturerId();
    if (!BPartnerId.equals(vendorId, manufacturerId)) {
        final SecurPharmAttributesStatus status = SecurPharmAttributesStatus.ofNullableCodeOrKnown(attributes.getValueAsString(AttributeConstants.ATTR_SecurPharmScannedStatus));
        if (status.isUnknown()) {
            return ProcessPreconditionsResolution.reject(Services.get(IMsgBL.class).getTranslatableMsgText(MSG_ScanRequired));
        }
    }
    // OK
    return ProcessPreconditionsResolution.accept();
}
Also used : SecurPharmAttributesStatus(de.metas.vertical.pharma.securpharm.attribute.SecurPharmAttributesStatus) HUEditorRowAttributes(de.metas.ui.web.handlingunits.HUEditorRowAttributes) BPartnerId(de.metas.bpartner.BPartnerId)

Example 15 with BPartnerId

use of de.metas.bpartner.BPartnerId in project metasfresh-webui-api by metasfresh.

the class WEBUI_M_HU_Pick_ParametersFiller method createPickingSlotLabel.

private String createPickingSlotLabel(@NonNull final I_M_PickingSlot pickingslot) {
    final StringBuilder result = new StringBuilder(pickingslot.getPickingSlot());
    final BPartnerId bpartnerId = BPartnerId.ofRepoIdOrNull(pickingslot.getC_BPartner_ID());
    if (bpartnerId != null) {
        final IBPartnerDAO bpartnersRepo = Services.get(IBPartnerDAO.class);
        final I_C_BPartner bpartner = bpartnersRepo.getById(bpartnerId);
        result.append("_").append(bpartner.getName()).append("_").append(bpartner.getValue());
    }
    return result.toString();
}
Also used : IBPartnerDAO(de.metas.bpartner.service.IBPartnerDAO) BPartnerId(de.metas.bpartner.BPartnerId) I_C_BPartner(org.compiere.model.I_C_BPartner)

Aggregations

BPartnerId (de.metas.bpartner.BPartnerId)25 ProductId (de.metas.product.ProductId)6 ITranslatableString (de.metas.i18n.ITranslatableString)5 AdempiereException (org.adempiere.exceptions.AdempiereException)5 HUPIItemProductId (de.metas.handlingunits.HUPIItemProductId)4 ZonedDateTime (java.time.ZonedDateTime)4 SOTrx (de.metas.lang.SOTrx)3 DocumentId (de.metas.ui.web.window.datatypes.DocumentId)3 LookupValuesList (de.metas.ui.web.window.datatypes.LookupValuesList)3 I_C_Order (de.metas.adempiere.model.I_C_Order)2 ShipmentAllocationBestBeforePolicy (de.metas.bpartner.ShipmentAllocationBestBeforePolicy)2 IBPartnerDAO (de.metas.bpartner.service.IBPartnerDAO)2 IHandlingUnitsBL (de.metas.handlingunits.IHandlingUnitsBL)2 I_M_HU_PI_Item (de.metas.handlingunits.model.I_M_HU_PI_Item)2 I_M_HU_PI_Item_Product (de.metas.handlingunits.model.I_M_HU_PI_Item_Product)2 OrderId (de.metas.order.OrderId)2 PriceListVersionId (de.metas.pricing.PriceListVersionId)2 IntegerLookupValue (de.metas.ui.web.window.datatypes.LookupValue.IntegerLookupValue)2 UserId (de.metas.user.UserId)2 Services (de.metas.util.Services)2