Skip to content

Commit

Permalink
found and hopefully fixed the actual problem
Browse files Browse the repository at this point in the history
  • Loading branch information
metas-ts committed Nov 30, 2020
1 parent fa5bd93 commit 7fc4543
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package de.metas.contracts.commission.salesrep;

import javax.annotation.Nullable;

import de.metas.contracts.commission.Beneficiary;
import de.metas.contracts.commission.Customer;
import de.metas.lang.SOTrx;
Expand All @@ -10,6 +8,8 @@
import lombok.NonNull;
import lombok.Setter;

import javax.annotation.Nullable;

/*
* #%L
* de.metas.contracts
Expand Down Expand Up @@ -78,7 +78,7 @@ public boolean validatesOK()
{
if (soTrx.isPurchase())
{
return true; // we don'T have any business with purchase documents
return true; // we don't have any business with purchase documents
}

if (!isSalesRepRequired())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
package de.metas.contracts.commission.salesrep.interceptor;

import static de.metas.common.util.CoalesceUtil.firstGreaterThanZero;
import static org.adempiere.model.InterfaceWrapperHelper.saveRecord;

import de.metas.bpartner.BPartnerId;
import de.metas.bpartner.service.IBPartnerDAO;
import de.metas.contracts.commission.salesrep.DocumentSalesRepDescriptor;
import de.metas.contracts.commission.salesrep.DocumentSalesRepDescriptorFactory;
import de.metas.contracts.commission.salesrep.DocumentSalesRepDescriptorService;
import de.metas.util.Check;
import de.metas.util.Services;
import lombok.NonNull;
import org.adempiere.ad.callout.annotations.Callout;
import org.adempiere.ad.callout.annotations.CalloutMethod;
import org.adempiere.ad.callout.spi.IProgramaticCalloutProvider;
import org.adempiere.ad.modelvalidator.ModelChangeType;
import org.adempiere.ad.modelvalidator.annotations.DocValidate;
import org.adempiere.ad.modelvalidator.annotations.Interceptor;
import org.adempiere.ad.modelvalidator.annotations.ModelChange;
Expand All @@ -14,13 +20,8 @@
import org.compiere.model.ModelValidator;
import org.springframework.stereotype.Component;

import de.metas.bpartner.BPartnerId;
import de.metas.bpartner.service.IBPartnerDAO;
import de.metas.contracts.commission.salesrep.DocumentSalesRepDescriptor;
import de.metas.contracts.commission.salesrep.DocumentSalesRepDescriptorFactory;
import de.metas.contracts.commission.salesrep.DocumentSalesRepDescriptorService;
import de.metas.util.Services;
import lombok.NonNull;
import static de.metas.common.util.CoalesceUtil.firstGreaterThanZero;
import static org.adempiere.model.InterfaceWrapperHelper.saveRecord;

/*
* #%L
Expand Down Expand Up @@ -62,8 +63,21 @@ public C_Order(
Services.get(IProgramaticCalloutProvider.class).registerAnnotatedCallout(this);
}

@ModelChange(
timings = { ModelValidator.TYPE_BEFORE_NEW, ModelValidator.TYPE_BEFORE_CHANGE },
ifColumnsChanged = { I_C_Order.COLUMNNAME_C_BPartner_ID, I_C_Order.COLUMNNAME_Bill_BPartner_ID })
public void updateSalesPartnerFromCustomer(@NonNull final I_C_Order orderRecord, @NonNull final ModelChangeType type)
{
// if on a new C_Order record both SalesPartnerCode and the BPartner-IDs were set at the same time,
// then don't override the sales partner from the BPartners' mater data, but assume that the sales partner shall remain the way it is.
final boolean currentPartnerCodeShallPrevail = type.isNew() && Check.isNotBlank(orderRecord.getSalesPartnerCode());
if (!currentPartnerCodeShallPrevail)
{
updateSalesPartnerFromCustomer(orderRecord);
}
}

@CalloutMethod(columnNames = { I_C_Order.COLUMNNAME_C_BPartner_ID, I_C_Order.COLUMNNAME_Bill_BPartner_ID })
@ModelChange(timings = { ModelValidator.TYPE_BEFORE_NEW, ModelValidator.TYPE_BEFORE_CHANGE }, ifColumnsChanged = { I_C_Order.COLUMNNAME_C_BPartner_ID, I_C_Order.COLUMNNAME_Bill_BPartner_ID })
public void updateSalesPartnerFromCustomer(@NonNull final I_C_Order orderRecord)
{
final DocumentSalesRepDescriptor documentSalesRepDescriptor = documentSalesRepDescriptorFactory.forDocumentRecord(orderRecord);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,24 +223,20 @@ private I_C_Order newOrder(@NonNull final OLCand candidateOfGroup)
order.setM_PricingSystem_ID(PricingSystemId.toRepoId(candidateOfGroup.getPricingSystemId()));
order.setM_Shipper_ID(ShipperId.toRepoId(candidateOfGroup.getShipperId()));

order.setC_BPartner_SalesRep_ID(BPartnerId.toRepoId(candidateOfGroup.getSalesRepId()));

final DocTypeId orderDocTypeId = candidateOfGroup.getOrderDocTypeId();
if (orderDocTypeId != null)
{
order.setC_DocTypeTarget_ID(candidateOfGroup.getOrderDocTypeId().getRepoId());
}

final BPartnerId salesRepId = candidateOfGroup.getSalesRepId();

if (salesRepId != null)
{
order.setC_BPartner_SalesRep_ID(salesRepId.getRepoId());

final I_C_BPartner salesPartner = bpartnerDAO.getById(salesRepId);

order.setSalesPartnerCode(salesPartner.getSalesPartnerCode());

}

// Save to SO the external header id, so that on completion it can be linked with its payment
Expand Down

0 comments on commit 7fc4543

Please sign in to comment.