lib/africompta/entities/account.rb in africompta-1.9.11 vs lib/africompta/entities/account.rb in africompta-1.9.13.pre.10

- old
+ new

@@ -175,11 +175,11 @@ def search_account(acc, month_start) years = Hash.new(0) acc.movements.each { |mov| if not mov.desc =~ /^-- Sum of/ - y, m, d = mov.date.to_s.split('-').collect { |d| d.to_i } + y, m, _ = mov.date.to_s.split('-').collect { |d| d.to_i } dputs(5) { "Date of #{mov.desc} is #{mov.date}" } m < month_start and y -= 1 years[y] += 1 end } @@ -205,11 +205,11 @@ end def move_movements(acc, years, month_start) acc.movements.each { |mov| dputs(5) { 'Start of each' } - y, m, d = mov.date.to_s.split('-').collect { |d| d.to_i } + y, m, _ = mov.date.to_s.split('-').collect { |d| d.to_i } dputs(5) { "Date of #{mov.desc} is #{mov.date}" } m < month_start and y -= 1 if years.has_key? y value = mov.value mov.value = 0 @@ -453,11 +453,11 @@ end def load super if Accounts.search_by_name('Root').count == 0 - dputs(0) { "Didn't find 'Root' in database - creating base" } + dputs(1) { "Didn't find 'Root' in database - creating base" } Accounts.init end end def migration_1(a) @@ -471,10 +471,22 @@ def migration_2(a) a.rev_index = a.id end + def migration_3(m) + # dp "Migrating #{m.inspect}" + if m.id == 1 && m.account_id != nil + dp 'Root-account has parent...' + m.account_id = 0 + m.name = 'Root' + m.desc = 'Root' + m.global_id = Digest::MD5.hexdigest((rand 2**128).to_s).to_s + '-1' + m.total = 0.0 + end + end + def listp_path dputs(3) { 'Being called' } Accounts.search_all.select { |a| !a.deleted }.collect { |a| [a.id, a.path] }. sort { |a, b| a[1] <=> b[1] @@ -511,11 +523,11 @@ 'multiplier, "index", rev_index, deleted, keep_total '+ 'from compta_accounts').sort_by { |a| a[4] }.each do |row| #dputs(3) { "Looking at #{row}" } @check_progress += progress_step - id_, acc_id_, name_, desc_, gid_, tot_, mult_, ind_, revind_, del_, keep_, = row + _, acc_id_, name_, desc_, gid_, tot_, mult_, _, _, del_, keep_, = row parent = if acc_id_ acc_id_ == 0 ? '' : db.execute("select * from compta_accounts where id=#{acc_id_}").first[4] else '' @@ -754,11 +766,11 @@ set_nochildmult(name, desc, parent, multiplier, users, keep_total) # All descendants shall have the same multiplier set_child_multiplier_total(multiplier, total) end - # Sort first regarding inverse date (newest first), then description, + # Sort first regarding inverse date (newest first), then description, # and finally the value def movements(from = nil, to = nil) dputs(5) { 'Account::movements' } movs = (movements_src + movements_dst) if (from != nil and to != nil) @@ -773,11 +785,11 @@ if a.date and b.date ret = a.date.to_s <=> b.date.to_s end if ret == 0 ret = a.rev_index <=> b.rev_index -=begin +=begin if a.desc and b.desc ret = a.desc <=> b.desc end if ret == 0 if a.value and b.value @@ -832,11 +844,11 @@ accounts.each { |acc| acc.set_child_multiplier_total(m, t) } self end - + def accounts # Some hand-optimized stuff. This would be written shorter like this: # Accounts.matches_by_account_id( self.id ) # But the code below is 3 times faster for some big data ret = [] @@ -851,18 +863,18 @@ # This is the parent account def account Accounts.match_by_id(self.account_id) end - def account= (a) + def account=(a) self.account_id = a.class == Account ? a.id : a end def parent account end - def parent= (a) + def parent=(a) self.account = a end def movements_src Movements.matches_by_account_src_id(self.id)