Skip to content

Commit

Permalink
Minimum expiration warning
Browse files Browse the repository at this point in the history
  • Loading branch information
Bramjetten committed Mar 1, 2022
1 parent 5216b5d commit 8469211
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
15 changes: 15 additions & 0 deletions app/helpers/spina/shop/admin/stock/stock_orders_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module Spina::Shop
module Admin
module Stock
module StockOrdersHelper

def minimum_expiration_period_warning?(stock_order, date)
return false if Spina::Shop.config.minimum_expiration_period.blank?
return false if stock_order.ordered_at.blank?
(stock_order.ordered_at + Spina::Shop.config.minimum_expiration_period) > date
end

end
end
end
end
7 changes: 5 additions & 2 deletions app/views/spina/shop/admin/stock/stock_orders/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,11 @@

%td.text-right
- ordered.product.stock_level_adjustments.where(description: "StockOrder ##{@stock_order.id}").where("expiration_month IS NOT NULL AND expiration_year IS NOT NULL").group("expiration_month, expiration_year").pluck("expiration_month, expiration_year").map{|tht| Date.parse("1-#{tht[0]}-#{tht[1]}")}.sort.each do |date|
=l date, format: "%b '%y"
%br/
- if minimum_expiration_period_warning?(@stock_order, date)
.text-danger=l date, format: "%b '%y"
- else
=l date, format: "%b '%y"
%br/

%td.text-right{style: 'width: 150px'}
.progress.progress-bar-primary{class: ("progress-bar-danger" if ordered.received > ordered.quantity.to_d)}
Expand Down
6 changes: 6 additions & 0 deletions lib/spina/shop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module Shop
:holding_cost_percentage,
:default_stock_order_cost,
:future_demand_factor,
:minimum_expiration_period,
:api_key

# Default tax settings
Expand Down Expand Up @@ -47,6 +48,11 @@ module Shop
# Default stock order cost
self.default_stock_order_cost = 5

# Minimum expiration period
# Spina will show a warning when adding items with an expiration period
# smaller than the one set here
self.minimum_expiration_period = nil

# Future demand factor
# Demand calculations are multiplied by this factor to
# represent future demand
Expand Down

0 comments on commit 8469211

Please sign in to comment.