diff --git a/app/models/ordergroup.rb b/app/models/ordergroup.rb index bc42e131..3d863834 100644 --- a/app/models/ordergroup.rb +++ b/app/models/ordergroup.rb @@ -4,7 +4,6 @@ # # Ordergroup have the following attributes, in addition to Group # * account_balance (decimal) -# * account_updated (datetime) class Ordergroup < Group APPLE_MONTH_AGO = 6 # How many month back we will count tasks and orders sum @@ -49,7 +48,6 @@ class Ordergroup < Group t = FinancialTransaction.new(:ordergroup => self, :amount => amount, :note => note, :user => user) t.save! self.account_balance = financial_transactions.sum('amount') - self.account_updated = t.created_on save! # Notify only when order group had a positive balance before the last transaction: if t.amount < 0 && self.account_balance < 0 && self.account_balance - t.amount >= 0 @@ -95,6 +93,10 @@ class Ordergroup < Group stats = Ordergroup.pluck(:stats) stats.sum {|s| s[:jobs_size].to_f } / stats.sum {|s| s[:orders_sum].to_f } end + + def account_updated + financial_transactions.last.try(:created_on) || created_on + end private diff --git a/db/migrate/20121230142516_remove_account_updated_from_ordergroups.rb b/db/migrate/20121230142516_remove_account_updated_from_ordergroups.rb new file mode 100644 index 00000000..0aedf521 --- /dev/null +++ b/db/migrate/20121230142516_remove_account_updated_from_ordergroups.rb @@ -0,0 +1,9 @@ +class RemoveAccountUpdatedFromOrdergroups < ActiveRecord::Migration + def up + remove_column :groups, :account_updated + end + + def down + add_column :groups, :account_updated, :datetime + end +end diff --git a/db/schema.rb b/db/schema.rb index 031fbdde..188ea83b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20121216180646) do +ActiveRecord::Schema.define(:version => 20121230142516) do create_table "article_categories", :force => true do |t| t.string "name", :default => "", :null => false @@ -137,7 +137,6 @@ ActiveRecord::Schema.define(:version => 20121216180646) do t.string "name", :default => "", :null => false t.string "description" t.decimal "account_balance", :precision => 8, :scale => 2, :default => 0.0, :null => false - t.datetime "account_updated" t.datetime "created_on", :null => false t.boolean "role_admin", :default => false, :null => false t.boolean "role_suppliers", :default => false, :null => false