From 73d426bfae090587f4b440e07de2eb4c1f676a68 Mon Sep 17 00:00:00 2001 From: bachir souldi Date: Sun, 3 Jul 2022 14:29:21 +0100 Subject: [PATCH 1/2] add rest of attributes importation folder && and calculation of cost price --- .../src/main/resources/domains/Invoice.xml | 3 + .../service/ImportationFolderService.java | 8 + .../service/ImportationFolderServiceImpl.java | 54 ++++++ .../service/PurchaseOrderService.java | 6 +- .../service/PurchaseOrderServiceImpl.java | 56 +++++- .../resources/domains/ImportationFolder.xml | 20 +- .../main/resources/domains/PurchaseOrder.xml | 2 +- .../resources/views/ImportationFolder.xml | 171 +++++++++++------- .../src/main/resources/views/Selects.xml | 7 + .../PurchaseOrderServiceSupplychainImpl.java | 6 +- 10 files changed, 261 insertions(+), 72 deletions(-) diff --git a/modules/axelor-open-suite/axelor-account/src/main/resources/domains/Invoice.xml b/modules/axelor-open-suite/axelor-account/src/main/resources/domains/Invoice.xml index 755560f..b95a823 100644 --- a/modules/axelor-open-suite/axelor-account/src/main/resources/domains/Invoice.xml +++ b/modules/axelor-open-suite/axelor-account/src/main/resources/domains/Invoice.xml @@ -143,6 +143,9 @@ + + + purchaseOrders,ImportationFolder importationFolder) throws MalformedURLException, JSONException, AxelorException; } \ No newline at end of file diff --git a/modules/axelor-open-suite/axelor-purchase/src/main/java/com/axelor/apps/purchase/service/ImportationFolderServiceImpl.java b/modules/axelor-open-suite/axelor-purchase/src/main/java/com/axelor/apps/purchase/service/ImportationFolderServiceImpl.java index 0a4076a..0e9a9b3 100644 --- a/modules/axelor-open-suite/axelor-purchase/src/main/java/com/axelor/apps/purchase/service/ImportationFolderServiceImpl.java +++ b/modules/axelor-open-suite/axelor-purchase/src/main/java/com/axelor/apps/purchase/service/ImportationFolderServiceImpl.java @@ -1,12 +1,26 @@ package com.axelor.apps.purchase.service; +import java.math.BigDecimal; +import java.net.MalformedURLException; +import java.util.List; + +import com.axelor.apps.base.db.Currency; +import com.axelor.apps.base.db.repo.CurrencyRepository; +import com.axelor.apps.base.service.CurrencyConversionService; +import com.axelor.apps.base.service.CurrencyService; import com.axelor.apps.base.service.administration.SequenceService; import com.axelor.apps.purchase.db.ImportationFolder; +import com.axelor.apps.purchase.db.PurchaseOrder; import com.axelor.apps.purchase.db.repo.ImportationFolderRepository; import com.axelor.exception.AxelorException; import com.google.inject.Inject; import com.google.inject.persist.Transactional; +import wslite.json.JSONException; + +import com.axelor.inject.Beans; + + public class ImportationFolderServiceImpl implements ImportationFolderService { @Inject @@ -36,5 +50,45 @@ public class ImportationFolderServiceImpl implements ImportationFolderService { public void cancelImportationFolder(ImportationFolder importationFolder) { // importationFolder.setStatusSelect(ImportationFolderRepository.STATUS_CANCELED); } + + @Override + @Transactional + public void calculateSum(List purchaseOrders,ImportationFolder importationFolder) throws MalformedURLException, JSONException, AxelorException { + BigDecimal amount = BigDecimal.ZERO; + BigDecimal taxAmount = BigDecimal.ZERO; + BigDecimal totalAmount = BigDecimal.ZERO; + + + for (PurchaseOrder purchaseOrder : purchaseOrders) { + if(purchaseOrder.getCurrency().getId() == 148 || purchaseOrder.getCurrency().getId() == 46){ + Currency currency = Beans.get(CurrencyRepository.class).find(purchaseOrder.getCurrency().getId()); + Currency currencyDzd = Beans.get(CurrencyRepository.class).findByCode("DZD"); + BigDecimal currencyAmount = Beans.get(CurrencyService.class).getCurrencyConversionRate(currency, currencyDzd); + + currencyAmount = currencyAmount.setScale(2, BigDecimal.ROUND_HALF_EVEN); + + BigDecimal finalAmount = purchaseOrder.getExTaxTotal().multiply(currencyAmount); + BigDecimal finalTaxAmount = purchaseOrder.getTaxTotal().multiply(currencyAmount); + BigDecimal finalTotalAmount = purchaseOrder.getInTaxTotal().multiply(currencyAmount); + + amount = amount.add(finalAmount).setScale(2, BigDecimal.ROUND_HALF_EVEN); + taxAmount = taxAmount.add(finalTaxAmount).setScale(2, BigDecimal.ROUND_HALF_EVEN); + totalAmount = totalAmount.add(finalTotalAmount).setScale(2, BigDecimal.ROUND_HALF_EVEN); + + }else{ + amount = amount.add(purchaseOrder.getExTaxTotal()); + taxAmount = taxAmount.add(purchaseOrder.getTaxTotal()); + totalAmount = totalAmount.add(purchaseOrder.getInTaxTotal()); + } + + } + + importationFolder.setAmount(amount); + importationFolder.setTaxAmount(taxAmount); + importationFolder.setTotalAmount(totalAmount); + + importationFolderRepository.save(importationFolder); + + } } diff --git a/modules/axelor-open-suite/axelor-purchase/src/main/java/com/axelor/apps/purchase/service/PurchaseOrderService.java b/modules/axelor-open-suite/axelor-purchase/src/main/java/com/axelor/apps/purchase/service/PurchaseOrderService.java index 2f451dc..48dec94 100644 --- a/modules/axelor-open-suite/axelor-purchase/src/main/java/com/axelor/apps/purchase/service/PurchaseOrderService.java +++ b/modules/axelor-open-suite/axelor-purchase/src/main/java/com/axelor/apps/purchase/service/PurchaseOrderService.java @@ -26,6 +26,10 @@ import com.axelor.apps.purchase.db.PurchaseOrder; import com.axelor.auth.db.User; import com.axelor.exception.AxelorException; import com.google.inject.persist.Transactional; + +import wslite.json.JSONException; + +import java.net.MalformedURLException; import java.time.LocalDate; import java.util.List; @@ -103,7 +107,7 @@ public interface PurchaseOrderService { public void draftPurchaseOrder(PurchaseOrder purchaseOrder); - public void validatePurchaseOrder(PurchaseOrder purchaseOrder) throws AxelorException; + public void validatePurchaseOrder(PurchaseOrder purchaseOrder) throws AxelorException, MalformedURLException, JSONException; public void finishPurchaseOrder(PurchaseOrder purchaseOrder); diff --git a/modules/axelor-open-suite/axelor-purchase/src/main/java/com/axelor/apps/purchase/service/PurchaseOrderServiceImpl.java b/modules/axelor-open-suite/axelor-purchase/src/main/java/com/axelor/apps/purchase/service/PurchaseOrderServiceImpl.java index 2994263..51b7c55 100644 --- a/modules/axelor-open-suite/axelor-purchase/src/main/java/com/axelor/apps/purchase/service/PurchaseOrderServiceImpl.java +++ b/modules/axelor-open-suite/axelor-purchase/src/main/java/com/axelor/apps/purchase/service/PurchaseOrderServiceImpl.java @@ -27,18 +27,22 @@ import com.axelor.apps.base.db.Product; import com.axelor.apps.base.db.TradingName; import com.axelor.apps.base.db.Unit; import com.axelor.apps.base.db.repo.BlockingRepository; +import com.axelor.apps.base.db.repo.CurrencyRepository; import com.axelor.apps.base.db.repo.PartnerRepository; import com.axelor.apps.base.db.repo.ProductRepository; import com.axelor.apps.base.db.repo.SequenceRepository; import com.axelor.apps.base.service.BlockingService; +import com.axelor.apps.base.service.CurrencyService; import com.axelor.apps.base.service.ProductService; import com.axelor.apps.base.service.ShippingCoefService; import com.axelor.apps.base.service.TradingNameService; import com.axelor.apps.base.service.UnitConversionService; import com.axelor.apps.base.service.administration.SequenceService; +import com.axelor.apps.purchase.db.ImportationFolder; import com.axelor.apps.purchase.db.PurchaseOrder; import com.axelor.apps.purchase.db.PurchaseOrderLine; import com.axelor.apps.purchase.db.PurchaseOrderLineTax; +import com.axelor.apps.purchase.db.repo.ImportationFolderRepository; import com.axelor.apps.purchase.db.repo.PurchaseOrderRepository; import com.axelor.apps.purchase.exception.IExceptionMessage; import com.axelor.apps.purchase.report.IReport; @@ -53,8 +57,12 @@ import com.axelor.inject.Beans; import com.google.common.base.Strings; import com.google.inject.Inject; import com.google.inject.persist.Transactional; + +import wslite.json.JSONException; + import java.lang.invoke.MethodHandles; import java.math.BigDecimal; +import java.net.MalformedURLException; import java.time.LocalDate; import java.util.ArrayList; import java.util.List; @@ -74,6 +82,7 @@ public class PurchaseOrderServiceImpl implements PurchaseOrderService { @Inject protected AppPurchaseService appPurchaseService; @Inject protected PurchaseOrderRepository purchaseOrderRepo; + @Inject protected ImportationFolderRepository importationFolderRepository; @Override public PurchaseOrder _computePurchaseOrderLines(PurchaseOrder purchaseOrder) @@ -449,7 +458,7 @@ public class PurchaseOrderServiceImpl implements PurchaseOrderService { @Override @Transactional(rollbackOn = {Exception.class}) - public void validatePurchaseOrder(PurchaseOrder purchaseOrder) throws AxelorException { + public void validatePurchaseOrder(PurchaseOrder purchaseOrder) throws AxelorException, MalformedURLException, JSONException { computePurchaseOrder(purchaseOrder); purchaseOrder.setStatusSelect(PurchaseOrderRepository.STATUS_VALIDATED); @@ -459,6 +468,12 @@ public class PurchaseOrderServiceImpl implements PurchaseOrderService { purchaseOrder.setSupplierPartner(validateSupplier(purchaseOrder)); updateCostPrice(purchaseOrder); + + if(purchaseOrder.getImportationFolder() != null){ + List purchaseOrders = purchaseOrder.getImportationFolder().getPurchaseOrderList(); + ImportationFolder importationFolder = purchaseOrder.getImportationFolder(); + calculateSum(purchaseOrders, importationFolder); + } } @Override @@ -474,4 +489,43 @@ public class PurchaseOrderServiceImpl implements PurchaseOrderService { purchaseOrder.setStatusSelect(PurchaseOrderRepository.STATUS_CANCELED); purchaseOrderRepo.save(purchaseOrder); } + + @Transactional + public void calculateSum(List purchaseOrders,ImportationFolder importationFolder) throws AxelorException { + BigDecimal amount = BigDecimal.ZERO; + BigDecimal taxAmount = BigDecimal.ZERO; + BigDecimal totalAmount = BigDecimal.ZERO; + + + for (PurchaseOrder purchaseOrder : purchaseOrders) { + if(purchaseOrder.getCurrency().getId() == 148 || purchaseOrder.getCurrency().getId() == 46){ + Currency currency = Beans.get(CurrencyRepository.class).find(purchaseOrder.getCurrency().getId()); + Currency currencyDzd = Beans.get(CurrencyRepository.class).findByCode("DZD"); + BigDecimal currencyAmount = Beans.get(CurrencyService.class).getCurrencyConversionRate(currency, currencyDzd); + + currencyAmount = currencyAmount.setScale(2, BigDecimal.ROUND_HALF_EVEN); + + BigDecimal finalAmount = purchaseOrder.getExTaxTotal().multiply(currencyAmount); + BigDecimal finalTaxAmount = purchaseOrder.getTaxTotal().multiply(currencyAmount); + BigDecimal finalTotalAmount = purchaseOrder.getInTaxTotal().multiply(currencyAmount); + + amount = amount.add(finalAmount).setScale(2, BigDecimal.ROUND_HALF_EVEN); + taxAmount = taxAmount.add(finalTaxAmount).setScale(2, BigDecimal.ROUND_HALF_EVEN); + totalAmount = totalAmount.add(finalTotalAmount).setScale(2, BigDecimal.ROUND_HALF_EVEN); + + }else{ + amount = amount.add(purchaseOrder.getExTaxTotal()); + taxAmount = taxAmount.add(purchaseOrder.getTaxTotal()); + totalAmount = totalAmount.add(purchaseOrder.getInTaxTotal()); + } + + } + + importationFolder.setAmount(amount); + importationFolder.setTaxAmount(taxAmount); + importationFolder.setTotalAmount(totalAmount); + + importationFolderRepository.save(importationFolder); + + } } diff --git a/modules/axelor-open-suite/axelor-purchase/src/main/resources/domains/ImportationFolder.xml b/modules/axelor-open-suite/axelor-purchase/src/main/resources/domains/ImportationFolder.xml index d40ce9b..19febcf 100644 --- a/modules/axelor-open-suite/axelor-purchase/src/main/resources/domains/ImportationFolder.xml +++ b/modules/axelor-open-suite/axelor-purchase/src/main/resources/domains/ImportationFolder.xml @@ -6,14 +6,14 @@ - + - + - + @@ -22,7 +22,7 @@ - + @@ -36,6 +36,18 @@ + + + + + + + + + + + + - + diff --git a/modules/axelor-open-suite/axelor-purchase/src/main/resources/views/ImportationFolder.xml b/modules/axelor-open-suite/axelor-purchase/src/main/resources/views/ImportationFolder.xml index ccffe96..0e23301 100644 --- a/modules/axelor-open-suite/axelor-purchase/src/main/resources/views/ImportationFolder.xml +++ b/modules/axelor-open-suite/axelor-purchase/src/main/resources/views/ImportationFolder.xml @@ -2,89 +2,132 @@ -
- - - - - Importation Folder - {{record.importationFolderSeq}} - - ]]> - - - - + + + + + + Dossier d'importation + {{record.name}} + + ]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - + + + + + + + + + + + + + + - + - - + + - -