Integrate Django-Oscar-Accounts with Django-Oscar

  • A user can have multiple accounts
  • An account can be created with — no users assigned, a single primary user assigned or set of users can be assigned
  • An account can have a start and end date to allow its usage in a limited time, can be restricted so that it can only be used to pay for a range of products.
  • An account has a credit limit which defaults to zero.
pip install django-oscar-accounts
from oscar.defaults import *OSCAR_DASHBOARD_NAVIGATION.append(
{
'label': 'Accounts',
'icon': 'icon-globe',
'children': [
{
'label': 'Accounts',
'url_name': 'accounts-list',
},
{
'label': 'Transfers',
'url_name': 'transfers-list',
},
{
'label': 'Deferred income report',
'url_name': 'report-deferred-income',
},
{
'label': 'Profit/loss report',
'url_name': 'report-profit-loss',
},
]
})
from oscar_accounts.dashboard.app import application as accounts_appurlpatterns = [
...
url(r'^dashboard/accounts/', include(accounts_app.urls)),
]
from oscar_accounts.models import Accountaccounts = Account.active.filter(user=user, balance__gt=0)
from oscar_accounts.models import Account
from oscar_accounts import facade, exceptions
source_account = user_selected_account
destination_account = Account.objects.get(name="Sales")
try:
transfer = facade.transfer(source_account,
destination_account,
order_total,
user=user
merchant_reference=order_number,
description="Redeemed to pay for order %s" % order_number)
except exceptions.AccountException, e:
raise PaymentError("Transfer Failed")
else:
# Add Payment source and Payment event
source_type, created = SourceType.objects.get_or_create(name="Accounts")
source = Source(source_type=source_type,
amount_allocated=order_total,
amount_debited=transfer.amount,
reference=transfer.reference)
self.add_payment_source(source)
self.add_payment_event("Transferred",
transfer.amount,
transfer.reference)
from oscar_accounts import facade
try:
self.place_order()
except Exception, e:
facade.reverse(transfer, user=user,
merchant_reference=order_number,
description="Payment Cancellation")

The article was originally published at MicroPyramid blog.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
MicroPyramid

MicroPyramid

1K Followers

Python, Django, Android and IOS, reactjs, react-native, AWS, Salesforce consulting & development company