From 8b48432b87ceee45a8c47ca7a5481e7f84a2b03f Mon Sep 17 00:00:00 2001 From: marcogbarcellos Date: Mon, 3 Dec 2018 17:54:43 -0500 Subject: [PATCH] fix(scripts/monthly/user-report): we should filter orders that either don't have subscription OR have active subscriptions, consider UsingVirtualCardFromCollectiveId as well --- cron/monthly/user-report.js | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/cron/monthly/user-report.js b/cron/monthly/user-report.js index 6f9f7a401fdc..8bc4c77a32ab 100755 --- a/cron/monthly/user-report.js +++ b/cron/monthly/user-report.js @@ -112,7 +112,10 @@ const processBacker = async FromCollectiveId => { const query = { attributes: ['CollectiveId', 'HostCollectiveId'], where: { - FromCollectiveId, + [Op.or]: { + FromCollectiveId, + UsingVirtualCardFromCollectiveId: FromCollectiveId, + }, type: 'CREDIT', createdAt: { [Op.gte]: startDate, [Op.lt]: endDate }, }, @@ -188,7 +191,7 @@ const processBacker = async FromCollectiveId => { { concurrency: 4 }, ); } - const orders = await models.Order.findAll({ + let orders = await models.Order.findAll({ attributes: ['id', 'CollectiveId', 'totalAmount', 'currency'], where: { FromCollectiveId, @@ -198,17 +201,10 @@ const processBacker = async FromCollectiveId => { }, deletedAt: null, }, - include: [ - { - model: models.Subscription, - where: { - isActive: true, - }, - }, - ], + include: [{ model: models.Subscription }], }); - - const ordersByCollectiveId = groupBy(orders, 'CollectiveId'); + // group orders(by collective) that either don't have subscription or have active subscription + const ordersByCollectiveId = groupBy(orders.filter(o => !o.Subscription || o.Subscription.isActive), 'CollectiveId'); const collectivesWithOrders = []; collectives.map(collective => { // It's only possible to have one order with subscription active Per Collective