wip
This commit is contained in:
parent
78da4feafe
commit
6835616170
5 changed files with 56 additions and 5 deletions
4
Gemfile
4
Gemfile
|
@ -90,8 +90,6 @@ group :development do
|
|||
|
||||
# Get infos when not using proper eager loading
|
||||
gem 'bullet'
|
||||
# Display Active Record queries as tables in the console
|
||||
gem 'table_print'
|
||||
end
|
||||
|
||||
group :development, :test do
|
||||
|
@ -103,6 +101,8 @@ group :development, :test do
|
|||
# allow to use `debugger` https://github.com/conradirwin/pry-rescue
|
||||
gem 'pry-rescue'
|
||||
gem 'pry-stack_explorer'
|
||||
# Display Active Record queries as tables in the console
|
||||
gem 'table_print'
|
||||
end
|
||||
|
||||
group :test do
|
||||
|
|
|
@ -35,6 +35,7 @@ class GroupOrder < ApplicationRecord
|
|||
data[:account_balance] = ordergroup.nil? ? BigDecimal.new('+Infinity') : ordergroup.account_balance
|
||||
data[:available_funds] = ordergroup.nil? ? BigDecimal.new('+Infinity') : ordergroup.get_available_funds(self)
|
||||
|
||||
|
||||
# load prices and other stuff....
|
||||
data[:order_articles] = {}
|
||||
order.articles_grouped_by_category.each do |article_category, order_articles|
|
||||
|
@ -59,9 +60,28 @@ class GroupOrder < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
# add counts from the previous group order
|
||||
if previous_group_order
|
||||
previous_group_order.group_order_articles.each do |goa|
|
||||
order_article_id = OrderArticle.find_by(order: order, article: goa.order_article.article)&.id
|
||||
data[:order_articles][order_article_id] ||= {}
|
||||
data[:order_articles][order_article_id][:previous_quantity] = goa.quantity
|
||||
data[:order_articles][order_article_id][:previous_tolerance] = goa.tolerance
|
||||
end
|
||||
end
|
||||
|
||||
puts data
|
||||
|
||||
data
|
||||
end
|
||||
|
||||
def previous_group_order
|
||||
previous_order = ordergroup.orders.where.not(id: order.id).recent.first
|
||||
return nil unless previous_order
|
||||
|
||||
ordergroup.group_orders.find_by(order_id: previous_order.id)
|
||||
end
|
||||
|
||||
def save_group_order_articles
|
||||
for order_article in order.order_articles
|
||||
# Find the group_order_article, create a new one if necessary...
|
||||
|
|
|
@ -109,6 +109,8 @@
|
|||
|
||||
%td.quantity
|
||||
%input{id: "q_#{order_article.id}", name: "group_order[group_order_articles_attributes][#{order_article.id}][quantity]", type: "hidden", value: @ordering_data[:order_articles][order_article.id][:quantity], 'data-min' => (@ordering_data[:order_articles][order_article.id][:quantity] if @order.boxfill?), 'data-max' => (@ordering_data[:order_articles][order_article.id][:quantity]+@ordering_data[:order_articles][order_article.id][:missing_units] if @order.boxfill?)}/
|
||||
= @ordering_data[:order_articles][order_article.id][:previous_quantity]
|
||||
hello
|
||||
%span.used{id: "q_used_#{order_article.id}"}= @ordering_data[:order_articles][order_article.id][:used_quantity]
|
||||
+
|
||||
%span.unused{id: "q_unused_#{order_article.id}"}= @ordering_data[:order_articles][order_article.id][:quantity] - @ordering_data[:order_articles][order_article.id][:used_quantity]
|
||||
|
|
|
@ -6,6 +6,7 @@ services:
|
|||
command: ./proc-start web
|
||||
ports:
|
||||
- "3000:3000"
|
||||
platform: linux/x86_64
|
||||
|
||||
foodsoft_worker:
|
||||
build:
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
require_relative '../spec_helper'
|
||||
|
||||
describe GroupOrder do
|
||||
let(:user) { create :user, groups: [create(:ordergroup)] }
|
||||
let(:order) { create :order }
|
||||
let(:ordergroup) { create(:ordergroup) }
|
||||
let(:user) { create :user, groups: [ordergroup] }
|
||||
let(:supplier) { create(:supplier, article_count: 3) }
|
||||
let(:order) { create :order, supplier: supplier }
|
||||
|
||||
# the following two tests are currently disabled - https://github.com/foodcoops/foodsoft/issues/158
|
||||
|
||||
|
@ -15,10 +17,36 @@ describe GroupOrder do
|
|||
# end
|
||||
|
||||
describe do
|
||||
let(:go) { create :group_order, order: order, ordergroup: user.ordergroup }
|
||||
let(:go) { create :group_order, order: order, ordergroup: ordergroup }
|
||||
|
||||
it 'has zero price initially' do
|
||||
expect(go.price).to eq(0)
|
||||
end
|
||||
end
|
||||
|
||||
describe "load data for javascript" do
|
||||
let(:group_order) { create :group_order, order: order, ordergroup: ordergroup }
|
||||
let!(:article) { order.articles.first }
|
||||
let(:order_article) { OrderArticle.find_or_create_by!(order: order, article: article) }
|
||||
let(:previous_order) { create :order, supplier: supplier, starts: 20.days.ago, ends: 18.days.ago }
|
||||
let(:previous_group_order) { create :group_order, order: previous_order, ordergroup: ordergroup }
|
||||
let(:previous_order_article) { OrderArticle.find_or_create_by!(order: previous_order, article: article) }
|
||||
|
||||
it "includes data from the last order" do
|
||||
create :group_order_article,
|
||||
order_article: previous_order_article,
|
||||
group_order: previous_group_order,
|
||||
quantity: 23,
|
||||
tolerance: 11
|
||||
|
||||
order.order_articles.map(&:update_results!)
|
||||
order.group_orders.map(&:update_price!)
|
||||
|
||||
order_article_data = group_order.load_data[:order_articles][order_article.id]
|
||||
|
||||
expect(order_article_data[:previous_quantity]).to eq(23)
|
||||
expect(order_article_data[:previous_tolerance]).to eq(11)
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue