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);
}
}
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);
}
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);
}
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));
}
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;
}
Aggregations