use of com.axelor.apps.production.db.BillOfMaterial in project axelor-open-suite by axelor.
the class BillOfMaterialController method checkOriginalBillOfMaterial.
public void checkOriginalBillOfMaterial(ActionRequest request, ActionResponse response) {
BillOfMaterialRepository billOfMaterialRepository = Beans.get(BillOfMaterialRepository.class);
BillOfMaterial billOfMaterial = billOfMaterialRepository.find(request.getContext().asType(BillOfMaterial.class).getId());
List<BillOfMaterial> BillOfMaterialSet = Lists.newArrayList();
BillOfMaterialSet = billOfMaterialRepository.all().filter("self.originalBillOfMaterial = :origin").bind("origin", billOfMaterial).fetch();
String message;
if (!BillOfMaterialSet.isEmpty()) {
String existingVersions = "";
for (BillOfMaterial billOfMaterialVersion : BillOfMaterialSet) {
existingVersions += "<li>" + billOfMaterialVersion.getFullName() + "</li>";
}
message = String.format(I18n.get("This bill of materials already has the following versions : <br/><ul> %s </ul>And these versions may also have ones. Do you still wish to create a new one ?"), existingVersions);
} else {
message = I18n.get("Do you really wish to create a new version of this bill of materials ?");
}
response.setAlert(message);
}
use of com.axelor.apps.production.db.BillOfMaterial in project axelor-open-suite by axelor.
the class BillOfMaterialController method addRawMaterials.
public void addRawMaterials(ActionRequest request, ActionResponse response) {
try {
BillOfMaterial billOfMaterial = request.getContext().asType(BillOfMaterial.class);
@SuppressWarnings("unchecked") ArrayList<LinkedHashMap<String, Object>> rawMaterials = (ArrayList<LinkedHashMap<String, Object>>) request.getContext().get("rawMaterials");
if (rawMaterials != null && !rawMaterials.isEmpty()) {
Beans.get(BillOfMaterialService.class).addRawMaterials(billOfMaterial.getId(), rawMaterials);
response.setReload(true);
}
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.production.db.BillOfMaterial in project axelor-open-suite by axelor.
the class UnitCostCalculationServiceImpl method assignProductLevel.
/**
* Update the level of Bill of materials. The highest for each product (0: product with parent, 1:
* product with a parent, 2: product with a parent that have a parent, ...)
*
* @param billOfMaterial
* @param level
*/
protected void assignProductLevel(BillOfMaterial billOfMaterial, int level) {
if (billOfMaterial.getBillOfMaterialSet() == null || billOfMaterial.getBillOfMaterialSet().isEmpty() || level > 100) {
Product subProduct = billOfMaterial.getProduct();
log.debug("Add of the sub product : {} for the level : {} ", subProduct.getFullName(), level);
this.productMap.put(subProduct.getId(), this.getMaxLevel(subProduct, level));
} else {
level = level + 1;
for (BillOfMaterial subBillOfMaterial : billOfMaterial.getBillOfMaterialSet()) {
Product subProduct = subBillOfMaterial.getProduct();
if (this.productMap.containsKey(subProduct.getId())) {
this.assignProductLevel(subBillOfMaterial, level);
if (hasValidBillOfMaterial(subProduct)) {
this.assignProductLevel(subProduct.getDefaultBillOfMaterial(), level);
}
}
}
}
}
use of com.axelor.apps.production.db.BillOfMaterial in project axelor-open-suite by axelor.
the class MrpServiceProductionImpl method createProposalMrpLine.
@Override
@Transactional(rollbackOn = { Exception.class })
protected void createProposalMrpLine(Mrp mrp, Product product, MrpLineType mrpLineType, BigDecimal reorderQty, StockLocation stockLocation, LocalDate maturityDate, List<MrpLineOrigin> mrpLineOriginList, String relatedToSelectName) throws AxelorException {
super.createProposalMrpLine(mrp, product, mrpLineType, reorderQty, stockLocation, maturityDate, mrpLineOriginList, relatedToSelectName);
if (!Beans.get(AppProductionService.class).isApp("production")) {
return;
}
BillOfMaterial defaultBillOfMaterial = product.getDefaultBillOfMaterial();
if (mrpLineType.getElementSelect() == MrpLineTypeRepository.ELEMENT_MANUFACTURING_PROPOSAL && defaultBillOfMaterial != null) {
MrpLineType manufProposalNeedMrpLineType = this.getMrpLineType(MrpLineTypeRepository.ELEMENT_MANUFACTURING_PROPOSAL_NEED);
if (manufProposalNeedMrpLineType == null) {
return;
}
for (BillOfMaterial billOfMaterial : defaultBillOfMaterial.getBillOfMaterialSet()) {
Product subProduct = billOfMaterial.getProduct();
if (this.isMrpProduct(subProduct)) {
// TODO take the time to do the Manuf order (use machine planning)
super.createProposalMrpLine(mrp, subProduct, manufProposalNeedMrpLineType, reorderQty.multiply(billOfMaterial.getQty()).setScale(appBaseService.getNbDecimalDigitForQty(), RoundingMode.HALF_UP), stockLocation, maturityDate, mrpLineOriginList, relatedToSelectName);
}
}
}
}
use of com.axelor.apps.production.db.BillOfMaterial in project axelor-open-suite by axelor.
the class BillOfMaterialServiceImpl method createBomFromRawMaterial.
@Transactional
protected BillOfMaterial createBomFromRawMaterial(long productId, int priority) throws AxelorException {
BillOfMaterial newBom = new BillOfMaterial();
Product rawMaterial = productRepo.find(productId);
newBom.setDefineSubBillOfMaterial(false);
newBom.setPriority(priority);
newBom.setProduct(rawMaterial);
newBom.setQty(new BigDecimal(1));
if (rawMaterial.getUnit() == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.BOM_MISSING_UNIT_ON_PRODUCT), rawMaterial.getFullName());
}
newBom.setUnit(rawMaterial.getUnit());
newBom.setWasteRate(BigDecimal.ZERO);
newBom.setHasNoManageStock(false);
billOfMaterialRepo.save(newBom);
// need to save first cuz computeName uses the id.
String name = this.computeName(newBom);
newBom.setName(name);
newBom.setFullName(name);
return newBom;
}
Aggregations