Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
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
Roque
erp5
Commits
b6b51f61
Commit
b6b51f61
authored
1 month ago
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
accounting: update Base_importGapFile to use python's csv module
This was reimplemented a broken version of csv.DictReader
parent
fff85e8d
erp5_monitoring_app
erp5_forum
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
3 additions
and
53 deletions
+3
-53
bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/Base_importGapFile.py
...teItem/portal_skins/erp5_accounting/Base_importGapFile.py
+3
-53
No files found.
bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/Base_importGapFile.py
View file @
b6b51f61
import
csv
def
recursiveDocumentList
(
obj
):
def
recursiveDocumentList
(
obj
):
ret
=
[]
ret
=
[]
ret
.
append
(
obj
.
getPath
())
ret
.
append
(
obj
.
getPath
())
...
@@ -5,64 +7,12 @@ def recursiveDocumentList(obj):
...
@@ -5,64 +7,12 @@ def recursiveDocumentList(obj):
ret
.
extend
(
recursiveDocumentList
(
i
))
ret
.
extend
(
recursiveDocumentList
(
i
))
return
ret
return
ret
def
splitCsvLine
(
str_line
):
unclean_list
=
[]
pieces_of_line
=
str_line
.
split
(
','
)
p_stack
=
''
for
p
in
pieces_of_line
:
p_stack
+=
p
if
p_stack
.
count
(
'"'
)
%
2
==
0
:
unclean_list
.
append
(
p_stack
)
p_stack
=
''
clean_list
=
[]
for
item
in
unclean_list
:
clean_item
=
item
if
clean_item
.
find
(
'"'
)
!=
-
1
:
if
len
(
clean_item
)
<=
2
:
clean_item
=
''
else
:
clean_item
=
clean_item
[
1
:]
clean_item
=
clean_item
[:
-
1
]
clean_item
=
clean_item
.
replace
(
'""'
,
'"'
)
else
:
if
len
(
clean_item
)
>
0
:
if
clean_item
.
find
(
'.'
)
!=
-
1
:
clean_item
=
float
(
clean_item
)
else
:
clean_item
=
int
(
clean_item
)
else
:
clean_item
=
None
clean_list
.
append
(
clean_item
)
return
clean_list
def
getSubCategory
(
parent
,
category_id
):
def
getSubCategory
(
parent
,
category_id
):
try
:
try
:
return
parent
[
category_id
]
return
parent
[
category_id
]
except
KeyError
:
except
KeyError
:
return
parent
.
newContent
(
id
=
category_id
)
return
parent
.
newContent
(
id
=
category_id
)
csv_file_line_list
=
import_file
.
readlines
()
csv_line_list
=
[]
for
csv_line
in
csv_file_line_list
:
csv_line_list
.
append
(
string
.
replace
(
csv_line
,
'
\
n
'
,
''
).
decode
(
encoding
).
encode
(
'utf-8'
)
)
object_list
=
[]
csv_property_list
=
splitCsvLine
(
csv_line_list
[
0
])
for
csv_line
in
csv_line_list
[
2
:]:
property_dict
=
{}
csv_data_list
=
splitCsvLine
(
csv_line
)
data_n
=
0
for
property_
in
csv_property_list
:
property_dict
[
property_
]
=
csv_data_list
[
data_n
]
data_n
+=
1
object_list
.
append
(
property_dict
)
root
=
context
.
getPortalObject
().
portal_categories
root
=
context
.
getPortalObject
().
portal_categories
for
path
in
gap_root_path
.
split
(
'/'
):
for
path
in
gap_root_path
.
split
(
'/'
):
...
@@ -71,7 +21,7 @@ for path in gap_root_path.split('/'):
...
@@ -71,7 +21,7 @@ for path in gap_root_path.split('/'):
existing_path_list
=
recursiveDocumentList
(
root
)
existing_path_list
=
recursiveDocumentList
(
root
)
existing_path_list
.
remove
(
root
.
getPath
())
existing_path_list
.
remove
(
root
.
getPath
())
for
property_dict
in
object_list
:
for
property_dict
in
list
(
csv
.
DictReader
(
import_file
))
:
description
=
property_dict
.
get
(
'Description'
,
None
)
or
''
description
=
property_dict
.
get
(
'Description'
,
None
)
or
''
gap
=
property_dict
.
get
(
'Gap'
,
None
)
or
''
gap
=
property_dict
.
get
(
'Gap'
,
None
)
or
''
title
=
property_dict
.
get
(
'Title'
,
None
)
or
''
title
=
property_dict
.
get
(
'Title'
,
None
)
or
''
...
...
This diff is collapsed.
Click to expand it.
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