Skip to content

Commit

Permalink
fix: getTransactionsForInvoice returning invoiced transactions (#457)
Browse files Browse the repository at this point in the history
Also changes the name to `getEligibleTransactions` since that describes the function better.
  • Loading branch information
JustSamuel authored Feb 11, 2025
1 parent 7634f63 commit c3c8bd0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/controller/invoice-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ export default class InvoiceController extends BaseController {
}

try {
const transactions = await new InvoiceService().getTransactionsForInvoice({
const transactions = await new InvoiceService().getEligibleTransactions({
forId,
fromDate,
tillDate,
Expand Down
19 changes: 6 additions & 13 deletions src/service/invoice-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,11 +386,10 @@ export default class InvoiceService extends WithManager {
}

/**
* Gets transactions for an invoice
* returns false if the transactions contain invoiced transactions
* Gets all uninvoiced transactions for a given user
* @param params
*/
public async getTransactionsForInvoice(params: InvoiceTransactionsRequest): Promise<TransactionResponse[] | false> {
public async getEligibleTransactions(params: InvoiceTransactionsRequest): Promise<TransactionResponse[] | false> {
const { forId, fromDate, tillDate } = params;
const transactionService = new TransactionService(this.manager);

Expand All @@ -412,16 +411,10 @@ export default class InvoiceService extends WithManager {
pointOfSale: true,
};

const transactions = await this.manager.find(Transaction, { where: { id: In(tIds) },
relations });
transactions.forEach((t) => {
t.subTransactions.forEach((tSub) => {
tSub.subTransactionRows.forEach((tSubRow) => {
if (tSubRow.invoice) return false;
});
});
});

const transactions = await this.manager.find(Transaction, { where: { id: In(tIds),
subTransactions: { subTransactionRows: { invoice: false } } },
relations });

const response: Promise<TransactionResponse>[] = [];
transactions.forEach((t) => response.push(transactionService.asTransactionResponse(t)));

Expand Down
2 changes: 1 addition & 1 deletion test/unit/service/invoice-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ describe('InvoiceService', () => {
);
const total = transactionsAfterDate.total;

const transactions = await new InvoiceService().getTransactionsForInvoice({
const transactions = await new InvoiceService().getEligibleTransactions({
forId: debtor.id,
fromDate,
});
Expand Down

0 comments on commit c3c8bd0

Please sign in to comment.