Generate entity sequence codes in monthly timesheets

FEA: ItEr76S28UserDashboard
This commit is contained in:
Manuel Rego Casasnovas 2012-05-30 15:39:02 +02:00
parent 30259d73f4
commit c373c454fa

View file

@ -32,6 +32,8 @@ import org.hibernate.NonUniqueResultException;
import org.joda.time.LocalDate;
import org.libreplan.business.calendars.entities.ResourceCalendar;
import org.libreplan.business.common.daos.IConfigurationDAO;
import org.libreplan.business.common.daos.IEntitySequenceDAO;
import org.libreplan.business.common.entities.EntityNameEnum;
import org.libreplan.business.common.exceptions.InstanceNotFoundException;
import org.libreplan.business.costcategories.entities.TypeOfWorkHours;
import org.libreplan.business.orders.daos.IOrderDAO;
@ -109,6 +111,9 @@ public class MonthlyTimesheetModel implements IMonthlyTimesheetModel {
@Autowired
private IOrderDAO orderDAO;
@Autowired
private IEntitySequenceDAO entitySequenceDAO;
@Override
@Transactional(readOnly = true)
public void initCreateOrEdit(LocalDate date) {
@ -160,6 +165,9 @@ public class MonthlyTimesheetModel implements IMonthlyTimesheetModel {
// If it doesn't exist yet create a new one
workReport = WorkReport
.create(getMonthlyTimesheetsWorkReportType());
workReport
.setCode(entitySequenceDAO
.getNextEntityCodeWithoutTransaction(EntityNameEnum.WORK_REPORT));
workReport.setCodeAutogenerated(true);
workReport.setResource(user.getWorker());
}
@ -307,6 +315,7 @@ public class MonthlyTimesheetModel implements IMonthlyTimesheetModel {
private WorkReportLine createWorkReportLine(OrderElement orderElement,
LocalDate date) {
WorkReportLine workReportLine = WorkReportLine.create(workReport);
workReportLine.setCodeAutogenerated(true);
workReportLine.setOrderElement(orderElement);
workReportLine.setDate(date.toDateTimeAtStartOfDay().toDate());
workReportLine.setTypeOfWorkHours(getTypeOfWorkHours());
@ -332,6 +341,8 @@ public class MonthlyTimesheetModel implements IMonthlyTimesheetModel {
sumChargedEffortDAO
.updateRelatedSumChargedEffortWithWorkReportLineSet(workReport
.getWorkReportLines());
workReport.generateWorkReportLineCodes(entitySequenceDAO
.getNumberOfDigitsCode(EntityNameEnum.WORK_REPORT));
workReportDAO.save(workReport);
}