Skip to content

Commit

Permalink
Fixes #52
Browse files Browse the repository at this point in the history
  • Loading branch information
lentschi committed Mar 1, 2024
1 parent 8a288b8 commit 3aa7f50
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 15 deletions.
16 changes: 9 additions & 7 deletions app/assets/javascripts/group-order-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,17 +181,19 @@ class GroupOrderForm {
totalPrice$.data('price', round(totalPrice));

missing$.text(round(missing));
if (packSize > 1 || minimumOrderQuantity > 1) {
this.setRowStyle(row$, missing, granularity);
if (tolerance$.length === 1) {
this.setRowStyle(row$, missing, granularity, quantity);
}
}

setRowStyle(row$, missing, packSize) {
setRowStyle(row$, missing, granularity, quantity) {
row$.removeClass('missing-many missing-few missing-none');
if (missing === 0) {
row$.addClass('missing-none');
if (quantity !== 0) {
row$.addClass('missing-none');
}
} else {
row$.addClass(missing <= packSize ? 'missing-few' : 'missing-many');
row$.addClass(missing <= granularity ? 'missing-few' : 'missing-many');
}
}

Expand All @@ -206,8 +208,8 @@ class GroupOrderForm {
}

calcMissingItems(packSize, quantity, tolerance, minimumOrderQuantity) {
if (Big(quantity).add(tolerance).toNumber() < minimumOrderQuantity) {
return Big(minimumOrderQuantity).sub(quantity).sub(tolerance);
if (quantity !== 0 && Big(quantity).add(tolerance).toNumber() < minimumOrderQuantity) {
return Big(minimumOrderQuantity).sub(quantity).sub(tolerance).toNumber();
}

if (isNaN(quantity)) {
Expand Down
8 changes: 4 additions & 4 deletions app/helpers/group_orders_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ def requires_tolerance_input?(order_article, ordering_data)
) || (order_article.article_version.minimum_order_quantity.presence || 0) > order_article.article_version.group_order_granularity
end

def get_missing_units_css_class(quantity_missing)
if (quantity_missing == 1)
return 'missing-few';
elsif (quantity_missing == 0)
def get_missing_units_css_class(quantity_missing, article_version)
if (quantity_missing == 0)
return ''
elsif (quantity_missing <= article_version.group_order_granularity)
return 'missing-few';
else
return 'missing-many'
end
Expand Down
10 changes: 7 additions & 3 deletions app/models/order_article.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,12 @@ def update_global_price=(value)
# @return [Number] Units missing for the last +unit_quantity+ of the article.
def missing_units
unit_ratio = price.convert_quantity(1, price.supplier_order_unit, price.group_order_unit)
_missing_units(unit_ratio, quantity, tolerance)
_missing_units(unit_ratio, quantity, tolerance, price.minimum_order_quantity)
end

def missing_units_was
unit_ratio = price.convert_quantity(1, price.supplier_order_unit, price.group_order_unit)
_missing_units(unit_ratio, quantity_was, tolerance_was)
_missing_units(unit_ratio, quantity_was, tolerance_was, price.minimum_order_quantity)
end

# Check if the result of any associated GroupOrderArticle was overridden manually
Expand Down Expand Up @@ -264,7 +264,11 @@ def enforce_boxfill
end
end

def _missing_units(unit_ratio, quantity, tolerance)
def _missing_units(unit_ratio, quantity, tolerance, minimum_order_quantity)
if !minimum_order_quantity.nil? && quantity > 0 && quantity + tolerance < minimum_order_quantity
return minimum_order_quantity - quantity - tolerance
end

return 0 if article_version.supplier_order_unit_is_si_convertible

units = unit_ratio - ((quantity % unit_ratio) + tolerance)
Expand Down
2 changes: 1 addition & 1 deletion app/views/group_orders/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
%i.icon-tag
%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"}
%tr{class: "#{cycle('even', 'odd', name: 'articles')} order-article #{get_missing_units_css_class(@ordering_data[:order_articles][order_article.id][:missing_units], order_article.article_version)}", valign: "top"}
%td.name= order_article.article_version.name
- if @order.stockit?
%td= truncate order_article.article_version.article.supplier.name, length: 15
Expand Down

0 comments on commit 3aa7f50

Please sign in to comment.