Search in sources :

Example 46 with Partner

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

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

the class SyncContactService method updateSyncContact.

@Transactional(rollbackOn = { AxelorException.class, Exception.class })
public void updateSyncContact(Long id, SyncContactHistoric syncContactHistoric) {
    SyncContact syncContact;
    syncContact = syncContactRepo.find(id);
    syncContactHistoric.setUser(userService.getUser());
    Set<Partner> partnerSet = new HashSet<>();
    for (Partner partner : syncContactHistoric.getPartnerSet()) {
        Partner find = partnerRepo.find(partner.getId());
        if (find != null) {
            partnerSet.add(find);
        }
    }
    syncContactHistoric.clearPartnerSet();
    syncContactHistoric.setPartnerSet(partnerSet);
    syncContact.addSyncContactHistoricListItem(syncContactHistoric);
    syncContactRepo.save(syncContact);
}
Also used : SyncContact(com.axelor.apps.base.db.SyncContact) Partner(com.axelor.apps.base.db.Partner) HashSet(java.util.HashSet) Transactional(com.google.inject.persist.Transactional)

Example 48 with Partner

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

the class SyncContactService method importAllContact.

public void importAllContact(Long id, List<Person> people) {
    int i = 0;
    SyncContact syncContact = syncContactRepo.find(id);
    if (syncContact == null) {
        return;
    }
    SyncContactHistoric syncContactHistoric = new SyncContactHistoric();
    for (Person googlePerson : people) {
        Partner partner = importContact(googlePerson, syncContact.getUpdateContactField());
        if (partner != null) {
            syncContactHistoric.addPartnerSetItem(partner);
        }
        if (i % 10 == 0) {
            JPA.clear();
        }
        i++;
    }
    updateSyncContact(id, syncContactHistoric);
}
Also used : SyncContactHistoric(com.axelor.apps.base.db.SyncContactHistoric) SyncContact(com.axelor.apps.base.db.SyncContact) Person(com.google.api.services.people.v1.model.Person) Partner(com.axelor.apps.base.db.Partner)

Example 49 with Partner

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

the class CompanyBankDetailsController method fillCompanyBankDetailsDomain.

/**
 * Set the domain of company bank details field
 *
 * @param request
 * @param response
 * @throws AxelorException
 */
public void fillCompanyBankDetailsDomain(ActionRequest request, ActionResponse response) throws AxelorException {
    Partner partner = (Partner) request.getContext().get("partner");
    Company company = (Company) request.getContext().get("company");
    PaymentMode paymentMode = (PaymentMode) request.getContext().get("paymentMode");
    Integer operationTypeSelect = null;
    if (request.getContext().get("_operationTypeSelect") != null) {
        operationTypeSelect = Integer.valueOf(request.getContext().get("_operationTypeSelect").toString());
    }
    response.setAttr("companyBankDetails", "domain", Beans.get(BankDetailsServiceImpl.class).createCompanyBankDetailsDomain(partner, company, paymentMode, operationTypeSelect));
}
Also used : Company(com.axelor.apps.base.db.Company) Partner(com.axelor.apps.base.db.Partner) PaymentMode(com.axelor.apps.account.db.PaymentMode)

Example 50 with Partner

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

the class ExpenseServiceImpl method createAndSetMove.

protected Move createAndSetMove(Expense expense) throws AxelorException {
    LocalDate moveDate = expense.getMoveDate();
    if (moveDate == null) {
        moveDate = appAccountService.getTodayDate(expense.getCompany());
        expense.setMoveDate(moveDate);
    }
    Company company = expense.getCompany();
    Partner partner = expense.getUser().getPartner();
    Account account = null;
    AccountConfig accountConfig = accountConfigService.getAccountConfig(company);
    if (partner == null) {
        throw new AxelorException(expense, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(com.axelor.apps.account.exception.IExceptionMessage.USER_PARTNER), expense.getUser().getName());
    }
    Move move = moveService.getMoveCreateService().createMove(accountConfigService.getExpenseJournal(accountConfig), company, null, partner, moveDate, partner.getInPaymentMode(), MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_PURCHASE);
    List<MoveLine> moveLines = new ArrayList<>();
    Set<AnalyticAccount> analyticAccounts = new HashSet<>();
    BigDecimal exTaxTotal = null;
    int moveLineId = 1;
    int expenseLineId = 1;
    Account employeeAccount = accountingSituationService.getEmployeeAccount(partner, company);
    moveLines.add(moveLineService.createMoveLine(move, partner, employeeAccount, expense.getInTaxTotal(), false, moveDate, moveDate, moveLineId++, expense.getExpenseSeq(), expense.getFullName()));
    for (ExpenseLine expenseLine : getExpenseLineList(expense)) {
        analyticAccounts.clear();
        Product product = expenseLine.getExpenseProduct();
        account = accountManagementService.getProductAccount(product, company, partner.getFiscalPosition(), true, false);
        if (account == null) {
            throw new AxelorException(expense, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(com.axelor.apps.account.exception.IExceptionMessage.MOVE_LINE_4), expenseLineId, company.getName());
        }
        exTaxTotal = expenseLine.getUntaxedAmount();
        MoveLine moveLine = moveLineService.createMoveLine(move, partner, account, exTaxTotal, true, moveDate, moveDate, moveLineId++, expense.getExpenseSeq(), expenseLine.getComments() != null ? expenseLine.getComments().replaceAll("(\r\n|\n\r|\r|\n)", " ") : "");
        for (AnalyticMoveLine analyticDistributionLineIt : expenseLine.getAnalyticMoveLineList()) {
            AnalyticMoveLine analyticDistributionLine = Beans.get(AnalyticMoveLineRepository.class).copy(analyticDistributionLineIt, false);
            analyticDistributionLine.setExpenseLine(null);
            moveLine.addAnalyticMoveLineListItem(analyticDistributionLine);
        }
        moveLines.add(moveLine);
        expenseLineId++;
    }
    moveLineService.consolidateMoveLines(moveLines);
    account = accountConfigService.getExpenseTaxAccount(accountConfig);
    BigDecimal taxTotal = BigDecimal.ZERO;
    for (ExpenseLine expenseLine : getExpenseLineList(expense)) {
        exTaxTotal = expenseLine.getTotalTax();
        taxTotal = taxTotal.add(exTaxTotal);
    }
    if (taxTotal.signum() != 0) {
        MoveLine moveLine = moveLineService.createMoveLine(move, partner, account, taxTotal, true, moveDate, moveDate, moveLineId++, expense.getExpenseSeq(), expense.getFullName());
        moveLines.add(moveLine);
    }
    move.getMoveLineList().addAll(moveLines);
    moveService.getMoveValidateService().validate(move);
    expense.setMove(move);
    return move;
}
Also used : AnalyticAccount(com.axelor.apps.account.db.AnalyticAccount) Account(com.axelor.apps.account.db.Account) AxelorException(com.axelor.exception.AxelorException) Company(com.axelor.apps.base.db.Company) ArrayList(java.util.ArrayList) Product(com.axelor.apps.base.db.Product) AnalyticAccount(com.axelor.apps.account.db.AnalyticAccount) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) AccountConfig(com.axelor.apps.account.db.AccountConfig) AnalyticMoveLineRepository(com.axelor.apps.account.db.repo.AnalyticMoveLineRepository) Move(com.axelor.apps.account.db.Move) MoveLine(com.axelor.apps.account.db.MoveLine) AnalyticMoveLine(com.axelor.apps.account.db.AnalyticMoveLine) ExpenseLine(com.axelor.apps.hr.db.ExpenseLine) Partner(com.axelor.apps.base.db.Partner) HashSet(java.util.HashSet) AnalyticMoveLine(com.axelor.apps.account.db.AnalyticMoveLine)

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