africompta 1.9.10 → 1.9.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +6 -1
  3. data/Gemfile.lock +14 -8
  4. data/africompta.gemspec +3 -2
  5. data/bin/afri_compta.rb +119 -0
  6. data/bin/africompta.sh +23 -0
  7. data/config.yaml.default +19 -0
  8. data/lib/africompta.rb +7 -1
  9. data/lib/africompta/acaccess.rb +54 -68
  10. data/lib/africompta/acqooxview.rb +10 -10
  11. data/lib/africompta/entities/account.rb +120 -116
  12. data/lib/africompta/entities/config_base.rb +9 -0
  13. data/lib/africompta/entities/remote.rb +240 -6
  14. data/lib/africompta/entities/report.rb +136 -0
  15. data/lib/africompta/entities/users.rb +18 -6
  16. data/lib/africompta/views/compta/admin.rb +135 -0
  17. data/lib/africompta/views/compta/check.rb +245 -0
  18. data/lib/africompta/views/compta/edit_accounts.rb +138 -0
  19. data/lib/africompta/views/compta/edit_movements.rb +167 -0
  20. data/lib/africompta/views/compta/remotes.rb +23 -0
  21. data/lib/africompta/views/compta/tabs.rb +9 -0
  22. data/lib/africompta/views/compta/users.rb +23 -0
  23. data/lib/africompta/views/report/compta_executive.rb +221 -0
  24. data/lib/africompta/views/report/compta_flat.rb +79 -0
  25. data/lib/africompta/views/report/tabs.rb +7 -2
  26. data/po/afri_compta-ar.po +2356 -0
  27. data/po/afri_compta-en.po +2253 -0
  28. data/po/afri_compta-fr.po +4345 -0
  29. data/test/ac_account.rb +176 -0
  30. data/{Test → test}/ac_africompta.rb +0 -0
  31. data/{Test → test}/ac_big.rb +0 -0
  32. data/test/ac_merge.rb +177 -0
  33. data/{Test → test}/ac_movement.rb +14 -1
  34. data/{Test → test}/ac_sqlite.rb +0 -0
  35. data/{Test → test}/config_test.yaml +1 -6
  36. data/test/other.conf +1 -0
  37. data/test/other.rb +18 -0
  38. data/test/test.conf +1 -0
  39. data/{Test → test}/test.rb +7 -14
  40. metadata +63 -18
  41. data/Test/ac_account.rb +0 -128
  42. data/lib/africompta/africompta.rb +0 -83
  43. data/lib/africompta/views/edit/movement.rb +0 -8
  44. data/lib/africompta/views/edit/tabs.rb +0 -8
  45. data/lib/africompta/views/report/annual.rb +0 -3
@@ -0,0 +1,176 @@
1
+ require 'test/unit'
2
+
3
+ class TC_Account < Test::Unit::TestCase
4
+ def setup
5
+ dputs(1) { 'Setting up new data'
6
+ }
7
+ Entities.delete_all_data()
8
+
9
+ dputs(2) { 'Resetting SQLite' }
10
+ SQLite.dbs_close_all
11
+ FileUtils.cp('db.testGestion', 'data2/compta.db')
12
+ SQLite.dbs_open_load_migrate
13
+
14
+ dputs(2) { 'And searching for some accounts' }
15
+ @root = Accounts.match_by_name('Root')
16
+ @cash = Accounts.match_by_name('Cash')
17
+ @lending = Accounts.match_by_name('Lending')
18
+ @income = Accounts.match_by_name('Income')
19
+ @outcome = Accounts.match_by_name('Outcome')
20
+ @local = Users.match_by_name('local')
21
+
22
+ @user_1 = Users.create('user1', '', 'pass')
23
+ @user_2 = Users.create('user2', '', 'pass')
24
+ end
25
+
26
+ def teardown
27
+ Entities.save_all
28
+ end
29
+
30
+ def test_path
31
+ assert_equal 'Root::Cash', @cash.path
32
+ end
33
+
34
+ def test_del_account
35
+ AccountRoot.accounts.each { |a|
36
+ dputs(1) { "Found root-account #{a.inspect}" }
37
+ a.get_tree { |t|
38
+ dputs(1) {
39
+ "#{t.path} - #{t.deleted.inspect}"
40
+ }
41
+ }
42
+ }
43
+ assert_equal false, @root.delete, @root.inspect
44
+ assert_equal false, @income.delete
45
+ old_index = @lending.rev_index
46
+ assert_equal true, @lending.delete
47
+ assert_operator old_index, :<, @lending.rev_index
48
+
49
+ Accounts.create_path('Root::Cash::Foo', '')
50
+ end
51
+
52
+ def test_account_root
53
+ Accounts.create_path('Root::Archive')
54
+ assert_equal nil, AccountRoot.archive
55
+
56
+ Accounts.create_path('Archive')
57
+ assert_not_equal nil, AccountRoot.archive
58
+ end
59
+
60
+ def test_clean
61
+ Accounts.create_path('Test')
62
+ Accounts.dump true
63
+ count_mov, bad_mov, count_acc, bad_acc = AccountRoot.clean
64
+ assert_equal [4, 0, 19, 1],
65
+ [count_mov, bad_mov, count_acc, bad_acc]
66
+
67
+ Accounts.dump
68
+ count_mov, bad_mov, count_acc, bad_acc = AccountRoot.clean
69
+ assert_equal [4, 0, 19, 0],
70
+ [count_mov, bad_mov, count_acc, bad_acc]
71
+ end
72
+
73
+ def test_merge_two_users
74
+ @user_1.update_all
75
+ @u1 = {'user' => 'user1', 'pass' => 'pass'}
76
+ @user_2.update_all
77
+ @u2 = {'user' => 'user2', 'pass' => 'pass'}
78
+
79
+ a_id = ACaccess.post('account_get_id', @u1.merge('account' => 'Root'))
80
+ assert_equal '1', a_id
81
+
82
+ assert_equal '', ACaccess.get('accounts_get/user1,pass')
83
+ assert_equal '', ACaccess.get('accounts_get/user2,pass')
84
+ end
85
+
86
+ def test_merge_account_delete
87
+ test_merge_two_users
88
+
89
+ @lending.delete
90
+ dputs(3) { @lending.inspect }
91
+ ACaccess.post('account_put', @u1.merge('account' => @lending.to_s))
92
+ assert_equal '', ACaccess.get('accounts_get/user1,pass')
93
+ assert_equal @lending.to_s, ACaccess.get('accounts_get/user2,pass').chomp
94
+ end
95
+
96
+ def test_merge_account_change
97
+ test_merge_two_users
98
+
99
+ @lending.name = 'Lendings'
100
+ @lending.new_index
101
+ dputs(3) { @lending.inspect }
102
+ ACaccess.post('account_put', @u1.merge('account' => @lending.to_s))
103
+ assert_equal '', ACaccess.get('accounts_get/user1,pass')
104
+ assert_equal @lending.to_s, ACaccess.get('accounts_get/user2,pass').chomp
105
+
106
+ assert_equal 1, @lending.account_id
107
+ end
108
+
109
+ def test_print_pdf
110
+ @root.print_pdf('test.pdf', true)
111
+ end
112
+
113
+ def test_get_archives
114
+ (2011..2014).each { |y|
115
+ Movements.create('', Date.new(y), 1000, @income, @cash)
116
+ }
117
+ Movements.create('', Date.new(2013, 3, 3), 1000, @outcome, @cash)
118
+ Accounts.archive(1, 2014)
119
+
120
+ assert_equal %w(Archive::2011::Income Archive::2012::Income Archive::2013::Income),
121
+ Accounts.get_by_path('Root::Income').get_archives.collect { |a|
122
+ a.path }.sort
123
+ assert_equal %w(Archive::2012::Outcome Archive::2013::Outcome),
124
+ Accounts.get_by_path('Root::Outcome').get_archives.collect { |a|
125
+ a.path }.sort
126
+ end
127
+
128
+ def test_delete
129
+ acc = Accounts.create('newaccount', '', @cash)
130
+ assert acc.rev_index > 0
131
+ rindex = acc.rev_index
132
+ acc.delete
133
+ assert acc.rev_index > rindex
134
+ end
135
+
136
+ def test_report
137
+ date = Date.today
138
+
139
+ # Make a tree with depth two of accounts with movements inside
140
+ accs = Array.new(3) { Array.new(3) }
141
+ [1, 2].each { |src|
142
+ accs[src][0] = Accounts.create("src_#{src}", nil, @income)
143
+ [1, 2, 3].each { |sub|
144
+ accs[src][sub] = Accounts.create("sub_#{src}_#{sub}", nil, accs[src][0])
145
+ [1, 2, 3].each { |mov|
146
+ Movements.create("Mov for #{src}_#{sub} - #{mov}", date, 100 * src,
147
+ accs[src][sub], @cash)
148
+ }
149
+ assert_equal -300 * src, accs[src][sub].total
150
+ }
151
+ }
152
+
153
+ reportAccount = ReportAccounts.create(account: @income, level: 1)
154
+ report = Reports.create(name: 'test', accounts: [reportAccount])
155
+
156
+ line = report.print_account_monthly(reportAccount, date, 1, 1)
157
+ dp line
158
+ end
159
+
160
+ def test_report_man
161
+ SQLite.dbs_close_all
162
+ FileUtils.cp('db.man', 'data2/compta.db')
163
+ SQLite.dbs_open_load
164
+ dputs(0) { 'Finished loading' }
165
+ #Accounts.search_all_.each{|acc|dp acc.path}
166
+ AccountRoot.actual.dump
167
+ entry = Accounts.get_by_path('Root::SaS::MaN Repos II::Entrés')
168
+ assert_not_nil entry
169
+
170
+ reportAccount = ReportAccounts.create(account: entry, level: 1)
171
+ report = Reports.create(name: 'test', accounts: [reportAccount])
172
+
173
+ line = report.print_account_monthly(reportAccount, Date.new(2014, 6), 1, 1)
174
+ dp line
175
+ end
176
+ end
File without changes
File without changes
data/test/ac_merge.rb ADDED
@@ -0,0 +1,177 @@
1
+ require 'test/unit'
2
+ require 'net/http'
3
+
4
+ class TC_Merge < Test::Unit::TestCase
5
+ def setup
6
+ dputs(1) { 'Setting up new data' }
7
+
8
+ Entities.delete_all_data()
9
+
10
+ start_other
11
+ @remote = Remotes.get_db('http://localhost:3303/acaccess', 'other', 'other')
12
+
13
+ dputs(2) { 'And searching for some accounts' }
14
+ @root = Accounts.match_by_name('Root')
15
+ @cash = Accounts.match_by_name('Cash')
16
+ @lending = Accounts.match_by_name('Lending')
17
+ @income = Accounts.match_by_name('Income')
18
+ @outcome = Accounts.match_by_name('Outcome')
19
+ @local = Users.match_by_name('local')
20
+
21
+ @user_1 = Users.create('user1', '', 'pass')
22
+ @user_2 = Users.create('user2', '', 'pass')
23
+ end
24
+
25
+ def teardown
26
+ Entities.save_all
27
+ if @other
28
+ dputs(3) { "Killing #{@other}" }
29
+ Process.kill(9, @other)
30
+ Process.wait
31
+ dputs(3) { "Joined #{@other}" }
32
+ end
33
+ end
34
+
35
+ def test_path
36
+ assert_equal 'Root::Cash', @cash.path
37
+ end
38
+
39
+ def start_other(wait=true)
40
+ dir = 'thread1'
41
+ FileUtils.rm_rf(dir)
42
+ FileUtils.mkdir(dir)
43
+ FileUtils.cp('other.rb', dir)
44
+ FileUtils.cp('other.conf', dir)
45
+ @other = Process.spawn('./other.rb')
46
+
47
+ while wait
48
+ begin
49
+ Net::HTTP.get(URI('http://localhost:3303/acaccess'))
50
+ return
51
+ rescue Errno::ECONNREFUSED
52
+ dputs(3) { 'Waiting on -other-' }
53
+ sleep 0.5
54
+ end
55
+ end
56
+ end
57
+
58
+ def post_form(path, hash)
59
+ dputs(4) { "postForm with path #{path}" }
60
+ Net::HTTP.post_form(URI.parse(@remote.url + "/merge/#{path}"),
61
+ {'user' => @remote.name, 'pass' => @remote.pass}.merge(hash))
62
+ end
63
+
64
+ def get_form(path)
65
+ url = URI.parse(@remote.url)
66
+ dputs(4) { "Starting getForm with path #{path} - #{url.inspect}" }
67
+ Net::HTTP.get(url.host, "#{url.path}/merge/#{path}/#{@remote.name},#{@remote.pass}", url.port)
68
+ end
69
+
70
+ def test_start_other
71
+ assert Net::HTTP.get(URI('http://localhost:3303'))
72
+ end
73
+
74
+ def test_remote
75
+ @remote.check_version
76
+ end
77
+
78
+ def test_copied
79
+ # We test with a second user
80
+ @remote = Remotes.create(url: 'http://localhost:3303/acaccess', name: 'other2',
81
+ pass: 'other2')
82
+
83
+ assert_equal 5, get_form('accounts_get').split("\n").count
84
+ @remote.do_copied
85
+ assert_equal '5,0', get_form('index')
86
+ assert_equal 0, get_form('accounts_get').split("\n").count
87
+ end
88
+
89
+ def test_check_versions
90
+ assert @remote.check_version
91
+ oldversion = $VERSION
92
+ $VERSION = 0
93
+ assert_raise RuntimeError do
94
+ @remote.check_version(false)
95
+ end
96
+ $VERSION = oldversion
97
+ end
98
+
99
+ def print_remote_accounts
100
+ get_form('accounts_get_all').split("\n").each { |a| p a }
101
+ end
102
+
103
+ def print_accounts
104
+ Accounts.search_all_.each { |a| p a.to_s }
105
+ end
106
+
107
+ def print_remote_movements
108
+ get_form('movements_get_all').split("\n").each { |a| p a }
109
+ end
110
+
111
+ def print_movements
112
+ Movements.search_all_.each { |m| p m.to_json }
113
+ end
114
+
115
+ def test_get_remote_accounts
116
+ #p Accounts.search_all_.last.to_s
117
+ @remote.do_copied
118
+ post_form('account_put',
119
+ account: "Initialisation\r27d1cfc78ed2ae03109b8963707b18f2-10\t"+
120
+ "0.000\tNewAccount\t1\t#{AccountRoot.current.global_id}\tfalse\tfalse",
121
+ debug: true)
122
+ assert_equal 0, Accounts.search_by_name('NewAccount').count
123
+ @remote.get_remote_accounts
124
+ assert_equal 1, Accounts.search_by_name('NewAccount').count
125
+ end
126
+
127
+ def test_send_accounts
128
+ @remote.do_copied
129
+
130
+ Accounts.create('Salaries', 'salaries', @outcome)
131
+ remote_count = get_form('accounts_get_all').split("\n").count
132
+ @remote.setup_instance
133
+ @remote.send_accounts
134
+ assert_equal remote_count + 1,
135
+ get_form('accounts_get_all').split("\n").count
136
+ assert_equal 0, get_form('accounts_get').split("\n").count
137
+ end
138
+
139
+ def test_get_remote_movements
140
+ @remote.do_copied
141
+
142
+ @remote.get_remote_movements
143
+ assert_equal 0, Movements.search_all_.count
144
+
145
+ mov_str = "{\"str\":\"new\\r62f7b25f8dc249a7d2af9e96809e1a38-1\\t"+
146
+ "1000.000\\t2015-01-02\\t#{@cash.global_id}\\t#{@outcome.global_id}\"}"
147
+ post_form('movements_put',
148
+ movements: [mov_str].to_json,
149
+ debug: true)
150
+ assert_equal 0, Movements.search_all_.count
151
+ @remote.get_remote_movements
152
+ assert_equal 1, Movements.search_all_.count
153
+ end
154
+
155
+ def test_send_movements
156
+ @remote.do_copied
157
+
158
+ Movements.create('new', '2015-01-02', 1000, @cash, @outcome)
159
+ assert_equal 0, get_form('movements_get_all').split("\n").count
160
+ @remote.setup_instance
161
+ @remote.send_movements
162
+ assert_equal 1, get_form('movements_get_all').split("\n").count
163
+ @remote.get_remote_movements
164
+ assert_equal 1, Movements.search_all_.count
165
+ end
166
+
167
+ def test_get_db
168
+ Entities.delete_all_data()
169
+ assert_equal 0, Accounts.search_all_.count
170
+ @remote = Remotes.get_db('http://localhost:3303/acaccess', 'other', 'other')
171
+
172
+ assert_equal 1, Users.search_all_.count
173
+ assert_equal 1, Remotes.search_all_.count
174
+
175
+ assert @remote.check_version
176
+ end
177
+ end
@@ -7,7 +7,7 @@ class TC_Movement < Test::Unit::TestCase
7
7
 
8
8
  dputs(2) { 'Resetting SQLite' }
9
9
  SQLite.dbs_close_all
10
- FileUtils.cp('db.testGestion', 'data/compta.db')
10
+ FileUtils.cp('db.testGestion', 'data2/compta.db')
11
11
  SQLite.dbs_open_load_migrate
12
12
 
13
13
  dputs(2) { 'And searching for some accounts' }
@@ -56,4 +56,17 @@ class TC_Movement < Test::Unit::TestCase
56
56
  assert_equal Movement, res.first.class
57
57
  assert_equal [2, 3], res.map { |m| m.rev_index }
58
58
  end
59
+
60
+ def test_date
61
+ Movements.create('newmov', '2015-01-02', 100, @income, @cash)
62
+ Entities.reload
63
+ assert_equal Date, Movements.find_by_desc('newmov').date.class
64
+
65
+ Entities.delete_all_data
66
+ Entities.load_all
67
+ Movements.create('newmov', '2015-01-02', 100, @income, @cash)
68
+ Entities.reload
69
+
70
+ assert_equal Date, Movements.find_by_desc('newmov').date.class
71
+ end
59
72
  end
File without changes
@@ -1,6 +1,5 @@
1
1
  StorageType:
2
- CSV:
3
- csv_dir: ./data2/
2
+ data_dir: ./data2/
4
3
 
5
4
  #autologin: linus
6
5
  #autologin: admin
@@ -25,7 +24,3 @@ AfriCompta:
25
24
 
26
25
  DiplomaDir: Diplomas
27
26
 
28
- Entities:
29
- LogActions:
30
- logging: false
31
-
data/test/other.conf ADDED
@@ -0,0 +1 @@
1
+ DATA_DIR=thread1
data/test/other.rb ADDED
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+ Encoding.default_external = Encoding::UTF_8
4
+
5
+ require 'bundler/setup'
6
+ require 'africompta'
7
+
8
+ QooxView::init('entities', 'views')
9
+
10
+ webrick_port = 3303
11
+ dputs(2) { "Starting at port #{webrick_port}" }
12
+
13
+ # Set default functions to use africompta
14
+ ConfigBase.set_functions(%w(accounting accounting_standalone))
15
+ Welcome.nologin
16
+ Users.create(name:'other', pass:'other')
17
+ Users.create(name:'other2', pass:'other2')
18
+ QooxView::startWeb(webrick_port)
data/test/test.conf ADDED
@@ -0,0 +1 @@
1
+ DATA_DIR=.
@@ -1,23 +1,16 @@
1
1
  #!/usr/bin/env ruby
2
- ##!/usr/local/bin/ruby -I.
3
- ##!/usr/bin/ruby -I.. -I../../QooxView -I../../AfriCompta -I../../LibNet -I. -wKU
4
- %w( QooxView AfriCompta HelperClasses/lib ).each{|l|
5
- $LOAD_PATH.push "../../#{l}"
6
- }
7
- $LOAD_PATH.push '.'
8
2
 
3
+ require 'bundler/setup'
9
4
  require 'test/unit'
10
5
  require 'fileutils'
11
6
 
12
- FileUtils.rm_rf('data/')
13
7
  FileUtils.rm_rf('data2/')
14
8
 
15
- CONFIG_FILE='config_test.yaml'
16
- DEBUG_LVL=0
9
+ $config_file='config_test.yaml'
10
+ DEBUG_LVL=1
17
11
 
18
12
  require 'QooxView'
19
- require 'ACQooxView'
20
- require 'ACaccess'
13
+ require 'africompta'
21
14
 
22
15
  Permission.add( 'default', 'View,Welcome' )
23
16
  Permission.add( 'admin', '.*', '.*' )
@@ -30,10 +23,10 @@ qooxView = QooxView.init( '../Entities', '../Views' )
30
23
 
31
24
  tests = %w( africompta account movement sqlite )
32
25
  #tests = %w( africompta )
33
- #tests = %w( sqlite )
34
- #tests = %w( big )
26
+ tests = %w( account )
27
+ #tests = %w( merge )
35
28
  tests.each{|t|
36
- require "ac_#{t}"
29
+ require_relative "ac_#{t}"
37
30
  }
38
31
 
39
32
  # Fails test_archive_sum_up