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