use of de.metas.pricing.conditions.PricingConditionsBreak in project metasfresh-webui-api by metasfresh.
the class PricingConditionsView_CopyRowToEditable method createChangeRequest.
private PricingConditionsRowChangeRequest createChangeRequest(@NonNull final PricingConditionsRow templateRow) {
final PricingConditionsBreak templatePricingConditionsBreak = templateRow.getPricingConditionsBreak();
PriceSpecification price = templatePricingConditionsBreak.getPriceSpecification();
if (price.isNoPrice()) {
// In case row does not have a price then use BPartner's pricing system
final BPartnerId bpartnerId = templateRow.getBpartnerId();
final SOTrx soTrx = SOTrx.ofBoolean(templateRow.isCustomer());
price = createBasePricingSystemPrice(bpartnerId, soTrx);
}
final Percent discount = templatePricingConditionsBreak.getDiscount();
final PaymentTermId paymentTermIdOrNull = templatePricingConditionsBreak.getPaymentTermIdOrNull();
final Percent paymentDiscountOverrideOrNull = templatePricingConditionsBreak.getPaymentDiscountOverrideOrNull();
return PricingConditionsRowChangeRequest.builder().priceChange(CompletePriceChange.of(price)).discount(discount).paymentTermId(Optional.ofNullable(paymentTermIdOrNull)).paymentDiscount(Optional.ofNullable(paymentDiscountOverrideOrNull)).sourcePricingConditionsBreakId(templatePricingConditionsBreak.getId()).build();
}
use of de.metas.pricing.conditions.PricingConditionsBreak in project metasfresh-webui-api by metasfresh.
the class PricingConditionsView_SaveEditableRow method createPricingConditionsBreakChangeRequest.
private static PricingConditionsBreakChangeRequest createPricingConditionsBreakChangeRequest(final PricingConditionsRow row) {
if (!row.isEditable()) {
throw new AdempiereException("Saving not editable rows is not allowed").setParameter("row", row);
}
final PricingConditionsId pricingConditionsId = row.getPricingConditionsId();
final PricingConditionsBreak pricingConditionsBreak = row.getPricingConditionsBreak();
final PricingConditionsBreakId updateFromPricingConditionsBreakId = row.getCopiedFromPricingConditionsBreakId();
return preparePricingConditionsBreakChangeRequest(pricingConditionsBreak).pricingConditionsId(pricingConditionsId).updateFromPricingConditionsBreakId(updateFromPricingConditionsBreakId).build();
}
use of de.metas.pricing.conditions.PricingConditionsBreak in project metasfresh-webui-api by metasfresh.
the class PricingConditionsRowReducers method copyAndChange.
public PricingConditionsRow copyAndChange(@NonNull final PricingConditionsRowChangeRequest request, @NonNull final PricingConditionsRow row) {
row.assertEditable();
boolean changed = false;
final PricingConditionsBreak pricingConditionsBreakOld = row.getPricingConditionsBreak();
final PricingConditionsBreak pricingConditionsBreak = applyRequestTo(request, pricingConditionsBreakOld).toTemporaryPricingConditionsBreakIfPriceRelevantFieldsChanged(pricingConditionsBreakOld);
if (!Objects.equals(pricingConditionsBreak, pricingConditionsBreakOld)) {
changed = true;
}
//
// Copied from ID
PricingConditionsBreakId copiedFromPricingConditionsBreakId = row.getCopiedFromPricingConditionsBreakId();
if (!Objects.equals(request.getSourcePricingConditionsBreakId(), copiedFromPricingConditionsBreakId)) {
copiedFromPricingConditionsBreakId = request.getSourcePricingConditionsBreakId();
changed = true;
}
//
if (!changed) {
return row;
}
return row.toBuilder().pricingConditionsBreak(pricingConditionsBreak).copiedFromPricingConditionsBreakId(copiedFromPricingConditionsBreakId).build();
}
use of de.metas.pricing.conditions.PricingConditionsBreak in project metasfresh-webui-api by metasfresh.
the class PricingConditionsRowsLoader method createEditablePricingConditionsRowOrNull.
/**
* On-the-fly create a PricingConditionsRow using this instance's {@link #sourceDocumentLine}.
*/
private PricingConditionsRow createEditablePricingConditionsRowOrNull() {
if (sourceDocumentLine == null) {
return null;
}
final int discountSchemaId = bpartnerBL.getDiscountSchemaId(sourceDocumentLine.getBpartnerId(), sourceDocumentLine.getSoTrx());
final PricingConditionsId pricingConditionsId = PricingConditionsId.ofRepoIdOrNull(discountSchemaId);
final Money priceEntered = sourceDocumentLine.getPriceEntered();
final PricingConditionsBreak pricingConditionsBreak = PricingConditionsBreak.builder().id(// N/A
null).matchCriteria(PricingConditionsBreakMatchCriteria.builder().breakValue(BigDecimal.ZERO).productId(sourceDocumentLine.getProductId()).productCategoryId(sourceDocumentLine.getProductCategoryId()).build()).priceSpecification(PriceSpecification.fixedPrice(priceEntered)).paymentTermIdOrNull(sourceDocumentLine.getPaymentTermId()).discount(sourceDocumentLine.getDiscount()).dateCreated(// N/A; the PricingConditionsBreak hasn't been created (i.e. persisted on DB) yet
null).createdById(null).build();
return PricingConditionsRow.builder().lookups(lookups).editable(true).bpartner(lookups.lookupBPartner(sourceDocumentLine.getBpartnerId())).customer(sourceDocumentLine.getSoTrx().isSales()).pricingConditionsId(pricingConditionsId).pricingConditionsBreak(pricingConditionsBreak).basePricingSystemPriceCalculator(basePricingSystemPriceCalculator).dateLastInOut(getLastInOutDate(sourceDocumentLine.getBpartnerId(), sourceDocumentLine.getSoTrx(), pricingConditionsBreak)).build();
}
use of de.metas.pricing.conditions.PricingConditionsBreak in project metasfresh-webui-api by metasfresh.
the class PricingConditionsView_SaveEditableRow method doIt.
@Override
protected String doIt() {
final PricingConditionsBreak pricingConditionsBreak = pricingConditionsRepo.changePricingConditionsBreak(createPricingConditionsBreakChangeRequest(getEditableRow()));
patchEditableRow(PricingConditionsRowActions.saved(pricingConditionsBreak));
return MSG_OK;
}
Aggregations