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

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

View file

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