Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
6
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
I
invoice
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
2
Merge Requests
2
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Test Cases
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
kb
invoice
Commits
0a1daccb
Commit
0a1daccb
authored
Sep 13, 2019
by
Patrick Kimber
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Payment processor no longer needs a slug (see 'MagentoSitePaymentMethod' in the 'magento' app)
parent
11b6f23e
Pipeline
#82077049
passed with stage
in 5 minutes and 36 seconds
Changes
6
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
46 additions
and
51 deletions
+46
-51
invoice/migrations/0024_auto_20190912_1842.py
invoice/migrations/0024_auto_20190912_1842.py
+14
-1
invoice/models.py
invoice/models.py
+8
-18
invoice/templates/invoice/_batch_header.html
invoice/templates/invoice/_batch_header.html
+1
-1
invoice/tests/factories.py
invoice/tests/factories.py
+2
-2
invoice/tests/test_batch.py
invoice/tests/test_batch.py
+9
-9
invoice/tests/test_payment_processor.py
invoice/tests/test_payment_processor.py
+12
-20
No files found.
invoice/migrations/0024_auto_20190912_1
724
.py
→
invoice/migrations/0024_auto_20190912_1
842
.py
View file @
0a1daccb
# Generated by Django 2.2.4 on 2019-09-12 1
6:24
# Generated by Django 2.2.4 on 2019-09-12 1
7:42
from
django.db
import
migrations
,
models
import
django.db.models.deletion
...
...
@@ -29,6 +29,14 @@ class Migration(migrations.Migration):
"verbose_name_plural"
:
"Invoice Issue Lines"
,
},
),
migrations
.
AlterModelOptions
(
name
=
"paymentprocessor"
,
options
=
{
"ordering"
:
(
"description"
,),
"verbose_name"
:
"Payment Processor"
,
},
),
migrations
.
RemoveField
(
model_name
=
"paymentprocessor"
,
name
=
"slug"
),
migrations
.
AlterField
(
model_name
=
"invoiceissue"
,
name
=
"invoice"
,
...
...
@@ -37,6 +45,11 @@ class Migration(migrations.Migration):
to
=
"invoice.Invoice"
,
),
),
migrations
.
AlterField
(
model_name
=
"paymentprocessor"
,
name
=
"description"
,
field
=
models
.
CharField
(
max_length
=
100
,
unique
=
True
),
),
migrations
.
AlterUniqueTogether
(
name
=
"invoiceissue"
,
unique_together
=
set
()
),
...
...
invoice/models.py
View file @
0a1daccb
...
...
@@ -274,35 +274,25 @@ class InvoiceError(Exception):
class
PaymentProcessorManager
(
models
.
Manager
):
def
_create_payment_processor
(
self
,
slug
,
description
):
x
=
self
.
model
(
slug
=
slug
,
description
=
description
)
def
create_payment_processor
(
self
,
description
):
x
=
self
.
model
(
description
=
description
)
x
.
save
()
return
x
def
init_payment_processor
(
self
,
slug
,
description
):
try
:
x
=
self
.
model
.
objects
.
get
(
slug
=
slug
)
x
.
description
=
description
x
.
save
()
except
self
.
model
.
DoesNotExist
:
x
=
self
.
_create_payment_processor
(
slug
,
description
)
return
x
class
PaymentProcessor
(
TimeStampedModel
):
slug
=
models
.
SlugField
(
max_length
=
30
,
unique
=
True
)
description
=
models
.
CharField
(
max_length
=
100
)
description
=
models
.
CharField
(
max_length
=
100
,
unique
=
True
)
deleted
=
models
.
BooleanField
(
default
=
False
)
objects
=
PaymentProcessorManager
()
class
Meta
:
ordering
=
(
"description"
,)
verbose_name
=
"Payment Processor"
def
__str__
(
self
):
if
self
.
description
:
return
"{} - {}"
.
format
(
self
.
slug
,
self
.
description
)
else
:
return
self
.
slug
return
"{}{}"
.
format
(
self
.
description
,
" (deleted)"
if
self
.
deleted
else
""
)
class
InvoiceManager
(
TimedCreateModifyDeleteVersionModelManager
):
...
...
@@ -808,7 +798,7 @@ class Batch(TimeStampedModel):
self
.
batch_date
.
strftime
(
"%d/%m/%Y"
),
self
.
currency
.
slug
,
exchange
,
self
.
payment_processor
.
slug
,
self
.
payment_processor
.
description
,
)
)
...
...
invoice/templates/invoice/_batch_header.html
View file @
0a1daccb
...
...
@@ -29,7 +29,7 @@
Payment Processor
</td>
<td>
{{ batch.payment_processor.
slug
}}
{{ batch.payment_processor.
description
}}
</td>
</tr>
{% if batch_net %}
...
...
invoice/tests/factories.py
View file @
0a1daccb
...
...
@@ -36,8 +36,8 @@ class PaymentProcessorFactory(factory.django.DjangoModelFactory):
model
=
PaymentProcessor
@
factory
.
sequence
def
slug
(
n
):
return
"
slug
_{}"
.
format
(
n
)
def
description
(
n
):
return
"
description
_{}"
.
format
(
n
)
class
BatchFactory
(
factory
.
django
.
DjangoModelFactory
):
...
...
invoice/tests/test_batch.py
View file @
0a1daccb
...
...
@@ -26,7 +26,7 @@ def test_batch_number():
def
test_create_batch
():
batch_date
=
date
(
2018
,
2
,
22
)
currency
=
Currency
.
objects
.
get
(
slug
=
"GBP"
)
payment_processor
=
PaymentProcessorFactory
(
slug
=
"paypal"
)
payment_processor
=
PaymentProcessorFactory
()
invoice_1
=
InvoiceFactory
(
invoice_date
=
batch_date
,
currency
=
currency
,
...
...
@@ -52,7 +52,7 @@ def test_create_batch_exchange_rate():
batch_date
=
date
(
2018
,
2
,
22
)
currency
=
Currency
.
objects
.
get
(
slug
=
"EUR"
)
exchange_rate
=
Decimal
(
"0.987"
)
payment_processor
=
PaymentProcessorFactory
(
slug
=
"paypal"
)
payment_processor
=
PaymentProcessorFactory
()
InvoiceFactory
(
invoice_date
=
batch_date
,
currency
=
currency
,
...
...
@@ -76,7 +76,7 @@ def test_create_batch_exchange_rate():
def
test_create_batch_no_invoices
():
batch_date
=
date
(
2018
,
2
,
22
)
currency
=
Currency
.
objects
.
get
(
slug
=
"GBP"
)
payment_processor
=
PaymentProcessorFactory
(
slug
=
"paypal"
)
payment_processor
=
PaymentProcessorFactory
()
batch
=
Batch
.
objects
.
create_batch
(
batch_date
,
currency
,
None
,
payment_processor
)
...
...
@@ -89,7 +89,7 @@ def test_duplicate():
batch_date
=
date
(
2018
,
2
,
22
)
currency
=
Currency
.
objects
.
get
(
slug
=
"GBP"
)
exchange_rate
=
Decimal
()
payment_processor
=
PaymentProcessorFactory
(
slug
=
"paypal"
)
payment_processor
=
PaymentProcessorFactory
()
BatchFactory
(
batch_date
=
batch_date
,
currency
=
currency
,
...
...
@@ -101,7 +101,7 @@ def test_duplicate():
batch_date
=
batch_date
,
currency
=
currency
,
exchange_rate
=
exchange_rate
,
payment_processor
=
PaymentProcessorFactory
(
slug
=
"stripe"
),
payment_processor
=
PaymentProcessorFactory
(),
)
with
pytest
.
raises
(
IntegrityError
):
BatchFactory
(
...
...
@@ -197,7 +197,7 @@ def test_net_and_vat():
@
pytest
.
mark
.
django_db
def
test_str
():
currency
=
Currency
.
objects
.
get
(
slug
=
"GBP"
)
payment_processor
=
PaymentProcessorFactory
(
slug
=
"payp
al"
)
payment_processor
=
PaymentProcessorFactory
(
description
=
"PayP
al"
)
batch
=
BatchFactory
(
batch_date
=
date
(
2018
,
2
,
22
),
currency
=
currency
,
...
...
@@ -205,14 +205,14 @@ def test_str():
)
assert
(
"Invoice batch {} for 22/02/2018 currency "
"'GBP' payment processor '
payp
al'"
.
format
(
batch
.
pk
)
"'GBP' payment processor '
PayP
al'"
.
format
(
batch
.
pk
)
)
==
str
(
batch
)
@
pytest
.
mark
.
django_db
def
test_str_exchange_rate
():
currency
=
Currency
.
objects
.
get
(
slug
=
"EUR"
)
payment_processor
=
PaymentProcessorFactory
(
slug
=
"paypal
"
)
payment_processor
=
PaymentProcessorFactory
(
description
=
"Stripe
"
)
batch
=
BatchFactory
(
batch_date
=
date
(
2018
,
2
,
22
),
currency
=
currency
,
...
...
@@ -221,7 +221,7 @@ def test_str_exchange_rate():
)
assert
(
"Invoice batch {} for 22/02/2018 currency 'EUR' (0.834) "
"payment processor '
paypal
'"
.
format
(
batch
.
pk
)
"payment processor '
Stripe
'"
.
format
(
batch
.
pk
)
)
==
str
(
batch
)
...
...
invoice/tests/test_payment_processor.py
View file @
0a1daccb
...
...
@@ -6,34 +6,26 @@ from .factories import PaymentProcessorFactory
@
pytest
.
mark
.
django_db
def
test_init_payment_processor
():
PaymentProcessorFactory
(
slug
=
"ABC"
,
description
=
"Apple"
)
assert
1
==
PaymentProcessor
.
objects
.
count
()
PaymentProcessor
.
objects
.
init_payment_processor
(
"ABC"
,
"Orange"
)
assert
1
==
PaymentProcessor
.
objects
.
count
()
payment_processor
=
PaymentProcessor
.
objects
.
first
()
assert
"ABC"
==
payment_processor
.
slug
assert
"Orange"
==
payment_processor
.
description
def
test_create_payment_processor
():
PaymentProcessor
.
objects
.
create_payment_processor
(
"Orange"
)
PaymentProcessor
.
objects
.
create_payment_processor
(
"Apple"
)
assert
[
"Apple"
,
"Orange"
]
==
[
x
.
description
for
x
in
PaymentProcessor
.
objects
.
all
()
]
@
pytest
.
mark
.
django_db
def
test_init_payment_processor_create
():
assert
0
==
PaymentProcessor
.
objects
.
count
()
payment_processor
=
PaymentProcessor
.
objects
.
init_payment_processor
(
"ABC"
,
"Apple"
)
assert
1
==
PaymentProcessor
.
objects
.
count
()
assert
"ABC"
==
payment_processor
.
slug
assert
"Apple"
==
payment_processor
.
description
def
test_str
():
assert
"Apple"
==
str
(
PaymentProcessorFactory
(
description
=
"Apple"
))
@
pytest
.
mark
.
django_db
def
test_str
():
assert
"A
BC - Apple
"
==
str
(
PaymentProcessorFactory
(
slug
=
"ABC"
,
description
=
"Apple"
)
def
test_str
_deleted
():
assert
"A
pple (deleted)
"
==
str
(
PaymentProcessorFactory
(
description
=
"Apple"
,
deleted
=
True
)
)
@
pytest
.
mark
.
django_db
def
test_str_no_description
():
assert
"
ABC"
==
str
(
PaymentProcessorFactory
(
slug
=
"ABC"
,
description
=
""
))
assert
"
"
==
str
(
PaymentProcessorFactory
(
description
=
""
))
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