Nullify deliveries and orders depending on an invoice (#718)
This commit is contained in:
parent
5eb8abf431
commit
fc22a97f52
2 changed files with 10 additions and 2 deletions
|
@ -4,8 +4,8 @@ class Invoice < ApplicationRecord
|
||||||
belongs_to :supplier
|
belongs_to :supplier
|
||||||
belongs_to :created_by, :class_name => 'User', :foreign_key => 'created_by_user_id'
|
belongs_to :created_by, :class_name => 'User', :foreign_key => 'created_by_user_id'
|
||||||
belongs_to :financial_link
|
belongs_to :financial_link
|
||||||
has_many :deliveries
|
has_many :deliveries, dependent: :nullify
|
||||||
has_many :orders
|
has_many :orders, dependent: :nullify
|
||||||
|
|
||||||
validates_presence_of :supplier_id
|
validates_presence_of :supplier_id
|
||||||
validates_numericality_of :amount, :deposit, :deposit_credit
|
validates_numericality_of :amount, :deposit, :deposit_credit
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
class ClearInvalidInvoicesFromOrders < ActiveRecord::Migration
|
||||||
|
class Order < ActiveRecord::Base; end
|
||||||
|
class Invoice < ActiveRecord::Base; end
|
||||||
|
|
||||||
|
def up
|
||||||
|
Order.where.not(invoice_id: Invoice.all).update_all(invoice_id: nil)
|
||||||
|
end
|
||||||
|
end
|
Loading…
Add table
Reference in a new issue