Search in sources :

Example 1 with SOTrx

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();
}
Also used : PricingConditionsBreak(de.metas.pricing.conditions.PricingConditionsBreak) PaymentTermId(de.metas.payment.paymentterm.PaymentTermId) Percent(de.metas.util.lang.Percent) SOTrx(de.metas.lang.SOTrx) PriceSpecification(de.metas.pricing.conditions.PriceSpecification) BPartnerId(de.metas.bpartner.BPartnerId)

Example 2 with SOTrx

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();
}
Also used : CountryId(de.metas.location.CountryId) IBPartnerDAO(de.metas.bpartner.service.IBPartnerDAO) ViewFactory(de.metas.ui.web.view.ViewFactory) ZonedDateTime(java.time.ZonedDateTime) PriceListVersionId(de.metas.pricing.PriceListVersionId) ImmutableList(com.google.common.collect.ImmutableList) BPartnerProductStatsService(de.metas.bpartner.product.stats.BPartnerProductStatsService) ViewLayout(de.metas.ui.web.view.descriptor.ViewLayout) ViewCloseAction(de.metas.ui.web.view.ViewCloseAction) TableRecordReference(org.adempiere.util.lang.impl.TableRecordReference) I_C_BPartner(org.compiere.model.I_C_BPartner) CountryId(de.metas.location.CountryId) ImmutableSet(com.google.common.collect.ImmutableSet) WEBUI_BPartner_ProductsProposal_Launcher(de.metas.ui.web.order.products_proposal.process.WEBUI_BPartner_ProductsProposal_Launcher) ITranslatableString(de.metas.i18n.ITranslatableString) NonNull(lombok.NonNull) RelatedProcessDescriptor(de.metas.process.RelatedProcessDescriptor) Set(java.util.Set) WindowId(de.metas.ui.web.window.datatypes.WindowId) ProductsProposalRowsLoader(de.metas.ui.web.order.products_proposal.model.ProductsProposalRowsLoader) Services(de.metas.util.Services) SOTrx(de.metas.lang.SOTrx) List(java.util.List) AdempiereException(org.adempiere.exceptions.AdempiereException) WEBUI_ProductsProposal_ShowProductsToAddFromBasePriceList(de.metas.ui.web.order.products_proposal.process.WEBUI_ProductsProposal_ShowProductsToAddFromBasePriceList) BPartnerId(de.metas.bpartner.BPartnerId) ProductsProposalRow(de.metas.ui.web.order.products_proposal.model.ProductsProposalRow) PricingSystemId(de.metas.pricing.PricingSystemId) IPriceListDAO(de.metas.pricing.service.IPriceListDAO) WEBUI_ProductsProposal_SaveProductPriceToCurrentPriceListVersion(de.metas.ui.web.order.products_proposal.process.WEBUI_ProductsProposal_SaveProductPriceToCurrentPriceListVersion) SystemTime(de.metas.util.time.SystemTime) IPriceListDAO(de.metas.pricing.service.IPriceListDAO) SOTrx(de.metas.lang.SOTrx) PriceListVersionId(de.metas.pricing.PriceListVersionId) IBPartnerDAO(de.metas.bpartner.service.IBPartnerDAO) ZonedDateTime(java.time.ZonedDateTime) AdempiereException(org.adempiere.exceptions.AdempiereException) BPartnerId(de.metas.bpartner.BPartnerId) PricingSystemId(de.metas.pricing.PricingSystemId) I_C_BPartner(org.compiere.model.I_C_BPartner)

Example 3 with SOTrx

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());
}
Also used : ZonedDateTime(java.time.ZonedDateTime) BPartnerLocationId(de.metas.bpartner.BPartnerLocationId) SOTrx(de.metas.lang.SOTrx) Objects(java.util.Objects) PricingSystemId(de.metas.pricing.PricingSystemId)

Example 4 with SOTrx

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));
    }
}
Also used : AdempiereException(org.adempiere.exceptions.AdempiereException) SOTrx(de.metas.lang.SOTrx) ITranslatableString(de.metas.i18n.ITranslatableString) ArrayList(java.util.ArrayList) ProductId(de.metas.product.ProductId) HUPIItemProductId(de.metas.handlingunits.HUPIItemProductId) BPartnerId(de.metas.bpartner.BPartnerId) OrderLineInputValidatorResults(de.metas.order.OrderLineInputValidatorResults) IOrderLineInputValidator(de.metas.order.IOrderLineInputValidator)

Example 5 with SOTrx

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);
}
Also used : QuickInputLayoutDescriptor(de.metas.ui.web.quickinput.QuickInputLayoutDescriptor) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) ProductLookupDescriptor(de.metas.ui.web.window.descriptor.sql.ProductLookupDescriptor) DocumentLayoutElementDescriptor(de.metas.ui.web.window.descriptor.DocumentLayoutElementDescriptor) IADWindowDAO(org.adempiere.ad.window.api.IADWindowDAO) Characteristic(de.metas.ui.web.window.descriptor.DocumentFieldDescriptor.Characteristic) ICalloutField(org.adempiere.ad.callout.api.ICalloutField) IQuickInputDescriptorFactory(de.metas.ui.web.quickinput.IQuickInputDescriptorFactory) DetailId(de.metas.ui.web.window.descriptor.DetailId) DocumentEntityDescriptor(de.metas.ui.web.window.descriptor.DocumentEntityDescriptor) I_C_OrderLine(org.compiere.model.I_C_OrderLine) CablesConstants(de.metas.vertical.cables.CablesConstants) AdWindowId(org.adempiere.ad.element.api.AdWindowId) ImmutableSet(com.google.common.collect.ImmutableSet) I_C_Order(de.metas.adempiere.model.I_C_Order) ITranslatableString(de.metas.i18n.ITranslatableString) NonNull(lombok.NonNull) Set(java.util.Set) WidgetSize(de.metas.ui.web.window.descriptor.WidgetSize) ConstantLogicExpression(org.adempiere.ad.expression.api.ConstantLogicExpression) Profile(org.springframework.context.annotation.Profile) Services(de.metas.util.Services) SOTrx(de.metas.lang.SOTrx) DocumentFieldDescriptor(de.metas.ui.web.window.descriptor.DocumentFieldDescriptor) Component(org.springframework.stereotype.Component) DocumentFieldWidgetType(de.metas.ui.web.window.descriptor.DocumentFieldWidgetType) IMsgBL(de.metas.i18n.IMsgBL) Optional(java.util.Optional) QuickInputDescriptor(de.metas.ui.web.quickinput.QuickInputDescriptor) DocumentType(de.metas.ui.web.window.datatypes.DocumentType) QuickInputLayoutDescriptor(de.metas.ui.web.quickinput.QuickInputLayoutDescriptor) DocumentEntityDescriptor(de.metas.ui.web.window.descriptor.DocumentEntityDescriptor)

Aggregations

SOTrx (de.metas.lang.SOTrx)7 BPartnerId (de.metas.bpartner.BPartnerId)3 ITranslatableString (de.metas.i18n.ITranslatableString)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 PricingSystemId (de.metas.pricing.PricingSystemId)2 ProductId (de.metas.product.ProductId)2 Services (de.metas.util.Services)2 ZonedDateTime (java.time.ZonedDateTime)2 Set (java.util.Set)2 NonNull (lombok.NonNull)2 AdempiereException (org.adempiere.exceptions.AdempiereException)2 I_C_OrderLine (org.compiere.model.I_C_OrderLine)2 ImmutableList (com.google.common.collect.ImmutableList)1 I_C_Order (de.metas.adempiere.model.I_C_Order)1 BPartnerLocationId (de.metas.bpartner.BPartnerLocationId)1 BPartnerProductStatsService (de.metas.bpartner.product.stats.BPartnerProductStatsService)1 IBPartnerDAO (de.metas.bpartner.service.IBPartnerDAO)1 HUPIItemProductId (de.metas.handlingunits.HUPIItemProductId)1 IMsgBL (de.metas.i18n.IMsgBL)1 CountryId (de.metas.location.CountryId)1