Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
AE UTBM
Sith
Commits
0e171fbc
Commit
0e171fbc
authored
Jun 09, 2017
by
Krophil
Browse files
add some validationErrors on OperationForm
parent
1bcde80a
Pipeline
#1039
failed with stage
in 4 minutes and 42 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
accounting/models.py
View file @
0e171fbc
...
...
@@ -282,7 +282,9 @@ class Operation(models.Model):
def
clean
(
self
):
super
(
Operation
,
self
).
clean
()
if
self
.
date
<
self
.
journal
.
start_date
:
if
self
.
date
is
None
:
raise
ValidationError
(
_
(
"The date must be set."
))
elif
self
.
date
<
self
.
journal
.
start_date
:
raise
ValidationError
(
_
(
"""The date can not be before the start date of the journal, which is
%(start_date)s."""
)
%
{
'start_date'
:
defaultfilters
.
date
(
self
.
journal
.
start_date
,
settings
.
DATE_FORMAT
)})
if
self
.
target_type
!=
"OTHER"
and
self
.
get_target
()
is
None
:
...
...
accounting/views.py
View file @
0e171fbc
...
...
@@ -28,7 +28,7 @@ from django.shortcuts import render
from
django.core.urlresolvers
import
reverse_lazy
,
reverse
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.forms.models
import
modelform_factory
from
django.core.exceptions
import
PermissionDenied
from
django.core.exceptions
import
PermissionDenied
,
ValidationError
from
django.forms
import
HiddenInput
,
TextInput
from
django.db
import
transaction
from
django.db.models
import
Sum
...
...
@@ -305,14 +305,21 @@ class OperationForm(forms.ModelForm):
def
clean
(
self
):
self
.
cleaned_data
=
super
(
OperationForm
,
self
).
clean
()
if
'target_type'
in
self
.
cleaned_data
.
keys
():
if
self
.
cleaned_data
[
'target_type'
]
==
"USER"
:
self
.
cleaned_data
[
'target_id'
]
=
self
.
cleaned_data
[
'user'
].
id
elif
self
.
cleaned_data
[
'target_type'
]
==
"ACCOUNT"
:
self
.
cleaned_data
[
'target_id'
]
=
self
.
cleaned_data
[
'club_account'
].
id
elif
self
.
cleaned_data
[
'target_type'
]
==
"CLUB"
:
self
.
cleaned_data
[
'target_id'
]
=
self
.
cleaned_data
[
'club'
].
id
elif
self
.
cleaned_data
[
'target_type'
]
==
"COMPANY"
:
self
.
cleaned_data
[
'target_id'
]
=
self
.
cleaned_data
[
'company'
].
id
if
self
.
cleaned_data
.
get
(
"user"
)
is
None
or
self
.
cleaned_data
.
get
(
"club"
)
or
self
.
cleaned_data
.
get
(
"club_account"
)
is
None
or
self
.
cleaned_data
.
get
(
"company"
)
is
None
or
self
.
cleaned_data
.
get
(
"other"
):
self
.
add_error
(
'target_id'
,
ValidationError
(
_
(
"The target must be set."
)))
else
:
if
self
.
cleaned_data
[
'target_type'
]
==
"USER"
:
self
.
cleaned_data
[
'target_id'
]
=
self
.
cleaned_data
[
'user'
].
id
elif
self
.
cleaned_data
[
'target_type'
]
==
"ACCOUNT"
:
self
.
cleaned_data
[
'target_id'
]
=
self
.
cleaned_data
[
'club_account'
].
id
elif
self
.
cleaned_data
[
'target_type'
]
==
"CLUB"
:
self
.
cleaned_data
[
'target_id'
]
=
self
.
cleaned_data
[
'club'
].
id
elif
self
.
cleaned_data
[
'target_type'
]
==
"COMPANY"
:
self
.
cleaned_data
[
'target_id'
]
=
self
.
cleaned_data
[
'company'
].
id
if
self
.
cleaned_data
.
get
(
"amount"
)
is
None
:
self
.
add_error
(
'amount'
,
ValidationError
(
_
(
"The amount must be set."
)))
return
self
.
cleaned_data
def
save
(
self
):
...
...
Write
Preview
Supports
Markdown
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