Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
converse.js
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
converse.js
Commits
bf1dcce6
Commit
bf1dcce6
authored
Feb 10, 2016
by
Michal Čihař
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add interval validation and tests for it
Signed-off-by:
Michal Čihař
<
michal@cihar.com
>
parent
7352a459
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
2 deletions
+60
-2
weblate/billing/models.py
weblate/billing/models.py
+14
-0
weblate/billing/tests.py
weblate/billing/tests.py
+46
-2
No files found.
weblate/billing/models.py
View file @
bf1dcce6
...
...
@@ -23,7 +23,9 @@ from __future__ import unicode_literals
from
datetime
import
timedelta
from
django.db
import
models
from
django.db.models
import
Q
from
django.contrib.auth.models
import
User
from
django.core.exceptions
import
ValidationError
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.utils.encoding
import
python_2_unicode_compatible
from
django.utils
import
timezone
...
...
@@ -161,3 +163,15 @@ class Invoice(models.Model):
def
__str__
(
self
):
return
'{0} - {1}: {2}'
.
format
(
self
.
start
,
self
.
end
,
self
.
billing
)
def
clean
(
self
):
if
self
.
end
<=
self
.
start
:
raise
ValidationError
(
'Start has be to before end!'
)
overlapping
=
Invoice
.
objects
.
filter
(
(
Q
(
start__lte
=
self
.
end
)
&
Q
(
end__gte
=
self
.
end
))
|
(
Q
(
start__lte
=
self
.
start
)
&
Q
(
end__gte
=
self
.
start
))
).
filter
(
billing
=
self
.
billing
)
if
overlapping
.
exists
():
raise
ValidationError
(
'Overlapping invoices exist: {0}'
.
format
(
overlapping
)
)
weblate/billing/tests.py
View file @
bf1dcce6
...
...
@@ -24,6 +24,7 @@ from six import StringIO
from
django.test
import
TestCase
from
django.contrib.auth.models
import
User
from
django.core.exceptions
import
ValidationError
from
django.core.management
import
call_command
from
django.utils
import
timezone
...
...
@@ -38,8 +39,8 @@ class BillingTest(TestCase):
self
.
billing
=
Billing
.
objects
.
create
(
user
=
self
.
user
,
plan
=
self
.
plan
)
self
.
invoice
=
Invoice
.
objects
.
create
(
billing
=
self
.
billing
,
start
=
timezone
.
now
()
-
timedelta
(
days
=
2
),
end
=
timezone
.
now
()
+
timedelta
(
days
=
2
),
start
=
timezone
.
now
()
.
date
()
-
timedelta
(
days
=
2
),
end
=
timezone
.
now
()
.
date
()
+
timedelta
(
days
=
2
),
payment
=
10
,
)
self
.
projectnum
=
0
...
...
@@ -78,3 +79,46 @@ class BillingTest(TestCase):
'Following billings are over limit:
\
n
* bill (test)
\
n
'
'Following billings are past due date:
\
n
* bill (test)
\
n
'
)
def
test_invoice_validation
(
self
):
invoice
=
Invoice
(
billing
=
self
.
billing
,
start
=
self
.
invoice
.
start
,
end
=
self
.
invoice
.
end
,
payment
=
30
)
# Full overlap
self
.
assertRaises
(
ValidationError
,
invoice
.
clean
)
# Start overlap
invoice
.
start
=
self
.
invoice
.
end
+
timedelta
(
days
=
1
)
self
.
assertRaises
(
ValidationError
,
invoice
.
clean
)
# Zero interval
invoice
.
end
=
self
.
invoice
.
end
+
timedelta
(
days
=
1
)
self
.
assertRaises
(
ValidationError
,
invoice
.
clean
)
# Valid after existing
invoice
.
end
=
self
.
invoice
.
end
+
timedelta
(
days
=
2
)
invoice
.
clean
()
# End overlap
invoice
.
start
=
self
.
invoice
.
start
-
timedelta
(
days
=
4
)
invoice
.
end
=
self
.
invoice
.
end
self
.
assertRaises
(
ValidationError
,
invoice
.
clean
)
# Valid before existing
invoice
.
end
=
self
.
invoice
.
start
-
timedelta
(
days
=
1
)
invoice
.
clean
()
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