Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
ProjektMedizin
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Lorenz Zahn
ProjektMedizin
Commits
27efd1b4
Commit
27efd1b4
authored
2 years ago
by
Lorenz Zahn
Browse files
Options
Downloads
Patches
Plain Diff
formatierung
parent
58825a88
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
app/vkk/workhours/accounting/projects/project/export/receipts/views.py
+47
-37
47 additions, 37 deletions
...ours/accounting/projects/project/export/receipts/views.py
with
47 additions
and
37 deletions
app/vkk/workhours/accounting/projects/project/export/receipts/views.py
+
47
−
37
View file @
27efd1b4
import
json
,
csv
import
json
,
csv
,
datetime
from
django.utils.translation
import
gettext_lazy
as
_
from
django.http
import
JsonResponse
,
HttpResponse
from
django.views.generic
import
FormView
...
...
@@ -91,7 +91,7 @@ class ReceiptTemplateSelectionView(FormView, AccountantRequiredMixin):
# here be conversion
table
=
[
[
self
.
_data_cell_calculation
(
cell
,
receipt
,
data
)
for
cell
in
row
_data_cell_calculation
(
cell
,
receipt
,
data
)
for
cell
in
row
]
for
row
in
table_template
]
...
...
@@ -99,38 +99,48 @@ class ReceiptTemplateSelectionView(FormView, AccountantRequiredMixin):
writer
.
writerows
(
table
)
return
response
def
_data_cell_calculation
(
self
,
template
,
receipt
,
data
):
"""
This functions retrieves the required data point according to the template
"""
method
=
template
.
get
(
"
method
"
)
if
method
is
None
:
return
""
elif
method
==
"
FIXED
"
:
return
template
.
get
(
"
value
"
)
elif
method
==
"
GENERATED
"
:
value
=
template
.
get
(
"
value
"
)
args
=
value
.
split
(
"
"
)
out
=
[]
for
arg
in
args
:
parts
=
arg
.
split
(
"
.
"
)
if
parts
[
0
]
==
"
data
"
:
lookup
=
data
for
part
in
parts
[
1
:]:
lookup
=
lookup
.
get
(
part
)
if
lookup
is
None
:
break
if
lookup
is
not
None
:
out
.
append
(
str
(
lookup
))
elif
parts
[
0
]
in
vars
(
receipt
):
lookup
=
vars
(
receipt
)
for
part
in
parts
:
lookup
=
lookup
.
get
(
part
)
if
lookup
is
None
:
break
if
lookup
is
not
None
:
out
.
append
(
str
(
lookup
))
else
:
out
.
append
(
str
(
arg
))
return
"
"
.
join
(
out
)
else
:
return
""
def
_data_cell_calculation
(
template
,
receipt
,
data
):
"""
This functions retrieves the required data point according to the template
"""
method
=
template
.
get
(
"
method
"
)
if
method
is
None
:
return
""
elif
method
==
"
FIXED
"
:
return
template
.
get
(
"
value
"
)
elif
method
==
"
GENERATED
"
:
value
=
template
.
get
(
"
value
"
)
args
=
value
.
split
(
"
"
)
out
=
[]
for
arg
in
args
:
parts
=
arg
.
split
(
"
.
"
)
if
parts
[
0
]
==
"
data
"
:
lookup
=
data
for
part
in
parts
[
1
:]:
lookup
=
lookup
.
get
(
part
)
if
lookup
is
None
:
break
if
lookup
is
not
None
:
out
.
append
(
str
(
_format
(
lookup
)))
elif
parts
[
0
]
in
vars
(
receipt
):
lookup
=
vars
(
receipt
)
for
part
in
parts
:
lookup
=
lookup
.
get
(
part
)
if
lookup
is
None
:
break
if
lookup
is
not
None
:
out
.
append
(
str
(
_format
(
lookup
)))
else
:
out
.
append
(
str
(
arg
))
return
"
"
.
join
(
out
)
else
:
return
""
def
_format
(
value
):
if
isinstance
(
value
,
datetime
.
date
):
return
value
.
strftime
(
"
%d.%m.%Y
"
)
elif
isinstance
(
value
,
str
):
return
0
if
value
==
"
0.00
"
else
value
elif
isinstance
(
value
,
bool
):
return
_
(
"
Ja
"
)
if
value
else
_
(
"
Nein
"
)
else
:
return
value
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment