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();
}
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);
}
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);
}
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());
}
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();
}
Aggregations