-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
45 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from import_export import resources | ||
from import_export.fields import Field | ||
|
||
from .models import Payment | ||
|
||
|
||
class PaymentResource(resources.ModelResource): | ||
""" | ||
We take precise control of the output to separate amounts and currencies into separate columns for easier | ||
downstream processing. | ||
""" | ||
total_amount = Field() | ||
total_currency = Field() | ||
|
||
captured_amount = Field() | ||
captured_currency = Field() | ||
|
||
active = Field('is_active') | ||
|
||
class Meta: | ||
model = Payment | ||
fields = ['created', 'gateway', 'charge_status', 'customer_email'] | ||
export_order = ['active', 'total_amount', 'total_currency', 'captured_amount', 'captured_currency'] | ||
|
||
def dehydrate_total_amount(self, payment): | ||
return payment.total.amount | ||
|
||
def dehydrate_total_currency(self, payment): | ||
return payment.total.currency.code | ||
|
||
def dehydrate_captured_amount(self, payment): | ||
return payment.captured_amount.amount | ||
|
||
def dehydrate_captured_currency(self, payment): | ||
return payment.captured_amount.currency.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 |
---|---|---|
|
@@ -18,6 +18,7 @@ deps = | |
django-money | ||
structlog | ||
typing | ||
django-import-export | ||
pytest-django | ||
pytest-cov | ||
flake8 | ||
|