-
Notifications
You must be signed in to change notification settings - Fork 567
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
825 additions
and
432 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
...lingunits/material/interceptor/transactionevent/HUDescriptorFromInventoryLineService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* #%L | ||
* de.metas.handlingunits.base | ||
* %% | ||
* Copyright (C) 2020 metas GmbH | ||
* %% | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as | ||
* published by the Free Software Foundation, either version 2 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public | ||
* License along with this program. If not, see | ||
* <http://www.gnu.org/licenses/gpl-2.0.html>. | ||
* #L% | ||
*/ | ||
|
||
package de.metas.handlingunits.material.interceptor.transactionevent; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import de.metas.handlingunits.HuId; | ||
import de.metas.handlingunits.IHandlingUnitsDAO; | ||
import de.metas.handlingunits.inventory.InventoryLine; | ||
import de.metas.handlingunits.inventory.InventoryLineHU; | ||
import de.metas.handlingunits.inventory.InventoryRepository; | ||
import de.metas.material.event.commons.HUDescriptor; | ||
import de.metas.util.Services; | ||
import de.metas.util.collections.CollectionUtils; | ||
import lombok.NonNull; | ||
import org.adempiere.model.InterfaceWrapperHelper; | ||
import org.compiere.model.I_M_InventoryLine; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component // not calling it service, because right now it's intended to be used only from the M_Transaction model interceptor | ||
public class HUDescriptorFromInventoryLineService | ||
{ | ||
private final InventoryRepository inventoryRepository; | ||
private final HUDescriptorService huDescriptorService; | ||
private final IHandlingUnitsDAO handlingUnitsDAO = Services.get(IHandlingUnitsDAO.class); | ||
|
||
public HUDescriptorFromInventoryLineService( | ||
@NonNull final InventoryRepository inventoryRepository, | ||
@NonNull final HUDescriptorService huDescriptorService) | ||
{ | ||
this.inventoryRepository = inventoryRepository; | ||
this.huDescriptorService = huDescriptorService; | ||
} | ||
|
||
public ImmutableList<HUDescriptor> createHuDescriptorsForInventoryLine( | ||
@NonNull final I_M_InventoryLine inventoryLineRecord, | ||
final boolean deleted) | ||
{ | ||
final InventoryLine inventoryLine = inventoryRepository.toInventoryLine( | ||
InterfaceWrapperHelper.create(inventoryLineRecord, de.metas.handlingunits.model.I_M_InventoryLine.class)); | ||
|
||
final ImmutableList<InventoryLineHU> inventoryLineHUs = inventoryLine.getInventoryLineHUs(); | ||
final ImmutableList<HuId> huIds = CollectionUtils.extractDistinctElements(inventoryLineHUs, InventoryLineHU::getHuId); | ||
|
||
return handlingUnitsDAO | ||
.getByIds(huIds) | ||
.stream() | ||
.flatMap(huRecord -> huDescriptorService.createHuDescriptors(huRecord, deleted).stream()) | ||
.collect(ImmutableList.toImmutableList()); | ||
} | ||
} |
107 changes: 107 additions & 0 deletions
107
...ava/de/metas/handlingunits/material/interceptor/transactionevent/HUDescriptorService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* | ||
* #%L | ||
* de.metas.handlingunits.base | ||
* %% | ||
* Copyright (C) 2020 metas GmbH | ||
* %% | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as | ||
* published by the Free Software Foundation, either version 2 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public | ||
* License along with this program. If not, see | ||
* <http://www.gnu.org/licenses/gpl-2.0.html>. | ||
* #L% | ||
*/ | ||
|
||
package de.metas.handlingunits.material.interceptor.transactionevent; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import de.metas.handlingunits.IHUContext; | ||
import de.metas.handlingunits.IHUContextFactory; | ||
import de.metas.handlingunits.IMutableHUContext; | ||
import de.metas.handlingunits.model.I_M_HU; | ||
import de.metas.handlingunits.storage.IHUProductStorage; | ||
import de.metas.handlingunits.storage.IHUStorage; | ||
import de.metas.material.event.commons.AttributesKey; | ||
import de.metas.material.event.commons.HUDescriptor; | ||
import de.metas.material.event.commons.ProductDescriptor; | ||
import de.metas.util.Services; | ||
import lombok.NonNull; | ||
import org.adempiere.mm.attributes.AttributeSetInstanceId; | ||
import org.adempiere.mm.attributes.api.AttributesKeys; | ||
import org.adempiere.mm.attributes.api.IAttributeSet; | ||
import org.adempiere.mm.attributes.api.IAttributeSetInstanceBL; | ||
import org.adempiere.mm.attributes.api.ImmutableAttributeSet; | ||
import org.adempiere.util.lang.IPair; | ||
import org.adempiere.util.lang.ImmutablePair; | ||
import org.compiere.model.I_M_Attribute; | ||
import org.compiere.model.I_M_AttributeSetInstance; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.math.BigDecimal; | ||
|
||
@Service | ||
public class HUDescriptorService | ||
{ | ||
private final IHUContextFactory huContextFactory = Services.get(IHUContextFactory.class); | ||
private final IAttributeSetInstanceBL attributeSetInstanceBL = Services.get(IAttributeSetInstanceBL.class); | ||
|
||
public ImmutableList<HUDescriptor> createHuDescriptors( | ||
@NonNull final I_M_HU huRecord, | ||
final boolean deleted) | ||
{ | ||
final IMutableHUContext huContext = huContextFactory.createMutableHUContext(); | ||
final IHUStorage storage = huContext.getHUStorageFactory().getStorage(huRecord); | ||
|
||
// Important note: we could have the AttributesKey without making an ASI, but we need the ASI-ID for display reasons in the material dispo window. | ||
final IPair<AttributesKey, AttributeSetInstanceId> attributesKeyAndAsiId = createAttributesKeyAndAsiId(huContext, huRecord); | ||
final AttributesKey attributesKey = attributesKeyAndAsiId.getLeft(); | ||
final AttributeSetInstanceId asiId = attributesKeyAndAsiId.getRight(); | ||
|
||
final ImmutableList.Builder<HUDescriptor> descriptors = ImmutableList.builder(); | ||
for (final IHUProductStorage productStorage : storage.getProductStorages()) | ||
{ | ||
final ProductDescriptor productDescriptor = ProductDescriptor.forProductAndAttributes( | ||
productStorage.getProductId().getRepoId(), | ||
attributesKey, | ||
asiId.getRepoId()); | ||
|
||
final BigDecimal quantity = productStorage.getQtyInStockingUOM().toBigDecimal(); | ||
|
||
final HUDescriptor descriptor = HUDescriptor.builder() | ||
.huId(huRecord.getM_HU_ID()) | ||
.productDescriptor(productDescriptor) | ||
.quantity(deleted ? BigDecimal.ZERO : quantity) | ||
.quantityDelta(deleted ? quantity.negate() : quantity) | ||
.build(); | ||
descriptors.add(descriptor); | ||
} | ||
return descriptors.build(); | ||
} | ||
|
||
private IPair<AttributesKey, AttributeSetInstanceId> createAttributesKeyAndAsiId( | ||
@NonNull final IHUContext huContext, | ||
@NonNull final I_M_HU hu) | ||
{ | ||
final IAttributeSet attributeStorage = huContext.getHUAttributeStorageFactory().getAttributeStorage(hu); | ||
|
||
// we don't want all the non-storage-relevant attributes to pollute the ASI we will display in the material disposition window | ||
final IAttributeSet storageRelevantSubSet = ImmutableAttributeSet.createSubSet(attributeStorage, I_M_Attribute::isStorageRelevant); | ||
|
||
final I_M_AttributeSetInstance asi = attributeSetInstanceBL.createASIFromAttributeSet(storageRelevantSubSet); | ||
final AttributeSetInstanceId asiId = AttributeSetInstanceId.ofRepoIdOrNone(asi.getM_AttributeSetInstance_ID()); | ||
|
||
final AttributesKey attributesKey = AttributesKeys | ||
.createAttributesKeyFromASIStorageAttributes(asiId) | ||
.orElse(AttributesKey.NONE); | ||
|
||
return ImmutablePair.of(attributesKey, asiId); | ||
} | ||
} |
Oops, something went wrong.