Add stock group order
This allows us to add additional items to an order, which do not belong a specific user, but will be put into stock. The benefit of this change is that we use the same order for ordergroups and stock.
This commit is contained in:
parent
b56df39623
commit
9c4d9d5c20
8 changed files with 42 additions and 11 deletions
|
@ -12,7 +12,8 @@ class GroupOrdersController < ApplicationController
|
|||
end
|
||||
|
||||
def new
|
||||
@group_order = @order.group_orders.build(:ordergroup => @ordergroup, :updated_by => current_user)
|
||||
ordergroup = params[:stock_order] ? nil : @ordergroup
|
||||
@group_order = @order.group_orders.build(:ordergroup => ordergroup, :updated_by => current_user)
|
||||
@ordering_data = @group_order.load_data
|
||||
end
|
||||
|
||||
|
@ -84,10 +85,11 @@ class GroupOrdersController < ApplicationController
|
|||
end
|
||||
|
||||
def ensure_my_group_order
|
||||
@group_order = @ordergroup.group_orders.find(params[:id])
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
@group_order = GroupOrder.find_by_id(params[:id])
|
||||
if @group_order.ordergroup != @ordergroup && (@group_order.ordergroup || !current_user.role_orders?)
|
||||
redirect_to group_orders_url, alert: I18n.t('group_orders.errors.notfound')
|
||||
end
|
||||
end
|
||||
|
||||
def enough_apples?
|
||||
if @ordergroup.not_enough_apples?
|
||||
|
|
|
@ -10,7 +10,6 @@ class GroupOrder < ActiveRecord::Base
|
|||
belongs_to :updated_by, :class_name => "User", :foreign_key => "updated_by_user_id"
|
||||
|
||||
validates_presence_of :order_id
|
||||
validates_presence_of :ordergroup_id
|
||||
validates_numericality_of :price
|
||||
validates_uniqueness_of :ordergroup_id, :scope => :order_id # order groups can only order once per order
|
||||
|
||||
|
@ -22,7 +21,7 @@ class GroupOrder < ActiveRecord::Base
|
|||
# Generate some data for the javascript methods in ordering view
|
||||
def load_data
|
||||
data = {}
|
||||
data[:available_funds] = ordergroup.get_available_funds(self)
|
||||
data[:available_funds] = ordergroup.nil? ? BigDecimal.new('+Infinity') : ordergroup.get_available_funds(self)
|
||||
|
||||
# load prices and other stuff....
|
||||
data[:order_articles] = {}
|
||||
|
@ -87,4 +86,8 @@ class GroupOrder < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
def ordergroup_name
|
||||
ordergroup ? ordergroup.name : I18n.t('model.group_order.stock_ordergroup_name', :user => updated_by.name)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -31,6 +31,7 @@ class Order < ActiveRecord::Base
|
|||
scope :closed, -> { where(state: 'closed').order('ends DESC') }
|
||||
scope :stockit, -> { where(supplier_id: 0).order('ends DESC') }
|
||||
scope :recent, -> { order('starts DESC').limit(10) }
|
||||
scope :stock_group_order, -> { group_orders.where(ordergroup_id: nil).first }
|
||||
|
||||
# Allow separate inputs for date and time
|
||||
# with workaround for https://github.com/einzige/date_time_attribute/issues/14
|
||||
|
@ -125,6 +126,10 @@ class Order < ActiveRecord::Base
|
|||
group_orders.where(:ordergroup_id => ordergroup.id).first
|
||||
end
|
||||
|
||||
def stock_group_order
|
||||
group_orders.where(:ordergroup_id => nil).first
|
||||
end
|
||||
|
||||
# Returns OrderArticles in a nested Array, grouped by category and ordered by article name.
|
||||
# The array has the following form:
|
||||
# e.g: [["drugs",[teethpaste, toiletpaper]], ["fruits" => [apple, banana, lemon]]]
|
||||
|
@ -234,9 +239,11 @@ class Order < ActiveRecord::Base
|
|||
|
||||
transaction do # Start updating account balances
|
||||
for group_order in gos
|
||||
if group_order.ordergroup
|
||||
price = group_order.price * -1 # decrease! account balance
|
||||
group_order.ordergroup.add_financial_transaction!(price, transaction_note, user)
|
||||
end
|
||||
end
|
||||
|
||||
if stockit? # Decreases the quantity of stock_articles
|
||||
for oa in order_articles.includes(:article)
|
||||
|
|
|
@ -70,6 +70,10 @@
|
|||
- if @order.open?
|
||||
= link_to t('.action_end'), finish_order_path(@order), method: :post, class: 'btn btn-success',
|
||||
data: {confirm: t('.confirm_end', order: @order.name)}
|
||||
- if @order.stock_group_order
|
||||
= link_to t('.stock_order'), edit_group_order_path(@order.stock_group_order, :order_id => @order.id), class: 'btn'
|
||||
- else
|
||||
= link_to t('.stock_order'), new_group_order_path(:order_id => @order.id, :stock_order => true), class: 'btn'
|
||||
= link_to t('ui.edit'), edit_order_path(@order), class: 'btn'
|
||||
- elsif not @order.closed? and not @order.stockit?
|
||||
= receive_button @order
|
||||
|
|
|
@ -1170,6 +1170,8 @@ de:
|
|||
model:
|
||||
delivery:
|
||||
each_stock_article_must_be_unique: Lieferung darf jeden Lagerartikel höchstens einmal auflisten.
|
||||
group_order:
|
||||
stock_ordergroup_name: Lager (%{user})
|
||||
membership:
|
||||
no_admin_delete: Mitgliedschaft kann nicht beendet werden. Du bist die letzte Administratorin
|
||||
order_article:
|
||||
|
@ -1327,6 +1329,7 @@ de:
|
|||
show_invoice: Rechnung anzeigen
|
||||
sort_article: Sortiert nach Artikeln
|
||||
sort_group: Sortiert nach Gruppen
|
||||
stock_order: Lagerbestellung
|
||||
title: 'Bestellung: %{name}'
|
||||
warn_not_closed: Achtung, Bestellung wurde noch nicht abgerechnet.
|
||||
state:
|
||||
|
|
|
@ -1190,6 +1190,8 @@ en:
|
|||
model:
|
||||
delivery:
|
||||
each_stock_article_must_be_unique: Each stock article must not be listed more than once.
|
||||
group_order:
|
||||
stock_ordergroup_name: Stock (%{user})
|
||||
membership:
|
||||
no_admin_delete: Membership can not be withdrawn as you are the last administrator.
|
||||
order_article:
|
||||
|
@ -1349,6 +1351,7 @@ en:
|
|||
show_invoice: Show invoice
|
||||
sort_article: Sorted in articles
|
||||
sort_group: Sorted in groups
|
||||
stock_order: Stock Order
|
||||
title: 'Order: %{name}'
|
||||
warn_not_closed: Warning, order is not yet settled.
|
||||
state:
|
||||
|
|
9
db/migrate/20160224201529_allow_stock_group_order.rb
Normal file
9
db/migrate/20160224201529_allow_stock_group_order.rb
Normal file
|
@ -0,0 +1,9 @@
|
|||
class AllowStockGroupOrder < ActiveRecord::Migration
|
||||
def self.up
|
||||
change_column :group_orders, :ordergroup_id, :integer, :default => nil, :null => true
|
||||
end
|
||||
|
||||
def self.down
|
||||
change_column :group_orders, :ordergroup_id, :integer, :default => 0, :null => false
|
||||
end
|
||||
end
|
|
@ -11,7 +11,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20160217194036) do
|
||||
ActiveRecord::Schema.define(version: 20160224201529) do
|
||||
|
||||
create_table "article_categories", force: :cascade do |t|
|
||||
t.string "name", limit: 255, default: "", null: false
|
||||
|
@ -110,7 +110,7 @@ ActiveRecord::Schema.define(version: 20160217194036) do
|
|||
add_index "group_order_articles", ["order_article_id"], name: "index_group_order_articles_on_order_article_id", using: :btree
|
||||
|
||||
create_table "group_orders", force: :cascade do |t|
|
||||
t.integer "ordergroup_id", limit: 4, default: 0, null: false
|
||||
t.integer "ordergroup_id", limit: 4
|
||||
t.integer "order_id", limit: 4, default: 0, null: false
|
||||
t.decimal "price", precision: 8, scale: 2, default: 0, null: false
|
||||
t.integer "lock_version", limit: 4, default: 0, null: false
|
||||
|
|
Loading…
Reference in a new issue