From 1030d2179926ff947576ebff1b0eae0e1b53f6fa Mon Sep 17 00:00:00 2001 From: walid seghier Date: Thu, 10 Nov 2022 12:21:58 +0100 Subject: [PATCH] set Default Purchase Journal for Supplier --- .../apps/account/web/InvoiceController.java | 34 +++++++++++++++++++ .../main/resources/domains/AccountConfig.xml | 4 ++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/modules/axelor-open-suite/axelor-account/src/main/java/com/axelor/apps/account/web/InvoiceController.java b/modules/axelor-open-suite/axelor-account/src/main/java/com/axelor/apps/account/web/InvoiceController.java index a4c20c9..a4b4077 100644 --- a/modules/axelor-open-suite/axelor-account/src/main/java/com/axelor/apps/account/web/InvoiceController.java +++ b/modules/axelor-open-suite/axelor-account/src/main/java/com/axelor/apps/account/web/InvoiceController.java @@ -23,6 +23,7 @@ import com.axelor.apps.account.db.InvoicePayment; import com.axelor.apps.account.db.PaymentCondition; import com.axelor.apps.account.db.PaymentMode; import com.axelor.apps.account.db.PaymentVoucher; +import com.axelor.apps.account.db.Journal; import com.axelor.apps.account.db.repo.InvoiceRepository; import com.axelor.apps.account.exception.IExceptionMessage; import com.axelor.apps.account.service.AccountingSituationService; @@ -36,6 +37,7 @@ import com.axelor.apps.base.db.BankDetails; 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.PartnerCategory; import com.axelor.apps.base.db.PriceList; import com.axelor.apps.base.db.PrintingSettings; import com.axelor.apps.base.db.Wizard; @@ -1013,5 +1015,37 @@ public class InvoiceController { response.setView(ActionView.define(name).add("html", fileLink).map()); } + + + /** + * set default value for automatic invoice Journal = supplier Purchase Journal + * + * @param request + * @param response + * @throws AxelorException + */ + public void setDefaultJournalSupplier(ActionRequest request, ActionResponse response) { + Invoice invoice = request.getContext().asType(Invoice.class); + Company company = invoice.getCompany(); + Partner partner = invoice.getPartner(); + PartnerCategory partnerCategory = partner.getPartnerCategory(); + Journal journal = null ; + Integer operationTypeSelect = invoice.getOperationTypeSelect(); + + if (company != null && partner != null && operationTypeSelect != null ) { + if (operationTypeSelect.intValue() == InvoiceRepository.OPERATION_TYPE_SUPPLIER_PURCHASE) { + if( partnerCategory != null){ + if(partnerCategory.getCode().equals("FRETG")){ + journal = company.getAccountConfig().getSupplierPurchaseJournalForeigners(); + } + if(partnerCategory.getCode().equals("FRLOC")){ + journal = company.getAccountConfig().getSupplierPurchaseJournalLocal(); + } + } + response.setValue("journal", journal); + } + } + + } } 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 efeb455..fe427f2 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 @@ -27,7 +27,9 @@ - + + +