use of de.metas.lang.SOTrx 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.lang.SOTrx in project metasfresh-webui-api by metasfresh.
the class BPartnerProductsProposalViewFactory method createRowsLoaderFromRecord.
@Override
protected ProductsProposalRowsLoader createRowsLoaderFromRecord(TableRecordReference recordRef) {
final IBPartnerDAO bpartnersRepo = Services.get(IBPartnerDAO.class);
final IPriceListDAO priceListsRepo = Services.get(IPriceListDAO.class);
recordRef.assertTableName(I_C_BPartner.Table_Name);
final BPartnerId bpartnerId = BPartnerId.ofRepoId(recordRef.getRecord_ID());
final Set<CountryId> countryIds = bpartnersRepo.retrieveBPartnerLocationCountryIds(bpartnerId);
if (countryIds.isEmpty()) {
throw new AdempiereException("@NotFound@ @C_BPartner_Location_ID@");
}
final I_C_BPartner bpartnerRecord = bpartnersRepo.getById(bpartnerId);
PricingSystemId pricingSystemId = null;
SOTrx soTrx = null;
if (bpartnerRecord.isCustomer()) {
pricingSystemId = PricingSystemId.ofRepoIdOrNull(bpartnerRecord.getM_PricingSystem_ID());
soTrx = SOTrx.SALES;
}
if (pricingSystemId == null && bpartnerRecord.isVendor()) {
pricingSystemId = PricingSystemId.ofRepoIdOrNull(bpartnerRecord.getPO_PricingSystem_ID());
soTrx = SOTrx.PURCHASE;
}
if (pricingSystemId == null) {
throw new AdempiereException("@NotFound@ @M_PricingSystem_ID@");
}
final ZonedDateTime today = SystemTime.asZonedDateTime();
final Set<PriceListVersionId> priceListVersionIds = priceListsRepo.retrievePriceListsCollectionByPricingSystemId(pricingSystemId).filterAndStreamIds(countryIds).map(priceListId -> priceListsRepo.retrievePriceListVersionId(priceListId, today)).collect(ImmutableSet.toImmutableSet());
return ProductsProposalRowsLoader.builder().bpartnerProductStatsService(bpartnerProductStatsService).priceListVersionIds(priceListVersionIds).bpartnerId(bpartnerId).soTrx(soTrx).build();
}
use of de.metas.lang.SOTrx in project metasfresh-webui-api by metasfresh.
the class DefaultPackingItemCriteria method of.
public static Optional<DefaultPackingItemCriteria> of(final I_C_Order order, final ProductId productId) {
final BPartnerLocationId bpartnerLocationId = BPartnerLocationId.ofRepoIdOrNull(order.getC_BPartner_ID(), order.getC_BPartner_Location_ID());
final PricingSystemId pricingSystemId = PricingSystemId.ofRepoIdOrNull(order.getM_PricingSystem_ID());
final ZonedDateTime date = TimeUtil.asZonedDateTime(order.getDatePromised());
final SOTrx soTrx = SOTrx.ofBoolean(order.isSOTrx());
final boolean anyNull = Stream.of(bpartnerLocationId, pricingSystemId, date, productId).anyMatch(Objects::isNull);
if (anyNull) {
return Optional.empty();
}
return Optional.of(builder().bPartnerLocationId(bpartnerLocationId).productId(productId).pricingSystemId(pricingSystemId).date(date).soTrx(soTrx).build());
}
use of de.metas.lang.SOTrx in project metasfresh-webui-api by metasfresh.
the class OrderLineQuickInputProcessor method validateInput.
private void validateInput(final OrderLineCandidate candidate) {
final BPartnerId bpartnerId = candidate.getBpartnerId();
final ProductId productId = candidate.getProductId();
final SOTrx soTrx = candidate.getSoTrx();
final ArrayList<ITranslatableString> validationErrorMessages = new ArrayList<>();
for (final IOrderLineInputValidator validator : validators) {
final OrderLineInputValidatorResults validationResults = validator.validate(bpartnerId, productId, soTrx);
if (validationResults != null && !validationResults.isValid() && validationResults.getErrorMessage() != null) {
validationErrorMessages.add(validationResults.getErrorMessage());
}
}
if (!validationErrorMessages.isEmpty()) {
throw new AdempiereException(TranslatableStrings.joinList("\n", validationErrorMessages));
}
}
use of de.metas.lang.SOTrx in project metasfresh-webui-api by metasfresh.
the class CableSalesOrderLineQuickInputDescriptorFactory method createQuickInputDescriptor.
@Override
public QuickInputDescriptor createQuickInputDescriptor(final DocumentType documentType, final DocumentId documentTypeId, final DetailId detailId, final Optional<SOTrx> soTrx) {
final DocumentEntityDescriptor entityDescriptor = createDescriptorBuilder(documentTypeId, detailId, soTrx).addField(createProductFieldBuilder(ICablesOrderLineQuickInput.COLUMNNAME_Plug1_Product_ID).setMandatoryLogic(true)).addField(createProductFieldBuilder(ICablesOrderLineQuickInput.COLUMNNAME_Cable_Product_ID).setMandatoryLogic(false)).addField(createProductFieldBuilder(ICablesOrderLineQuickInput.COLUMNNAME_Plug2_Product_ID).setMandatoryLogic(false)).addField(createQuantityFieldBuilder(ICablesOrderLineQuickInput.COLUMNNAME_CableLength).setMandatoryLogic(false)).addField(createQuantityFieldBuilder(ICablesOrderLineQuickInput.COLUMNNAME_Qty).setMandatoryLogic(true)).build();
final QuickInputLayoutDescriptor.Builder quickInputBuilder = QuickInputLayoutDescriptor.builder();
DocumentLayoutElementDescriptor.builderOrEmpty(entityDescriptor, ICablesOrderLineQuickInput.COLUMNNAME_Plug1_Product_ID, ICablesOrderLineQuickInput.COLUMNNAME_Cable_Product_ID, ICablesOrderLineQuickInput.COLUMNNAME_Plug2_Product_ID).map(b -> b.setWidgetSize(WidgetSize.Large)).ifPresent(quickInputBuilder::element);
DocumentLayoutElementDescriptor.builderOrEmpty(entityDescriptor, ICablesOrderLineQuickInput.COLUMNNAME_CableLength).map(b -> b.setWidgetSize(WidgetSize.Small)).ifPresent(quickInputBuilder::element);
DocumentLayoutElementDescriptor.builderOrEmpty(entityDescriptor, ICablesOrderLineQuickInput.COLUMNNAME_Qty).map(b -> b.setWidgetSize(WidgetSize.Small)).ifPresent(quickInputBuilder::element);
final QuickInputLayoutDescriptor layout = quickInputBuilder.build();
return QuickInputDescriptor.of(entityDescriptor, layout, CableSalesOrderLineQuickInputProcessor.class);
}
Aggregations