Skip to content

Commit

Permalink
Updates work
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBestPessimist committed Apr 21, 2020
1 parent 4a0a94d commit 4600ad4
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 91 deletions.

This file was deleted.

Expand Up @@ -39,12 +39,6 @@
@Component
public class M_PriceList
{
// @Init
// public void registerCallouts()
// {
// Services.get(ITabCalloutFactory.class).registerTabCalloutForTable(I_M_PriceList_Version.Table_Name, M_PricelistVersion_TabCallout.class);
// }

@ModelChange(timings = { ModelValidator.TYPE_AFTER_NEW, ModelValidator.TYPE_AFTER_CHANGE })
public void assertBasePricingIsValid(final I_M_PriceList priceList)
{
Expand Down Expand Up @@ -84,7 +78,6 @@ public void assertBasePricingIsValid(final I_M_PriceList priceList)
public void updatePLVName(@NonNull final I_M_PriceList priceList)
{
final IPriceListDAO priceListDAO = Services.get(IPriceListDAO.class);
final PriceListId priceListId = PriceListId.ofRepoId(priceList.getM_PriceList_ID());
priceListDAO.updateAllPLVName(priceListId);
priceListDAO.updateAllPLVName(priceList.getName(), PriceListId.ofRepoId(priceList.getM_PriceList_ID()));
}
}
Expand Up @@ -28,6 +28,8 @@
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.annotations.Init;
import org.adempiere.ad.modelvalidator.annotations.Interceptor;
import org.adempiere.ad.modelvalidator.annotations.ModelChange;
import org.compiere.model.I_M_PriceList_Version;
Expand All @@ -42,25 +44,26 @@
@Component
public class M_PriceList_Version
{
@ModelChange(timings = { ModelValidator.TYPE_BEFORE_CHANGE, ModelValidator.TYPE_BEFORE_NEW }, ifColumnsChanged = { I_M_PriceList_Version.COLUMNNAME_ValidFrom })
public void updatePLVName_InterceptorOnly(@NonNull final I_M_PriceList_Version priceListVersion)
@Init
public void registerCallouts()
{
updatePLVName(priceListVersion);
Services.get(IProgramaticCalloutProvider.class).registerAnnotatedCallout(this);
}

@CalloutMethod(columnNames = I_M_PriceList_Version.COLUMNNAME_ValidFrom)
public void updatePLVName_CalloutOnly(@NonNull final I_M_PriceList_Version priceListVersion)
{ // callout doesn't work
updatePLVName(priceListVersion);
}

private void updatePLVName(final @NonNull I_M_PriceList_Version priceListVersion)
@ModelChange(timings = { ModelValidator.TYPE_BEFORE_CHANGE, ModelValidator.TYPE_BEFORE_NEW }, ifColumnsChanged = { I_M_PriceList_Version.COLUMNNAME_ValidFrom })
public void updatePLVName(@NonNull final I_M_PriceList_Version priceListVersion)
{
final IPriceListDAO priceListDAO = Services.get(IPriceListDAO.class);
final PriceListId priceListId = PriceListId.ofRepoId(priceListVersion.getM_PriceList_ID());
final LocalDate date = TimeUtil.asLocalDate(priceListVersion.getValidFrom());

final String plvName = priceListDAO.createPLVName(priceListId, date);
if (date == null)
{
return;
}

final String plvName = priceListDAO.createPLVName(priceList.getName(), date);
priceListVersion.setName(plvName);
}
}
Expand Up @@ -190,16 +190,18 @@ default Stream<I_M_ProductPrice> retrieveProductPrices(@NonNull final PriceListV
PricingSystemId getPricingSystemId(PriceListId priceListId);

/**
* Please keep in sync with {@link #updateAllPLVName(PriceListId)}
* Please keep in sync with {@link #updateAllPLVName(String, PriceListId)} )}
*/
String createPLVName(@NonNull PriceListId pricelistId, @NonNull LocalDate date);
String createPLVName(final @NonNull String priceListName, @NonNull LocalDate date);

/**
* Update the Name of all Price List Versions.
* <p>
* Please keep in sync with {@link #createPLVName(PriceListId, LocalDate)}
* The name has the format "Price List.Name + PLV.ValidFrom".
* <p>
* Please keep in sync with {@link #createPLVName(String, LocalDate)}
*
* @return number of updated records
*/
int updateAllPLVName(final PriceListId priceListId);
int updateAllPLVName(final String namePrefix, final PriceListId priceListId);
}
Expand Up @@ -751,13 +751,10 @@ public String createPLVName(@NonNull final PriceListId pricelistId, final @NonNu
}

@Override
public int updateAllPLVName(@NonNull final PriceListId priceListId)
public int updateAllPLVName(final String namePrefix, final PriceListId priceListId)
{
final I_M_PriceList priceList = getById(priceListId);

final String dateFormat = "YYYY-MM-DD"; // equivalent of DateTimeFormatter.ISO_LOCAL_DATE

final String priceListName = priceList.getName();
final UserId updatedBy = Env.getLoggedUserId();
final Timestamp now = SystemTime.asTimestamp();

Expand All @@ -768,7 +765,7 @@ public int updateAllPLVName(@NonNull final PriceListId priceListId)
+ " " + I_M_PriceList_Version.COLUMNNAME_Updated + " = ? "
+ " WHERE plv." + I_M_PriceList_Version.COLUMNNAME_M_PriceList_ID + " = ? ";

return DB.executeUpdateEx(sqlStr, new Object[] { priceListName, updatedBy, now, priceListId.getRepoId() }, ITrx.TRXNAME_ThreadInherited);
return DB.executeUpdateEx(sqlStr, new Object[] { namePrefix, updatedBy, now, priceListId }, ITrx.TRXNAME_ThreadInherited);
}

@VisibleForTesting
Expand Down

0 comments on commit 4600ad4

Please sign in to comment.