Commit 9b8400e9 authored by plb's avatar plb

Merge branch 'release/0.1'

parents 08c18e70 f998385a
*.pyc
.*.swp
python-env
tags
# himports
## Usage from repository
**Installation**
git clone
cd
./utils/pyenv-init
**Utilisation**
./utils/pyenv-himport
## Configuration
You can copy the configuration file from ``himport.conf.template``
cp himport.conf.template himport.conf
......@@ -5,93 +5,100 @@ from __future__ import unicode_literals
import getopt
import locale
import logging
import os
import shutil
import sys
import csv
import datetime
import codecs
import getpass
from himports import settings
from himports.hledger import *
from himports.dolibarrWriter import Writer
from himports.dolibarrAlchemyHledger import HledgerDolibarrSQLAlchemy
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger('hreport')
sys.stdout = codecs.getwriter(locale.getpreferredencoding())(sys.stdout)
def process_args(argv):
options = {}
usage = u'himport -p'
usage = u'''Usage: himport -v -y <YEAR> [ -y <YEAR> ] ...
options:
-v : verbose mode
-y <YEAR> : import the corresponding accounting year
'''
try:
opts, args = getopt.getopt(
argv, "hp:P:",
["mysql-password=","mysql-port" ])
argv, "hvy:",
["mysql-password=", "mysql-port", "year="]
)
except getopt.GetoptError:
print usage
print "himport: Invalid options"
print usage
sys.exit(2)
options['years'] = list()
options['verbose'] = 0
for opt, arg in opts:
if opt == '-h':
print usage
sys.exit()
elif opt in ("-p", "--mysql-password"):
options['mysql_password'] = arg
elif opt in ("-P", "--mysql-port"):
options['mysql_port'] = arg
elif opt in ("-v", "--verbose"):
options['verbose'] += 1
elif opt in ("-y", "--year"):
options['years'].append(str(arg))
if len(options['years']) == 0:
print "You need to specify the accounting years"
print ""
print usage
sys.exit(1)
return options
def do_mysql(options):
# On récupère les données via la base de données de dolibarr
def do_sqlalchemy(options):
# On recupere les donnees via la base de donnees de dolibarr
s = settings.get('MYSQL_SETTINGS')
password = s['password']
if 'mysql_password' in options:
password = options['mysql_password']
if password is None or password == "":
password = getpass.getpass("password for mysql user '%s': " % (s['user']))
port = s['port']
if 'mysql_port' in options:
port = options['mysql_port']
dolibarr = DolibarrSQL(s['host'],port, s['database'], s['user'], password)
dolibarr = HledgerDolibarrSQLAlchemy(s['host'], s['port'], s['database'], s['user'], password, options['verbose'] >= 2)
dolibarr.connect()
bank_entries = dolibarr.get_bank_entries()
sell_entries = dolibarr.get_sell_entries()
supplier_entries = dolibarr.get_supplier_entries()
social_entries = dolibarr.get_social_entries()
dolibarr.disconnect()
bank_journal = dolibarr.get_bank_journal()
sell_journal = dolibarr.get_sell_journal()
supplier_journal = dolibarr.get_supplier_journal()
social_journal = dolibarr.get_social_journal()
# On vérifie s'il manque des postes comptables dans les écritures
# On verifie s'il manque des postes comptables dans les ecritures
pc_missing = set()
pc_missing.update(bank_entries.check_pc())
pc_missing.update(sell_entries.check_pc())
pc_missing.update(supplier_entries.check_pc())
pc_missing.update(social_entries.check_pc())
pc_missing.update(bank_journal.check_pc())
pc_missing.update(sell_journal.check_pc())
pc_missing.update(supplier_journal.check_pc())
pc_missing.update(social_journal.check_pc())
if len(pc_missing) > 0:
print "WARNING: poste comptable manquant"
for pc in pc_missing:
sys.stdout.write("%s\n" % (pc))
# On écrie les fichiers hledger
Writer.write("bank",bank_entries)
Writer.write("sells",sell_entries)
Writer.write("suppliers",supplier_entries)
Writer.write("social",social_entries)
Writer.write_hreport_plan()
# On ecrie les fichiers hledger
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_chart_of_accounts(options['years'])
dolibarr.disconnect()
def main(argv):
locale.setlocale(locale.LC_ALL, b'fr_FR.utf-8')
options = process_args(argv)
do_mysql(options)
do_sqlalchemy(options)
if __name__ == "__main__":
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
import settings
import os
import codecs
class Writer(object):
output_files = settings.get('OUTPUT_FILES')
output_dir = settings.get('OUTPUT_DIR')
@staticmethod
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:
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_chart_of_accounts(years):
pc_names = settings.get('PC_NAMES')
pc_descriptions = settings.get('PC_DESCRIPTIONS')
for year in years:
filename = Writer.output_files['chart_of_accounts']
output_file = os.path.join(Writer.output_dir, filename).replace("%year%", year)
f = codecs.open(output_file, 'w', 'utf-8')
f.write("%s/01/01 * Chart of account\n" % (year))
for pc in sorted(pc_names.keys()):
name = pc_names[pc]
if pc in pc_descriptions:
desc = pc_descriptions[pc]
else:
desc = name
s = " %s 0 ; %s %s\n" % (name, pc, desc)
f.write(s)
f.close()
This diff is collapsed.
......@@ -51,3 +51,7 @@ if 'ACCOUNTING_YEARS' in __settings:
datetime.datetime.strptime(dbegin, "%Y/%m/%d").date(),
datetime.datetime.strptime(dend, "%Y/%m/%d").date(),
) for (year, dbegin, dend) in __settings['ACCOUNTING_YEARS']]
if 'TVA_TYPE' not in __settings or\
__settings['TVA_TYPE'] not in ["standard", "service_sur_debit"]:
raise Exception("need TVA_TYPE settings either: standard | service_sur_debit")
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment