Search in sources :

Example 21 with BPartnerId

use of de.metas.bpartner.BPartnerId in project metasfresh-webui-api by metasfresh.

the class PackageableRowsRepository method createPackageableRow.

private PackageableRow createPackageableRow(final Collection<Packageable> packageables) {
    Check.assumeNotEmpty(packageables, "packageables is not empty");
    final BPartnerId customerId = Packageable.extractSingleValue(packageables, Packageable::getCustomerId).get();
    final LookupValue customer = bpartnerLookup.get().findById(customerId);
    final WarehouseTypeId warehouseTypeId = Packageable.extractSingleValue(packageables, Packageable::getWarehouseTypeId).orElse(null);
    final ITranslatableString warehouseTypeName;
    if (warehouseTypeId != null) {
        warehouseTypeName = warehousesRepo.getWarehouseTypeById(warehouseTypeId).getName();
    } else {
        warehouseTypeName = null;
    }
    final ShipperId shipperId = Packageable.extractSingleValue(packageables, Packageable::getShipperId).orElse(null);
    final LookupValue shipper = shipperLookup.get().findById(shipperId);
    final OrderId salesOrderId = Packageable.extractSingleValue(packageables, Packageable::getSalesOrderId).get();
    final String salesOrderDocumentNo = Packageable.extractSingleValue(packageables, Packageable::getSalesOrderDocumentNo).get();
    final UserId lockedByUserId = Packageable.extractSingleValue(packageables, Packageable::getLockedBy).orElse(null);
    final LookupValue lockedByUser = userLookup.get().findById(lockedByUserId);
    return PackageableRow.builder().orderId(salesOrderId).orderDocumentNo(salesOrderDocumentNo).customer(customer).warehouseTypeId(warehouseTypeId).warehouseTypeName(warehouseTypeName).lockedByUser(lockedByUser).lines(packageables.size()).shipper(shipper).lineNetAmt(buildNetAmtTranslatableString(packageables)).packageables(packageables).build();
}
Also used : UserId(de.metas.user.UserId) ITranslatableString(de.metas.i18n.ITranslatableString) WarehouseTypeId(org.adempiere.warehouse.WarehouseTypeId) BPartnerId(de.metas.bpartner.BPartnerId) ITranslatableString(de.metas.i18n.ITranslatableString) OrderId(de.metas.order.OrderId) ShipperId(de.metas.shipping.ShipperId) LookupValue(de.metas.ui.web.window.datatypes.LookupValue)

Example 22 with BPartnerId

use of de.metas.bpartner.BPartnerId in project metasfresh-webui-api by metasfresh.

the class LetterRestController method createNewLetter.

@PostMapping
@ApiOperation("Creates a new letter")
public JSONLetter createNewLetter(@RequestBody final JSONLetterRequest request) {
    userSession.assertLoggedIn();
    final DocumentPath contextDocumentPath = JSONDocumentPath.toDocumentPathOrNull(request.getDocumentPath());
    // 
    // Extract context BPartner, Location and Contact
    final BoilerPlateContext context = documentCollection.createBoilerPlateContext(contextDocumentPath);
    final BPartnerId bpartnerId = BPartnerId.ofRepoIdOrNull(context.getC_BPartner_ID(-1));
    final BPartnerLocationId bpartnerLocationId = BPartnerLocationId.ofRepoIdOrNull(bpartnerId, context.getC_BPartner_Location_ID(-1));
    final UserId contactId = UserId.ofRepoIdOrNull(context.getAD_User_ID(-1));
    // 
    // Build BPartnerAddress
    final PlainDocumentLocation documentLocation = PlainDocumentLocation.builder().bpartnerId(bpartnerId).bpartnerLocationId(bpartnerLocationId).contactId(contactId).build();
    Services.get(IDocumentLocationBL.class).setBPartnerAddress(documentLocation);
    final String bpartnerAddress = documentLocation.getBPartnerAddress();
    final WebuiLetter letter = lettersRepo.createNewLetter(WebuiLetter.builder().contextDocumentPath(contextDocumentPath).ownerUserId(userSession.getLoggedUserId()).adOrgId(context.getAD_Org_ID(userSession.getOrgId().getRepoId())).bpartnerId(BPartnerId.toRepoId(bpartnerId)).bpartnerLocationId(BPartnerLocationId.toRepoId(bpartnerLocationId)).bpartnerContactId(UserId.toRepoId(contactId)).bpartnerAddress(bpartnerAddress));
    return JSONLetter.of(letter);
}
Also used : UserId(de.metas.user.UserId) BPartnerLocationId(de.metas.bpartner.BPartnerLocationId) DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath) JSONDocumentPath(de.metas.ui.web.window.datatypes.json.JSONDocumentPath) BoilerPlateContext(de.metas.letters.model.MADBoilerPlate.BoilerPlateContext) BPartnerId(de.metas.bpartner.BPartnerId) PlainDocumentLocation(de.metas.document.model.impl.PlainDocumentLocation) IDocumentLocationBL(de.metas.document.IDocumentLocationBL) PostMapping(org.springframework.web.bind.annotation.PostMapping) ApiOperation(io.swagger.annotations.ApiOperation)

Example 23 with BPartnerId

use of de.metas.bpartner.BPartnerId in project metasfresh-webui-api by metasfresh.

the class InvoiceLineQuickInputProcessor method process.

@Override
public Set<DocumentId> process(final QuickInput quickInput) {
    final IInvoiceBL invoiceBL = Services.get(IInvoiceBL.class);
    final IInvoiceLineBL invoiceLineBL = Services.get(IInvoiceLineBL.class);
    final I_C_Invoice invoice = quickInput.getRootDocumentAs(I_C_Invoice.class);
    final IInvoiceLineQuickInput invoiceLineQuickInput = quickInput.getQuickInputDocumentAs(IInvoiceLineQuickInput.class);
    // 3834
    final ProductId productId = ProductId.ofRepoId(invoiceLineQuickInput.getM_Product_ID());
    final BPartnerId partnerId = BPartnerId.ofRepoId(invoice.getC_BPartner_ID());
    Services.get(IBPartnerProductBL.class).assertNotExcludedFromSaleToCustomer(productId, partnerId);
    final I_C_InvoiceLine invoiceLine = InterfaceWrapperHelper.newInstance(I_C_InvoiceLine.class, invoice);
    invoiceLine.setC_Invoice(invoice);
    invoiceBL.setProductAndUOM(invoiceLine, invoiceLineQuickInput.getM_Product_ID());
    final PlainHUPackingAware huPackingAware = new PlainHUPackingAware();
    huPackingAware.setBpartnerId(partnerId);
    huPackingAware.setInDispute(false);
    huPackingAware.setProductId(productId);
    huPackingAware.setUomId(UomId.ofRepoIdOrNull(invoiceLine.getC_UOM_ID()));
    huPackingAware.setPiItemProductId(invoiceLineQuickInput.getM_HU_PI_Item_Product_ID() > 0 ? HUPIItemProductId.ofRepoId(invoiceLineQuickInput.getM_HU_PI_Item_Product_ID()) : HUPIItemProductId.VIRTUAL_HU);
    huPackingAwareBL.computeAndSetQtysForNewHuPackingAware(huPackingAware, invoiceLineQuickInput.getQty());
    huPackingAwareBL.prepareCopyFrom(huPackingAware).overridePartner(false).copyTo(InvoiceLineHUPackingAware.of(invoiceLine));
    invoiceLineBL.updatePrices(invoiceLine);
    // invoiceBL.setLineNetAmt(invoiceLine); // not needed; will be called on save
    // invoiceBL.setTaxAmt(invoiceLine);// not needed; will be called on save
    InterfaceWrapperHelper.save(invoiceLine);
    final DocumentId documentId = DocumentId.of(invoiceLine.getC_InvoiceLine_ID());
    return ImmutableSet.of(documentId);
}
Also used : I_C_Invoice(org.compiere.model.I_C_Invoice) PlainHUPackingAware(de.metas.adempiere.gui.search.impl.PlainHUPackingAware) I_C_InvoiceLine(de.metas.adempiere.model.I_C_InvoiceLine) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) HUPIItemProductId(de.metas.handlingunits.HUPIItemProductId) ProductId(de.metas.product.ProductId) IInvoiceBL(org.adempiere.invoice.service.IInvoiceBL) IInvoiceLineBL(de.metas.invoice.IInvoiceLineBL) BPartnerId(de.metas.bpartner.BPartnerId) IBPartnerProductBL(de.metas.bpartner_product.IBPartnerProductBL)

Example 24 with BPartnerId

use of de.metas.bpartner.BPartnerId in project metasfresh-webui-api by metasfresh.

the class OrderLineQuickInputCallout method updateBestBeforePolicy.

private void updateBestBeforePolicy(@NonNull final QuickInput quickInput) {
    if (!quickInput.hasField(IOrderLineQuickInput.COLUMNNAME_ShipmentAllocation_BestBefore_Policy)) {
        return;
    }
    final I_C_Order order = quickInput.getRootDocumentAs(I_C_Order.class);
    final BPartnerId bpartnerId = BPartnerId.ofRepoIdOrNull(order.getC_BPartner_ID());
    if (bpartnerId == null) {
        return;
    }
    final ShipmentAllocationBestBeforePolicy bestBeforePolicy = bpartnersService.getBestBeforePolicy(bpartnerId);
    final IOrderLineQuickInput quickInputModel = quickInput.getQuickInputDocumentAs(IOrderLineQuickInput.class);
    quickInputModel.setShipmentAllocation_BestBefore_Policy(bestBeforePolicy.getCode());
}
Also used : I_C_Order(de.metas.adempiere.model.I_C_Order) BPartnerId(de.metas.bpartner.BPartnerId) ShipmentAllocationBestBeforePolicy(de.metas.bpartner.ShipmentAllocationBestBeforePolicy)

Example 25 with BPartnerId

use of de.metas.bpartner.BPartnerId in project metasfresh-webui-api by metasfresh.

the class OrderProductProposalsService method getOrderById.

public Order getOrderById(@NonNull final OrderId orderId) {
    final I_C_Order orderRecord = ordersRepo.getById(orderId);
    final ZonedDateTime datePromised = TimeUtil.asZonedDateTime(orderRecord.getDatePromised());
    final PriceListId priceListId = PriceListId.ofRepoId(orderRecord.getM_PriceList_ID());
    final I_M_PriceList priceList = priceListsRepo.getById(priceListId);
    final PriceListVersionId priceListVersionId = priceListsRepo.retrievePriceListVersionId(priceListId, datePromised);
    final BPartnerId bpartnerId = BPartnerId.ofRepoId(orderRecord.getC_BPartner_ID());
    final String bpartnerName = bpartnersService.getBPartnerName(bpartnerId);
    return Order.builder().orderId(orderId).soTrx(SOTrx.ofBoolean(orderRecord.isSOTrx())).datePromised(datePromised).bpartnerId(bpartnerId).bpartnerName(bpartnerName).pricingSystemId(priceListsRepo.getPricingSystemId(priceListId)).priceListId(priceListId).priceListVersionId(priceListVersionId).countryId(CountryId.ofRepoIdOrNull(priceList.getC_Country_ID())).currencyId(CurrencyId.ofRepoId(priceList.getC_Currency_ID())).lines(ordersRepo.retrieveOrderLines(orderId, I_C_OrderLine.class).stream().map(this::toOrderLine).collect(ImmutableList.toImmutableList())).build();
}
Also used : I_M_PriceList(org.compiere.model.I_M_PriceList) I_C_Order(org.compiere.model.I_C_Order) ZonedDateTime(java.time.ZonedDateTime) PriceListId(de.metas.pricing.PriceListId) BPartnerId(de.metas.bpartner.BPartnerId) I_C_OrderLine(de.metas.handlingunits.model.I_C_OrderLine) PriceListVersionId(de.metas.pricing.PriceListVersionId)

Aggregations

BPartnerId (de.metas.bpartner.BPartnerId)25 ProductId (de.metas.product.ProductId)6 ITranslatableString (de.metas.i18n.ITranslatableString)5 AdempiereException (org.adempiere.exceptions.AdempiereException)5 HUPIItemProductId (de.metas.handlingunits.HUPIItemProductId)4 ZonedDateTime (java.time.ZonedDateTime)4 SOTrx (de.metas.lang.SOTrx)3 DocumentId (de.metas.ui.web.window.datatypes.DocumentId)3 LookupValuesList (de.metas.ui.web.window.datatypes.LookupValuesList)3 I_C_Order (de.metas.adempiere.model.I_C_Order)2 ShipmentAllocationBestBeforePolicy (de.metas.bpartner.ShipmentAllocationBestBeforePolicy)2 IBPartnerDAO (de.metas.bpartner.service.IBPartnerDAO)2 IHandlingUnitsBL (de.metas.handlingunits.IHandlingUnitsBL)2 I_M_HU_PI_Item (de.metas.handlingunits.model.I_M_HU_PI_Item)2 I_M_HU_PI_Item_Product (de.metas.handlingunits.model.I_M_HU_PI_Item_Product)2 OrderId (de.metas.order.OrderId)2 PriceListVersionId (de.metas.pricing.PriceListVersionId)2 IntegerLookupValue (de.metas.ui.web.window.datatypes.LookupValue.IntegerLookupValue)2 UserId (de.metas.user.UserId)2 Services (de.metas.util.Services)2