Compare commits

...

5 Commits

Author SHA1 Message Date
FGU 66c56ea24d WIP on favorites 2023-02-23 12:12:19 +01:00
FGU e5cd68a4ad wip 2023-02-20 16:24:46 +01:00
FGU 32547e495f wip 2023-02-15 16:30:45 +01:00
FGU b808f83931 wip 2023-02-15 16:09:11 +01:00
FGU 6835616170 wip 2023-02-15 16:06:12 +01:00
6 changed files with 74 additions and 8 deletions

View File

@ -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

View File

@ -226,10 +226,14 @@ $(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')));
});
updateButtons($(document));
});
});

View File

@ -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,31 @@ 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,7 +95,17 @@
%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
%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
- if @order.stockit?
%td= truncate order_article.article.supplier.name, length: 15
%td= h order_article.article.origin

View File

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

View File

@ -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