settings.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. with open(conf_file) as f:
  25. code = compile(f.read(), conf_file, 'exec')
  26. exec(code, __settings)
  27. if __settings is None:
  28. raise Exception(
  29. "Need a configuration file. One of %s" % ','.join(CONF_FILES))
  30. if 'OUTPUT_DIR' not in __settings:
  31. raise Exception('need OUTPUT_DIR settings')
  32. if 'PC_REFS' not in __settings:
  33. raise Exception('need PC_REFS settings')
  34. if 'PC_NAMES' not in __settings:
  35. raise Exception('need PC_NAMES settings')
  36. if 'ACCOUNTING_YEARS' in __settings:
  37. __settings['ACCOUNTING_YEARS'] = [(
  38. year,
  39. datetime.datetime.strptime(dbegin, "%Y/%m/%d").date(),
  40. datetime.datetime.strptime(dend, "%Y/%m/%d").date(),
  41. ) for (year, dbegin, dend) in __settings['ACCOUNTING_YEARS']]
  42. if 'TVA_TYPE' not in __settings or\
  43. __settings['TVA_TYPE'] not in ["standard", "service_sur_debit", "none"]:
  44. raise Exception("need TVA_TYPE settings either: standard | service_sur_debit | none")