Search in sources :

Example 26 with PurchaseOrder

use of com.axelor.apps.purchase.db.PurchaseOrder in project axelor-open-suite by axelor.

the class PurchaseOrderLinePurchaseRepository method populate.

@Override
public Map<String, Object> populate(Map<String, Object> json, Map<String, Object> context) {
    if (context.get("_model") != null && context.get("_model").toString().contains("PurchaseOrder") && context.get("id") != null) {
        Long id = (Long) json.get("id");
        if (id != null) {
            PurchaseOrderLine purchaseOrderLine = find(id);
            PurchaseOrder purchaseOrder = purchaseOrderLine.getPurchaseOrder();
            Product product = purchaseOrderLine.getProduct();
            json.put("$hasWarning", purchaseOrder != null && product != null && product.getDefaultSupplierPartner() != null && purchaseOrder.getSupplierPartner() != null && product.getDefaultSupplierPartner() != purchaseOrder.getSupplierPartner());
        }
    }
    return super.populate(json, context);
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) Product(com.axelor.apps.base.db.Product)

Example 27 with PurchaseOrder

use of com.axelor.apps.purchase.db.PurchaseOrder in project axelor-open-suite by axelor.

the class PurchaseOrderServiceImpl method createPurchaseOrder.

@Override
public PurchaseOrder createPurchaseOrder(User buyerUser, Company company, Partner contactPartner, Currency currency, LocalDate deliveryDate, String internalReference, String externalReference, LocalDate orderDate, PriceList priceList, Partner supplierPartner, TradingName tradingName) throws AxelorException {
    logger.debug("Création d'une commande fournisseur : Société = {},  Reference externe = {}, Fournisseur = {}", new Object[] { company.getName(), externalReference, supplierPartner.getFullName() });
    PurchaseOrder purchaseOrder = new PurchaseOrder();
    purchaseOrder.setBuyerUser(buyerUser);
    purchaseOrder.setCompany(company);
    purchaseOrder.setContactPartner(contactPartner);
    purchaseOrder.setCurrency(currency);
    purchaseOrder.setDeliveryDate(deliveryDate);
    purchaseOrder.setInternalReference(internalReference);
    purchaseOrder.setExternalReference(externalReference);
    purchaseOrder.setOrderDate(orderDate);
    purchaseOrder.setPriceList(priceList);
    purchaseOrder.setTradingName(tradingName);
    purchaseOrder.setPurchaseOrderLineList(new ArrayList<>());
    purchaseOrder.setPrintingSettings(Beans.get(TradingNameService.class).getDefaultPrintingSettings(null, company));
    purchaseOrder.setPurchaseOrderSeq(this.getSequence(company));
    purchaseOrder.setStatusSelect(PurchaseOrderRepository.STATUS_DRAFT);
    purchaseOrder.setSupplierPartner(supplierPartner);
    return purchaseOrder;
}
Also used : PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder)

Example 28 with PurchaseOrder

use of com.axelor.apps.purchase.db.PurchaseOrder in project axelor-open-suite by axelor.

the class PurchaseOrderManagementRepository method copy.

@Override
public PurchaseOrder copy(PurchaseOrder entity, boolean deep) {
    PurchaseOrder copy = super.copy(entity, deep);
    copy.setStatusSelect(PurchaseOrderRepository.STATUS_DRAFT);
    copy.setPurchaseOrderSeq(null);
    copy.setVersionNumber(1);
    copy.setDeliveryDate(null);
    copy.setValidatedByUser(null);
    copy.setValidationDate(null);
    if (copy.getPurchaseOrderLineList() != null) {
        for (PurchaseOrderLine purchaseOrderLine : copy.getPurchaseOrderLineList()) {
            purchaseOrderLine.setDesiredDelivDate(null);
            purchaseOrderLine.setEstimatedDelivDate(null);
        }
    }
    return copy;
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder)

Example 29 with PurchaseOrder

use of com.axelor.apps.purchase.db.PurchaseOrder in project axelor-open-suite by axelor.

the class PurchaseOrderLineController method generateSuppliersRequests.

public void generateSuppliersRequests(ActionRequest request, ActionResponse response) {
    PurchaseOrderLine purchaseOrderLine = Beans.get(PurchaseOrderLineRepository.class).find(request.getContext().asType(PurchaseOrderLine.class).getId());
    try {
        if (purchaseOrderLine.getPurchaseOrder() == null) {
            PurchaseOrder purchaseOrder = request.getContext().getParent().asType(PurchaseOrder.class);
            Beans.get(PurchaseOrderSupplierService.class).generateSuppliersRequests(purchaseOrderLine, purchaseOrder);
        } else {
            Beans.get(PurchaseOrderSupplierService.class).generateSuppliersRequests(purchaseOrderLine);
        }
        response.setReload(true);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) PurchaseOrderLineRepository(com.axelor.apps.purchase.db.repo.PurchaseOrderLineRepository) PurchaseOrderSupplierService(com.axelor.apps.suppliermanagement.service.PurchaseOrderSupplierService) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder)

Example 30 with PurchaseOrder

use of com.axelor.apps.purchase.db.PurchaseOrder in project axelor-open-suite by axelor.

the class MrpLineManagementRepository method populate.

/**
 * set alert if purchase delivery date is to far from proposal
 */
@Override
public Map<String, Object> populate(Map<String, Object> json, Map<String, Object> context) {
    Long mrpLineId = (Long) json.get("id");
    MrpLine mrpLine = find(mrpLineId);
    Map<String, Object> mrpLineMap = super.populate(json, context);
    if (PurchaseOrder.class.getName().equals(mrpLine.getProposalSelect())) {
        PurchaseOrder purchaseOrder = Beans.get(PurchaseOrderRepository.class).find(mrpLine.getProposalSelectId());
        mrpLine.setIsOutDayNbBetweenPurchaseAndProposal(mrpLine.getProduct() != null && mrpLine.getMaturityDate() != null && (purchaseOrder.getDeliveryDate() == null || mrpLine.getProduct().getMrpFamily() == null || Math.abs(mrpLine.getMaturityDate().toEpochDay() - purchaseOrder.getDeliveryDate().toEpochDay()) > mrpLine.getProduct().getMrpFamily().getDayNbBetweenPurchaseAndProposal()));
        json.put("isOutDayNbBetweenPurchaseAndProposal", mrpLine.getIsOutDayNbBetweenPurchaseAndProposal());
    }
    return mrpLineMap;
}
Also used : MrpLine(com.axelor.apps.supplychain.db.MrpLine) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) PurchaseOrderRepository(com.axelor.apps.purchase.db.repo.PurchaseOrderRepository)

Aggregations

PurchaseOrder (com.axelor.apps.purchase.db.PurchaseOrder)84 PurchaseOrderLine (com.axelor.apps.purchase.db.PurchaseOrderLine)26 AxelorException (com.axelor.exception.AxelorException)26 Transactional (com.google.inject.persist.Transactional)16 BigDecimal (java.math.BigDecimal)12 Company (com.axelor.apps.base.db.Company)11 Context (com.axelor.rpc.Context)10 Partner (com.axelor.apps.base.db.Partner)9 Product (com.axelor.apps.base.db.Product)9 ArrayList (java.util.ArrayList)9 Invoice (com.axelor.apps.account.db.Invoice)7 List (java.util.List)7 PurchaseOrderRepository (com.axelor.apps.purchase.db.repo.PurchaseOrderRepository)6 SaleOrder (com.axelor.apps.sale.db.SaleOrder)6 PurchaseOrderSupplychainService (com.axelor.apps.supplychain.service.PurchaseOrderSupplychainService)6 LocalDate (java.time.LocalDate)6 PurchaseOrderService (com.axelor.apps.purchase.service.PurchaseOrderService)5 StockMove (com.axelor.apps.stock.db.StockMove)5 Unit (com.axelor.apps.base.db.Unit)4 PurchaseOrderLineService (com.axelor.apps.purchase.service.PurchaseOrderLineService)4