Search in sources :

Example 1 with PartnerService

use of com.axelor.apps.base.service.PartnerService in project axelor-open-suite by axelor.

the class AddressController method createPartnerAddress.

public void createPartnerAddress(ActionRequest request, ActionResponse response) {
    Context context = request.getContext();
    Context parentContext = context.getParent();
    if (parentContext.isEmpty()) {
        return;
    }
    String parentModel = (String) parentContext.get("_model");
    LOG.debug("Create partner address : Parent model = {}", parentModel);
    String partnerField = PartnerAddressRepository.modelPartnerFieldMap.get(parentModel);
    LOG.debug("Create partner address : Parent field = {}", partnerField);
    Partner partner = null;
    if (parentContext.get(partnerField) instanceof Partner) {
        partner = (Partner) parentContext.get(partnerField);
    } else if (parentContext.get(partnerField) instanceof Map) {
        partner = Mapper.toBean(Partner.class, (Map<String, Object>) parentContext.get(partnerField));
    }
    LOG.debug("Create partner address : Partner = {}", partner);
    if (partner == null || partner.getId() == null) {
        return;
    }
    Address address = context.asType(Address.class);
    PartnerAddress partnerAddress = Beans.get(PartnerAddressRepository.class).all().filter("self.partner.id = ? AND self.address.id = ?", partner.getId(), address.getId()).fetchOne();
    LOG.debug("Create partner address : Partner Address = {}", partnerAddress);
    if (partnerAddress == null) {
        partner = Beans.get(PartnerRepository.class).find(partner.getId());
        address = Beans.get(AddressRepository.class).find(address.getId());
        Boolean invoicing = (Boolean) context.get("isInvoicingAddr");
        if (invoicing == null) {
            invoicing = false;
        }
        Boolean delivery = (Boolean) context.get("isDeliveryAddr");
        if (delivery == null) {
            delivery = false;
        }
        Boolean isDefault = (Boolean) context.get("isDefault");
        if (isDefault == null) {
            isDefault = false;
        }
        PartnerService partnerService = Beans.get(PartnerService.class);
        partnerService.addPartnerAddress(partner, address, isDefault, invoicing, delivery);
        partnerService.savePartner(partner);
    }
}
Also used : Context(com.axelor.rpc.Context) PartnerAddressRepository(com.axelor.apps.base.db.repo.PartnerAddressRepository) PartnerAddress(com.axelor.apps.base.db.PartnerAddress) Address(com.axelor.apps.base.db.Address) PartnerAddress(com.axelor.apps.base.db.PartnerAddress) PartnerService(com.axelor.apps.base.service.PartnerService) Partner(com.axelor.apps.base.db.Partner) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with PartnerService

use of com.axelor.apps.base.service.PartnerService in project axelor-open-suite by axelor.

the class PartnerController method checkPartnerName.

/**
 * Called from partner view on name change and onLoad. Call {@link
 * PartnerService#isThereDuplicatePartner(Partner)}
 *
 * @param request
 * @param response
 */
public void checkPartnerName(ActionRequest request, ActionResponse response) {
    try {
        Partner partner = request.getContext().asType(Partner.class);
        response.setAttr("duplicatePartnerText", "hidden", !Beans.get(PartnerService.class).isThereDuplicatePartner(partner));
    } catch (Exception e) {
        TraceBackService.trace(e);
    }
}
Also used : PartnerService(com.axelor.apps.base.service.PartnerService) Partner(com.axelor.apps.base.db.Partner) BirtException(org.eclipse.birt.core.exception.BirtException) IbanFormatException(org.iban4j.IbanFormatException) InvalidCheckDigitException(org.iban4j.InvalidCheckDigitException) AxelorException(com.axelor.exception.AxelorException) UnsupportedCountryException(org.iban4j.UnsupportedCountryException) IOException(java.io.IOException)

Example 3 with PartnerService

use of com.axelor.apps.base.service.PartnerService 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 4 with PartnerService

use of com.axelor.apps.base.service.PartnerService in project axelor-open-suite by axelor.

the class PartnerController method normalizePhoneNumber.

public void normalizePhoneNumber(ActionRequest request, ActionResponse response) {
    PartnerService partnerService = Beans.get(PartnerService.class);
    try {
        String phoneNumberFieldName = partnerService.getPhoneNumberFieldName(request.getAction());
        String phoneNumber = (String) request.getContext().get(phoneNumberFieldName);
        if (!StringUtils.isBlank(phoneNumber)) {
            String normalizedPhoneNumber = partnerService.normalizePhoneNumber(phoneNumber);
            if (!phoneNumber.equals(normalizedPhoneNumber)) {
                response.setValue(phoneNumberFieldName, normalizedPhoneNumber);
            }
            if (!partnerService.checkPhoneNumber(normalizedPhoneNumber)) {
                response.addError(phoneNumberFieldName, I18n.get("Invalid phone number"));
            }
        }
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : PartnerService(com.axelor.apps.base.service.PartnerService) BirtException(org.eclipse.birt.core.exception.BirtException) IbanFormatException(org.iban4j.IbanFormatException) InvalidCheckDigitException(org.iban4j.InvalidCheckDigitException) AxelorException(com.axelor.exception.AxelorException) UnsupportedCountryException(org.iban4j.UnsupportedCountryException) IOException(java.io.IOException)

Example 5 with PartnerService

use of com.axelor.apps.base.service.PartnerService in project axelor-open-suite by axelor.

the class IntercoServiceImpl method generateIntercoInvoice.

@Override
public Invoice generateIntercoInvoice(Invoice invoice) throws AxelorException {
    PartnerService partnerService = Beans.get(PartnerService.class);
    InvoiceRepository invoiceRepository = Beans.get(InvoiceRepository.class);
    InvoiceService invoiceService = Beans.get(InvoiceService.class);
    boolean isPurchase;
    // set the status
    int generatedOperationTypeSelect;
    int priceListRepositoryType;
    switch(invoice.getOperationTypeSelect()) {
        case InvoiceRepository.OPERATION_TYPE_SUPPLIER_PURCHASE:
            generatedOperationTypeSelect = InvoiceRepository.OPERATION_TYPE_CLIENT_SALE;
            priceListRepositoryType = PriceListRepository.TYPE_SALE;
            isPurchase = false;
            break;
        case InvoiceRepository.OPERATION_TYPE_SUPPLIER_REFUND:
            generatedOperationTypeSelect = InvoiceRepository.OPERATION_TYPE_CLIENT_REFUND;
            priceListRepositoryType = PriceListRepository.TYPE_SALE;
            isPurchase = false;
            break;
        case InvoiceRepository.OPERATION_TYPE_CLIENT_SALE:
            generatedOperationTypeSelect = InvoiceRepository.OPERATION_TYPE_SUPPLIER_PURCHASE;
            priceListRepositoryType = PriceListRepository.TYPE_PURCHASE;
            isPurchase = true;
            break;
        case InvoiceRepository.OPERATION_TYPE_CLIENT_REFUND:
            generatedOperationTypeSelect = InvoiceRepository.OPERATION_TYPE_SUPPLIER_REFUND;
            priceListRepositoryType = PriceListRepository.TYPE_PURCHASE;
            isPurchase = true;
            break;
        default:
            throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.INVOICE_MISSING_TYPE), invoice);
    }
    Company intercoCompany = findIntercoCompany(invoice.getPartner());
    Partner intercoPartner = invoice.getCompany().getPartner();
    PaymentMode intercoPaymentMode = Beans.get(PaymentModeService.class).reverseInOut(invoice.getPaymentMode());
    Address intercoAddress = partnerService.getInvoicingAddress(intercoPartner);
    BankDetails intercoBankDetails = partnerService.getDefaultBankDetails(intercoPartner);
    AccountingSituation accountingSituation = Beans.get(AccountingSituationService.class).getAccountingSituation(intercoPartner, intercoCompany);
    PriceList intercoPriceList = Beans.get(PartnerPriceListService.class).getDefaultPriceList(intercoPartner, priceListRepositoryType);
    Invoice intercoInvoice = invoiceRepository.copy(invoice, true);
    intercoInvoice.setOperationTypeSelect(generatedOperationTypeSelect);
    intercoInvoice.setCompany(intercoCompany);
    intercoInvoice.setPartner(intercoPartner);
    intercoInvoice.setAddress(intercoAddress);
    intercoInvoice.setAddressStr(Beans.get(AddressService.class).computeAddressStr(intercoAddress));
    intercoInvoice.setPaymentMode(intercoPaymentMode);
    intercoInvoice.setBankDetails(intercoBankDetails);
    Set<Invoice> invoices = invoiceService.getDefaultAdvancePaymentInvoice(intercoInvoice);
    intercoInvoice.setAdvancePaymentInvoiceSet(invoices);
    if (accountingSituation != null) {
        intercoInvoice.setInvoiceAutomaticMail(accountingSituation.getInvoiceAutomaticMail());
        intercoInvoice.setInvoiceMessageTemplate(accountingSituation.getInvoiceMessageTemplate());
        intercoInvoice.setPfpValidatorUser(accountingSituation.getPfpValidatorUser());
    }
    intercoInvoice.setPriceList(intercoPriceList);
    intercoInvoice.setInvoicesCopySelect((intercoPartner.getInvoicesCopySelect() == 0) ? DEFAULT_INVOICE_COPY : intercoPartner.getInvoicesCopySelect());
    intercoInvoice.setCreatedByInterco(true);
    intercoInvoice.setInterco(false);
    intercoInvoice.setPrintingSettings(intercoCompany.getPrintingSettings());
    if (intercoInvoice.getInvoiceLineList() != null) {
        for (InvoiceLine invoiceLine : intercoInvoice.getInvoiceLineList()) {
            invoiceLine.setInvoice(intercoInvoice);
            createIntercoInvoiceLine(invoiceLine, isPurchase);
        }
    }
    invoiceService.compute(intercoInvoice);
    intercoInvoice.setExternalReference(invoice.getInvoiceId());
    intercoInvoice = invoiceRepository.save(intercoInvoice);
    if (Beans.get(AppSupplychainService.class).getAppSupplychain().getIntercoInvoiceCreateValidated()) {
        Beans.get(InvoiceService.class).validate(intercoInvoice);
    }
    invoice.setExternalReference(intercoInvoice.getInvoiceId());
    return intercoInvoice;
}
Also used : AxelorException(com.axelor.exception.AxelorException) Company(com.axelor.apps.base.db.Company) PaymentModeService(com.axelor.apps.account.service.payment.PaymentModeService) Invoice(com.axelor.apps.account.db.Invoice) Address(com.axelor.apps.base.db.Address) PartnerPriceListService(com.axelor.apps.base.service.PartnerPriceListService) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) BankDetails(com.axelor.apps.base.db.BankDetails) InvoiceService(com.axelor.apps.account.service.invoice.InvoiceService) PartnerService(com.axelor.apps.base.service.PartnerService) AccountingSituation(com.axelor.apps.account.db.AccountingSituation) InvoiceRepository(com.axelor.apps.account.db.repo.InvoiceRepository) Partner(com.axelor.apps.base.db.Partner) PriceList(com.axelor.apps.base.db.PriceList) AccountingSituationService(com.axelor.apps.account.service.AccountingSituationService) PaymentMode(com.axelor.apps.account.db.PaymentMode)

Aggregations

PartnerService (com.axelor.apps.base.service.PartnerService)5 Partner (com.axelor.apps.base.db.Partner)4 AxelorException (com.axelor.exception.AxelorException)3 Address (com.axelor.apps.base.db.Address)2 IOException (java.io.IOException)2 BirtException (org.eclipse.birt.core.exception.BirtException)2 IbanFormatException (org.iban4j.IbanFormatException)2 InvalidCheckDigitException (org.iban4j.InvalidCheckDigitException)2 UnsupportedCountryException (org.iban4j.UnsupportedCountryException)2 AccountingSituation (com.axelor.apps.account.db.AccountingSituation)1 Invoice (com.axelor.apps.account.db.Invoice)1 InvoiceLine (com.axelor.apps.account.db.InvoiceLine)1 PaymentMode (com.axelor.apps.account.db.PaymentMode)1 InvoiceRepository (com.axelor.apps.account.db.repo.InvoiceRepository)1 AccountingSituationService (com.axelor.apps.account.service.AccountingSituationService)1 InvoiceService (com.axelor.apps.account.service.invoice.InvoiceService)1 PaymentModeService (com.axelor.apps.account.service.payment.PaymentModeService)1 BankDetails (com.axelor.apps.base.db.BankDetails)1 Company (com.axelor.apps.base.db.Company)1 PartnerAddress (com.axelor.apps.base.db.PartnerAddress)1