Search in sources :

Example 96 with Partner

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

the class SaleOrderSupplychainRepository method remove.

@Override
public void remove(SaleOrder order) {
    Partner partner = order.getClientPartner();
    super.remove(order);
    try {
        Beans.get(AccountingSituationSupplychainService.class).updateUsedCredit(partner);
    } catch (AxelorException e) {
        e.printStackTrace();
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) AccountingSituationSupplychainService(com.axelor.apps.supplychain.service.AccountingSituationSupplychainService) Partner(com.axelor.apps.base.db.Partner)

Example 97 with Partner

use of com.axelor.apps.base.db.Partner 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)

Example 98 with Partner

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

the class CampaignController method markPartnerPresent.

public void markPartnerPresent(ActionRequest request, ActionResponse response) {
    Campaign campaign = request.getContext().getParent().asType(Campaign.class);
    Partner partner = request.getContext().asType(Partner.class);
    partner = Beans.get(PartnerRepository.class).find(partner.getId());
    try {
        Beans.get(CampaignService.class).markPartnerPresent(Beans.get(CampaignRepository.class).find(campaign.getId()), partner);
        response.setReload(true);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : CampaignService(com.axelor.apps.marketing.service.CampaignService) Campaign(com.axelor.apps.marketing.db.Campaign) Partner(com.axelor.apps.base.db.Partner)

Example 99 with Partner

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

the class SaleOrderServiceSupplychainImpl method getClientInformations.

public SaleOrder getClientInformations(SaleOrder saleOrder) {
    Partner client = saleOrder.getClientPartner();
    PartnerService partnerService = Beans.get(PartnerService.class);
    if (client != null) {
        saleOrder.setPaymentCondition(client.getPaymentCondition());
        saleOrder.setPaymentMode(client.getInPaymentMode());
        saleOrder.setMainInvoicingAddress(partnerService.getInvoicingAddress(client));
        this.computeAddressStr(saleOrder);
        saleOrder.setDeliveryAddress(partnerService.getDeliveryAddress(client));
        saleOrder.setPriceList(Beans.get(PartnerPriceListService.class).getDefaultPriceList(client, PriceListRepository.TYPE_SALE));
    }
    return saleOrder;
}
Also used : PartnerService(com.axelor.apps.base.service.PartnerService) Partner(com.axelor.apps.base.db.Partner)

Example 100 with Partner

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

the class SaleOrderServiceSupplychainImpl method setDefaultInvoicedAndDeliveredPartners.

protected void setDefaultInvoicedAndDeliveredPartners(SaleOrder saleOrder, Partner clientPartner) {
    if (!CollectionUtils.isEmpty(clientPartner.getPartner1SupplychainLinkList())) {
        List<PartnerSupplychainLink> partnerSupplychainLinkList = clientPartner.getPartner1SupplychainLinkList();
        // Retrieve all Invoiced by Type
        List<PartnerSupplychainLink> partnerSupplychainLinkInvoicedByList = partnerSupplychainLinkList.stream().filter(partnerSupplychainLink -> PartnerSupplychainLinkTypeRepository.TYPE_SELECT_INVOICED_BY.equals(partnerSupplychainLink.getPartnerSupplychainLinkType().getTypeSelect())).collect(Collectors.toList());
        // Retrieve all Delivered by Type
        List<PartnerSupplychainLink> partnerSupplychainLinkDeliveredByList = partnerSupplychainLinkList.stream().filter(partnerSupplychainLink -> PartnerSupplychainLinkTypeRepository.TYPE_SELECT_DELIVERED_BY.equals(partnerSupplychainLink.getPartnerSupplychainLinkType().getTypeSelect())).collect(Collectors.toList());
        // If there is only one, then it is the default one
        if (partnerSupplychainLinkInvoicedByList.size() == 1) {
            PartnerSupplychainLink partnerSupplychainLinkInvoicedBy = partnerSupplychainLinkInvoicedByList.get(0);
            saleOrder.setInvoicedPartner(partnerSupplychainLinkInvoicedBy.getPartner2());
        } else if (partnerSupplychainLinkInvoicedByList.size() == 0) {
            saleOrder.setInvoicedPartner(clientPartner);
        } else {
            saleOrder.setInvoicedPartner(null);
        }
        if (partnerSupplychainLinkDeliveredByList.size() == 1) {
            PartnerSupplychainLink partnerSupplychainLinkDeliveredBy = partnerSupplychainLinkDeliveredByList.get(0);
            saleOrder.setDeliveredPartner(partnerSupplychainLinkDeliveredBy.getPartner2());
        } else if (partnerSupplychainLinkDeliveredByList.size() == 0) {
            saleOrder.setDeliveredPartner(clientPartner);
        } else {
            saleOrder.setDeliveredPartner(null);
        }
    } else {
        saleOrder.setInvoicedPartner(clientPartner);
        saleOrder.setDeliveredPartner(clientPartner);
    }
}
Also used : IExceptionMessage(com.axelor.apps.supplychain.exception.IExceptionMessage) PartnerService(com.axelor.apps.base.service.PartnerService) PartnerSupplychainLink(com.axelor.apps.supplychain.db.PartnerSupplychainLink) Inject(com.google.inject.Inject) LoggerFactory(org.slf4j.LoggerFactory) StockMoveService(com.axelor.apps.stock.service.StockMoveService) AddressService(com.axelor.apps.base.service.AddressService) Transactional(com.google.inject.persist.Transactional) ArrayList(java.util.ArrayList) SaleOrderLineRepository(com.axelor.apps.sale.db.repo.SaleOrderLineRepository) BigDecimal(java.math.BigDecimal) SaleOrderRepository(com.axelor.apps.sale.db.repo.SaleOrderRepository) AppSupplychain(com.axelor.apps.base.db.AppSupplychain) AxelorException(com.axelor.exception.AxelorException) CollectionUtils(org.apache.commons.collections.CollectionUtils) CancelReason(com.axelor.apps.base.db.CancelReason) I18n(com.axelor.i18n.I18n) SaleOrder(com.axelor.apps.sale.db.SaleOrder) CustomerShippingCarriagePaid(com.axelor.apps.supplychain.db.CustomerShippingCarriagePaid) PartnerSupplychainLinkTypeRepository(com.axelor.apps.supplychain.db.repo.PartnerSupplychainLinkTypeRepository) Logger(org.slf4j.Logger) TraceBackRepository(com.axelor.exception.db.repo.TraceBackRepository) StockMove(com.axelor.apps.stock.db.StockMove) StockMoveRepository(com.axelor.apps.stock.db.repo.StockMoveRepository) Timetable(com.axelor.apps.supplychain.db.Timetable) MethodHandles(java.lang.invoke.MethodHandles) PartnerPriceListService(com.axelor.apps.base.service.PartnerPriceListService) SaleOrderLineService(com.axelor.apps.sale.service.saleorder.SaleOrderLineService) MoreObjects(com.google.common.base.MoreObjects) PartnerRepository(com.axelor.apps.base.db.repo.PartnerRepository) ShipmentMode(com.axelor.apps.stock.db.ShipmentMode) SaleOrderComputeService(com.axelor.apps.sale.service.saleorder.SaleOrderComputeService) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) Collectors(java.util.stream.Collectors) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) List(java.util.List) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) Beans(com.axelor.inject.Beans) Product(com.axelor.apps.base.db.Product) SaleOrderServiceImpl(com.axelor.apps.sale.service.saleorder.SaleOrderServiceImpl) Optional(java.util.Optional) AppSupplychainService(com.axelor.apps.supplychain.service.app.AppSupplychainService) Partner(com.axelor.apps.base.db.Partner) Collections(java.util.Collections) PriceListRepository(com.axelor.apps.base.db.repo.PriceListRepository) SaleOrderMarginService(com.axelor.apps.sale.service.saleorder.SaleOrderMarginService) PartnerSupplychainLink(com.axelor.apps.supplychain.db.PartnerSupplychainLink)

Aggregations

Partner (com.axelor.apps.base.db.Partner)199 AxelorException (com.axelor.exception.AxelorException)68 Company (com.axelor.apps.base.db.Company)67 Transactional (com.google.inject.persist.Transactional)54 BigDecimal (java.math.BigDecimal)43 ArrayList (java.util.ArrayList)34 MoveLine (com.axelor.apps.account.db.MoveLine)32 Move (com.axelor.apps.account.db.Move)30 PaymentMode (com.axelor.apps.account.db.PaymentMode)26 LocalDate (java.time.LocalDate)26 Account (com.axelor.apps.account.db.Account)25 Invoice (com.axelor.apps.account.db.Invoice)24 BankDetails (com.axelor.apps.base.db.BankDetails)24 List (java.util.List)22 PartnerService (com.axelor.apps.base.service.PartnerService)18 Map (java.util.Map)18 Journal (com.axelor.apps.account.db.Journal)17 Address (com.axelor.apps.base.db.Address)14 Currency (com.axelor.apps.base.db.Currency)14 AccountConfig (com.axelor.apps.account.db.AccountConfig)13