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
FFDN
himport
Commits
d69bc30c
Commit
d69bc30c
authored
Feb 20, 2016
by
plb
Browse files
ajout de l'option --year
parent
a4ce257b
Changes
2
Hide whitespace changes
Inline
Side-by-side
bin/himport
View file @
d69bc30c
...
...
@@ -21,11 +21,11 @@ sys.stdout = codecs.getwriter(locale.getpreferredencoding())(sys.stdout)
def
process_args
(
argv
):
options
=
{}
usage
=
u
'himport -a -p -d -v'
usage
=
u
'himport -a -p -d -v
-y
'
try
:
opts
,
args
=
getopt
.
getopt
(
argv
,
"hp:P:adv"
,
[
"mysql-password="
,
"mysql-port"
]
argv
,
"hp:P:adv
y:
"
,
[
"mysql-password="
,
"mysql-port"
,
"year="
]
)
except
getopt
.
GetoptError
:
print
usage
...
...
@@ -33,6 +33,7 @@ def process_args(argv):
options
[
'alchemy'
]
=
False
options
[
'pdb'
]
=
False
options
[
'years'
]
=
list
()
options
[
'verbose'
]
=
0
for
opt
,
arg
in
opts
:
...
...
@@ -49,6 +50,8 @@ def process_args(argv):
options
[
'verbose'
]
+=
1
elif
opt
in
(
"-d"
,
"--pdb"
):
options
[
'pdb'
]
=
True
elif
opt
in
(
"-y"
,
"--year"
):
options
[
'years'
].
append
(
str
(
arg
))
return
options
...
...
@@ -87,10 +90,10 @@ def do_sqlalchemy(options):
sys
.
stdout
.
write
(
"%s
\n
"
%
(
pc
))
# On ecrie les fichiers hledger
Writer
.
write
(
"bank"
,
bank_journal
)
Writer
.
write
(
"sells"
,
sell_journal
)
Writer
.
write
(
"suppliers"
,
supplier_journal
)
Writer
.
write
(
"social"
,
social_journal
)
Writer
.
write
(
"bank"
,
bank_journal
,
options
[
'years'
]
)
Writer
.
write
(
"sells"
,
sell_journal
,
options
[
'years'
]
)
Writer
.
write
(
"suppliers"
,
supplier_journal
,
options
[
'years'
]
)
Writer
.
write
(
"social"
,
social_journal
,
options
[
'years'
]
)
Writer
.
write_hreport_plan
()
dolibarr
.
disconnect
()
...
...
himports/dolibarrWriter.py
View file @
d69bc30c
...
...
@@ -8,25 +8,26 @@ class Writer(object):
output_dir
=
settings
.
get
(
'OUTPUT_DIR'
)
@
staticmethod
def
write
(
journal
,
entries
):
def
write
(
journal
,
entries
,
years
):
filename
=
Writer
.
output_files
[
journal
]
output
=
os
.
path
.
join
(
Writer
.
output_dir
,
filename
)
entries_by_year
=
entries
.
get_by_year
()
for
year
in
entries_by_year
:
output_file
=
output
.
replace
(
"%year%"
,
year
)
output_dir
=
os
.
path
.
dirname
(
output_file
)
if
not
os
.
path
.
exists
(
output_dir
):
os
.
makedirs
(
os
.
path
.
dirname
(
output_file
))
elif
not
os
.
path
.
isdir
(
output_dir
):
print
"Error: %s is not a dir
\n
"
%
(
output_dir
)
raise
os
.
error
()
f
=
codecs
.
open
(
output_file
,
'w'
,
'utf-8'
)
for
entry
in
entries_by_year
[
year
]:
f
.
write
(
entry
.
get_ledger
())
f
.
write
(
"
\n
"
)
f
.
close
()
if
year
in
years
:
output_file
=
output
.
replace
(
"%year%"
,
year
)
output_dir
=
os
.
path
.
dirname
(
output_file
)
if
not
os
.
path
.
exists
(
output_dir
):
os
.
makedirs
(
os
.
path
.
dirname
(
output_file
))
elif
not
os
.
path
.
isdir
(
output_dir
):
print
"Error: %s is not a dir
\n
"
%
(
output_dir
)
raise
os
.
error
()
f
=
codecs
.
open
(
output_file
,
'w'
,
'utf-8'
)
for
entry
in
entries_by_year
[
year
]:
f
.
write
(
entry
.
get_ledger
())
f
.
write
(
"
\n
"
)
f
.
close
()
@
staticmethod
def
write_hreport_plan
():
...
...
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