Compare commits

..

No commits in common. "66c56ea24df151b0f2c74fa479e48f6418709cd4" and "78da4feafe2efeebd4ee295ac51d634b4a4aff57" have entirely different histories.

6 changed files with 8 additions and 74 deletions

View file

@ -90,6 +90,8 @@ 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
@ -101,8 +103,6 @@ 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

View file

@ -226,10 +226,6 @@ $(function() {
$('a[data-decrease_tolerance]').on('touchclick', function() {
decreaseTolerance($(this).data('decrease_tolerance'));
});
$('a[data-reorder_previous]').on('touchclick', function() {
console.log('reorder_previous');
// update($(this).data('reorder_previous'), $(this).data('quantity'), $(this).data('tolerance'));
});
$('a[data-confirm_switch_order]').on('touchclick', function() {
return (!modified || confirm(I18n.t('js.ordering.confirm_change')));

View file

@ -35,7 +35,6 @@ 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|
@ -60,31 +59,9 @@ 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
puts " order ID: #{order.id}"
puts " article ID: #{goa.order_article.article.id}"
puts "ID: #{order_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(supplier: order.supplier).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...

View file

@ -95,17 +95,7 @@
%td{colspan: "9"}
- order_articles.each do |order_article|
%tr{class: "#{cycle('even', 'odd', name: 'articles')} order-article #{get_missing_units_css_class(@ordering_data[:order_articles][order_article.id][:missing_units])}", valign: "top"}
%td.name
= order_article.article.name
- if @ordering_data[:order_articles][order_article.id][:previous_quantity]
%span.label
last time:
= @ordering_data[:order_articles][order_article.id][:previous_quantity]
+
= @ordering_data[:order_articles][order_article.id][:previous_tolerance]
%a.btn.btn-ordering{"data-reorder_previous": order_article.id, "data-quantity": @ordering_data[:order_articles][order_article.id][:previous_quantity], "data-tolerance": @ordering_data[:order_articles][order_article.id][:previous_tolerance]}
%i.icon-repeat
order previous
%td.name= order_article.article.name
- if @order.stockit?
%td= truncate order_article.article.supplier.name, length: 15
%td= h order_article.article.origin

View file

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

View file

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