2009-03-01 18:45:34 +01:00
|
|
|
class OrderGroup < Group; end # Needed for renaming of OrderGroup to Ordergroup
|
|
|
|
|
2020-08-07 01:14:14 +02:00
|
|
|
class RoadToVersionThree < ActiveRecord::Migration[4.2]
|
2009-01-29 01:57:51 +01:00
|
|
|
def self.up
|
|
|
|
# TODO: Combine migrations since foodsoft3-development into one file
|
|
|
|
# and try to build a migration path from old data.
|
2009-02-06 16:26:35 +01:00
|
|
|
|
2009-03-01 18:45:34 +01:00
|
|
|
# == Message
|
|
|
|
drop_table :messages
|
|
|
|
create_table :messages do |t|
|
|
|
|
t.references :sender
|
|
|
|
t.text :recipients_ids
|
2023-05-12 13:01:12 +02:00
|
|
|
t.string :subject, null: false
|
2009-03-01 18:45:34 +01:00
|
|
|
t.text :body
|
2023-05-12 13:01:12 +02:00
|
|
|
t.integer :email_state, default: 0, null: false
|
|
|
|
t.boolean :private, default: false
|
2009-03-01 18:45:34 +01:00
|
|
|
t.datetime :created_at
|
|
|
|
end
|
|
|
|
|
|
|
|
# Acts_as_paranoid
|
|
|
|
add_column :suppliers, :deleted_at, :datetime
|
|
|
|
add_column :articles, :deleted_at, :datetime
|
|
|
|
add_column :groups, :deleted_at, :datetime
|
|
|
|
|
|
|
|
# == Workgroups
|
2023-05-12 13:01:12 +02:00
|
|
|
puts 'Migrate all groups to workgroups..'
|
|
|
|
Group.find(:all, conditions: { type: '' }).each do |workgroup|
|
|
|
|
workgroup.update_attribute(:type, 'Workgroup')
|
2009-03-01 18:45:34 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
# == Ordergroups
|
2021-03-01 15:27:26 +01:00
|
|
|
remove_column :groups, :actual_size # Useless, desposits are better stored within a transaction.note
|
2009-03-01 18:45:34 +01:00
|
|
|
# rename from OrderGroup to Ordergroup
|
|
|
|
rename_column :financial_transactions, :order_group_id, :ordergroup_id
|
|
|
|
rename_column :group_orders, :order_group_id, :ordergroup_id
|
|
|
|
rename_column :tasks, :group_id, :workgroup_id
|
2023-05-12 13:01:12 +02:00
|
|
|
remove_index :group_orders, name: 'index_group_orders_on_order_group_id_and_order_id'
|
|
|
|
add_index :group_orders, %i[ordergroup_id order_id], unique: true
|
2009-03-01 18:45:34 +01:00
|
|
|
|
2023-05-12 13:01:12 +02:00
|
|
|
Group.find(:all, conditions: { type: 'OrderGroup' }).each do |ordergroup|
|
|
|
|
ordergroup.update_attribute(:type, 'Ordergroup')
|
2009-03-01 18:45:34 +01:00
|
|
|
end
|
|
|
|
# move contact-infos from users to ordergroups
|
|
|
|
add_column :groups, :contact_person, :string
|
|
|
|
add_column :groups, :contact_phone, :string
|
|
|
|
add_column :groups, :contact_address, :string
|
|
|
|
Ordergroup.all.each do |ordergroup|
|
|
|
|
contact = ordergroup.users.first
|
2023-05-12 13:01:12 +02:00
|
|
|
ordergroup.update(contact_person: contact.name, contact_phone: contact.phone, contact_address: contact.address) if contact
|
2009-03-01 18:45:34 +01:00
|
|
|
end
|
|
|
|
remove_column :users, :address
|
|
|
|
|
|
|
|
# == Order
|
|
|
|
drop_table :orders
|
|
|
|
drop_table :group_order_results
|
|
|
|
drop_table :order_article_results
|
|
|
|
drop_table :group_order_article_results
|
2023-05-12 13:01:12 +02:00
|
|
|
GroupOrder.delete_all
|
|
|
|
OrderArticle.delete_all
|
|
|
|
GroupOrderArticle.delete_all
|
|
|
|
GroupOrderArticleQuantity.delete_all
|
2009-03-01 18:45:34 +01:00
|
|
|
|
|
|
|
create_table :orders do |t|
|
|
|
|
t.references :supplier
|
|
|
|
t.text :note
|
|
|
|
t.datetime :starts
|
|
|
|
t.datetime :ends
|
2023-05-12 13:01:12 +02:00
|
|
|
t.string :state, default: 'open' # Statemachine ... open -> finished -> closed
|
|
|
|
t.integer :lock_version, default: 0, null: false
|
2009-03-01 18:45:34 +01:00
|
|
|
t.integer :updated_by_user_id
|
|
|
|
end
|
|
|
|
|
|
|
|
# == Invoice
|
|
|
|
create_table :invoices do |t|
|
|
|
|
t.references :supplier
|
|
|
|
t.references :delivery
|
|
|
|
t.references :order
|
|
|
|
t.string :number
|
|
|
|
t.date :date
|
|
|
|
t.date :paid_on
|
|
|
|
t.text :note
|
2023-05-12 13:01:12 +02:00
|
|
|
t.decimal :amount, null: false, precision: 8, scale: 2, default: 0.0
|
|
|
|
t.decimal :deposit, precision: 8, scale: 2, default: 0.0, null: false
|
|
|
|
t.decimal :deposit_credit, precision: 8, scale: 2, default: 0.0, null: false
|
2009-03-01 18:45:34 +01:00
|
|
|
t.timestamps
|
|
|
|
end
|
|
|
|
|
|
|
|
# == Delivery
|
2021-03-01 15:27:26 +01:00
|
|
|
create_table :deliveries do |t|
|
2009-03-01 18:45:34 +01:00
|
|
|
t.integer :supplier_id
|
|
|
|
t.date :delivered_on
|
|
|
|
t.datetime :created_at
|
|
|
|
end
|
|
|
|
|
|
|
|
# == Comment
|
|
|
|
drop_table :comments
|
|
|
|
create_table :order_comments do |t|
|
|
|
|
t.references :order
|
|
|
|
t.references :user
|
|
|
|
t.text :text
|
|
|
|
t.datetime :created_at
|
|
|
|
end
|
|
|
|
|
|
|
|
# == Article
|
|
|
|
rename_column :articles, :net_price, :price
|
|
|
|
remove_column :articles, :gross_price
|
|
|
|
|
|
|
|
# == ArticlePrice
|
|
|
|
create_table :article_prices do |t|
|
|
|
|
t.references :article
|
2023-05-12 13:01:12 +02:00
|
|
|
t.decimal :price, precision: 8, scale: 2, default: 0.0, null: false
|
|
|
|
t.decimal :tax, precision: 8, scale: 2, default: 0.0, null: false
|
|
|
|
t.decimal :deposit, precision: 8, scale: 2, default: 0.0, null: false
|
2009-03-01 18:45:34 +01:00
|
|
|
t.integer :unit_quantity
|
|
|
|
t.datetime :created_at
|
|
|
|
end
|
|
|
|
# Create price history for every Article
|
|
|
|
Article.all.each do |a|
|
2023-05-12 13:01:12 +02:00
|
|
|
a.article_prices.create price: a.price, tax: a.tax,
|
|
|
|
deposit: a.deposit, unit_quantity: a.unit_quantity
|
2009-03-01 18:45:34 +01:00
|
|
|
end
|
|
|
|
# Every Article has now a Category. Fix it if neccessary.
|
2023-05-12 13:01:12 +02:00
|
|
|
Article.all(conditions: { article_category_id: nil }).each do |article|
|
2021-03-01 15:27:26 +01:00
|
|
|
article.update_attribute(:article_category, ArticleCategory.first)
|
2009-03-01 18:45:34 +01:00
|
|
|
end
|
|
|
|
# order-articles
|
|
|
|
add_column :order_articles, :article_price_id, :integer
|
|
|
|
|
|
|
|
# == GroupOrder
|
2023-05-12 13:01:12 +02:00
|
|
|
change_column :group_orders, :updated_by_user_id, :integer, default: nil, null: true
|
2009-03-01 18:45:34 +01:00
|
|
|
|
|
|
|
# == GroupOrderArticle
|
|
|
|
# The total order result in ordergroup is now saved!
|
2023-05-12 13:01:12 +02:00
|
|
|
add_column :group_order_articles, :result, :integer, default: nil
|
2009-03-01 18:45:34 +01:00
|
|
|
|
|
|
|
# == StockArticle
|
|
|
|
add_column :articles, :type, :string
|
2023-05-12 13:01:12 +02:00
|
|
|
add_column :articles, :quantity, :integer, default: 0
|
2009-03-01 18:45:34 +01:00
|
|
|
|
|
|
|
# == StockChanges
|
|
|
|
create_table :stock_changes do |t|
|
|
|
|
t.references :delivery
|
|
|
|
t.references :order
|
|
|
|
t.references :stock_article
|
2023-05-12 13:01:12 +02:00
|
|
|
t.integer :quantity, default: 0
|
2009-03-01 18:45:34 +01:00
|
|
|
t.datetime :created_at
|
|
|
|
end
|
2009-02-06 16:26:35 +01:00
|
|
|
|
2009-02-12 18:32:20 +01:00
|
|
|
# == StockTaking
|
|
|
|
create_table :stock_takings do |t|
|
|
|
|
t.date :date
|
|
|
|
t.text :note
|
|
|
|
t.datetime :created_at
|
|
|
|
end
|
|
|
|
add_column :stock_changes, :stock_taking_id, :integer
|
2009-02-06 16:26:35 +01:00
|
|
|
|
2009-03-01 18:45:34 +01:00
|
|
|
# == User
|
|
|
|
# Ativate all Users for notification on upcoming tasks
|
|
|
|
User.all.each { |u| u.settings['notify.upcoming_tasks'] = 1 }
|
2009-01-29 01:57:51 +01:00
|
|
|
end
|
|
|
|
|
2023-05-12 13:01:12 +02:00
|
|
|
def self.down; end
|
2009-01-29 01:57:51 +01:00
|
|
|
end
|