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