-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* WIP: Perk fulfillment code * Lint fixes * Lint fixes * Lint fixes * Lint fixes * Test fix * Email templates for perk fulfillment * Test adjustment * Updates to address comments/requests * Lint fixes * Addressing PR comments * Lint fixes * Disabling Daklapack ordering & celery tasks for testing * Get transactions on celery start * Route invalid address emails to myself temporarily * Test perks without fulfillment details * Test new perk fulfillment * Test shipping updates * Fix shipping update query * Fix shipping update query * Email adjustments * Re-test get fundrazr transactions to verify email fixes * Re-test fulfillment to verify email fixes * Test date limiting of address verification * Test date limiting of address verification * Test date limiting of address verification * Debug not getting new transaction * Re-test perk fulfillment w/ Daklapack ordering * Cleaning up from testing * Lint fixes * Add unit test for shipping updates * Lint fixes * Run Celery tasks on startup * Only send Fundrazr email if transactions > 0 * Add email logging to perk fulfillment * Resolve db patch filename conflict * Test email logging * Lint * Fix subscription fulfillment bug + expand unit tests * Lint * Update perk_fulfillment_repo.py * Update celery_utils.py * Update server_config.json * Update admin_impl.py * Update test_perk_fulfillment_repo.py * Update subscription.py
- Loading branch information
1 parent
e499dad
commit 06344e9
Showing
20 changed files
with
3,186 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
-- Add a flag to the campaign.fundrazr_transaction_perk table to reflect whether it has been processed | ||
ALTER TABLE campaign.fundrazr_transaction_perk ADD COLUMN processed BOOLEAN NOT NULL DEFAULT FALSE; | ||
|
||
-- Add a flag to the campaign.fundrazr_daklapack_orders table to reflect whether we've sent out a tracking number | ||
ALTER TABLE campaign.fundrazr_daklapack_orders ADD COLUMN tracking_sent BOOLEAN NOT NULL DEFAULT FALSE; | ||
|
||
-- The campaign.fundrazr_perk_to_daklapack_article table hasn't been used yet, so it's safe to drop. | ||
DROP TABLE campaign.fundrazr_perk_to_daklapack_article; | ||
|
||
-- Since our model has changed to include perks that are FFQ-only and subscriptions, | ||
-- we're going to retool the table to better reflect how perks function. | ||
-- For subscriptions, we'll utilize the fulfillment_spacing_* columns to control scheduling. | ||
-- E.g., fulfillment_spacing_number = 3 and fulfillment_spacing_unit = 'months' will schedule quarterly orders. | ||
-- If we decide to offer perks with multiple kits shipped at once in the future, fulfillment_spacing_number = 0 can be used to reflect this behavior. | ||
CREATE TYPE FULFILLMENT_SPACING_UNIT AS ENUM ('days', 'months'); | ||
CREATE TABLE campaign.fundrazr_perk_fulfillment_details ( | ||
perk_id VARCHAR NOT NULL PRIMARY KEY, | ||
ffq_quantity INTEGER NOT NULL, | ||
kit_quantity INTEGER NOT NULL, | ||
dak_article_code VARCHAR, -- Must be nullable, as not all perks include a kit | ||
fulfillment_spacing_number INTEGER NOT NULL, | ||
fulfillment_spacing_unit FULFILLMENT_SPACING_UNIT, | ||
CONSTRAINT fk_perk_to_dak FOREIGN KEY (dak_article_code) REFERENCES barcodes.daklapack_article (dak_article_code) | ||
); | ||
|
||
INSERT INTO campaign.transaction_source_to_campaign | ||
SELECT '57xV2' AS remote_campaign_id, campaign_id AS internal_campaign_id, 'usd' AS currency | ||
FROM campaign.campaigns | ||
WHERE title='The Microsetta Initiative'; | ||
|
||
-- The API will pull down perks automatically, but we need it to exist so we can add the fullfilment info, | ||
-- so we're just going to insert them here | ||
|
||
-- Perk values for Fundrazr's production environment | ||
INSERT INTO campaign.fundrazr_perk | ||
(id, remote_campaign_id, title, price) | ||
VALUES ('3QeVd', '4Tqx5', 'Analyze Your Nutrition', 20), | ||
('3QeW6', '4Tqx5', 'Explore Your Microbiome', 180), | ||
('0QeXa', '4Tqx5', 'Follow Your Gut', 720); | ||
|
||
-- Perk values for Fundrazr's staging environment | ||
INSERT INTO campaign.fundrazr_perk | ||
(id, remote_campaign_id, title, price) | ||
VALUES ('13lja', '57xV2', 'Analyze Your Nutrition', 20), | ||
('93lk8', '57xV2', 'Explore Your Microbiome', 180), | ||
('13ll7', '57xV2', 'Follow Your Gut', 720); | ||
|
||
-- Insert the fulfillment info for the perks we're offering | ||
-- Production perks | ||
INSERT INTO campaign.fundrazr_perk_fulfillment_details | ||
(perk_id, ffq_quantity, kit_quantity, dak_article_code, fulfillment_spacing_number, fulfillment_spacing_unit) | ||
VALUES ('3QeVd', 1, 0, NULL, 0, NULL), | ||
('3QeW6', 1, 1, '3510005E', 0, NULL), | ||
('0QeXa', 4, 4, '3510005E', 3, 'months'); | ||
-- Staging perks | ||
INSERT INTO campaign.fundrazr_perk_fulfillment_details | ||
(perk_id, ffq_quantity, kit_quantity, dak_article_code, fulfillment_spacing_number, fulfillment_spacing_unit) | ||
VALUES ('13lja', 1, 0, NULL, 0, NULL), | ||
('93lk8', 1, 1, '3510005E', 0, NULL), | ||
('13ll7', 4, 4, '3510005E', 3, 'months'); | ||
|
||
-- Both the subscriptions and subscriptions_fulfillment tables will have cancelled flags to create | ||
-- an audit trail in the event someone contacts us to cancel scheduled shipments. | ||
-- We're storing the flag at both levels so we can track what portion of a subscription was actually sent. | ||
-- We say "No refunds" but it would be good to have the granular data on what people received, just in case. | ||
CREATE TABLE campaign.subscriptions ( | ||
subscription_id UUID PRIMARY KEY DEFAULT uuid_generate_v4(), | ||
account_id UUID, -- Must be nullable in case someone contributes to receive a subscription before creating their account | ||
transaction_id VARCHAR NOT NULL, | ||
fundrazr_transaction_perk_id UUID NOT NULL, | ||
cancelled BOOLEAN NOT NULL DEFAULT FALSE, | ||
CONSTRAINT fk_account_id FOREIGN KEY (account_id) REFERENCES ag.account (id), | ||
CONSTRAINT fk_transaction_id FOREIGN KEY (transaction_id) REFERENCES campaign.transaction (id), | ||
CONSTRAINT fk_ftp_id FOREIGN KEY (fundrazr_transaction_perk_id) REFERENCES campaign.fundrazr_transaction_perk (id) | ||
); | ||
|
||
-- Participants can alter shipment dates, but only once per shipment. | ||
-- The fulfillment_date_changed column will manage this. | ||
CREATE TYPE FULFILLMENT_TYPE AS ENUM ('ffq', 'kit'); | ||
CREATE TABLE campaign.subscriptions_fulfillment ( | ||
fulfillment_id UUID PRIMARY KEY DEFAULT uuid_generate_v4(), | ||
subscription_id UUID NOT NULL, | ||
fulfillment_type FULFILLMENT_TYPE NOT NULL, | ||
dak_article_code VARCHAR, -- Must be nullable, as not all perks include a kit | ||
fulfillment_date DATE, | ||
fulfillment_date_changed BOOLEAN NOT NULL DEFAULT FALSE, | ||
fulfilled BOOLEAN NOT NULL DEFAULT FALSE, | ||
cancelled BOOLEAN NOT NULL DEFAULT FALSE, | ||
CONSTRAINT fk_subscription_id FOREIGN KEY (subscription_id) REFERENCES campaign.subscriptions (subscription_id), | ||
CONSTRAINT fk_dak_article_code FOREIGN KEY (dak_article_code) REFERENCES barcodes.daklapack_article (dak_article_code) | ||
); | ||
|
||
-- FFQs will have a registration code (similar to the old activation code) moving forward, | ||
-- although it will not be tied to an email address. | ||
CREATE TABLE campaign.ffq_registration_codes ( | ||
ffq_registration_code VARCHAR PRIMARY KEY, | ||
registration_code_used TIMESTAMP -- Nullable as null = unused code | ||
); | ||
|
||
-- Create a record of the fulfillment of FFQ codes relative to a transaction/perk combination. | ||
CREATE TABLE campaign.fundrazr_ffq_codes ( | ||
fundrazr_transaction_perk_id UUID NOT NULL, | ||
ffq_registration_code VARCHAR NOT NULL, | ||
CONSTRAINT fk_ftp_id FOREIGN KEY (fundrazr_transaction_perk_id) REFERENCES campaign.fundrazr_transaction_perk (id), | ||
CONSTRAINT fk_ffq_code FOREIGN KEY (ffq_registration_code) REFERENCES campaign.ffq_registration_codes (ffq_registration_code) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from microsetta_private_api.model.model_base import ModelBase | ||
|
||
|
||
class Subscription(ModelBase): | ||
def __init__(self, **kwargs): | ||
# subscription_id won't exist yet on new subscriptions | ||
self.subscription_id = kwargs.get('subscription_id') | ||
|
||
# absolute minimum fields required for a subscription | ||
self.transaction_id = kwargs['transaction_id'] | ||
|
||
# remaining fields are either optional or auto-created later | ||
self.account_id = kwargs.get('account_id') | ||
self.cancelled = kwargs.get('cancelled', False) | ||
|
||
def to_api(self): | ||
return self.__dict__.copy() | ||
|
||
@classmethod | ||
def from_dict(cls, values_dict): | ||
return cls(**values_dict) |
Oops, something went wrong.