From 8f05dd440e2b395b7eeb27f10cee150a57b9d57c Mon Sep 17 00:00:00 2001 From: viehlieb Date: Fri, 13 Oct 2023 19:03:55 +0200 Subject: [PATCH] fix one flaky test --- .../finance/balancing_controller.rb | 2 +- .../finance/balancing/_article_results.haml | 1 + .../_edit_results_by_articles.html.haml | 18 ++--- .../finance/balancing/_results.html.haml | 3 - app/views/finance/balancing/new.html.haml | 3 +- .../app/documents/group_order_invoice_pdf.rb | 75 ++++++++++++++----- ...ce_contents_order_article.html.haml.deface | 2 +- spec/integration/balancing_spec.rb | 13 +++- spec/models/order_spec.rb | 2 + spec/spec_helper.rb | 7 ++ 10 files changed, 89 insertions(+), 37 deletions(-) create mode 100644 app/views/finance/balancing/_article_results.haml delete mode 100644 app/views/finance/balancing/_results.html.haml rename plugins/automatic_invoices/app/overrides/finance/balancing/{_results => _results_section}/replace_contents_order_article.html.haml.deface (68%) diff --git a/app/controllers/finance/balancing_controller.rb b/app/controllers/finance/balancing_controller.rb index e1a2dafb..fad07684 100644 --- a/app/controllers/finance/balancing_controller.rb +++ b/app/controllers/finance/balancing_controller.rb @@ -8,6 +8,7 @@ class Finance::BalancingController < Finance::BaseController flash.now.alert = t('.alert') if @order.closed? @comments = @order.comments + @articles = @order.order_articles.ordered_or_member.includes(:article, :article_price, group_order_articles: { group_order: :ordergroup }) @@ -24,7 +25,6 @@ class Finance::BalancingController < Finance::BaseController else @articles end - render layout: false if request.xhr? end diff --git a/app/views/finance/balancing/_article_results.haml b/app/views/finance/balancing/_article_results.haml new file mode 100644 index 00000000..acae2a1c --- /dev/null +++ b/app/views/finance/balancing/_article_results.haml @@ -0,0 +1 @@ += render partial: 'finance/balancing/edit_results_by_articles', locals: {order: @order, articles: @articles, comments: @comments } diff --git a/app/views/finance/balancing/_edit_results_by_articles.html.haml b/app/views/finance/balancing/_edit_results_by_articles.html.haml index 61ada1b8..4518223b 100644 --- a/app/views/finance/balancing/_edit_results_by_articles.html.haml +++ b/app/views/finance/balancing/_edit_results_by_articles.html.haml @@ -36,28 +36,28 @@ %th= heading_helper Article, :tax %th= heading_helper Article, :deposit %th{:colspan => "2"} - - unless @order.closed? + - unless order.closed? .btn-group - = link_to t('.add_article'), new_order_order_article_path(@order), remote: true, + = link_to t('.add_article'), new_order_order_article_path(order), remote: true, class: 'btn btn-small' = link_to '#', data: {toggle: 'dropdown'}, class: 'btn btn-small dropdown-toggle' do %span.caret %ul.dropdown-menu - %li= link_to t('.add_article'), new_order_order_article_path(@order), remote: true - %li= link_to t('.edit_transport'), edit_transport_finance_order_path(@order), remote: true + %li= link_to t('.add_article'), new_order_order_article_path(order), remote: true + %li= link_to t('.edit_transport'), edit_transport_finance_order_path(order), remote: true %tbody.list#result_table - - for order_article in @articles.select { |oa| oa.units > 0 } + - for order_article in articles.select { |oa| oa.units > 0 } = render :partial => "order_article_result", :locals => {:order_article => order_article} %tr %td{ colspan: 10 } The following were not ordered - - for order_article in @articles.select { |oa| oa.units == 0 } + - for order_article in articles.select { |oa| oa.units == 0 } = render :partial => "order_article_result", :locals => {:order_article => order_article} - - if @order.transport + - if order.transport %tr %td{ colspan: 5 }= heading_helper Order, :transport - %td{ colspan: 3, data: {value: @order.transport} }= number_to_currency(@order.transport) - %td= link_to t('ui.edit'), edit_transport_finance_order_path(@order), remote: true, + %td{ colspan: 3, data: {value: order.transport} }= number_to_currency(order.transport) + %td= link_to t('ui.edit'), edit_transport_finance_order_path(order), remote: true, class: 'btn btn-mini' unless order_article.order.closed? diff --git a/app/views/finance/balancing/_results.html.haml b/app/views/finance/balancing/_results.html.haml deleted file mode 100644 index dacab7b3..00000000 --- a/app/views/finance/balancing/_results.html.haml +++ /dev/null @@ -1,3 +0,0 @@ -%section#results - = render 'edit_results_by_articles' - \ No newline at end of file diff --git a/app/views/finance/balancing/new.html.haml b/app/views/finance/balancing/new.html.haml index 0e238d2e..d1e91731 100644 --- a/app/views/finance/balancing/new.html.haml +++ b/app/views/finance/balancing/new.html.haml @@ -76,6 +76,7 @@ %li= link_to t('.articles_overview'), new_finance_order_path(order_id: @order.id, view: 'articles_overview'), remote: true -= render "results" +%section#results + = render partial: 'article_results', locals: { order: @order, articles: @articles, comments: @comments } %p= link_to_top diff --git a/plugins/automatic_invoices/app/documents/group_order_invoice_pdf.rb b/plugins/automatic_invoices/app/documents/group_order_invoice_pdf.rb index 902fd03e..daf8ff0b 100644 --- a/plugins/automatic_invoices/app/documents/group_order_invoice_pdf.rb +++ b/plugins/automatic_invoices/app/documents/group_order_invoice_pdf.rb @@ -93,6 +93,7 @@ class GroupOrderInvoicePdf < RenderPdf number_to_currency(goa.order_article.price.fc_price_without_deposit), number_to_currency(goa_total_price)] total_gross += goa_total_price + next unless separate_deposits && goa.order_article.price.deposit > 0.0 goa_total_deposit = goa.result * goa.order_article.price.fc_deposit_price @@ -151,13 +152,16 @@ class GroupOrderInvoicePdf < RenderPdf tax_hash_net = Hash.new(0) # for summing up article net prices grouped into vat percentage tax_hash_gross = Hash.new(0) # same here with gross prices - + tax_hash_fc = Hash.new(0) + tax_hash_deposit_total = Hash.new(0) # for summing up deposit prices grouped into vat percentage if separate_deposits total_deposit = 0 + total_deposit_fc = 0 total_deposit_gross = 0 - tax_hash_deposit_gross = Hash.new(0) # for summing up deposit gross prices grouped into vat percentage tax_hash_deposit_net = Hash.new(0) # same here with gross prices + tax_hash_deposit_gross = Hash.new(0) # for summing up deposit gross prices grouped into vat percentage + tax_hash_deposit_fc = Hash.new(0) end marge = FoodsoftConfig[:price_markup] @@ -176,15 +180,15 @@ class GroupOrderInvoicePdf < RenderPdf order_article = goa.order_article goa_total_net = goa.result * order_article.price.price - - goa_total_gross = separate_deposits ? goa.total_price_without_deposit : goa.total_price + goa_total_fc = separate_deposits ? goa.total_price_without_deposit : goa.total_price + goa_total = goa.total_price data << [order_article.article.name, goa.result.to_i, number_to_currency(order_article.price.price), number_to_currency(goa_total_net), tax.to_s + '%', - number_to_currency(goa_total_gross)] + number_to_currency(goa_total_fc)] if separate_deposits && order_article.price.deposit > 0.0 goa_deposit = goa.result * order_article.price.net_deposit_price @@ -198,17 +202,20 @@ class GroupOrderInvoicePdf < RenderPdf number_to_currency(goa_total_deposit)] total_deposit += goa_deposit - total_deposit_gross += goa_total_deposit + total_deposit_fc += goa_total_deposit + total_deposit_gross += goa.result * order_article.price.gross_price tax_hash_deposit_net[tax.to_i] += goa_deposit - tax_hash_deposit_gross[tax.to_i] += goa_total_deposit + tax_hash_deposit_gross[tax.to_i] += goa.result * order_article.price.deposit + tax_hash_deposit_total[tax.to_i] += goa_total_deposit end tax_hash_net[tax.to_i] += goa_total_net - tax_hash_gross[tax.to_i] += goa_total_gross + tax_hash_fc[tax.to_i] += goa_total + tax_hash_gross[tax.to_i] += goa.result * order_article.price.gross_price total_net += goa_total_net - total_gross += goa_total_gross + total_gross += goa_total_fc end end @@ -226,14 +233,42 @@ class GroupOrderInvoicePdf < RenderPdf table.columns(1..6).align = :right end - sum = [[nil, nil, nil, "Netto", "MwSt", "Brutto"]] - [7, 19].each do |key| - sum << [nil, nil, "Produkte mit #{key}%", number_to_currency(tax_hash_net[key]), number_to_currency(tax_hash_gross[key] - tax_hash_net[key]), number_to_currency(tax_hash_gross[key])] - sum << [nil, nil, "Pfand mit #{key}%", number_to_currency(tax_hash_deposit_net[key]), number_to_currency(tax_hash_deposit_gross[key] - tax_hash_deposit_net[key]), number_to_currency(tax_hash_deposit_gross[key])] if separate_deposits + sum = if marge > 0 + [[nil, nil, "Netto", "MwSt", "FC marge", "Brutto"]] + else + [[nil, nil, nil, "Netto", "MwSt", "Brutto"]] + end + + tax_hash_net.each_key do |key| + if tax_hash_gross[key] > 0 + tmp_sum_array = [nil, "Produkte mit #{key}%", number_to_currency(tax_hash_net[key]), number_to_currency(tax_hash_gross[key] - tax_hash_net[key])] + if marge > 0 + tmp_sum_array << number_to_currency(tax_hash_fc[key] - tax_hash_gross[key]) + else + tmp_sum_array.unshift(nil) + end + tmp_sum_array << number_to_currency(tax_hash_fc[key]) + sum << tmp_sum_array + end + + if separate_deposits && (tax_hash_deposit_total[key] > 0) + tmp_sum_array = [nil, "Pfand mit #{key}%", number_to_currency(tax_hash_deposit_net[key]), number_to_currency(tax_hash_deposit_gross[key] - tax_hash_deposit_net[key])] + if marge > 0 + tmp_sum_array << number_to_currency(tax_hash_deposit_total[key] - tax_hash_deposit_gross[key]) + else + tmp_sum_array.unshift(nil) + end + tmp_sum_array << number_to_currency(tax_hash_deposit_total[key]) + sum << tmp_sum_array + end end - total_deposit_gross ||= 0 - sum << [nil, nil, nil, nil, I18n.t('documents.group_order_invoice_pdf.sum_to_pay_gross'), number_to_currency(total_gross + total_deposit_gross)] + total_deposit_fc ||= 0 + tmp_total_sum = [nil, nil, nil, nil] + + tmp_total_sum << I18n.t('documents.group_order_invoice_pdf.sum_to_pay_gross') + tmp_total_sum << number_to_currency(total_gross + total_deposit_fc) + sum << tmp_total_sum move_down 10 table sum, cell_style: { size: fontsize(8), overflow: :shrink_to_fit } do |table| @@ -241,18 +276,20 @@ class GroupOrderInvoicePdf < RenderPdf table.position = :center table.cells.border_width = 1 table.cells.border_color = '666666' - table.row(0).columns(2..6).style(align: :bottom) + table.row(0).columns(2..7).style(align: :bottom) table.row(0).border_bottom_width = 2 - table.row(0..-1).columns(0..1).border_width = 0 + table.row(0..-1).column(0).border_width = 0 + + table.rows(0..-1).columns(0..7).width = 80 + - table.rows(0..-1).columns(0..6).width = 80 table.row(-1).column(-1).style(font_style: :bold) table.row(-1).column(-2).style(font_style: :bold) table.row(-1).column(-1).size = fontsize(10) table.row(-1).column(-2).size = fontsize(10) table.columns(1).align = :right - table.columns(1..6).align = :right + table.columns(1..7).align = :right end if FoodsoftConfig[:group_order_invoices][:vat_exempt] diff --git a/plugins/automatic_invoices/app/overrides/finance/balancing/_results/replace_contents_order_article.html.haml.deface b/plugins/automatic_invoices/app/overrides/finance/balancing/_results_section/replace_contents_order_article.html.haml.deface similarity index 68% rename from plugins/automatic_invoices/app/overrides/finance/balancing/_results/replace_contents_order_article.html.haml.deface rename to plugins/automatic_invoices/app/overrides/finance/balancing/_results_section/replace_contents_order_article.html.haml.deface index 72c89b63..720768af 100644 --- a/plugins/automatic_invoices/app/overrides/finance/balancing/_results/replace_contents_order_article.html.haml.deface +++ b/plugins/automatic_invoices/app/overrides/finance/balancing/_results_section/replace_contents_order_article.html.haml.deface @@ -1,3 +1,3 @@ -/ replace_contents "section#results" +/ replace 'erb:contains("edit_results_by_articles")' - if FoodsoftAutomaticInvoices.enabled? = render :partial => 'finance/balancing/edit_results_by_articles_override' \ No newline at end of file diff --git a/spec/integration/balancing_spec.rb b/spec/integration/balancing_spec.rb index d8e58e6d..0925f6ae 100644 --- a/spec/integration/balancing_spec.rb +++ b/spec/integration/balancing_spec.rb @@ -14,25 +14,32 @@ feature 'settling an order', js: true do let(:goa2) { create(:group_order_article, group_order: go2, order_article: oa) } before do + Rails.cache.clear + login admin goa1.update_quantities(3, 0) goa2.update_quantities(1, 0) oa.update_results! + oa.reload + order.reload order.finish!(admin) goa1.reload goa2.reload + visit new_finance_order_path(order_id: order.id) end - before { visit new_finance_order_path(order_id: order.id) } - before { login admin } + after do + Rails.cache.clear + end it 'has correct order result' do + oa.reload expect(oa.quantity).to eq(4) expect(oa.tolerance).to eq(0) expect(goa1.result).to eq(3) expect(goa2.result).to eq(1) end - it 'has product ordered visible' do + it 'has product ordered visible', js: true do expect(page).to have_content(article.name) expect(page).to have_selector("#order_article_#{oa.id}") end diff --git a/spec/models/order_spec.rb b/spec/models/order_spec.rb index 71c46a84..23d176a7 100644 --- a/spec/models/order_spec.rb +++ b/spec/models/order_spec.rb @@ -170,8 +170,10 @@ describe Order do oa.update_results! order.finish!(user) + goa.reload order.reload order.close!(user, ftt) + goa.reload end it 'creates financial transaction with correct amount' do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 3bbf03ea..1a456332 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -40,6 +40,13 @@ RSpec.configure do |config| FoodsoftConfig.init_mailing end + config.before(:each, type: :feature) do + Rails.cache.clear + end + config.after(:each, type: :feature) do + Rails.cache.clear + end + # If true, the base class of anonymous controllers will be inferred # automatically. This will be the default behavior in future versions of # rspec-rails.