settings.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # -*- coding: utf-8 -*-
  2. from __future__ import unicode_literals
  3. import os
  4. import datetime
  5. CONF_FILES = [
  6. "himport.conf",
  7. "himport.conf.local",
  8. ]
  9. __settings = None
  10. def get(opt):
  11. ret = __settings.get(opt)
  12. if ret is None:
  13. raise "Settings not found"
  14. return ret
  15. def get_ledger_account(code):
  16. account_names = __settings.get("PC_NAMES")
  17. if code in account_names:
  18. return account_names[code]
  19. else:
  20. return code
  21. __settings = {}
  22. for conf_file in CONF_FILES:
  23. if os.path.isfile(conf_file):
  24. execfile(conf_file, __settings)
  25. if __settings is None:
  26. raise Exception(
  27. "Need a configuration file. One of %s" % ','.join(CONF_FILES))
  28. if 'OUTPUT_DIR' not in __settings:
  29. raise Exception('need OUTPUT_DIR settings')
  30. if 'PC_REFS' not in __settings:
  31. raise Exception('need PC_REFS settings')
  32. if 'PC_NAMES' not in __settings:
  33. raise Exception('need PC_NAMES settings')
  34. if 'ACCOUNTING_YEARS' in __settings:
  35. __settings['ACCOUNTING_YEARS'] = [(
  36. year,
  37. datetime.datetime.strptime(dbegin, "%Y/%m/%d").date(),
  38. datetime.datetime.strptime(dend, "%Y/%m/%d").date(),
  39. ) for (year, dbegin, dend) in __settings['ACCOUNTING_YEARS']]
  40. if 'TVA_TYPE' not in __settings or\
  41. __settings['TVA_TYPE'] not in ["standard", "service_sur_debit"]:
  42. raise Exception("need TVA_TYPE settings either: standard | service_sur_debit")