ItEr42S17CUGravacionModelosUnidadesTraballoItEr41S20: Extracting MaterialInfo component from Materials class
This commit is contained in:
parent
c5ae760130
commit
e2b6e542b4
3 changed files with 88 additions and 21 deletions
|
|
@ -24,7 +24,7 @@ import java.math.BigDecimal;
|
|||
import java.math.RoundingMode;
|
||||
import java.util.Date;
|
||||
|
||||
import org.hibernate.validator.NotNull;
|
||||
import org.hibernate.validator.Valid;
|
||||
import org.navalplanner.business.common.BaseEntity;
|
||||
import org.navalplanner.business.orders.entities.OrderElement;
|
||||
|
||||
|
|
@ -35,11 +35,7 @@ import org.navalplanner.business.orders.entities.OrderElement;
|
|||
*/
|
||||
public class MaterialAssignment extends BaseEntity implements Comparable {
|
||||
|
||||
private Material material;
|
||||
|
||||
private Double units = 0.0;
|
||||
|
||||
private BigDecimal unitPrice = BigDecimal.ZERO;
|
||||
private MaterialInfo materialInfo = new MaterialInfo();
|
||||
|
||||
private Date estimatedAvailability;
|
||||
|
||||
|
|
@ -72,31 +68,36 @@ public class MaterialAssignment extends BaseEntity implements Comparable {
|
|||
return result;
|
||||
}
|
||||
|
||||
@NotNull(message = "material not specified")
|
||||
@Valid
|
||||
private MaterialInfo getMaterialInfo() {
|
||||
if (materialInfo == null) {
|
||||
materialInfo = new MaterialInfo();
|
||||
}
|
||||
return materialInfo;
|
||||
}
|
||||
|
||||
public Material getMaterial() {
|
||||
return material;
|
||||
return getMaterialInfo().getMaterial();
|
||||
}
|
||||
|
||||
public void setMaterial(Material material) {
|
||||
this.material = material;
|
||||
getMaterialInfo().setMaterial(material);
|
||||
}
|
||||
|
||||
@NotNull(message = "units not specified")
|
||||
public Double getUnits() {
|
||||
return units;
|
||||
return getMaterialInfo().getUnits();
|
||||
}
|
||||
|
||||
public void setUnits(Double units) {
|
||||
this.units = units;
|
||||
getMaterialInfo().setUnits(units);
|
||||
}
|
||||
|
||||
@NotNull(message = "unit price not specified")
|
||||
public BigDecimal getUnitPrice() {
|
||||
return unitPrice;
|
||||
return getMaterialInfo().getUnitPrice();
|
||||
}
|
||||
|
||||
public void setUnitPrice(BigDecimal unitPrice) {
|
||||
this.unitPrice = unitPrice;
|
||||
getMaterialInfo().setUnitPrice(unitPrice);
|
||||
}
|
||||
|
||||
public BigDecimal getTotalPrice() {
|
||||
|
|
@ -106,7 +107,8 @@ public class MaterialAssignment extends BaseEntity implements Comparable {
|
|||
|
||||
public void setTotalPrice(BigDecimal totalPrice) {
|
||||
BigDecimal unitPrice = totalPrice;
|
||||
unitPrice = unitPrice.divide(new BigDecimal(units), 3, RoundingMode.HALF_UP);
|
||||
unitPrice = unitPrice.divide(new BigDecimal(getUnits()), 3,
|
||||
RoundingMode.HALF_UP);
|
||||
setUnitPrice(unitPrice);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* This file is part of ###PROJECT_NAME###
|
||||
*
|
||||
* Copyright (C) 2009 Fundación para o Fomento da Calidade Industrial e
|
||||
* Desenvolvemento Tecnolóxico de Galicia
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.navalplanner.business.materials.entities;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import org.hibernate.validator.NotNull;
|
||||
|
||||
/**
|
||||
* @author Óscar González Fernández <ogonzalez@igalia.com>
|
||||
*
|
||||
*/
|
||||
public class MaterialInfo {
|
||||
|
||||
private Material material;
|
||||
|
||||
private Double units = 0.0;
|
||||
|
||||
private BigDecimal unitPrice = BigDecimal.ZERO;
|
||||
|
||||
@NotNull(message = "material not specified")
|
||||
public Material getMaterial() {
|
||||
return material;
|
||||
}
|
||||
|
||||
public void setMaterial(Material material) {
|
||||
this.material = material;
|
||||
}
|
||||
|
||||
@NotNull(message = "units not specified")
|
||||
public Double getUnits() {
|
||||
return units;
|
||||
}
|
||||
|
||||
public void setUnits(Double units) {
|
||||
this.units = units;
|
||||
}
|
||||
|
||||
@NotNull(message = "unit price not specified")
|
||||
public BigDecimal getUnitPrice() {
|
||||
return unitPrice;
|
||||
}
|
||||
|
||||
public void setUnitPrice(BigDecimal unitPrice) {
|
||||
this.unitPrice = unitPrice;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -63,9 +63,11 @@
|
|||
</id>
|
||||
<version name="version" access="property" type="long" />
|
||||
|
||||
<property name="units" />
|
||||
|
||||
<property name="unitPrice" column="UNIT_PRICE" />
|
||||
<component name="materialInfo">
|
||||
<property name="units" />
|
||||
<property name="unitPrice" column="UNIT_PRICE" />
|
||||
<many-to-one name="material" class="Material" column="MATERIAL_ID" />
|
||||
</component>
|
||||
|
||||
<property name="estimatedAvailability" column="ESTIMATED_AVAILABILITY" />
|
||||
|
||||
|
|
@ -77,8 +79,6 @@
|
|||
|
||||
<many-to-one name="orderElement" class="org.navalplanner.business.orders.entities.OrderElement" column="ORDER_ELEMENT_ID" />
|
||||
|
||||
<many-to-one name="material" class="Material" column="MATERIAL_ID" />
|
||||
|
||||
</class>
|
||||
|
||||
</hibernate-mapping>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue