From 948c480fcb6708f79c210ed6aa424259bcda1b02 Mon Sep 17 00:00:00 2001 From: Florian Lentsch Date: Fri, 29 Dec 2023 17:10:32 +0100 Subject: [PATCH] Some more bugfixing --- app/assets/javascripts/delta_input.js | 14 ++++++++++---- app/controllers/orders_controller.rb | 12 ++++++------ app/models/order_article.rb | 5 ++++- .../finance/balancing/_order_article.html.haml | 2 +- app/views/group_order_articles/_form.html.haml | 2 +- app/views/orders/_edit_amount.html.haml | 4 ++-- ...026102301_alter_articles_add_more_unit_logic.rb | 4 +++- 7 files changed, 27 insertions(+), 16 deletions(-) diff --git a/app/assets/javascripts/delta_input.js b/app/assets/javascripts/delta_input.js index 0ae7f4a5..5c0da86f 100644 --- a/app/assets/javascripts/delta_input.js +++ b/app/assets/javascripts/delta_input.js @@ -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; @@ -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'); } } diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index 703b5114..dc8a62bb 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -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 @@ -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] diff --git a/app/models/order_article.rb b/app/models/order_article.rb index 3e3cd073..d57afdf4 100644 --- a/app/models/order_article.rb +++ b/app/models/order_article.rb @@ -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 diff --git a/app/views/finance/balancing/_order_article.html.haml b/app/views/finance/balancing/_order_article.html.haml index 07b76fa8..6c3a4988 100644 --- a/app/views/finance/balancing/_order_article.html.haml +++ b/app/views/finance/balancing/_order_article.html.haml @@ -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 diff --git a/app/views/group_order_articles/_form.html.haml b/app/views/group_order_articles/_form.html.haml index 54a28e4e..7a7ade62 100644 --- a/app/views/group_order_articles/_form.html.haml +++ b/app/views/group_order_articles/_form.html.haml @@ -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' diff --git a/app/views/orders/_edit_amount.html.haml b/app/views/orders/_edit_amount.html.haml index 906878cf..ad334c02 100644 --- a/app/views/orders/_edit_amount.html.haml +++ b/app/views/orders/_edit_amount.html.haml @@ -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 diff --git a/db/migrate/20221026102301_alter_articles_add_more_unit_logic.rb b/db/migrate/20221026102301_alter_articles_add_more_unit_logic.rb index 5a5a77d0..d0a36c0c 100644 --- a/db/migrate/20221026102301_alter_articles_add_more_unit_logic.rb +++ b/db/migrate/20221026102301_alter_articles_add_more_unit_logic.rb @@ -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