Skip to content

Commit

Permalink
Merge pull request CS2103-AY1819S2-W15-2#290 from jhocx/v1.4
Browse files Browse the repository at this point in the history
Fix bug regarding EditRecurring resetting the lastConvertedDate.
  • Loading branch information
jhocx authored Apr 15, 2019
2 parents 194f441 + 6d22b94 commit 70388e4
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/DeveloperGuide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ image::ConvertRecurringSequenceDiagram.png[width="800"]

6. If the expense's date is before or equals to the current date, and after the `lastConvertedDate`, this recurring expense will have to be converted into an expense and added into the FinanceTracker. This is done by calling Model#addExpense(recurringListOfExpenses.get(j)).

7. This is done for each expense of the recurring. After the iteration, the recurring's `lastConvertedDate` is set to the current date.
7. This is done for every expense that is supposed to be added by this recurring to determine which has to be added into the expense list. After the iteration, the recurring's `lastConvertedDate` is set to the current date.

8. This is done for each recurring in the list.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_REMARKS;
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_RECURRING;

import java.time.LocalDate;
import java.util.List;
import java.util.Optional;

Expand Down Expand Up @@ -98,6 +99,8 @@ private static Recurring createEditedRecurring(Recurring recurringToEdit,
EditRecurringDescriptor editRecurringDescriptor) {
assert recurringToEdit != null;

LocalDate lastConvertedDate = recurringToEdit.getLastConvertedDate();

Name updatedName = editRecurringDescriptor.getName().orElse(recurringToEdit.getName());
Amount updatedAmount = editRecurringDescriptor.getAmount().orElse(recurringToEdit.getAmount());
Category updatedCategory = editRecurringDescriptor.getCategory().orElse(recurringToEdit.getCategory());
Expand All @@ -107,7 +110,7 @@ private static Recurring createEditedRecurring(Recurring recurringToEdit,
Occurrence updatedOccurrence = editRecurringDescriptor.getOccurrence().orElse(recurringToEdit.getOccurrence());

return new Recurring(updatedName, updatedAmount, updatedDate, updatedCategory, updatedRemarks,
updatedFrequency, updatedOccurrence);
updatedFrequency, updatedOccurrence, lastConvertedDate);
}

@Override
Expand Down
29 changes: 29 additions & 0 deletions src/main/java/seedu/address/model/recurring/Recurring.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,35 @@ public Recurring(Name name, Amount amount, Date date, Category category, String
}
}

/**
* Initializes a newly created Recurring object that contains the compulsory fields and the lastConvertedDate.
*/
public Recurring(Name name, Amount amount, Date date, Category category, String remarks, Frequency frequency,
Occurrence occurrence, LocalDate lastConvertedDate) {
super(name, amount, date, category, remarks);
requireAllNonNull(frequency, occurrence);
this.frequency = frequency;
this.occurrence = occurrence;
this.lastConvertedDate = lastConvertedDate;
this.recurringListOfExpenses = new ArrayList<>(occurrence.value);
for (int i = 0; i < occurrence.value; i++) {
Name newName = new Name(name.name + " (Recurring)");

Date newDate = new Date(date);
if (frequency.value.equals("D")) {
newDate.setLocalDate(date.getLocalDate().plusDays(i));
} else if (frequency.value.equals("M")) {
newDate.setLocalDate(date.getLocalDate().plusMonths(i));
} else if (frequency.value.equals("Y")) {
newDate.setLocalDate(date.getLocalDate().plusYears(i));
}

Expense toAdd = new Expense(newName, amount, newDate, category, remarks);
//System.out.println(toAdd);
this.recurringListOfExpenses.add(toAdd);
}
}

/**
* Initializes a Recurring object from Jackson.
*/
Expand Down

0 comments on commit 70388e4

Please sign in to comment.