use of com.axelor.apps.base.db.Address in project axelor-open-suite by axelor.
the class PurchaseOrderStockServiceImpl method createStockMove.
protected List<Long> createStockMove(PurchaseOrder purchaseOrder, LocalDate estimatedDeliveryDate, List<PurchaseOrderLine> purchaseOrderLineList) throws AxelorException {
List<Long> stockMoveIdList = new ArrayList<>();
Partner supplierPartner = purchaseOrder.getSupplierPartner();
Company company = purchaseOrder.getCompany();
Address address = Beans.get(PartnerService.class).getDeliveryAddress(supplierPartner);
StockLocation startLocation = getStartStockLocation(purchaseOrder);
StockMove stockMove = stockMoveService.createStockMove(address, null, company, supplierPartner, startLocation, purchaseOrder.getStockLocation(), null, estimatedDeliveryDate, purchaseOrder.getNotes(), purchaseOrder.getShipmentMode(), purchaseOrder.getFreightCarrierMode(), null, null, null, StockMoveRepository.TYPE_INCOMING);
StockMove qualityStockMove = stockMoveService.createStockMove(address, null, company, supplierPartner, startLocation, appBaseService.getAppBase().getEnableTradingNamesManagement() ? purchaseOrder.getTradingName().getQualityControlDefaultStockLocation() : company.getStockConfig().getQualityControlDefaultStockLocation(), null, estimatedDeliveryDate, purchaseOrder.getNotes(), purchaseOrder.getShipmentMode(), purchaseOrder.getFreightCarrierMode(), null, null, null, StockMoveRepository.TYPE_INCOMING);
stockMove.setOriginId(purchaseOrder.getId());
stockMove.setOriginTypeSelect(StockMoveRepository.ORIGIN_PURCHASE_ORDER);
stockMove.setOrigin(purchaseOrder.getPurchaseOrderSeq());
stockMove.setTradingName(purchaseOrder.getTradingName());
stockMove.setGroupProductsOnPrintings(purchaseOrder.getGroupProductsOnPrintings());
qualityStockMove.setOriginId(purchaseOrder.getId());
qualityStockMove.setOriginTypeSelect(StockMoveRepository.ORIGIN_PURCHASE_ORDER);
qualityStockMove.setOrigin(purchaseOrder.getPurchaseOrderSeq());
qualityStockMove.setTradingName(purchaseOrder.getTradingName());
qualityStockMove.setGroupProductsOnPrintings(purchaseOrder.getGroupProductsOnPrintings());
SupplyChainConfig supplychainConfig = Beans.get(SupplyChainConfigService.class).getSupplyChainConfig(purchaseOrder.getCompany());
if (supplychainConfig.getDefaultEstimatedDateForPurchaseOrder() == SupplyChainConfigRepository.CURRENT_DATE && stockMove.getEstimatedDate() == null) {
stockMove.setEstimatedDate(appBaseService.getTodayDate(company));
} else if (supplychainConfig.getDefaultEstimatedDateForPurchaseOrder() == SupplyChainConfigRepository.CURRENT_DATE_PLUS_DAYS && stockMove.getEstimatedDate() == null) {
stockMove.setEstimatedDate(appBaseService.getTodayDate(company).plusDays(supplychainConfig.getNumberOfDaysForPurchaseOrder().longValue()));
}
for (PurchaseOrderLine purchaseOrderLine : purchaseOrderLineList) {
BigDecimal qty = purchaseOrderLineServiceSupplychainImpl.computeUndeliveredQty(purchaseOrderLine);
if (qty.signum() > 0 && !existActiveStockMoveForPurchaseOrderLine(purchaseOrderLine)) {
this.createStockMoveLine(stockMove, qualityStockMove, purchaseOrderLine, qty);
}
}
if (stockMove.getStockMoveLineList() != null && !stockMove.getStockMoveLineList().isEmpty()) {
stockMoveService.plan(stockMove);
stockMoveIdList.add(stockMove.getId());
}
if (qualityStockMove.getStockMoveLineList() != null && !qualityStockMove.getStockMoveLineList().isEmpty()) {
stockMoveService.plan(qualityStockMove);
stockMoveIdList.add(qualityStockMove.getId());
}
return stockMoveIdList;
}
use of com.axelor.apps.base.db.Address in project axelor-open-suite by axelor.
the class ImportAddress method importAddress.
public Object importAddress(Object bean, Map<String, Object> values) {
Address address = (Address) bean;
address.setFullName(addressService.computeFullName(address));
address.setZip(addressService.getZipCode(address));
return address;
}
use of com.axelor.apps.base.db.Address in project axelor-open-suite by axelor.
the class EmploymentContractService method employmentContractExportSilae.
public void employmentContractExportSilae(EmploymentContract employmentContract, List<String[]> list) {
String[] item = new String[21];
item[0] = employmentContract.getId().toString();
item[1] = employmentContract.getStartDate() == null ? "" : employmentContract.getStartDate().toString();
item[2] = employmentContract.getEndDate() == null ? "" : employmentContract.getEndDate().toString();
Employee employee = employmentContract.getEmployee();
item[4] = employee.getMaritalName();
Partner contactPartner = employee.getContactPartner();
if (contactPartner != null) {
item[3] = contactPartner.getName();
item[5] = contactPartner.getFirstName();
Address mainAddress = contactPartner.getMainAddress();
if (mainAddress != null) {
item[6] = mainAddress.getAddressL4();
item[7] = mainAddress.getAddressL2();
item[8] = mainAddress.getZip();
if (mainAddress.getCity() != null) {
item[9] = mainAddress.getCity().getName();
} else {
item[9] = "";
}
}
item[10] = contactPartner.getMobilePhone();
item[11] = contactPartner.getFixedPhone();
item[12] = contactPartner.getEmailAddress() == null ? "" : contactPartner.getEmailAddress().getAddress();
}
item[13] = employee.getBirthDate() == null ? "" : employee.getBirthDate().toString();
Department birthDepartment = employee.getDepartmentOfBirth();
if (birthDepartment != null) {
item[14] = birthDepartment.getName();
item[16] = !birthDepartment.getCode().equals("99") ? "FR - FRANCE" : "Oui";
}
item[15] = employee.getCityOfBirth() == null ? "" : employee.getCityOfBirth().getName();
item[17] = employee.getSocialSecurityNumber();
item[18] = employmentContract.getPayCompany().getName();
item[19] = employmentContract.getContractType() == null ? "" : employmentContract.getContractType().getId().toString();
item[20] = employee.getMaidenName();
list.add(item);
}
use of com.axelor.apps.base.db.Address in project axelor-open-suite by axelor.
the class OpportunityServiceImpl method createClientFromLead.
@Override
@Transactional(rollbackOn = { Exception.class })
public Partner createClientFromLead(Opportunity opportunity) throws AxelorException {
Lead lead = opportunity.getLead();
if (lead == null) {
throw new AxelorException(opportunity, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.LEAD_PARTNER));
}
String name = lead.getFullName();
Address address = null;
if (lead.getPrimaryAddress() != null) {
// avoids printing 'null'
String addressL6 = lead.getPrimaryPostalCode() == null ? "" : lead.getPrimaryPostalCode() + " ";
addressL6 += lead.getPrimaryCity() == null ? "" : lead.getPrimaryCity().getName();
address = addressService.createAddress(null, null, lead.getPrimaryAddress(), null, addressL6, lead.getPrimaryCountry());
address.setFullName(addressService.computeFullName(address));
}
EmailAddress email = null;
if (lead.getEmailAddress() != null) {
email = new EmailAddress(lead.getEmailAddress().getAddress());
}
Partner partner = Beans.get(PartnerService.class).createPartner(name, null, lead.getFixedPhone(), lead.getMobilePhone(), email, opportunity.getCurrency(), address, address, true);
opportunity.setPartner(partner);
opportunityRepo.save(opportunity);
return partner;
}
use of com.axelor.apps.base.db.Address in project axelor-open-suite by axelor.
the class StockMoveMultiInvoiceServiceImpl method createInvoiceFromMultiOutgoingStockMove.
@Override
@Transactional(rollbackOn = { Exception.class })
public Optional<Invoice> createInvoiceFromMultiOutgoingStockMove(List<StockMove> stockMoveList) throws AxelorException {
if (stockMoveList == null || stockMoveList.isEmpty()) {
return Optional.empty();
}
Set<Address> deliveryAddressSet = new HashSet<>();
// create dummy invoice from the first stock move
Invoice dummyInvoice = createDummyOutInvoice(stockMoveList.get(0));
// Check if field constraints are respected
for (StockMove stockMove : stockMoveList) {
completeInvoiceInMultiOutgoingStockMove(dummyInvoice, stockMove);
if (stockMove.getToAddressStr() != null) {
deliveryAddressSet.add(stockMove.getToAddress());
}
}
/* check if some other fields are different and assign a default value */
if (dummyInvoice.getAddress() == null) {
dummyInvoice.setAddress(Beans.get(PartnerService.class).getInvoicingAddress(dummyInvoice.getPartner()));
dummyInvoice.setAddressStr(Beans.get(AddressService.class).computeAddressStr(dummyInvoice.getAddress()));
}
fillReferenceInvoiceFromMultiOutStockMove(stockMoveList, dummyInvoice);
InvoiceGenerator invoiceGenerator = new InvoiceGenerator(InvoiceRepository.OPERATION_TYPE_CLIENT_SALE, dummyInvoice.getCompany(), dummyInvoice.getPaymentCondition(), dummyInvoice.getPaymentMode(), dummyInvoice.getAddress(), dummyInvoice.getPartner(), dummyInvoice.getContactPartner(), dummyInvoice.getCurrency(), dummyInvoice.getPriceList(), dummyInvoice.getInternalReference(), dummyInvoice.getExternalReference(), dummyInvoice.getInAti(), null, dummyInvoice.getTradingName(), dummyInvoice.getGroupProductsOnPrintings()) {
@Override
public Invoice generate() throws AxelorException {
Invoice invoice = super.createInvoiceHeader();
invoice.setPartnerTaxNbr(partner.getTaxNbr());
return invoice;
}
};
Invoice invoice = invoiceGenerator.generate();
invoice.setAddressStr(dummyInvoice.getAddressStr());
StringBuilder deliveryAddressStr = new StringBuilder();
AddressService addressService = Beans.get(AddressService.class);
for (Address address : deliveryAddressSet) {
deliveryAddressStr.append(addressService.computeAddressStr(address).replaceAll("\n", ", ") + "\n");
}
invoice.setDeliveryAddressStr(deliveryAddressStr.toString());
List<InvoiceLine> invoiceLineList = new ArrayList<>();
for (StockMove stockMoveLocal : stockMoveList) {
stockMoveInvoiceService.checkSplitSalePartiallyInvoicedStockMoveLines(stockMoveLocal, stockMoveLocal.getStockMoveLineList());
List<InvoiceLine> createdInvoiceLines = stockMoveInvoiceService.createInvoiceLines(invoice, stockMoveLocal, stockMoveLocal.getStockMoveLineList(), null);
if (stockMoveLocal.getTypeSelect() == StockMoveRepository.TYPE_INCOMING) {
createdInvoiceLines.forEach(this::negateInvoiceLinePrice);
}
invoiceLineList.addAll(createdInvoiceLines);
}
invoiceGenerator.populate(invoice, invoiceLineList);
invoiceRepository.save(invoice);
invoice = toPositivePriceInvoice(invoice);
if (invoice.getExTaxTotal().signum() == 0 && stockMoveList.stream().allMatch(StockMove::getIsReversion)) {
invoice.setOperationTypeSelect(InvoiceRepository.OPERATION_TYPE_CLIENT_REFUND);
}
stockMoveList.forEach(invoice::addStockMoveSetItem);
return Optional.of(invoice);
}
Aggregations