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
c55253cb
Commit
c55253cb
authored
Sep 05, 2016
by
Vedran Karacic
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change order-basket-lines queries to order-lines.
parent
d2749b4a
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
6 additions
and
66 deletions
+6
-66
ecommerce/extensions/api/serializers.py
+2
-2
ecommerce/extensions/api/v2/tests/views/test_coupons.py
+3
-3
ecommerce/extensions/api/v2/views/coupons.py
+1
-1
ecommerce/invoice/management/__init__.py
+0
-0
ecommerce/invoice/management/commands/__init__.py
+0
-0
ecommerce/invoice/management/commands/squash_duplicate_invoices.py
+0
-26
ecommerce/invoice/tests.py
+0
-34
No files found.
ecommerce/extensions/api/serializers.py
View file @
c55253cb
...
@@ -495,7 +495,7 @@ class CouponSerializer(ProductPaymentInfoMixin, serializers.ModelSerializer):
...
@@ -495,7 +495,7 @@ class CouponSerializer(ProductPaymentInfoMixin, serializers.ModelSerializer):
return
offer
.
condition
.
range
.
catalog_query
return
offer
.
condition
.
range
.
catalog_query
def
get_client
(
self
,
obj
):
def
get_client
(
self
,
obj
):
return
Invoice
.
objects
.
get
(
order__
basket__
lines__product
=
obj
)
.
business_client
.
name
return
Invoice
.
objects
.
get
(
order__lines__product
=
obj
)
.
business_client
.
name
def
get_code
(
self
,
obj
):
def
get_code
(
self
,
obj
):
if
self
.
retrieve_quantity
(
obj
)
==
1
:
if
self
.
retrieve_quantity
(
obj
)
==
1
:
...
@@ -544,7 +544,7 @@ class CouponSerializer(ProductPaymentInfoMixin, serializers.ModelSerializer):
...
@@ -544,7 +544,7 @@ class CouponSerializer(ProductPaymentInfoMixin, serializers.ModelSerializer):
Currently only invoices are supported, in the event of adding another
Currently only invoices are supported, in the event of adding another
payment processor append it to the response dictionary.
payment processor append it to the response dictionary.
"""
"""
invoice
=
Invoice
.
objects
.
filter
(
order__
basket__
lines__product
=
obj
)
.
first
()
invoice
=
Invoice
.
objects
.
filter
(
order__lines__product
=
obj
)
.
first
()
response
=
{
'Invoice'
:
InvoiceSerializer
(
invoice
)
.
data
}
response
=
{
'Invoice'
:
InvoiceSerializer
(
invoice
)
.
data
}
return
response
return
response
...
...
ecommerce/extensions/api/v2/tests/views/test_coupons.py
View file @
c55253cb
...
@@ -507,7 +507,7 @@ class CouponViewSetFunctionalTest(CouponMixin, CourseCatalogTestMixin, CourseCat
...
@@ -507,7 +507,7 @@ class CouponViewSetFunctionalTest(CouponMixin, CourseCatalogTestMixin, CourseCat
self
.
assertEqual
(
invoice
.
business_client
.
name
,
client_username
)
self
.
assertEqual
(
invoice
.
business_client
.
name
,
client_username
)
def
test_update_invoice_data
(
self
):
def
test_update_invoice_data
(
self
):
invoice
=
Invoice
.
objects
.
get
(
order__
basket__
lines__product
=
self
.
coupon
)
invoice
=
Invoice
.
objects
.
get
(
order__lines__product
=
self
.
coupon
)
self
.
assertEqual
(
invoice
.
discount_type
,
Invoice
.
PERCENTAGE
)
self
.
assertEqual
(
invoice
.
discount_type
,
Invoice
.
PERCENTAGE
)
CouponViewSet
()
.
update_invoice_data
(
CouponViewSet
()
.
update_invoice_data
(
coupon
=
self
.
coupon
,
coupon
=
self
.
coupon
,
...
@@ -516,7 +516,7 @@ class CouponViewSetFunctionalTest(CouponMixin, CourseCatalogTestMixin, CourseCat
...
@@ -516,7 +516,7 @@ class CouponViewSetFunctionalTest(CouponMixin, CourseCatalogTestMixin, CourseCat
}
}
)
)
invoice
=
Invoice
.
objects
.
get
(
order__
basket__
lines__product
=
self
.
coupon
)
invoice
=
Invoice
.
objects
.
get
(
order__lines__product
=
self
.
coupon
)
self
.
assertEqual
(
invoice
.
discount_type
,
Invoice
.
FIXED
)
self
.
assertEqual
(
invoice
.
discount_type
,
Invoice
.
FIXED
)
@ddt.data
(
'audit'
,
'honor'
)
@ddt.data
(
'audit'
,
'honor'
)
...
@@ -593,7 +593,7 @@ class CouponViewSetFunctionalTest(CouponMixin, CourseCatalogTestMixin, CourseCat
...
@@ -593,7 +593,7 @@ class CouponViewSetFunctionalTest(CouponMixin, CourseCatalogTestMixin, CourseCat
""" Verify an invoice is created with the proper data. """
""" Verify an invoice is created with the proper data. """
self
.
update_prepaid_invoice_data
()
self
.
update_prepaid_invoice_data
()
response
=
self
.
get_response_json
(
'POST'
,
COUPONS_LINK
,
data
=
self
.
data
)
response
=
self
.
get_response_json
(
'POST'
,
COUPONS_LINK
,
data
=
self
.
data
)
invoice
=
Invoice
.
objects
.
get
(
order__
basket__
lines__product__id
=
response
[
'coupon_id'
])
invoice
=
Invoice
.
objects
.
get
(
order__lines__product__id
=
response
[
'coupon_id'
])
self
.
assertEqual
(
invoice
.
type
,
self
.
data
[
'invoice_type'
])
self
.
assertEqual
(
invoice
.
type
,
self
.
data
[
'invoice_type'
])
self
.
assertEqual
(
invoice
.
number
,
self
.
data
[
'invoice_number'
])
self
.
assertEqual
(
invoice
.
number
,
self
.
data
[
'invoice_number'
])
self
.
assertEqual
(
invoice
.
payment_date
.
isoformat
(),
self
.
data
[
'invoice_payment_date'
])
self
.
assertEqual
(
invoice
.
payment_date
.
isoformat
(),
self
.
data
[
'invoice_payment_date'
])
...
...
ecommerce/extensions/api/v2/views/coupons.py
View file @
c55253cb
...
@@ -418,7 +418,7 @@ class CouponViewSet(EdxOrderPlacementMixin, viewsets.ModelViewSet):
...
@@ -418,7 +418,7 @@ class CouponViewSet(EdxOrderPlacementMixin, viewsets.ModelViewSet):
invoice_data
=
self
.
create_update_data_dict
(
data
=
data
,
fields
=
Invoice
.
UPDATEABLE_INVOICE_FIELDS
)
invoice_data
=
self
.
create_update_data_dict
(
data
=
data
,
fields
=
Invoice
.
UPDATEABLE_INVOICE_FIELDS
)
if
invoice_data
:
if
invoice_data
:
Invoice
.
objects
.
filter
(
order__
basket__
lines__product
=
coupon
)
.
update
(
**
invoice_data
)
Invoice
.
objects
.
filter
(
order__lines__product
=
coupon
)
.
update
(
**
invoice_data
)
def
destroy
(
self
,
request
,
pk
):
# pylint: disable=unused-argument
def
destroy
(
self
,
request
,
pk
):
# pylint: disable=unused-argument
try
:
try
:
...
...
ecommerce/invoice/management/__init__.py
deleted
100644 → 0
View file @
d2749b4a
ecommerce/invoice/management/commands/__init__.py
deleted
100644 → 0
View file @
d2749b4a
ecommerce/invoice/management/commands/squash_duplicate_invoices.py
deleted
100644 → 0
View file @
d2749b4a
import
logging
from
django.core.management
import
BaseCommand
from
ecommerce.extensions.catalogue.models
import
Product
from
ecommerce.invoice.models
import
Invoice
logger
=
logging
.
getLogger
(
__name__
)
class
Command
(
BaseCommand
):
"""
Squash duplicate invoices for coupon orders.
When we moved from re-using a coupon some of them had already more than one invoice,
and we are not having that! Monogamy rulez here, yerr damn hippies!
"""
ch
=
logging
.
StreamHandler
()
ch
.
setLevel
(
logging
.
DEBUG
)
logger
.
addHandler
(
ch
)
def
handle
(
self
,
*
args
,
**
options
):
for
coupon
in
Product
.
objects
.
filter
(
product_class__name
=
'Coupon'
):
qs
=
Invoice
.
objects
.
filter
(
order__basket__lines__product
=
coupon
)
.
order_by
(
'created'
)
if
qs
.
count
()
>
1
:
qs
.
exclude
(
pk
=
qs
.
first
()
.
id
)
.
delete
()
logger
.
info
(
'Deleted douplicate invoices of coupon
%
s'
,
coupon
.
id
)
ecommerce/invoice/tests.py
View file @
c55253cb
from
django.core.management
import
call_command
from
oscar.test
import
factories
from
oscar.test
import
factories
from
ecommerce.invoice.models
import
Invoice
from
ecommerce.invoice.models
import
Invoice
...
@@ -26,36 +25,3 @@ class InvoiceTests(TestCase):
...
@@ -26,36 +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
InvoiceCommandTests
(
TestCase
):
"""Tests for the squash_duplicate_invoices command."""
def
setUp
(
self
):
super
(
InvoiceCommandTests
,
self
)
.
setUp
()
coupon_pc
=
factories
.
ProductClassFactory
(
name
=
'Coupon'
)
self
.
product
=
factories
.
ProductFactory
(
product_class
=
coupon_pc
)
self
.
basket
=
factories
.
BasketFactory
()
self
.
basket
.
add_product
(
self
.
product
,
1
)
self
.
order
=
factories
.
create_order
(
basket
=
self
.
basket
)
self
.
invoice
=
Invoice
.
objects
.
create
(
order
=
self
.
order
)
def
assert_unique_invoice
(
self
,
product
,
invoice
):
"""Helper method for asserting there is only one invoice for given product."""
invoice_qs
=
Invoice
.
objects
.
filter
(
order__basket__lines__product
=
product
)
self
.
assertEqual
(
invoice_qs
.
count
(),
1
)
self
.
assertEqual
(
invoice_qs
.
first
(),
invoice
)
def
test_squashing_invoices
(
self
):
"""Verify after calling the command the duplicate invoices are squashed."""
Invoice
.
objects
.
create
(
order
=
self
.
order
)
self
.
assertEqual
(
Invoice
.
objects
.
filter
(
order__basket__lines__product
=
self
.
product
)
.
count
(),
2
)
call_command
(
'squash_duplicate_invoices'
)
self
.
assert_unique_invoice
(
self
.
product
,
self
.
invoice
)
def
test_not_squashing_invoices
(
self
):
"""Verify the non-duplicate invoices are left the same."""
self
.
assertEqual
(
Invoice
.
objects
.
filter
(
order__basket__lines__product
=
self
.
product
)
.
count
(),
1
)
call_command
(
'squash_duplicate_invoices'
)
self
.
assert_unique_invoice
(
self
.
product
,
self
.
invoice
)
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