djaodjin / djaodjin-saas

Django application for software-as-service and subscription businesses
Other
564 stars 124 forks source link

Export coupon applications as a CSV #23

Closed rene-armida closed 9 years ago

rene-armida commented 9 years ago

Allow the user to download a CSV showing the instances of coupons being redeemed. This should include one row per coupon invocation. This should include:

rene-armida commented 9 years ago

Hey @smirolo should any other fields be added to this export?

smirolo commented 9 years ago

Those fields should be enough, email included. Thanks.

rene-armida commented 9 years ago

When I sign up via the "cowork" demo app, and I use a coupon, the resulting CartItem record has an empty first_name, last_name, and email property. I see a note in the code that says these fields should be preferred to Organization ones here: https://github.com/marmida/djaodjin-saas/blob/01640d3c821fa94547daefebca7f67544dc60154/saas/models.py#L1191-1193

@smirolo is this expected? If so, where should I look for the registrant's info?

smirolo commented 9 years ago

Correct, this is expected. Once you turn the field is_bulk_buyer to True in an Organization, you will have one more screen in the payment pipeline, with the opportunity to pay for a subscription but actually subscribe a third-party Organization (that might or might not exist at the time of checkout). This is done for group payments where often one person is in charge of the credit card payments, while others are subscribed/using the service.

CartItem.first_name, CartItem.last_name and CartItem.email are to email a one-time use 100% discount Coupon to the third-party (see Pipeline to Bulk Subscribe Third-parties).

CartItem.user is the request.user(identified by a login/password) at the time of payment which has actually added a Plan to her own cart, then paid using the credit card associated with an Organization the CartItem.user is a manager for, and subscribed either that Organization, or a 3rd party Organization, directly to the CartItem.plan.

Important concepts:

Does that answer the question?

rene-armida commented 9 years ago

Yes, thanks! But now I have further questions. :clap:

Specifically: what should I be looking up to build the queryset of coupon invocations? I've been studying the Database Models diagram, and I'm not certain which path to take between CartItem - which is the only place I can see a coupon_id being stored - and a price field, maybe in Transaction?

Perhaps I should be looking through CartItem to User to Organization to Transaction? Or perhaps Charge? I'm not certain.

rene-armida commented 9 years ago

After some in-person discussion with @smirolo, we've decided to remove the "amount" field from the export, for now. It's not centrally important to the feature, and it's not super easy to get it from the database, in its current incarnation, because there is no explicit link between historical transactions and the current state of the coupon.

rene-armida commented 9 years ago

This is working for me in #27. It could use code unification with the other CSV download I recently built, but I will make another pass to do that later.