Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
ecommerce
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
ecommerce
Commits
e3e9e3d7
Commit
e3e9e3d7
authored
Jul 25, 2016
by
Vedran Karačić
Committed by
GitHub
Jul 25, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #863 from edx/vkaracic/remove_create_invoice_cmd
Removing the create_invoice management command.
parents
a711b290
5607f53f
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
0 additions
and
102 deletions
+0
-102
ecommerce/invoice/management/__init__.py
+0
-0
ecommerce/invoice/management/commands/__init__.py
+0
-0
ecommerce/invoice/management/commands/create_invoices.py
+0
-40
ecommerce/invoice/tests.py
+0
-62
No files found.
ecommerce/invoice/management/__init__.py
deleted
100644 → 0
View file @
a711b290
ecommerce/invoice/management/commands/__init__.py
deleted
100644 → 0
View file @
a711b290
ecommerce/invoice/management/commands/create_invoices.py
deleted
100644 → 0
View file @
a711b290
""" This command invoices for orders that don't have them. """
import
logging
from
django.core.management
import
BaseCommand
from
ecommerce.core.models
import
BusinessClient
from
ecommerce.extensions.basket.models
import
Basket
from
ecommerce.extensions.catalogue.models
import
Product
from
ecommerce.extensions.order.models
import
Order
from
ecommerce.extensions.payment.processors.invoice
import
InvoicePayment
from
ecommerce.invoice.models
import
Invoice
logger
=
logging
.
getLogger
(
__name__
)
class
Command
(
BaseCommand
):
"""
Create invoices for orders that don't have them.
At some point in the past we decided to use the BusinessClient from invoices,
before that it was used from basket objects, and the orders back then didn't have
invoices. This command creates invoices for those orders.
"""
def
handle
(
self
,
*
args
,
**
options
):
for
coupon
in
Product
.
objects
.
filter
(
product_class__name
=
'Coupon'
):
try
:
basket
=
Basket
.
objects
.
filter
(
lines__product
=
coupon
,
status
=
Basket
.
SUBMITTED
)
.
first
()
if
basket
is
None
:
raise
Basket
.
DoesNotExist
order
=
Order
.
objects
.
get
(
basket
=
basket
)
Invoice
.
objects
.
get
(
order
=
order
)
logger
.
info
(
'Invoice for order
%
s already exists - skipping.'
,
order
.
number
)
except
Basket
.
DoesNotExist
:
logger
.
error
(
'Basket for coupon
%
s does not exist!'
,
coupon
.
id
)
except
Order
.
DoesNotExist
:
logger
.
error
(
'Order for basket
%
s does not exist!'
,
basket
.
id
)
except
Invoice
.
DoesNotExist
:
client
,
__
=
BusinessClient
.
objects
.
get_or_create
(
name
=
basket
.
owner
.
username
)
InvoicePayment
()
.
handle_processor_response
(
response
=
{},
order
=
order
,
business_client
=
client
)
logger
.
info
(
'Created new invoice for order
%
s.'
,
order
.
number
)
ecommerce/invoice/tests.py
View file @
e3e9e3d7
from
django.core.management
import
call_command
from
oscar.core.loading
import
get_model
from
oscar.test
import
factories
from
oscar.test
import
factories
from
testfixtures
import
LogCapture
from
ecommerce.core.models
import
BusinessClient
,
Client
from
ecommerce.coupons.tests.mixins
import
CouponMixin
from
ecommerce.invoice.models
import
Invoice
from
ecommerce.invoice.models
import
Invoice
from
ecommerce.tests.testcases
import
TestCase
from
ecommerce.tests.testcases
import
TestCase
Basket
=
get_model
(
'basket'
,
'Basket'
)
ProductClass
=
get_model
(
'catalogue'
,
'ProductClass'
)
class
InvoiceTests
(
TestCase
):
class
InvoiceTests
(
TestCase
):
"""Test to ensure Invoice objects are created correctly"""
"""Test to ensure Invoice objects are created correctly"""
...
@@ -33,57 +25,3 @@ class InvoiceTests(TestCase):
...
@@ -33,57 +25,3 @@ class InvoiceTests(TestCase):
def
test_total
(
self
):
def
test_total
(
self
):
"""Test to check invoice total"""
"""Test to check invoice total"""
self
.
assertEqual
(
self
.
basket
.
order
.
total_incl_tax
,
self
.
invoice
.
total
)
self
.
assertEqual
(
self
.
basket
.
order
.
total_incl_tax
,
self
.
invoice
.
total
)
class
InvoiceManagementCommandTests
(
CouponMixin
,
TestCase
):
""" Tests for the invoice management commands. """
def
setUp
(
self
):
super
(
InvoiceManagementCommandTests
,
self
)
.
setUp
()
self
.
product
=
factories
.
ProductFactory
(
product_class
=
ProductClass
.
objects
.
get
(
name
=
'Coupon'
))
client
=
Client
.
objects
.
create
(
username
=
'Tester'
)
self
.
basket
=
factories
.
BasketFactory
(
owner
=
client
)
self
.
basket
.
add_product
(
self
.
product
,
1
)
self
.
order
=
factories
.
create_order
(
basket
=
self
.
basket
)
def
test_invoice_created
(
self
):
""" Verify a new invoice is created for an order that does not have it. """
self
.
assertEqual
(
Invoice
.
objects
.
count
(),
0
)
call_command
(
'create_invoices'
)
self
.
assertEqual
(
Invoice
.
objects
.
count
(),
1
)
invoice
=
Invoice
.
objects
.
first
()
self
.
assertEqual
(
invoice
.
order
,
self
.
order
)
self
.
assertEqual
(
invoice
.
business_client
.
name
,
self
.
basket
.
owner
.
username
)
def
test_invoice_not_created
(
self
):
""" Verify no new invoices are created when orders already have invoices. """
business_client
=
BusinessClient
.
objects
.
create
(
name
=
'Tester'
)
Invoice
.
objects
.
create
(
order
=
self
.
order
,
business_client
=
business_client
)
self
.
assertEqual
(
Invoice
.
objects
.
count
(),
1
)
call_command
(
'create_invoices'
)
self
.
assertEqual
(
Invoice
.
objects
.
count
(),
1
)
class
InvoiceManagementCommandExceptionsTest
(
CouponMixin
,
TestCase
):
""" Moved to this new test class because of a segmentation error. """
def
setUp
(
self
):
super
(
InvoiceManagementCommandExceptionsTest
,
self
)
.
setUp
()
self
.
product
=
factories
.
ProductFactory
(
product_class
=
ProductClass
.
objects
.
get
(
name
=
'Coupon'
))
self
.
basket
=
factories
.
BasketFactory
()
self
.
basket
.
add_product
(
self
.
product
,
1
)
self
.
basket
.
submit
()
def
assert_log_message
(
self
,
msg
):
logger_name
=
'ecommerce.invoice.management.commands.create_invoices'
with
LogCapture
(
logger_name
)
as
l
:
call_command
(
'create_invoices'
)
l
.
check
((
logger_name
,
'ERROR'
,
msg
))
def
test_command_basket_exception
(
self
):
Basket
.
objects
.
all
()
.
delete
()
self
.
assert_log_message
(
'Basket for coupon {} does not exist!'
.
format
(
self
.
product
.
id
))
def
test_command_order_exception
(
self
):
self
.
assert_log_message
(
'Order for basket {} does not exist!'
.
format
(
self
.
basket
.
id
))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment