diff --git a/app/helpers/spina/shop/admin/stock/stock_orders_helper.rb b/app/helpers/spina/shop/admin/stock/stock_orders_helper.rb new file mode 100644 index 00000000..be4a88b3 --- /dev/null +++ b/app/helpers/spina/shop/admin/stock/stock_orders_helper.rb @@ -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 \ No newline at end of file diff --git a/app/views/spina/shop/admin/stock/stock_orders/show.html.haml b/app/views/spina/shop/admin/stock/stock_orders/show.html.haml index ce46c406..8921badc 100644 --- a/app/views/spina/shop/admin/stock/stock_orders/show.html.haml +++ b/app/views/spina/shop/admin/stock/stock_orders/show.html.haml @@ -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)} diff --git a/lib/spina/shop.rb b/lib/spina/shop.rb index 781b357d..579fcb6b 100644 --- a/lib/spina/shop.rb +++ b/lib/spina/shop.rb @@ -17,6 +17,7 @@ module Shop :holding_cost_percentage, :default_stock_order_cost, :future_demand_factor, + :minimum_expiration_period, :api_key # Default tax settings @@ -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