Change supplier_id of stock orders to NULL

This commit is contained in:
Patrick Gansterer 2020-08-13 16:23:01 +02:00
parent aa44291b69
commit 5f60844a13
4 changed files with 16 additions and 5 deletions

View file

@ -20,8 +20,8 @@ module OrdersHelper
def options_for_suppliers_to_select def options_for_suppliers_to_select
options = [[I18n.t('helpers.orders.option_choose')]] options = [[I18n.t('helpers.orders.option_choose')]]
options += Supplier.map {|s| [ s.name, url_for(action: "new", supplier_id: s)] } options += Supplier.map {|s| [ s.name, url_for(action: "new", supplier_id: s.id)] }
options += [[I18n.t('helpers.orders.option_stock'), url_for(action: 'new', supplier_id: 0)]] options += [[I18n.t('helpers.orders.option_stock'), url_for(action: 'new', supplier_id: nil)]]
options_for_select(options) options_for_select(options)
end end

View file

@ -34,7 +34,7 @@ class Order < ApplicationRecord
scope :finished, -> { where("orders.state = 'finished' OR orders.state = 'closed'").order('ends DESC') } scope :finished, -> { where("orders.state = 'finished' OR orders.state = 'closed'").order('ends DESC') }
scope :finished_not_closed, -> { where(state: 'finished').order('ends DESC') } scope :finished_not_closed, -> { where(state: 'finished').order('ends DESC') }
scope :closed, -> { where(state: 'closed').order('ends DESC') } scope :closed, -> { where(state: 'closed').order('ends DESC') }
scope :stockit, -> { where(supplier_id: 0).order('ends DESC') } scope :stockit, -> { where(supplier_id: nil).order('ends DESC') }
scope :recent, -> { order('starts DESC').limit(10) } scope :recent, -> { order('starts DESC').limit(10) }
scope :stock_group_order, -> { group_orders.where(ordergroup_id: nil).first } scope :stock_group_order, -> { group_orders.where(ordergroup_id: nil).first }
scope :with_invoice, -> { where.not(invoice: nil) } scope :with_invoice, -> { where.not(invoice: nil) }
@ -45,7 +45,7 @@ class Order < ApplicationRecord
date_time_attribute :starts, :boxfill, :ends date_time_attribute :starts, :boxfill, :ends
def stockit? def stockit?
supplier_id == 0 supplier_id.nil?
end end
def name def name

View file

@ -39,7 +39,7 @@
%li= link_to t('.toggle_unavailable'), "#", 'data-toggle-this' => 'tr.unavailable', tabindex: -1 %li= link_to t('.toggle_unavailable'), "#", 'data-toggle-this' => 'tr.unavailable', tabindex: -1
.btn-group .btn-group
= link_to_if @current_user.role_orders?, t('.order_online'), new_order_path(supplier_id: 0), = link_to_if @current_user.role_orders?, t('.order_online'), new_order_path(supplier_id: nil),
class: 'btn', class: 'btn btn-primary' class: 'btn', class: 'btn btn-primary'
= link_to t('.new_stock_article'), new_stock_article_path, remote: true, class: 'btn' = link_to t('.new_stock_article'), new_stock_article_path, remote: true, class: 'btn'
= link_to t('.new_stock_taking'), new_stock_taking_path, class: 'btn' = link_to t('.new_stock_taking'), new_stock_taking_path, class: 'btn'

View file

@ -0,0 +1,11 @@
class ChangeStockSupplierToNullInOrder < ActiveRecord::Migration
class Order < ActiveRecord::Base; end
def up
Order.where(supplier_id: 0).update_all(supplier_id: nil)
end
def down
Order.where(supplier_id: nil).update_all(supplier_id: 0)
end
end