Search in sources :

Example 81 with Company

use of com.axelor.apps.base.db.Company in project axelor-open-suite by axelor.

the class PurchaseOrderServiceImpl method requestPurchaseOrder.

@Override
@Transactional(rollbackOn = { Exception.class })
public void requestPurchaseOrder(PurchaseOrder purchaseOrder) throws AxelorException {
    purchaseOrder.setStatusSelect(PurchaseOrderRepository.STATUS_REQUESTED);
    Partner partner = purchaseOrder.getSupplierPartner();
    Company company = purchaseOrder.getCompany();
    Blocking blocking = Beans.get(BlockingService.class).getBlocking(partner, company, BlockingRepository.PURCHASE_BLOCKING);
    if (blocking != null) {
        String reason = blocking.getBlockingReason() != null ? blocking.getBlockingReason().getName() : "";
        throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.SUPPLIER_BLOCKED) + " " + reason, partner);
    }
    if (purchaseOrder.getVersionNumber() == 1 && sequenceService.isEmptyOrDraftSequenceNumber(purchaseOrder.getPurchaseOrderSeq())) {
        purchaseOrder.setPurchaseOrderSeq(this.getSequence(purchaseOrder.getCompany()));
    }
    purchaseOrderRepo.save(purchaseOrder);
    if (appPurchaseService.getAppPurchase().getManagePurchaseOrderVersion()) {
        this.savePurchaseOrderPDFAsAttachment(purchaseOrder);
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) Company(com.axelor.apps.base.db.Company) Blocking(com.axelor.apps.base.db.Blocking) BlockingService(com.axelor.apps.base.service.BlockingService) Partner(com.axelor.apps.base.db.Partner) Transactional(com.google.inject.persist.Transactional)

Example 82 with Company

use of com.axelor.apps.base.db.Company in project axelor-open-suite by axelor.

the class PurchaseOrderSupplierLineService method accept.

@Transactional(rollbackOn = { Exception.class })
public void accept(PurchaseOrderSupplierLine purchaseOrderSupplierLine) throws AxelorException {
    PurchaseOrderLine purchaseOrderLine = purchaseOrderSupplierLine.getPurchaseOrderLine();
    purchaseOrderLine.setEstimatedDelivDate(purchaseOrderSupplierLine.getEstimatedDelivDate());
    Partner supplierPartner = purchaseOrderSupplierLine.getSupplierPartner();
    Company company = purchaseOrderLine.getPurchaseOrder().getCompany();
    if (Beans.get(BlockingService.class).getBlocking(supplierPartner, company, BlockingRepository.PURCHASE_BLOCKING) != null) {
        throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.SUPPLIER_BLOCKED), supplierPartner);
    }
    purchaseOrderLine.setSupplierPartner(supplierPartner);
    purchaseOrderLine.setPrice(purchaseOrderSupplierLine.getPrice());
    purchaseOrderLine.setExTaxTotal(PurchaseOrderLineServiceImpl.computeAmount(purchaseOrderLine.getQty(), purchaseOrderLine.getPrice()));
    purchaseOrderSupplierLine.setStateSelect(PurchaseOrderSupplierLineRepository.STATE_ACCEPTED);
    poSupplierLineRepo.save(purchaseOrderSupplierLine);
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) AxelorException(com.axelor.exception.AxelorException) Company(com.axelor.apps.base.db.Company) Partner(com.axelor.apps.base.db.Partner) Transactional(com.google.inject.persist.Transactional)

Example 83 with Company

use of com.axelor.apps.base.db.Company in project axelor-open-suite by axelor.

the class ProjectTaskBusinessProjectServiceImpl method computeDefaultInformation.

@Override
public ProjectTask computeDefaultInformation(ProjectTask projectTask) throws AxelorException {
    Product product = projectTask.getProduct();
    if (product != null) {
        projectTask.setInvoicingType(ProjectTaskRepository.INVOICING_TYPE_PACKAGE);
        if (projectTask.getUnitPrice() == null || projectTask.getUnitPrice().compareTo(BigDecimal.ZERO) == 0) {
            projectTask.setUnitPrice(this.computeUnitPrice(projectTask));
        }
    } else {
        ProjectTaskCategory projectTaskCategory = projectTask.getProjectTaskCategory();
        if (projectTaskCategory == null) {
            return projectTask;
        }
        projectTask.setInvoicingType(projectTaskCategory.getDefaultInvoicingType());
        projectTask.setProduct(projectTaskCategory.getDefaultProduct());
        product = projectTask.getProduct();
        if (product == null) {
            return projectTask;
        }
        projectTask.setUnitPrice(this.computeUnitPrice(projectTask));
    }
    Company company = projectTask.getProject() != null ? projectTask.getProject().getCompany() : null;
    Unit salesUnit = (Unit) productCompanyService.get(product, "salesUnit", company);
    projectTask.setUnit(salesUnit != null ? salesUnit : (Unit) productCompanyService.get(product, "unit", company));
    projectTask.setCurrency((Currency) productCompanyService.get(product, "saleCurrency", company));
    projectTask.setQuantity(projectTask.getBudgetedTime());
    projectTask.setQuantity(projectTask.getBudgetedTime() == null || projectTask.getBudgetedTime().compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ONE : projectTask.getBudgetedTime());
    projectTask = this.updateDiscount(projectTask);
    projectTask = this.compute(projectTask);
    return projectTask;
}
Also used : ProjectTaskCategory(com.axelor.apps.project.db.ProjectTaskCategory) Company(com.axelor.apps.base.db.Company) Product(com.axelor.apps.base.db.Product) Unit(com.axelor.apps.base.db.Unit)

Example 84 with Company

use of com.axelor.apps.base.db.Company in project axelor-open-suite by axelor.

the class ProjectTaskBusinessProjectServiceImpl method computeUnitPrice.

private BigDecimal computeUnitPrice(ProjectTask projectTask) throws AxelorException {
    Product product = projectTask.getProduct();
    Company company = projectTask.getProject() != null ? projectTask.getProject().getCompany() : null;
    BigDecimal unitPrice = (BigDecimal) productCompanyService.get(product, "salePrice", company);
    PriceList priceList = partnerPriceListService.getDefaultPriceList(projectTask.getProject().getClientPartner(), PriceListRepository.TYPE_SALE);
    if (priceList == null) {
        return unitPrice;
    }
    PriceListLine priceListLine = this.getPriceListLine(projectTask, priceList, unitPrice);
    Map<String, Object> discounts = priceListService.getReplacedPriceAndDiscounts(priceList, priceListLine, unitPrice);
    if (discounts == null) {
        return unitPrice;
    } else {
        unitPrice = priceListService.computeDiscount(unitPrice, (Integer) discounts.get("discountTypeSelect"), (BigDecimal) discounts.get("discountAmount"));
    }
    return unitPrice;
}
Also used : Company(com.axelor.apps.base.db.Company) PriceListLine(com.axelor.apps.base.db.PriceListLine) Product(com.axelor.apps.base.db.Product) PriceList(com.axelor.apps.base.db.PriceList) BigDecimal(java.math.BigDecimal)

Example 85 with Company

use of com.axelor.apps.base.db.Company in project axelor-open-suite by axelor.

the class ProjectBusinessServiceImpl method generateQuotation.

@Override
@Transactional(rollbackOn = { Exception.class })
public SaleOrder generateQuotation(Project project) throws AxelorException {
    SaleOrder order = Beans.get(SaleOrderCreateService.class).createSaleOrder(project.getCompany());
    Partner clientPartner = project.getClientPartner();
    Partner contactPartner = project.getContactPartner();
    if (contactPartner == null && clientPartner.getContactPartnerSet().size() == 1) {
        contactPartner = clientPartner.getContactPartnerSet().iterator().next();
    }
    Company company = project.getCompany();
    order.setProject(projectRepo.find(project.getId()));
    order.setClientPartner(clientPartner);
    order.setContactPartner(contactPartner);
    order.setCompany(company);
    order.setMainInvoicingAddress(partnerService.getInvoicingAddress(clientPartner));
    order.setMainInvoicingAddressStr(addressService.computeAddressStr(order.getMainInvoicingAddress()));
    order.setDeliveryAddress(partnerService.getDeliveryAddress(clientPartner));
    order.setDeliveryAddressStr(addressService.computeAddressStr(order.getDeliveryAddress()));
    order.setIsNeedingConformityCertificate(clientPartner.getIsNeedingConformityCertificate());
    order.setCompanyBankDetails(Beans.get(AccountingSituationService.class).getCompanySalesBankDetails(company, clientPartner));
    if (project.getCurrency() != null) {
        order.setCurrency(project.getCurrency());
    } else if (clientPartner.getCurrency() != null) {
        order.setCurrency(clientPartner.getCurrency());
    } else {
        order.setCurrency(company.getCurrency());
    }
    if (project.getPriceList() != null) {
        order.setPriceList(project.getPriceList());
    } else {
        order.setPriceList(Beans.get(PartnerPriceListService.class).getDefaultPriceList(clientPartner, PriceListRepository.TYPE_SALE));
    }
    if (order.getPriceList() != null) {
        order.setHideDiscount(order.getPriceList().getHideDiscount());
    }
    if (clientPartner.getPaymentCondition() != null) {
        order.setPaymentCondition(clientPartner.getPaymentCondition());
    } else {
        if (company != null && company.getAccountConfig() != null) {
            order.setPaymentCondition(company.getAccountConfig().getDefPaymentCondition());
        }
    }
    if (clientPartner.getInPaymentMode() != null) {
        order.setPaymentMode(clientPartner.getInPaymentMode());
    } else {
        if (company != null && company.getAccountConfig() != null) {
            order.setPaymentMode(company.getAccountConfig().getInPaymentMode());
        }
    }
    AppSupplychain appSupplychain = Beans.get(AppSupplychainService.class).getAppSupplychain();
    if (appSupplychain != null) {
        order.setShipmentMode(clientPartner.getShipmentMode());
        order.setFreightCarrierMode(clientPartner.getFreightCarrierMode());
        if (clientPartner.getFreightCarrierMode() != null) {
            order.setCarrierPartner(clientPartner.getFreightCarrierMode().getCarrierPartner());
        }
        Boolean interco = appSupplychain.getIntercoFromSale() && !order.getCreatedByInterco() && clientPartner != null && Beans.get(CompanyRepository.class).all().filter("self.partner = ?", clientPartner).fetchOne() != null;
        order.setInterco(interco);
        // Automatic invoiced and delivered partners set in case of partner delegations
        if (appSupplychain.getActivatePartnerRelations()) {
            Beans.get(SaleOrderSupplychainService.class).setDefaultInvoicedAndDeliveredPartnersAndAddresses(order);
        }
    }
    return Beans.get(SaleOrderRepository.class).save(order);
}
Also used : SaleOrderCreateService(com.axelor.apps.sale.service.saleorder.SaleOrderCreateService) Company(com.axelor.apps.base.db.Company) CompanyRepository(com.axelor.apps.base.db.repo.CompanyRepository) AppSupplychain(com.axelor.apps.base.db.AppSupplychain) SaleOrderSupplychainService(com.axelor.apps.supplychain.service.SaleOrderSupplychainService) SaleOrderRepository(com.axelor.apps.sale.db.repo.SaleOrderRepository) SaleOrder(com.axelor.apps.sale.db.SaleOrder) Partner(com.axelor.apps.base.db.Partner) AppSupplychainService(com.axelor.apps.supplychain.service.app.AppSupplychainService) Transactional(com.google.inject.persist.Transactional)

Aggregations

Company (com.axelor.apps.base.db.Company)213 Transactional (com.google.inject.persist.Transactional)72 Partner (com.axelor.apps.base.db.Partner)68 AxelorException (com.axelor.exception.AxelorException)65 BigDecimal (java.math.BigDecimal)54 Move (com.axelor.apps.account.db.Move)35 MoveLine (com.axelor.apps.account.db.MoveLine)35 LocalDate (java.time.LocalDate)35 ArrayList (java.util.ArrayList)31 PaymentMode (com.axelor.apps.account.db.PaymentMode)28 AccountConfig (com.axelor.apps.account.db.AccountConfig)27 Journal (com.axelor.apps.account.db.Journal)26 Account (com.axelor.apps.account.db.Account)25 Invoice (com.axelor.apps.account.db.Invoice)25 BankDetails (com.axelor.apps.base.db.BankDetails)22 Currency (com.axelor.apps.base.db.Currency)19 Product (com.axelor.apps.base.db.Product)17 StockLocation (com.axelor.apps.stock.db.StockLocation)17 StockMove (com.axelor.apps.stock.db.StockMove)15 List (java.util.List)15