This commit is contained in:
FGU 2023-02-15 16:06:12 +01:00
parent 78da4feafe
commit 6835616170
5 changed files with 56 additions and 5 deletions

View file

@ -90,8 +90,6 @@ group :development do
# Get infos when not using proper eager loading # Get infos when not using proper eager loading
gem 'bullet' gem 'bullet'
# Display Active Record queries as tables in the console
gem 'table_print'
end end
group :development, :test do group :development, :test do
@ -103,6 +101,8 @@ group :development, :test do
# allow to use `debugger` https://github.com/conradirwin/pry-rescue # allow to use `debugger` https://github.com/conradirwin/pry-rescue
gem 'pry-rescue' gem 'pry-rescue'
gem 'pry-stack_explorer' gem 'pry-stack_explorer'
# Display Active Record queries as tables in the console
gem 'table_print'
end end
group :test do group :test do

View file

@ -35,6 +35,7 @@ class GroupOrder < ApplicationRecord
data[:account_balance] = ordergroup.nil? ? BigDecimal.new('+Infinity') : ordergroup.account_balance data[:account_balance] = ordergroup.nil? ? BigDecimal.new('+Infinity') : ordergroup.account_balance
data[:available_funds] = ordergroup.nil? ? BigDecimal.new('+Infinity') : ordergroup.get_available_funds(self) data[:available_funds] = ordergroup.nil? ? BigDecimal.new('+Infinity') : ordergroup.get_available_funds(self)
# load prices and other stuff.... # load prices and other stuff....
data[:order_articles] = {} data[:order_articles] = {}
order.articles_grouped_by_category.each do |article_category, order_articles| order.articles_grouped_by_category.each do |article_category, order_articles|
@ -59,9 +60,28 @@ class GroupOrder < ApplicationRecord
end end
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 data
end 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 def save_group_order_articles
for order_article in order.order_articles for order_article in order.order_articles
# Find the group_order_article, create a new one if necessary... # Find the group_order_article, create a new one if necessary...

View file

@ -109,6 +109,8 @@
%td.quantity %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?)}/ %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.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] %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]

View file

@ -6,6 +6,7 @@ services:
command: ./proc-start web command: ./proc-start web
ports: ports:
- "3000:3000" - "3000:3000"
platform: linux/x86_64
foodsoft_worker: foodsoft_worker:
build: build:

View file

@ -1,8 +1,10 @@
require_relative '../spec_helper' require_relative '../spec_helper'
describe GroupOrder do describe GroupOrder do
let(:user) { create :user, groups: [create(:ordergroup)] } let(:ordergroup) { create(:ordergroup) }
let(:order) { create :order } 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 # the following two tests are currently disabled - https://github.com/foodcoops/foodsoft/issues/158
@ -15,10 +17,36 @@ describe GroupOrder do
# end # end
describe do 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 it 'has zero price initially' do
expect(go.price).to eq(0) expect(go.price).to eq(0)
end end
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 end