Search in sources :

Example 36 with Partner

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

the class CampaignServiceImpl method addNotParticipatingTargets.

@Override
@Transactional
public void addNotParticipatingTargets(Campaign campaign, Campaign campaignContext) {
    for (Partner partner : campaignContext.getInvitedPartnerSet()) {
        if (partner.isSelected()) {
            campaign.addNotParticipatingPartnerSetItem(partner);
            campaign.removeInvitedPartnerSetItem(partner);
        }
    }
    for (Lead lead : campaignContext.getInvitedLeadSet()) {
        if (lead.isSelected()) {
            campaign.addNotParticipatingLeadSetItem(lead);
            campaign.removeInvitedLeadSetItem(lead);
        }
    }
    Beans.get(CampaignRepository.class).save(campaign);
}
Also used : Lead(com.axelor.apps.crm.db.Lead) CampaignRepository(com.axelor.apps.marketing.db.repo.CampaignRepository) Partner(com.axelor.apps.base.db.Partner) Transactional(com.google.inject.persist.Transactional)

Example 37 with Partner

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

the class CampaignServiceImpl method inviteAllTargets.

@Override
@Transactional
public void inviteAllTargets(Campaign campaign) {
    Set<Partner> partners = campaign.getPartners();
    Set<Partner> notParticipatingPartnerSet = campaign.getNotParticipatingPartnerSet();
    for (Partner partner : campaign.getPartnerSet()) {
        if (!partners.contains(partner) && !notParticipatingPartnerSet.contains(partner)) {
            campaign.addInvitedPartnerSetItem(partner);
        }
    }
    Set<Lead> leads = campaign.getLeads();
    Set<Lead> notParticipatingLeadSet = campaign.getNotParticipatingLeadSet();
    for (Lead lead : campaign.getLeadSet()) {
        if (!leads.contains(lead) && !notParticipatingLeadSet.contains(lead)) {
            campaign.addInvitedLeadSetItem(lead);
        }
    }
    Beans.get(CampaignRepository.class).save(campaign);
}
Also used : Lead(com.axelor.apps.crm.db.Lead) CampaignRepository(com.axelor.apps.marketing.db.repo.CampaignRepository) Partner(com.axelor.apps.base.db.Partner) Transactional(com.google.inject.persist.Transactional)

Example 38 with Partner

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

the class ManufOrderWorkflowService method setPurchaseOrderSupplierDetails.

private PurchaseOrder setPurchaseOrderSupplierDetails(PurchaseOrder purchaseOrder) throws AxelorException {
    Partner supplierPartner = purchaseOrder.getSupplierPartner();
    if (supplierPartner != null) {
        purchaseOrder.setCurrency(supplierPartner.getCurrency());
        purchaseOrder.setShipmentMode(supplierPartner.getShipmentMode());
        purchaseOrder.setFreightCarrierMode(supplierPartner.getFreightCarrierMode());
        purchaseOrder.setNotes(supplierPartner.getPurchaseOrderComments());
        if (supplierPartner.getPaymentCondition() != null) {
            purchaseOrder.setPaymentCondition(supplierPartner.getPaymentCondition());
        } else {
            purchaseOrder.setPaymentCondition(purchaseOrder.getCompany().getAccountConfig().getDefPaymentCondition());
        }
        if (supplierPartner.getOutPaymentMode() != null) {
            purchaseOrder.setPaymentMode(supplierPartner.getOutPaymentMode());
        } else {
            purchaseOrder.setPaymentMode(purchaseOrder.getCompany().getAccountConfig().getOutPaymentMode());
        }
        if (supplierPartner.getContactPartnerSet().size() == 1) {
            purchaseOrder.setContactPartner(supplierPartner.getContactPartnerSet().iterator().next());
        }
        purchaseOrder.setCompanyBankDetails(Beans.get(BankDetailsService.class).getDefaultCompanyBankDetails(purchaseOrder.getCompany(), purchaseOrder.getPaymentMode(), purchaseOrder.getSupplierPartner(), null));
        purchaseOrder.setPriceList(Beans.get(PartnerPriceListService.class).getDefaultPriceList(purchaseOrder.getSupplierPartner(), PriceListRepository.TYPE_PURCHASE));
        if (Beans.get(AppSupplychainService.class).isApp("supplychain") && Beans.get(AppSupplychainService.class).getAppSupplychain().getIntercoFromPurchase() && !purchaseOrder.getCreatedByInterco() && (Beans.get(CompanyRepository.class).all().filter("self.partner = ?", supplierPartner).fetchOne() != null)) {
            purchaseOrder.setInterco(true);
        }
    }
    return purchaseOrder;
}
Also used : Partner(com.axelor.apps.base.db.Partner) AppSupplychainService(com.axelor.apps.supplychain.service.app.AppSupplychainService)

Example 39 with Partner

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

the class CostSheetLineServiceImpl method getComponentCostPrice.

protected BigDecimal getComponentCostPrice(Product product, int componentsValuationMethod, Company company) throws AxelorException {
    BigDecimal price = null;
    Currency companyCurrency = company.getCurrency();
    if (componentsValuationMethod == ProductRepository.COMPONENTS_VALUATION_METHOD_AVERAGE) {
        price = weightedAveragePriceService.computeAvgPriceForCompany(product, company);
        if (price == null || price.compareTo(BigDecimal.ZERO) == 0) {
            price = (BigDecimal) productCompanyService.get(product, "costPrice", company);
        }
    } else if (componentsValuationMethod == ProductRepository.COMPONENTS_VALUATION_METHOD_COST) {
        price = (BigDecimal) productCompanyService.get(product, "costPrice", company);
        if (price == null || price.compareTo(BigDecimal.ZERO) == 0) {
            price = weightedAveragePriceService.computeAvgPriceForCompany(product, company);
        }
    }
    if (product.getPurchasable() && (price == null || price.compareTo(BigDecimal.ZERO) == 0)) {
        price = (BigDecimal) productCompanyService.get(product, "purchasePrice", company);
        price = unitConversionService.convert(product.getUnit(), product.getPurchasesUnit() != null ? product.getPurchasesUnit() : product.getUnit(), price, appProductionService.getNbDecimalDigitForUnitPrice(), product);
        BigDecimal shippingCoef = shippingCoefService.getShippingCoef(product, (Partner) productCompanyService.get(product, "defaultSupplierPartner", company), company, new BigDecimal(9999999));
        price = price.multiply(shippingCoef);
        if (productCompanyService.get(product, "purchaseCurrency", company) == null) {
            throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.MISSING_PRODUCT_PURCHASE_CURRENCY), product.getFullName());
        }
        price = currencyService.getAmountCurrencyConvertedAtDate((Currency) productCompanyService.get(product, "purchaseCurrency", company), companyCurrency, price, appProductionService.getTodayDate(company));
        if (price == null || price.compareTo(BigDecimal.ZERO) == 0) {
            @SuppressWarnings("unchecked") List<SupplierCatalog> supplierCatalogList = (List<SupplierCatalog>) productCompanyService.get(product, "supplierCatalogList", company);
            for (SupplierCatalog supplierCatalog : supplierCatalogList) {
                if (BigDecimal.ZERO.compareTo(supplierCatalog.getPrice()) < 0) {
                    price = unitConversionService.convert(product.getUnit(), product.getPurchasesUnit() != null ? product.getPurchasesUnit() : product.getUnit(), supplierCatalog.getPrice(), appProductionService.getNbDecimalDigitForUnitPrice(), product);
                    Partner supplierPartner = supplierCatalog.getSupplierPartner();
                    if (supplierPartner != null) {
                        shippingCoef = shippingCoefService.getShippingCoef(product, supplierPartner, company, new BigDecimal(9999999));
                        price = price.multiply(shippingCoef);
                        price = currencyService.getAmountCurrencyConvertedAtDate(supplierPartner.getCurrency(), companyCurrency, price, appProductionService.getTodayDate(company));
                    }
                    break;
                }
            }
        }
    }
    return price;
}
Also used : AxelorException(com.axelor.exception.AxelorException) Currency(com.axelor.apps.base.db.Currency) SupplierCatalog(com.axelor.apps.purchase.db.SupplierCatalog) ArrayList(java.util.ArrayList) List(java.util.List) Partner(com.axelor.apps.base.db.Partner) BigDecimal(java.math.BigDecimal)

Example 40 with Partner

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

the class InvoiceController method fillCompanyBankDetails.

/**
 * Called on load and in partner, company or payment mode change. Fill the bank details with a
 * default value.
 *
 * @param request
 * @param response
 * @throws AxelorException
 */
public void fillCompanyBankDetails(ActionRequest request, ActionResponse response) throws AxelorException {
    Invoice invoice = request.getContext().asType(Invoice.class);
    PaymentMode paymentMode = invoice.getPaymentMode();
    Company company = invoice.getCompany();
    Partner partner = invoice.getPartner();
    if (company == null) {
        return;
    }
    if (partner != null) {
        partner = Beans.get(PartnerRepository.class).find(partner.getId());
    }
    BankDetails defaultBankDetails = Beans.get(BankDetailsService.class).getDefaultCompanyBankDetails(company, paymentMode, partner, invoice.getOperationTypeSelect());
    response.setValue("companyBankDetails", defaultBankDetails);
}
Also used : BankDetailsService(com.axelor.apps.base.service.BankDetailsService) Company(com.axelor.apps.base.db.Company) Invoice(com.axelor.apps.account.db.Invoice) BankDetails(com.axelor.apps.base.db.BankDetails) Partner(com.axelor.apps.base.db.Partner) PaymentMode(com.axelor.apps.account.db.PaymentMode)

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