Skip to content

Commit

Permalink
Some more bugfixing
Browse files Browse the repository at this point in the history
  • Loading branch information
lentschi committed Dec 29, 2023
1 parent 380f279 commit 948c480
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 16 deletions.
14 changes: 10 additions & 4 deletions app/assets/javascripts/delta_input.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ function data_delta_update(el, direction) {
var delta = $(el).data('delta');
var granularity = $(el).data('granularity');

var val = $(el).val();
var val = $(el).val().replace(',', '.');
const valueContainedColon = $(el).val() != val;
var oldval = $.isNumeric(val) ? Number(val) : 0;
var newval = oldval + delta*direction;

Expand All @@ -31,11 +32,16 @@ function data_delta_update(el, direction) {
$('button[data-increment='+id+']').attr('disabled', newval>=max ? 'disabled' : null);

// warn when what was entered is not a number
$(el).toggleClass('error', val!='' && val!='.' && (!$.isNumeric(val) || val < 0));
const erroneousValue = val!='' && val!='.' && (!$.isNumeric(val) || val < 0)
$(el).toggleClass('error', erroneousValue);

// update field, unless the user is typing
if (!$(el).is(':focus')) {
$(el).val(round_float(newval, granularity));
if (!$(el).is(':focus') && !erroneousValue) {
let roundedValue = String(round_float(newval, granularity));
if (valueContainedColon) {
roundedValue = roundedValue.replace('.', ',');
}
$(el).val(roundedValue);
$(el).trigger('changed');
}
}
Expand Down
12 changes: 6 additions & 6 deletions app/controllers/orders_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ def new
redirect_to orders_url, alert: t('errors.general_msg', msg: error.message)
end

# Page to edit an exsiting order.
# editing finished orders is done in FinanceController
def edit
@order = Order.includes(:articles).find(params[:id])
end

# Save a new order.
# order_articles will be saved in Order.article_ids=()
def create
Expand All @@ -85,12 +91,6 @@ def create
end
end

# Page to edit an exsiting order.
# editing finished orders is done in FinanceController
def edit
@order = Order.includes(:articles).find(params[:id])
end

# Update an existing order.
def update
@order = Order.find params[:id]
Expand Down
5 changes: 4 additions & 1 deletion app/models/order_article.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,10 @@ def redistribute(quantity, surplus = [:tolerance], update_totals = true)
end

# Recompute
group_order_articles.each { |goa| goa.save_results! qty_for_members }
group_order_articles.each do |goa|
group_order_total = article_version.convert_quantity(qty_for_members, article_version.supplier_order_unit, article_version.group_order_unit)
goa.save_results!(group_order_total)
end
qty_left -= qty_for_members

# if there's anything left, move to stock if wanted
Expand Down
2 changes: 1 addition & 1 deletion app/views/finance/balancing/_order_article.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
= pkg_helper(order_article.article_version, unit: order_article.article_version.billing_unit)
- if s=ordered_quantities_different_from_group_orders?(order_article)
%span{:style => "color:red;font-weight: bold"}= s
%td #{order_article.article_version.unit}
%td #{format_group_order_unit_with_ratios(order_article.article_version)}
%td
= number_to_currency(order_article.article_version.price, :unit => "")
:plain
Expand Down
2 changes: 1 addition & 1 deletion app/views/group_order_articles/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
%h3= t('.amount_change_for', article: @order_article.article_version.name)
.modal-body
= form.input :ordergroup_id, as: :select, collection: Ordergroup.undeleted.map { |g| [g.name, g.id] }
= form.input :result, hint: I18n.t('group_order_articles.form.result_hint', unit: @order_article.article_version.unit) # Why do we need the full prefix?
= form.input :result, hint: I18n.t('group_order_articles.form.result_hint', unit: format_group_order_unit_with_ratios(@order_article.article_version)) # Why do we need the full prefix?
.modal-footer
= link_to t('ui.close'), '#', class: 'btn', data: {dismiss: 'modal'}
= form.submit t('ui.save'), class: 'btn btn-primary'
4 changes: 2 additions & 2 deletions app/views/orders/_edit_amount.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
- order_title.append Article.human_attribute_name(:note)+': ' + order_article.article_version.note unless order_article.article_version.note.to_s.empty?
%td= order_article.article_version.order_number
%td.name{title: order_title.join("\n")}= order_article.article_version.name
%td.unit= format_supplier_article_unit(order_article.article_version)
%td.unit= format_group_order_unit_with_ratios(order_article.article_version)
%td.article_version
= number_to_currency order_article.article_version.price
= number_to_currency order_article.article_version.group_order_price
= article_version_change_hint(order_article)
%td #{order_article.quantity} + #{order_article.tolerance}
%td
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ def up
update(%{
UPDATE article_versions
SET unit = #{quote compound_unit},
supplier_order_unit = #{quote 'XPP'},
group_order_granularity = #{quote 1},
group_order_unit = #{quote 'XPP'},
price = #{quote article_version['price'].to_f * article_version['unit_quantity']},
price_unit = #{quote 'XPP'}
price_unit = #{quote 'XPP'},
billing_unit = #{quote 'XPP'}
WHERE article_versions.id = #{quote article_version['id']}
})
end
Expand Down

0 comments on commit 948c480

Please sign in to comment.