Search in sources :

Example 36 with Company

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

the class OperationOrderStockMoveService method createToConsumeStockMove.

public void createToConsumeStockMove(OperationOrder operationOrder) throws AxelorException {
    Company company = operationOrder.getManufOrder().getCompany();
    if (operationOrder.getToConsumeProdProductList() != null && company != null) {
        StockMove stockMove = this._createToConsumeStockMove(operationOrder, company);
        stockMove.setOriginId(operationOrder.getId());
        stockMove.setOriginTypeSelect(StockMoveRepository.ORIGIN_OPERATION_ORDER);
        stockMove.setOrigin(operationOrder.getOperationName());
        for (ProdProduct prodProduct : operationOrder.getToConsumeProdProductList()) {
            StockMoveLine stockMoveLine = this._createStockMoveLine(prodProduct, stockMove);
        }
        if (stockMove.getStockMoveLineList() != null && !stockMove.getStockMoveLineList().isEmpty()) {
            stockMoveService.plan(stockMove);
            operationOrder.addInStockMoveListItem(stockMove);
        }
        // case where we had to split tracked stock move lines
        if (stockMove.getStockMoveLineList() != null) {
            for (StockMoveLine stockMoveLine : stockMove.getStockMoveLineList()) {
                operationOrder.addConsumedStockMoveLineListItem(stockMoveLine);
            }
        }
    }
}
Also used : Company(com.axelor.apps.base.db.Company) StockMove(com.axelor.apps.stock.db.StockMove) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) ProdProduct(com.axelor.apps.production.db.ProdProduct)

Example 37 with Company

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

the class CostSheetServiceImpl method computeCostPrice.

@Override
@Transactional(rollbackOn = { Exception.class })
public CostSheet computeCostPrice(ManufOrder manufOrder, int calculationTypeSelect, LocalDate calculationDate) throws AxelorException {
    this.init();
    List<CostSheet> costSheetList = manufOrder.getCostSheetList();
    LocalDate previousCostSheetDate = null;
    for (CostSheet costSheet : costSheetList) {
        if ((costSheet.getCalculationTypeSelect() == CostSheetRepository.CALCULATION_END_OF_PRODUCTION || costSheet.getCalculationTypeSelect() == CostSheetRepository.CALCULATION_PARTIAL_END_OF_PRODUCTION) && costSheet.getCalculationDate() != null) {
            if (previousCostSheetDate == null) {
                previousCostSheetDate = costSheet.getCalculationDate();
            } else if (costSheet.getCalculationDate().isAfter(previousCostSheetDate)) {
                previousCostSheetDate = costSheet.getCalculationDate();
            }
        }
    }
    manufOrder.addCostSheetListItem(costSheet);
    costSheet.setCalculationTypeSelect(calculationTypeSelect);
    costSheet.setCalculationDate(calculationDate != null ? calculationDate : Beans.get(AppBaseService.class).getTodayDate(manufOrder.getCompany()));
    BigDecimal producedQty = computeTotalProducedQty(manufOrder.getProduct(), manufOrder.getProducedStockMoveLineList(), costSheet.getCalculationDate(), previousCostSheetDate, costSheet.getCalculationTypeSelect());
    CostSheetLine producedCostSheetLine = costSheetLineService.createProducedProductCostSheetLine(manufOrder.getProduct(), manufOrder.getUnit(), producedQty);
    costSheet.addCostSheetLineListItem(producedCostSheetLine);
    Company company = manufOrder.getCompany();
    if (company != null && company.getCurrency() != null) {
        costSheet.setCurrency(company.getCurrency());
    }
    BigDecimal totalToProduceQty = getTotalToProduceQty(manufOrder);
    BigDecimal ratio = BigDecimal.ZERO;
    if (totalToProduceQty.compareTo(BigDecimal.ZERO) != 0) {
        ratio = producedQty.divide(totalToProduceQty, 5, RoundingMode.HALF_UP);
    }
    costSheet.setManufOrderProducedRatio(ratio);
    this.computeRealCostPrice(manufOrder, 0, producedCostSheetLine, previousCostSheetDate);
    this.computeRealResidualProduct(manufOrder);
    this.computeCostPrice(costSheet);
    manufOrder.setCostPrice(costSheet.getCostPrice());
    Beans.get(ManufOrderRepository.class).save(manufOrder);
    return costSheet;
}
Also used : CostSheetLine(com.axelor.apps.production.db.CostSheetLine) Company(com.axelor.apps.base.db.Company) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) ManufOrderRepository(com.axelor.apps.production.db.repo.ManufOrderRepository) LocalDate(java.time.LocalDate) CostSheet(com.axelor.apps.production.db.CostSheet) BigDecimal(java.math.BigDecimal) Transactional(com.google.inject.persist.Transactional)

Example 38 with Company

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

the class CostSheetServiceImpl method computeCostPrice.

@Override
@Transactional(rollbackOn = { Exception.class })
public CostSheet computeCostPrice(BillOfMaterial billOfMaterial, int origin, UnitCostCalculation unitCostCalculation) throws AxelorException {
    this.init();
    billOfMaterial.addCostSheetListItem(costSheet);
    CostSheetLine producedCostSheetLine = costSheetLineService.createProducedProductCostSheetLine(billOfMaterial.getProduct(), billOfMaterial.getUnit(), billOfMaterial.getQty());
    costSheet.addCostSheetLineListItem(producedCostSheetLine);
    costSheet.setCalculationTypeSelect(CostSheetRepository.CALCULATION_BILL_OF_MATERIAL);
    costSheet.setCalculationDate(Beans.get(AppBaseService.class).getTodayDate(billOfMaterial.getCompany()));
    Company company = billOfMaterial.getCompany();
    if (company != null && company.getCurrency() != null) {
        costSheet.setCurrency(company.getCurrency());
    }
    this._computeCostPrice(billOfMaterial.getCompany(), billOfMaterial, 0, producedCostSheetLine, origin, unitCostCalculation);
    this.computeResidualProduct(billOfMaterial);
    billOfMaterial.setCostPrice(this.computeCostPrice(costSheet));
    billOfMaterialRepo.save(billOfMaterial);
    return costSheet;
}
Also used : CostSheetLine(com.axelor.apps.production.db.CostSheetLine) Company(com.axelor.apps.base.db.Company) Transactional(com.google.inject.persist.Transactional)

Example 39 with Company

use of com.axelor.apps.base.db.Company 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)

Example 40 with Company

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

the class UserController method comparePfpValidatorCompanySet.

@SuppressWarnings("unchecked")
public void comparePfpValidatorCompanySet(ActionRequest request, ActionResponse response) {
    Integer pfpValidatorUserId = (Integer) request.getContext().get("_userId");
    LinkedHashMap<String, Object> newPfpValidatorUserMap = (LinkedHashMap<String, Object>) request.getContext().get("newPfpValidatorUser");
    if (newPfpValidatorUserMap == null) {
        return;
    }
    UserRepository userRepository = Beans.get(UserRepository.class);
    User newPfpValidatorUser = userRepository.find(((Integer) newPfpValidatorUserMap.get("id")).longValue());
    User pfpValidatorUser = userRepository.find(pfpValidatorUserId.longValue());
    Set<Company> pfpValidatorUserCompanySet = pfpValidatorUser.getCompanySet();
    Set<Company> newPfpValidatorUserCompanySet = newPfpValidatorUser.getCompanySet();
    if (!pfpValidatorUserCompanySet.equals(newPfpValidatorUserCompanySet)) {
        response.setAttr("$pfpValidatorCompanySetLabel", "title", String.format(I18n.get(IExceptionMessage.USER_PFP_VALIDATOR_COMPANY_SET_NOT_EQUAL), newPfpValidatorUser.getName(), pfpValidatorUser.getName()));
        response.setAttr("$pfpValidatorCompanySetLabel", "hidden", false);
    } else {
        response.setAttr("$pfpValidatorCompanySetLabel", "hidden", true);
    }
}
Also used : Company(com.axelor.apps.base.db.Company) UserRepository(com.axelor.auth.db.repo.UserRepository) User(com.axelor.auth.db.User) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

Company (com.axelor.apps.base.db.Company)213 Transactional (com.google.inject.persist.Transactional)72 Partner (com.axelor.apps.base.db.Partner)68 AxelorException (com.axelor.exception.AxelorException)65 BigDecimal (java.math.BigDecimal)54 Move (com.axelor.apps.account.db.Move)35 MoveLine (com.axelor.apps.account.db.MoveLine)35 LocalDate (java.time.LocalDate)35 ArrayList (java.util.ArrayList)31 PaymentMode (com.axelor.apps.account.db.PaymentMode)28 AccountConfig (com.axelor.apps.account.db.AccountConfig)27 Journal (com.axelor.apps.account.db.Journal)26 Account (com.axelor.apps.account.db.Account)25 Invoice (com.axelor.apps.account.db.Invoice)25 BankDetails (com.axelor.apps.base.db.BankDetails)22 Currency (com.axelor.apps.base.db.Currency)19 Product (com.axelor.apps.base.db.Product)17 StockLocation (com.axelor.apps.stock.db.StockLocation)17 StockMove (com.axelor.apps.stock.db.StockMove)15 List (java.util.List)15