| [4bde242] | 1 | if __name__ == '__main__': |
|---|
| 2 | import sys |
|---|
| 3 | import os |
|---|
| 4 | |
|---|
| 5 | cur_file = os.path.abspath(__file__) |
|---|
| 6 | django_dir = os.path.abspath(os.path.join(os.path.dirname(cur_file), '..')) |
|---|
| 7 | sys.path.append(django_dir) |
|---|
| 8 | os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' |
|---|
| 9 | |
|---|
| 10 | import finance_core.models |
|---|
| 11 | import vouchers.models |
|---|
| 12 | |
|---|
| 13 | expense_gls = ( |
|---|
| 14 | ('Travel', 420050), |
|---|
| 15 | ('Audio-Visual', 420106), |
|---|
| 16 | ('Conference Expense', 420140), |
|---|
| 17 | ('Entertainment', 420166), |
|---|
| 18 | ('Materials and Services', 420226), |
|---|
| 19 | ('Office Supplies', 420258), |
|---|
| 20 | ('Professional Services', 420298), |
|---|
| 21 | ('Copying', 420392), |
|---|
| 22 | ('Books and Publications', 420800), |
|---|
| 23 | ('Food', None), |
|---|
| 24 | ('Food.Meetings', 421000), |
|---|
| 25 | ('Food.Events', 421200), |
|---|
| 26 | ('Computer Supplies', 421900), |
|---|
| 27 | ) |
|---|
| 28 | |
|---|
| 29 | def add_gl_accounts(): |
|---|
| 30 | try: |
|---|
| 31 | base = finance_core.models.BudgetArea.get_by_path(['Accounts', 'Expenses', ]) |
|---|
| 32 | except KeyError: |
|---|
| 33 | base = finance_core.models.BudgetArea.get_by_path(['Accounts',]) |
|---|
| 34 | base = base.add_child(name='Expenses', always=True, use_owner=True) |
|---|
| 35 | |
|---|
| 36 | for name, number in expense_gls: |
|---|
| 37 | try: |
|---|
| 38 | path = 'Accounts.Expenses.' + name |
|---|
| 39 | elem = finance_core.models.BudgetArea.get_by_pathstr(path) |
|---|
| 40 | except KeyError: |
|---|
| 41 | print "Adding %s (%s)" % (name, number,) |
|---|
| 42 | # It doesn't exist |
|---|
| 43 | if '.' in name: |
|---|
| 44 | parts = name.rsplit('.', 1) |
|---|
| 45 | path = 'Accounts.Expenses.'+parts[0] |
|---|
| 46 | name = parts[1] |
|---|
| 47 | parent = finance_core.models.BudgetArea.get_by_pathstr(path) |
|---|
| 48 | else: |
|---|
| 49 | parent = base |
|---|
| [c1d9650] | 50 | parent.add_child(name=name, account_number=number, always=True, ) |
|---|
| [4bde242] | 51 | else: |
|---|
| 52 | print "%s (%s) already present" % (name, number,) |
|---|
| 53 | |
|---|
| 54 | if __name__ == '__main__': |
|---|
| 55 | add_gl_accounts() |
|---|