From 11e5cad88f5abf7907441115bde7dfa2b82babb3 Mon Sep 17 00:00:00 2001 From: bachir souldi Date: Wed, 18 Jan 2023 08:24:36 +0100 Subject: [PATCH] seperate sequences (invoices - stock Moves) --- .../db/repo/InvoiceManagementRepository.java | 2 +- .../service/config/AccountConfigService.java | 25 +++++++ .../service/invoice/InvoiceService.java | 2 + .../service/invoice/InvoiceServiceImpl.java | 43 ++++++++++++ .../workflow/ventilate/VentilateState.java | 11 +++- .../main/resources/domains/AccountConfig.xml | 2 + .../src/main/resources/domains/Invoice.xml | 4 ++ .../stock/service/StockMoveServiceImpl.java | 66 +++++++++++++------ .../service/StockMoveToolServiceImpl.java | 41 ++++++++++++ .../src/main/resources/domains/Sequence.xml | 7 ++ .../src/main/resources/domains/StockMove.xml | 8 +++ .../service/StockMoveInvoiceServiceImpl.java | 19 +++++- 12 files changed, 207 insertions(+), 23 deletions(-) diff --git a/modules/axelor-open-suite/axelor-account/src/main/java/com/axelor/apps/account/db/repo/InvoiceManagementRepository.java b/modules/axelor-open-suite/axelor-account/src/main/java/com/axelor/apps/account/db/repo/InvoiceManagementRepository.java index df84adb8..4a34e116 100644 --- a/modules/axelor-open-suite/axelor-account/src/main/java/com/axelor/apps/account/db/repo/InvoiceManagementRepository.java +++ b/modules/axelor-open-suite/axelor-account/src/main/java/com/axelor/apps/account/db/repo/InvoiceManagementRepository.java @@ -74,7 +74,7 @@ public class InvoiceManagementRepository extends InvoiceRepository { public Invoice save(Invoice invoice) { try { invoice = super.save(invoice); - Beans.get(InvoiceService.class).setDraftSequence(invoice); + Beans.get(InvoiceService.class).setSequence(invoice); return invoice; } catch (Exception e) { diff --git a/modules/axelor-open-suite/axelor-account/src/main/java/com/axelor/apps/account/service/config/AccountConfigService.java b/modules/axelor-open-suite/axelor-account/src/main/java/com/axelor/apps/account/service/config/AccountConfigService.java index 216538ca..590f35c2 100644 --- a/modules/axelor-open-suite/axelor-account/src/main/java/com/axelor/apps/account/service/config/AccountConfigService.java +++ b/modules/axelor-open-suite/axelor-account/src/main/java/com/axelor/apps/account/service/config/AccountConfigService.java @@ -550,6 +550,31 @@ public class AccountConfigService { return accountConfig.getCustRefSequence(); } + // ff + public Sequence getFinancialCustInvSequence(AccountConfig accountConfig) throws AxelorException { + + if (accountConfig.getFinancialCustInvSequence() == null) { + throw new AxelorException( + TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, + I18n.get(IExceptionMessage.ACCOUNT_CONFIG_SEQUENCE_2), + I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION), + accountConfig.getCompany().getName()); + } + return accountConfig.getFinancialCustInvSequence(); + } + + // AVR + public Sequence getFinancialCustRefSequence(AccountConfig accountConfig) throws AxelorException { + if (accountConfig.getFinancialCustRefSequence() == null) { + throw new AxelorException( + TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, + I18n.get(IExceptionMessage.ACCOUNT_CONFIG_SEQUENCE_2), + I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION), + accountConfig.getCompany().getName()); + } + return accountConfig.getFinancialCustRefSequence(); + } + public Sequence getSuppInvSequence(AccountConfig accountConfig) throws AxelorException { if (accountConfig.getSuppInvSequence() == null) { diff --git a/modules/axelor-open-suite/axelor-account/src/main/java/com/axelor/apps/account/service/invoice/InvoiceService.java b/modules/axelor-open-suite/axelor-account/src/main/java/com/axelor/apps/account/service/invoice/InvoiceService.java index bacc6d8d..47eb959d 100644 --- a/modules/axelor-open-suite/axelor-account/src/main/java/com/axelor/apps/account/service/invoice/InvoiceService.java +++ b/modules/axelor-open-suite/axelor-account/src/main/java/com/axelor/apps/account/service/invoice/InvoiceService.java @@ -148,6 +148,8 @@ public interface InvoiceService { public void setDraftSequence(Invoice invoice) throws AxelorException; + public void setSequence(Invoice invoice) throws AxelorException; + public Invoice mergeInvoiceProcess( List invoiceList, Company company, diff --git a/modules/axelor-open-suite/axelor-account/src/main/java/com/axelor/apps/account/service/invoice/InvoiceServiceImpl.java b/modules/axelor-open-suite/axelor-account/src/main/java/com/axelor/apps/account/service/invoice/InvoiceServiceImpl.java index 63318b32..70cc78da 100644 --- a/modules/axelor-open-suite/axelor-account/src/main/java/com/axelor/apps/account/service/invoice/InvoiceServiceImpl.java +++ b/modules/axelor-open-suite/axelor-account/src/main/java/com/axelor/apps/account/service/invoice/InvoiceServiceImpl.java @@ -52,6 +52,7 @@ import com.axelor.apps.base.db.Company; import com.axelor.apps.base.db.Currency; import com.axelor.apps.base.db.Partner; import com.axelor.apps.base.db.PriceList; +import com.axelor.apps.base.db.Sequence; import com.axelor.apps.base.db.repo.BankDetailsRepository; import com.axelor.apps.base.db.repo.PriceListRepository; import com.axelor.apps.base.service.PartnerService; @@ -440,6 +441,48 @@ public class InvoiceServiceImpl extends InvoiceRepository implements InvoiceServ } } + @Override + public void setSequence(Invoice invoice) throws AxelorException { + + if (invoice.getId() != null && Strings.isNullOrEmpty(invoice.getInvoiceId())) { + invoice.setInvoiceId(Beans.get(SequenceService.class).getSequenceNumber(getSequence(invoice), Beans.get(AppBaseService.class).getTodayDate())); + } + } + + protected Sequence getSequence(Invoice invoice) throws AxelorException { + + AccountConfig accountConfig = accountConfigService.getAccountConfig(invoice.getCompany()); + + switch (invoice.getOperationTypeSelect()) { + case InvoiceRepository.OPERATION_TYPE_SUPPLIER_PURCHASE: + return accountConfigService.getSuppInvSequence(accountConfig); + + case InvoiceRepository.OPERATION_TYPE_SUPPLIER_REFUND: + return accountConfigService.getSuppRefSequence(accountConfig); + + case InvoiceRepository.OPERATION_TYPE_CLIENT_SALE: + if(invoice.getOperationSubTypeSelect() == InvoiceRepository.OPERATION_SUB_TYPE_FINANCIAL_DISCOUNT){ + return accountConfigService.getFinancialCustInvSequence(accountConfig); + }else{ + return accountConfigService.getCustInvSequence(accountConfig); + } + case InvoiceRepository.OPERATION_TYPE_CLIENT_REFUND: + if(invoice.getOperationSubTypeSelect() == InvoiceRepository.OPERATION_SUB_TYPE_FINANCIAL_REFUNDS){ + return accountConfigService.getFinancialCustRefSequence(accountConfig); + }else{ + return accountConfigService.getCustRefSequence(accountConfig); + } + + default: + throw new AxelorException( + invoice, + TraceBackRepository.CATEGORY_MISSING_FIELD, + I18n.get(IExceptionMessage.JOURNAL_1), + invoice.getInvoiceId()); + } + } + + public Invoice mergeInvoiceProcess( List invoiceList, Company company, diff --git a/modules/axelor-open-suite/axelor-account/src/main/java/com/axelor/apps/account/service/invoice/workflow/ventilate/VentilateState.java b/modules/axelor-open-suite/axelor-account/src/main/java/com/axelor/apps/account/service/invoice/workflow/ventilate/VentilateState.java index f6ada22c..745f5fb6 100644 --- a/modules/axelor-open-suite/axelor-account/src/main/java/com/axelor/apps/account/service/invoice/workflow/ventilate/VentilateState.java +++ b/modules/axelor-open-suite/axelor-account/src/main/java/com/axelor/apps/account/service/invoice/workflow/ventilate/VentilateState.java @@ -319,10 +319,17 @@ public class VentilateState extends WorkflowInvoice { return accountConfigService.getSuppRefSequence(accountConfig); case InvoiceRepository.OPERATION_TYPE_CLIENT_SALE: + if(invoice.getOperationSubTypeSelect() == InvoiceRepository.OPERATION_SUB_TYPE_FINANCIAL_DISCOUNT){ + return accountConfigService.getFinancialCustInvSequence(accountConfig); + }else{ return accountConfigService.getCustInvSequence(accountConfig); - + } case InvoiceRepository.OPERATION_TYPE_CLIENT_REFUND: - return accountConfigService.getCustRefSequence(accountConfig); + if(invoice.getOperationSubTypeSelect() == InvoiceRepository.OPERATION_SUB_TYPE_FINANCIAL_REFUNDS){ + return accountConfigService.getFinancialCustRefSequence(accountConfig); + }else{ + return accountConfigService.getCustRefSequence(accountConfig); + } default: throw new AxelorException( diff --git a/modules/axelor-open-suite/axelor-account/src/main/resources/domains/AccountConfig.xml b/modules/axelor-open-suite/axelor-account/src/main/resources/domains/AccountConfig.xml index fe427f25..7fd9a7f7 100644 --- a/modules/axelor-open-suite/axelor-account/src/main/resources/domains/AccountConfig.xml +++ b/modules/axelor-open-suite/axelor-account/src/main/resources/domains/AccountConfig.xml @@ -133,7 +133,9 @@ + + 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 7221fb21..f4d5a125 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 @@ -181,6 +181,10 @@ public static final int OPERATION_SUB_TYPE_DEFAULT = 1; public static final int OPERATION_SUB_TYPE_ADVANCE = 2; public static final int OPERATION_SUB_TYPE_BALANCE = 3; + + public static final int OPERATION_SUB_TYPE_FINANCIAL_DISCOUNT = 9; + public static final int OPERATION_SUB_TYPE_FINANCIAL_REFUNDS = 10; + // REPORT TYPE public static final int REPORT_TYPE_PROFORMA = 1; diff --git a/modules/axelor-open-suite/axelor-stock/src/main/java/com/axelor/apps/stock/service/StockMoveServiceImpl.java b/modules/axelor-open-suite/axelor-stock/src/main/java/com/axelor/apps/stock/service/StockMoveServiceImpl.java index f474807a..2cbb21bd 100644 --- a/modules/axelor-open-suite/axelor-stock/src/main/java/com/axelor/apps/stock/service/StockMoveServiceImpl.java +++ b/modules/axelor-open-suite/axelor-stock/src/main/java/com/axelor/apps/stock/service/StockMoveServiceImpl.java @@ -287,9 +287,24 @@ public class StockMoveServiceImpl implements StockMoveService { if (Beans.get(SequenceService.class) .isEmptyOrDraftSequenceNumber(stockMove.getStockMoveSeq())) { draftSeq = stockMove.getStockMoveSeq(); - stockMove.setStockMoveSeq( + if (stockMove.getTypeSelect() == StockMoveRepository.TYPE_INCOMING && stockMove.getIsReversion() == true){ + stockMove.setStockMoveSeq( + stockMoveToolService.getSequenceStockMove(StockMoveRepository.TYPE_INCOMING_CLIENT, stockMove.getCompany())); + }else if(stockMove.getTypeSelect() == StockMoveRepository.TYPE_OUTGOING && stockMove.getIsReversion() == false && stockMove.getPartner().getId() != 853 ){ + stockMove.setStockMoveSeq( + stockMoveToolService.getSequenceStockMove(StockMoveRepository.TYPE_OUTGOING_CLIENT, stockMove.getCompany())); + } else if(stockMove.getTypeSelect() == StockMoveRepository.TYPE_OUTGOING && stockMove.getIsReversion() == false && stockMove.getPartner().getId() == 853){ + stockMove.setStockMoveSeq( + stockMoveToolService.getSequenceStockMove(StockMoveRepository.TYPE_INTERNAL_OUTGOING_CLIENT, stockMove.getCompany())); + }else if(stockMove.getTypeSelect() == StockMoveRepository.TYPE_OUTGOING && stockMove.getIsReversion() == true){ + stockMove.setStockMoveSeq( + stockMoveToolService.getSequenceStockMove(StockMoveRepository.TYPE_SUPPLIER_OUTGOING_CLIENT, stockMove.getCompany())); + } + else{ + stockMove.setStockMoveSeq( stockMoveToolService.getSequenceStockMove( stockMove.getTypeSelect(), stockMove.getCompany())); + } } else { draftSeq = null; } @@ -632,6 +647,24 @@ public class StockMoveServiceImpl implements StockMoveService { stockMoveLines = MoreObjects.firstNonNull(stockMoveLines, Collections.emptyList()); StockMove newStockMove = stockMoveRepo.copy(stockMove, false); + if (stockMove.getTypeSelect() == StockMoveRepository.TYPE_INCOMING && stockMove.getIsReversion() == true){ + stockMove.setStockMoveSeq( + stockMoveToolService.getSequenceStockMove(StockMoveRepository.TYPE_INCOMING_CLIENT, stockMove.getCompany())); + }else{ + newStockMove.setStockMoveSeq( + stockMoveToolService.getSequenceStockMove( + newStockMove.getTypeSelect(), newStockMove.getCompany())); + } + + newStockMove.setName( + stockMoveToolService.computeName( + newStockMove, + newStockMove.getStockMoveSeq() + + " " + + I18n.get(IExceptionMessage.STOCK_MOVE_7) + + " " + + stockMove.getStockMoveSeq() + + " )")); // In copy OriginTypeSelect set null. newStockMove.setOriginTypeSelect(stockMove.getOriginTypeSelect()); for (StockMoveLine stockMoveLine : stockMoveLines) { @@ -647,18 +680,7 @@ public class StockMoveServiceImpl implements StockMoveService { } newStockMove.setRealDate(null); - newStockMove.setStockMoveSeq( - stockMoveToolService.getSequenceStockMove( - newStockMove.getTypeSelect(), newStockMove.getCompany())); - newStockMove.setName( - stockMoveToolService.computeName( - newStockMove, - newStockMove.getStockMoveSeq() - + " " - + I18n.get(IExceptionMessage.STOCK_MOVE_7) - + " " - + stockMove.getStockMoveSeq() - + " )")); + newStockMove.setExTaxTotal(stockMoveToolService.compute(newStockMove)); plan(newStockMove); @@ -714,9 +736,15 @@ public class StockMoveServiceImpl implements StockMoveService { newStockMove.setTypeSelect(StockMoveRepository.TYPE_INCOMING); if (stockMove.getTypeSelect() == StockMoveRepository.TYPE_INTERNAL) newStockMove.setTypeSelect(StockMoveRepository.TYPE_INTERNAL); - newStockMove.setStockMoveSeq( - stockMoveToolService.getSequenceStockMove( - newStockMove.getTypeSelect(), newStockMove.getCompany())); + + if (stockMove.getTypeSelect() == StockMoveRepository.TYPE_OUTGOING && stockMove.getIsReversion() == false){ + newStockMove.setStockMoveSeq( + stockMoveToolService.getSequenceStockMove(StockMoveRepository.TYPE_INCOMING_CLIENT, stockMove.getCompany()));} + else{ + newStockMove.setStockMoveSeq( + stockMoveToolService.getSequenceStockMove( + newStockMove.getTypeSelect(), newStockMove.getCompany())); + } for (StockMoveLine stockMoveLine : stockMoveLines) { @@ -739,9 +767,9 @@ public class StockMoveServiceImpl implements StockMoveService { return Optional.empty(); } - newStockMove.setStockMoveSeq( - stockMoveToolService.getSequenceStockMove( - newStockMove.getTypeSelect(), newStockMove.getCompany())); + // newStockMove.setStockMoveSeq( + // stockMoveToolService.getSequenceStockMove( + // newStockMove.getTypeSelect(), newStockMove.getCompany())); newStockMove.setName( stockMoveToolService.computeName( newStockMove, diff --git a/modules/axelor-open-suite/axelor-stock/src/main/java/com/axelor/apps/stock/service/StockMoveToolServiceImpl.java b/modules/axelor-open-suite/axelor-stock/src/main/java/com/axelor/apps/stock/service/StockMoveToolServiceImpl.java index 43069ee0..5f4d34ea 100644 --- a/modules/axelor-open-suite/axelor-stock/src/main/java/com/axelor/apps/stock/service/StockMoveToolServiceImpl.java +++ b/modules/axelor-open-suite/axelor-stock/src/main/java/com/axelor/apps/stock/service/StockMoveToolServiceImpl.java @@ -129,6 +129,47 @@ public class StockMoveToolServiceImpl implements StockMoveToolService { } break; + case StockMoveRepository.TYPE_INCOMING_CLIENT: + ref = sequenceService.getSequenceNumber(SequenceRepository.INCOMING_CLIENT, company); + if (ref == null) { + throw new AxelorException( + TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, + I18n.get(IExceptionMessage.STOCK_MOVE_3), + company.getName()); + } + break; + + case StockMoveRepository.TYPE_OUTGOING_CLIENT: + ref = sequenceService.getSequenceNumber(SequenceRepository.OUTGOING_CLIENT, company); + if (ref == null) { + throw new AxelorException( + TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, + I18n.get(IExceptionMessage.STOCK_MOVE_3), + company.getName()); + } + break; + + + case StockMoveRepository.TYPE_INTERNAL_OUTGOING_CLIENT: + ref = sequenceService.getSequenceNumber(SequenceRepository.CUST_DELIVERY, company); + if (ref == null) { + throw new AxelorException( + TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, + I18n.get(IExceptionMessage.STOCK_MOVE_3), + company.getName()); + } + break; + + case StockMoveRepository.TYPE_SUPPLIER_OUTGOING_CLIENT: + ref = sequenceService.getSequenceNumber(SequenceRepository.SUP_RETURN, company); + if (ref == null) { + throw new AxelorException( + TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, + I18n.get(IExceptionMessage.STOCK_MOVE_3), + company.getName()); + } + break; + default: throw new AxelorException( TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, diff --git a/modules/axelor-open-suite/axelor-stock/src/main/resources/domains/Sequence.xml b/modules/axelor-open-suite/axelor-stock/src/main/resources/domains/Sequence.xml index d7e7974a..2bbe3ed2 100644 --- a/modules/axelor-open-suite/axelor-stock/src/main/resources/domains/Sequence.xml +++ b/modules/axelor-open-suite/axelor-stock/src/main/resources/domains/Sequence.xml @@ -14,6 +14,13 @@ public static final String INTERNAL = "intStockMove"; public static final String OUTGOING = "outStockMove"; public static final String INCOMING = "inStockMove"; + public static final String INCOMING_CLIENT = "customerReturn"; + public static final String OUTGOING_CLIENT = "clientDelivery"; + //sortie de stock + public static final String CUST_DELIVERY = "internalDelivery"; + //retour fournisseur + public static final String SUP_RETURN = "supReturn"; + public static final String PRODUCT_TRACKING_NUMBER = "productTrackingNumber"; public static final String LOGISTICAL_FORM = "logisticalForm"; diff --git a/modules/axelor-open-suite/axelor-stock/src/main/resources/domains/StockMove.xml b/modules/axelor-open-suite/axelor-stock/src/main/resources/domains/StockMove.xml index 7ec86a20..3367f29a 100644 --- a/modules/axelor-open-suite/axelor-stock/src/main/resources/domains/StockMove.xml +++ b/modules/axelor-open-suite/axelor-stock/src/main/resources/domains/StockMove.xml @@ -123,6 +123,14 @@ public static final int TYPE_INTERNAL = 1; public static final int TYPE_OUTGOING = 2; public static final int TYPE_INCOMING = 3; + // client return + public static final int TYPE_INCOMING_CLIENT = 4; + // client delivery + public static final int TYPE_OUTGOING_CLIENT = 5; + // internal delivery + public static final int TYPE_INTERNAL_OUTGOING_CLIENT = 6; + // supplier return + public static final int TYPE_SUPPLIER_OUTGOING_CLIENT = 7; // CONFORMITY SELECT public static final int CONFORMITY_NONE = 1; diff --git a/modules/axelor-open-suite/axelor-supplychain/src/main/java/com/axelor/apps/supplychain/service/StockMoveInvoiceServiceImpl.java b/modules/axelor-open-suite/axelor-supplychain/src/main/java/com/axelor/apps/supplychain/service/StockMoveInvoiceServiceImpl.java index e0dc9c86..7dcf2c16 100644 --- a/modules/axelor-open-suite/axelor-supplychain/src/main/java/com/axelor/apps/supplychain/service/StockMoveInvoiceServiceImpl.java +++ b/modules/axelor-open-suite/axelor-supplychain/src/main/java/com/axelor/apps/supplychain/service/StockMoveInvoiceServiceImpl.java @@ -571,8 +571,25 @@ public class StockMoveInvoiceServiceImpl implements StockMoveInvoiceService { AccountConfigService accountConfigService = Beans.get(AccountConfigService.class); AccountConfig accountConfig = accountConfigService.getAccountConfig(invoice.getCompany()); + switch (invoice.getOperationTypeSelect()) { + case InvoiceRepository.OPERATION_TYPE_SUPPLIER_PURCHASE: + return accountConfigService.getSuppInvSequence(accountConfig); + case InvoiceRepository.OPERATION_TYPE_SUPPLIER_REFUND: + return accountConfigService.getSuppRefSequence(accountConfig); + + case InvoiceRepository.OPERATION_TYPE_CLIENT_SALE: return accountConfigService.getCustInvSequence(accountConfig); - + case InvoiceRepository.OPERATION_TYPE_CLIENT_REFUND: + return accountConfigService.getCustRefSequence(accountConfig); + + default: + throw new AxelorException( + invoice, + TraceBackRepository.CATEGORY_MISSING_FIELD, + I18n.get("Invoice type missing %s"), + invoice.getInvoiceId()); + } + } }