Change relationship of invoices #390

This change will allow us to have invoices for more than one order/delivery
in the future. There are no UI changes for now.
This commit is contained in:
Patrick Gansterer 2016-02-25 12:56:34 +01:00 committed by wvengen
parent 9f919c3e54
commit 460cf1e82c
13 changed files with 70 additions and 38 deletions

View file

@ -1,7 +1,7 @@
class Delivery < ActiveRecord::Base
belongs_to :supplier
has_one :invoice
belongs_to :invoice
has_many :stock_changes, -> { includes(:stock_article).order('articles.name ASC') }, :dependent => :destroy
scope :recent, -> { order('created_at DESC').limit(10) }

View file

@ -1,9 +1,9 @@
class Invoice < ActiveRecord::Base
belongs_to :supplier
belongs_to :delivery
belongs_to :order
belongs_to :created_by, :class_name => 'User', :foreign_key => 'created_by_user_id'
has_many :deliveries
has_many :orders
validates_presence_of :supplier_id
validates_numericality_of :amount, :deposit, :deposit_credit

View file

@ -9,9 +9,9 @@ class Order < ActiveRecord::Base
has_many :group_orders, :dependent => :destroy
has_many :ordergroups, :through => :group_orders
has_many :users_ordered, :through => :ordergroups, :source => :users
has_one :invoice
has_many :comments, -> { order('created_at') }, :class_name => "OrderComment"
has_many :stock_changes
belongs_to :invoice
belongs_to :supplier
belongs_to :updated_by, :class_name => 'User', :foreign_key => 'updated_by_user_id'
belongs_to :created_by, :class_name => 'User', :foreign_key => 'created_by_user_id'