Skip to content

Commit

Permalink
#6915 Extend BPartner-Relation and add it as BPartner-Tab
Browse files Browse the repository at this point in the history
  • Loading branch information
BodorAnnamaria committed Feb 8, 2021
1 parent a0c53c0 commit b0788f2
Show file tree
Hide file tree
Showing 10 changed files with 2,796 additions and 525 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ public class BPartnerDAO implements IBPartnerDAO
{
private static final Logger logger = LogManager.getLogger(BPartnerDAO.class);
private final IQueryBL queryBL = Services.get(IQueryBL.class);
private final IBPartnerDAO bPartnersRepo = Services.get(IBPartnerDAO.class);

private final GLNLoadingCache glnsLoadingCache = new GLNLoadingCache();
private final CCache<BPartnerId, BPartnerPrintFormatMap> printFormatsCache = CCache.<BPartnerId, BPartnerPrintFormatMap>builder()
Expand Down Expand Up @@ -932,7 +933,7 @@ public I_C_BPartner_Location retrieveBillToLocation(
.firstOnly(I_C_BP_Relation.class); // just added an UC
if (billtoRelation != null)
{
return InterfaceWrapperHelper.create(billtoRelation.getC_BPartnerRelation_Location(), I_C_BPartner_Location.class);
return InterfaceWrapperHelper.create(bPartnersRepo.getBPartnerLocationById(BPartnerLocationId.ofRepoId(billtoRelation.getC_BPartner_ID(), billtoRelation.getC_BPartnerRelation_Location_ID())), I_C_BPartner_Location.class);
}
return null;
}
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

import de.metas.interfaces.I_C_BP_Relation;
import de.metas.util.Services;
import org.compiere.model.X_C_BP_Relation;

public class SubProducerAttributeDAO implements ISubProducerAttributeDAO
{
Expand All @@ -43,8 +44,8 @@ public List<I_C_BPartner> retrieveSubProducerBPartners(final Properties ctx, fin
{
final IQuery<I_C_BP_Relation> bpRelationQuery = Services.get(IQueryBL.class)
.createQueryBuilder(I_C_BP_Relation.class, ctx, ITrx.TRXNAME_None)
.addEqualsFilter(org.compiere.model.I_C_BP_Relation.COLUMNNAME_C_BPartnerRelation_ID, bpartnerId)
.addEqualsFilter(I_C_BP_Relation.COLUMNNAME_IsMainProducer, true)
.addEqualsFilter(org.compiere.model.I_C_BP_Relation.COLUMNNAME_C_BPartner_ID, bpartnerId)
.addEqualsFilter(I_C_BP_Relation.COLUMNNAME_Role, X_C_BP_Relation.ROLE_MainProducer)
.addOnlyActiveRecordsFilter()
.addOnlyContextClient(ctx)
.create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class HUSubProducerBPartnerAttributeValuesProvider implements IAttributeValuesPr
* NOTE: we use a static cache for optimization purposes
*/
private static final CCache<Integer, List<KeyNamePair>> bpartnerId2subProducers = CCache.<Integer, List<KeyNamePair>> builder()
.cacheName(CACHE_PREFIX + "#by#" + I_C_BP_Relation.COLUMNNAME_C_BPartner_ID + "#" + I_C_BP_Relation.COLUMNNAME_IsMainProducer)
.cacheName(CACHE_PREFIX + "#by#" + I_C_BP_Relation.COLUMNNAME_C_BPartner_ID + "#" + I_C_BP_Relation.COLUMNNAME_Role)
.initialCapacity(10)
.additionalTableNameToResetFor(I_C_BPartner.Table_Name)
.additionalTableNameToResetFor(I_C_BP_Relation.Table_Name)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/*
* #%L
* de.metas.handlingunits.base
* %%
* Copyright (C) 2021 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 org.adempiere.mm.attributes.api.impl;

import de.metas.util.Services;
import org.adempiere.mm.attributes.api.ISubProducerAttributeDAO;
import org.adempiere.service.ClientId;
import org.adempiere.test.AdempiereTestHelper;
import de.metas.interfaces.I_C_BP_Relation;
import org.compiere.model.I_C_BPartner;
import org.compiere.model.X_C_BP_Relation;
import org.compiere.util.Env;
import org.junit.Before;
import org.junit.Test;

import java.util.List;
import java.util.Properties;

import static org.adempiere.model.InterfaceWrapperHelper.newInstance;
import static org.adempiere.model.InterfaceWrapperHelper.save;
import static org.assertj.core.api.Assertions.*;

public class SubProducerAttributeDAOTest
{
private I_C_BPartner bp;
private I_C_BPartner bp2;
private I_C_BP_Relation bpRelation;
private ISubProducerAttributeDAO dao = Services.get(ISubProducerAttributeDAO.class);

@Before
public void init()
{
AdempiereTestHelper.get().init();
final Properties ctx = Env.getCtx();
Env.setClientId(ctx, ClientId.METASFRESH);
Env.setOrgId(ctx, AdempiereTestHelper.createOrgWithTimeZone());

setUpBpRelationData();
}

@Test
public void testRetrieveSubProducerBPartners() {
List<I_C_BPartner> bpPartnerList = dao.retrieveSubProducerBPartners(Env.getCtx(), bp.getC_BPartner_ID());
assertThat(bpPartnerList.size()).isEqualTo(1);

bpPartnerList = dao.retrieveSubProducerBPartners(Env.getCtx(), bp2.getC_BPartner_ID());
assertThat(bpPartnerList.size()).isEqualTo(0);
}

private void setUpBpRelationData() {
bp = newInstance(I_C_BPartner.class);
bp.setIsActive(true);
bp.setName("Test Partner");
save(bp);

bpRelation = newInstance(I_C_BP_Relation.class);
bpRelation.setC_BPartner_ID(bp.getC_BPartner_ID());
bpRelation.setName("Test Rel1");
bpRelation.setRole(X_C_BP_Relation.ROLE_MainProducer);
bpRelation.setIsActive(true);
save(bpRelation);

bpRelation = newInstance(I_C_BP_Relation.class);
bpRelation.setC_BPartner_ID(bp.getC_BPartner_ID());
bpRelation.setName("Test Rel2");
bpRelation.setRole(null);
bpRelation.setIsActive(true);
save(bpRelation);

bpRelation = newInstance(I_C_BP_Relation.class);
bpRelation.setC_BPartner_ID(bp.getC_BPartner_ID());
bpRelation.setName("Test Rel3");
bpRelation.setRole(X_C_BP_Relation.ROLE_MainProducer);
bpRelation.setIsActive(false);
save(bpRelation);

bpRelation = newInstance(I_C_BP_Relation.class);
bpRelation.setC_BPartner_ID(bp.getC_BPartner_ID());
bpRelation.setName("Test Rel4");
bpRelation.setRole(X_C_BP_Relation.ROLE_Caregiver);
bpRelation.setIsActive(true);
save(bpRelation);

bpRelation = newInstance(I_C_BP_Relation.class);
bpRelation.setC_BPartner_ID(bp.getC_BPartner_ID());
bpRelation.setName("Test Rel5");
bpRelation.setRole(X_C_BP_Relation.ROLE_MainProducer);
bpRelation.setIsActive(true);
save(bpRelation);

bp2 = newInstance(I_C_BPartner.class);
bp2.setIsActive(true);
bp2.setName("Test Partner");
save(bp2);

bpRelation = newInstance(I_C_BP_Relation.class);
bpRelation.setC_BPartner_ID(bp2.getC_BPartner_ID());
bpRelation.setName("Test Rel21");
bpRelation.setRole(null);
bpRelation.setIsActive(true);
save(bpRelation);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.common.collect.ImmutableSet;
import de.metas.bpartner.BPartnerId;
import de.metas.bpartner.BPartnerLocationId;
import de.metas.bpartner.api.IBPRelationDAO;
import de.metas.bpartner.service.IBPartnerDAO;
import de.metas.bpartner_product.IBPartnerProductDAO;
Expand Down Expand Up @@ -283,7 +284,8 @@ private void updateHandoverLocationOverride(@NonNull final I_C_OLCand olCand)
}
else
{
org.compiere.model.I_C_BPartner_Location handOverLocation = handoverRelation.getC_BPartnerRelation_Location();
org.compiere.model.I_C_BPartner_Location handOverLocation = Services.get(IBPartnerDAO.class).getBPartnerLocationById(BPartnerLocationId.ofRepoId(handoverRelation.getC_BP_Relation_ID(), handoverRelation.getC_BPartnerRelation_Location_ID()));

if (handOverLocation == null)
{
// this should also not happen because C_BPartnerRelation_Location is mandatory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,21 @@
* #L%
*/

import de.metas.bpartner.BPartnerId;
import de.metas.bpartner.BPartnerLocationId;
import de.metas.bpartner.service.IBPartnerBL;
import de.metas.bpartner.service.IBPartnerDAO;
import de.metas.process.JavaProcess;
import de.metas.process.ProcessInfoParameter;
import de.metas.util.Services;
import org.adempiere.exceptions.AdempiereException;
import org.adempiere.exceptions.DBMoreThanOneRecordsFoundException;
import org.adempiere.model.InterfaceWrapperHelper;
import org.compiere.model.I_C_BP_Relation;
import org.compiere.model.I_C_BPartner_Location;
import org.compiere.model.I_C_Order;
import org.compiere.model.Query;

import de.metas.process.ProcessInfoParameter;
import de.metas.process.JavaProcess;

/**
* Create BP relation from document.
*
Expand Down Expand Up @@ -64,6 +69,7 @@ public class CreateBPRelationFromDocument extends JavaProcess
private boolean p_IsRemitTo = false;
private boolean p_IsShipTo = false;

private final IBPartnerDAO bPartnersRepo = Services.get(IBPartnerDAO.class);
@Override
protected void prepare()
{
Expand Down Expand Up @@ -203,23 +209,24 @@ private void setName(final I_C_BP_Relation rel)
{
final StringBuffer name = new StringBuffer();

final String nameFrom = rel.getC_BPartner().getName();
final String nameFrom = Services.get(IBPartnerBL.class).getBPartnerName(BPartnerId.ofRepoId(rel.getC_BPartner_ID()));
name.append(nameFrom);

if (rel.getC_BPartner_Location_ID() > 0)
{
final String locFrom = rel.getC_BPartner_Location().getName();
final I_C_BPartner_Location bPartnerLocation = bPartnersRepo.getBPartnerLocationById(BPartnerLocationId.ofRepoId(rel.getC_BPartner_ID(), rel.getC_BPartner_Location_ID()));
final String locFrom = bPartnerLocation.getName();
name.append("(").append(locFrom).append(")");
}

name.append("->");

final String nameTo = rel.getC_BPartnerRelation().getName();
final String nameTo = bPartnersRepo.getBPartnerNameById(BPartnerId.ofRepoId(rel.getC_BPartnerRelation_ID()));
name.append(nameTo);

if (rel.getC_BPartnerRelation_Location_ID() > 0)
{
final String locTo = rel.getC_BPartnerRelation_Location().getName();
final String locTo = bPartnersRepo.getBPartnerLocationById(BPartnerLocationId.ofRepoId(rel.getC_BPartner_ID(), rel.getC_BPartnerRelation_Location_ID())).getName();
name.append("(").append(locTo).append(")");
}
rel.setName(name.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,4 @@ public interface I_C_BP_Relation extends org.compiere.model.I_C_BP_Relation
public static String COLUMNNAME_IsHandOverLocation = "IsHandOverLocation";
public boolean isHandOverLocation();
public void setIsHandOverLocation(boolean IsHandOverLocation);

public static String COLUMNNAME_IsMainProducer = "IsMainProducer";
public boolean isMainProducer();
public void setIsMainProducer(boolean IsMainProducer);
}

0 comments on commit b0788f2

Please sign in to comment.