Skip to content

Commit

Permalink
Merge b777384 into d109f5b
Browse files Browse the repository at this point in the history
  • Loading branch information
liakify committed Nov 9, 2019
2 parents d109f5b + b777384 commit 3f1533d
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ public CommandResult execute(Model model) throws CommandException {
String description = String.format(EXPENSE_DESCRIPTION, payingName, receivingName);

try {
Expense e = new Expense(payingId, amount, description, receivingId);
e.setIsSettlement(true);
Expense e = new Expense(payingId, amount, description, true, receivingId);
activity.addExpense(e);
} catch (PersonNotInActivityException e) {
throw new CommandException(MESSAGE_MISSING_PERSON_DESCRIPTION);
Expand Down
29 changes: 24 additions & 5 deletions src/main/java/seedu/address/model/activity/Expense.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class Expense {
private int[] involvedIds;
private final Amount amount;
private final String description;
private boolean isSettlement;
private final boolean isSettlement;
private boolean isDeleted;

/**
Expand All @@ -37,6 +37,29 @@ public Expense(int personId, Amount amount, String description, int ... ids) {
this.involvedIds = ids;
}

/**
* Constructor for Expense.
* @param personId ID of the person who paid.
* @param amount The amount paid.
* @param description Description of the expense (can be an empty string).
* @param isSettlement The flag to indicate whether this is a settlement expense.
*/
public Expense(int personId, Amount amount, String description, boolean isSettlement) {
requireAllNonNull(personId, amount, description);
this.personId = personId;
this.amount = amount;
this.description = description;
this.isDeleted = false;
this.isSettlement = isSettlement;
involvedIds = null;
}

public Expense(int personId, Amount amount, String description, boolean isSettlement, int ... ids) {
this(personId, amount, description, isSettlement);
requireAllNonNull(ids);
this.involvedIds = ids;
}

/**
* Returns an array of all the primary keys of involved people in this expense.
* Note that this function can return null, in that case it means no list has
Expand Down Expand Up @@ -71,10 +94,6 @@ public boolean isDeleted() {
return isDeleted;
}

public void setIsSettlement(boolean isSettlement) {
this.isSettlement = isSettlement;
}

/**
* Marks an expense as deleted for soft-deleting expenses.
*/
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/seedu/address/storage/JsonAdaptedExpense.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,14 @@ public Expense toModelType() throws IllegalValueException {
final Amount amount = new Amount(this.amount);
Expense res;
if (involvedIds == null) {
res = new Expense(personId, amount, description);
res = new Expense(personId, amount, description, isSettlement);
} else {
res = new Expense(personId, amount, description, involvedIds);
res = new Expense(personId, amount, description, isSettlement, involvedIds);
}

if (isDeleted) {
res.delete();
}
res.setIsSettlement(isSettlement);

return res;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ public void execute_activityViewContextParticipantsPresent_addSuccessful() throw
String.format(SettleCommand.EXPENSE_DESCRIPTION,
TypicalPersons.ALICE.getName(),
TypicalPersons.BENSON.getName()),
true,
TypicalPersons.BENSON.getPrimaryKey());
settlement.setIsSettlement(true);
expenses.add(settlement);
assertEquals(expenses, model.getActivityBook().getActivityList().get(0).getExpenses());
}
Expand Down Expand Up @@ -185,8 +185,8 @@ public void execute_automaticallySettleZeroAmount_success() throws Exception {
String.format(SettleCommand.EXPENSE_DESCRIPTION,
TypicalPersons.ALICE.getName(),
TypicalPersons.BENSON.getName()),
true,
TypicalPersons.BENSON.getPrimaryKey());
settle.setIsSettlement(true);
expectedActivity.addExpense(settle);

Model expectedModel = new ModelManager();
Expand Down
6 changes: 2 additions & 4 deletions src/test/java/seedu/address/model/activity/ActivityTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,7 @@ public void debtAlgo_checkSettleDebts() {
a.addExpense(two);
a.addExpense(three);

Expense settle = new Expense(aid, new Amount(0), "", gid);
settle.setIsSettlement(true);
Expense settle = new Expense(aid, new Amount(0), "", true, gid);
a.addExpense(settle);

ArrayList<ArrayList<Double>> matrix = new ArrayList<>(
Expand All @@ -139,8 +138,7 @@ public void debtAlgo_checkSettleDebts() {
a.addExpense(two);
a.addExpense(three);

Expense settlepartial = new Expense(aid, new Amount(1), "", gid);
settlepartial.setIsSettlement(true);
Expense settlepartial = new Expense(aid, new Amount(1), "", true, gid);
a.addExpense(settlepartial);

ArrayList<ArrayList<Double>> matrixreloaded = new ArrayList<>(
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/seedu/address/model/activity/ExpenseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public void isDeleted_deleteExpense() {
public void isSettlement_makeSettlement() {
Expense expense = new Expense(BENSON.getPrimaryKey(), amount, description);
assertFalse(expense.isSettlement());
expense.setIsSettlement(true);

expense = new Expense(BENSON.getPrimaryKey(), amount, description, true);
assertTrue(expense.isSettlement());
}
}

0 comments on commit 3f1533d

Please sign in to comment.