From 2880fd5a87b18ef75272c2f71e2de852d9a8b54b Mon Sep 17 00:00:00 2001 From: Mohamed ABDELLANI Date: Mon, 23 Jan 2023 13:27:57 +0100 Subject: [PATCH 01/46] implement EnterpriseFeesWithTaxReportByProducer squash Re-format code squash Apply suggestions from code review Co-authored-by: Maikel squash More refactor squash Update lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb --- config/locales/en.yml | 13 +- ...rprise_fees_with_tax_report_by_producer.rb | 314 ++++++++++++++++++ lib/reporting/reports/list.rb | 6 +- 3 files changed, 326 insertions(+), 7 deletions(-) create mode 100644 lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb diff --git a/config/locales/en.yml b/config/locales/en.yml index 7652de335b..6a4be353cd 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1577,6 +1577,7 @@ en: name: "Enterprise Fee Summary" description: "Summary of Enterprise Fees collected" enterprise_fees_with_tax_report_by_order: "Enterprise Fees With Tax Report By Order" + enterprise_fees_with_tax_report_by_producer: "Enterprise Fees With Tax Report By Producer" errors: no_report_type: "Please specify a report type" report_not_found: "Report not found" @@ -1760,10 +1761,10 @@ en: orders: failed_to_update: "Failed to update order" query_param: - error: + error: title: Invalid query parameter - extra_fields: "Unsupported fields: %{fields}" - + extra_fields: "Unsupported fields: %{fields}" + # Frontend views # @@ -2137,8 +2138,8 @@ en: cancel: Back to Your details voucher: voucher: "%{voucher_amount} Voucher" - apply_voucher: Apply voucher - apply: Apply + apply_voucher: Apply voucher + apply: Apply placeholder: Enter voucher code remove_code: Remove code confirm_delete: Are you sure you want to remove the voucher? @@ -3036,7 +3037,7 @@ See the %{link} to find out more about %{sitename}'s features and to start using report_header_distributor_address: Distributor address report_header_distributor_city: Distributor city report_header_distributor_postcode: Distributor postcode - report_header_distributor_tax_status: Distributor Tax Status + report_header_distributor_tax_status: Distributor Tax Status report_header_delivery_address: Delivery Address report_header_delivery_postcode: Delivery Postcode report_header_bulk_unit_size: Bulk Unit Size diff --git a/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb b/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb new file mode 100644 index 0000000000..ad03abaa3b --- /dev/null +++ b/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb @@ -0,0 +1,314 @@ +# frozen_string_literal: true + +module Reporting + module Reports + module EnterpriseFeeSummary + class EnterpriseFeesWithTaxReportByProducer < ReportTemplate + attr_accessor :permissions, :parameters + + def initialize(user, params = {}, render: false) + super(user, params, render: render) + @parameters = Parameters.new(p || {}) + @parameters.validate! + @permissions = Permissions.new(user) + @parameters.authorize!(@permissions) + end + + def search + report_line_items.orders + end + + def order_permissions + @order_permissions ||= ::Permissions::Order.new(user, ransack_params) + end + + def report_line_items + @report_line_items ||= Reporting::LineItems.new(order_permissions, params) + end + + def query_result + # The objective is to group the orders by + # [entreprise_rate, tax_rate, supplier_id, distributor_id and order_cycle_id] + + # The order.all_adjustment describes + # - the enterprise fees applied on the order + # - the enterprise fees applied on the line items + # - all the taxes including, the taxes applied on the enterprise fees + # The access to enterprise fee tax rates is done in two steps + # 1.we'll need to store two attributes for each order.all_adjustemnt.enterprise_fee + # a. originator_id will refer to the enterprise fee instance + # b. id of the adjustment + # 2. order.all_adjustemnt.tax.where(adjustment_id: id,"Spree::Adjustment") + # - this will return the tax applied on the enterprise fees + orders = search.result.to_a + orders.flat_map(&join_enterprise_fee) + .flat_map(&join_tax_rate) + .flat_map(&join_supplier) + .group_by(&group_keys) + .each(&change_root_to_order) + end + + def join_enterprise_fee + proc do |order| + order + .all_adjustments + .enterprise_fee + .group('originator_id') + .pluck("originator_id", 'array_agg(id)') + .map do |enterprise_fee_id, enterprise_fee_adjustment_ids| + { + enterprise_fee_id: enterprise_fee_id, + enterprise_fee_adjustment_ids: enterprise_fee_adjustment_ids, + order: order + } + end + end + end + + def join_tax_rate + proc do |item| + tax_rate_ids = item[:order].all_adjustments.tax.where( + adjustable_id: item[:enterprise_fee_adjustment_ids], + adjustable_type: "Spree::Adjustment" + ).pluck(:originator_id) + + tax_rate_ids << nil if tax_rate_ids.empty? + tax_rate_ids.map do |tax_rate_id| + { + tax_rate_id: tax_rate_id, + enterprise_fee_id: item[:enterprise_fee_id], + order: item[:order], + } + end + end + end + + def join_supplier + proc do |item| + order = item[:order] + order + .line_items + .map(&:supplier_id) + .map do |supplier_id| + { + tax_rate_id: item[:tax_rate_id], + enterprise_fee_id: item[:enterprise_fee_id], + supplier_id: supplier_id, + order: order + } + end + end + end + + def group_keys + proc do |hash| + [ + hash[:tax_rate_id], + hash[:enterprise_fee_id], + hash[:supplier_id], + hash[:order].distributor_id, + hash[:order].order_cycle_id + ] + end + end + + def change_root_to_order + proc do |_, v| + v.map!{ |item| item[:order] } + end + end + + def columns + { + distributor: :distributor, + producer: :producer, + producer_tax_status: :producer_tax_status, + order_cycle: :order_cycle, + enterprise_fee_name: :enterprise_fee_name, + enterprise_fee_type: :enterprise_fee_type, + enterprise_fee_owner: :enterprise_fee_owner, + tax_category: :tax_category, + tax_rate_name: :tax_rate_name, + tax_rate: :tax_rate_amount, + total_excl_tax: :total_excl_tax, + tax: :tax, + total_incl_tax: :total_incl_tax + } + end + + def rules + [ + { group_by: :distributor }, + { group_by: :producer }, + { group_by: :order_cycle, summary_row: order_cycle_totals_row } + ] + end + + def order_cycle_totals_row + proc do |_key, items, _rows| + order_ids = items.flat_map(&:second).map(&:id).uniq + + total_excl_tax = total_fees_excl_tax(order_ids) + tax = tax_for_order_ids(order_ids) + { + total_excl_tax: total_excl_tax, + tax: tax, + total_incl_tax: total_excl_tax + tax + } + end + end + + def total_fees_excl_tax(order_ids) + enterprise_fees_amount_for_orders(order_ids) - included_tax_for_order_ids(order_ids) + end + + def included_tax_for_order_ids(order_ids) + Spree::Adjustment.tax + .where(order: order_ids) + .where(included: true) + .where(adjustable_type: 'Spree::Adjustment') + .where(adjustable_id: enterprise_fee_adjustment_ids_for_orders(order_ids)) + .pluck("sum(amount)") + .first || 0 + end + + def tax_for_order_ids(order_ids) + Spree::Adjustment.tax + .where(order: order_ids) + .where(adjustable_type: 'Spree::Adjustment') + .where(adjustable_id: enterprise_fee_adjustment_ids_for_orders(order_ids)) + .pluck("sum(amount)") + .first || 0 + end + + def enterprise_fee_adjustment_ids_for_orders(order_ids) + enterprise_fees_for_orders(order_ids).pluck(:id) + end + + def enterprise_fees_amount_for_orders(order_ids) + enterprise_fees_for_orders(order_ids).pluck("sum(amount)").first || 0 + end + + def enterprise_fees_for_orders(order_ids) + Spree::Adjustment.enterprise_fee + .where(order_id: order_ids) + end + + def distributor(query_result_row) + first_order(query_result_row).distributor&.name + end + + def producer(query_result_row) + Enterprise.where(id: supplier_id(query_result_row)).pick(:name) + end + + def producer_tax_status(query_result_row) + Enterprise.where(id: supplier_id(query_result_row)).pluck(:charges_sales_tax).first + end + + def order_cycle(query_result_row) + first_order(query_result_row).order_cycle&.name + end + + def enterprise_fee_name(query_result_row) + enterprise_fee(query_result_row).name + end + + def enterprise_fee_type(query_result_row) + enterprise_fee(query_result_row).fee_type + end + + def enterprise_fee_owner(query_result_row) + enterprise_fee(query_result_row).enterprise.name + end + + def tax_category(query_result_row) + tax_rate(query_result_row)&.tax_category&.name + end + + def tax_rate_name(query_result_row) + tax_rate(query_result_row)&.name + end + + def tax_rate_amount(query_result_row) + tax_rate(query_result_row)&.amount + end + + def total_excl_tax(query_result_row) + order_ids = orders(query_result_row).map(&:id) + enterprise_fee_id = enterprise_fee_id(query_result_row) + amount = Spree::Adjustment.enterprise_fee + .where(order_id: order_ids) + .where(originator_id: enterprise_fee_id) + .pluck("sum(amount)") + .first + amount - tax(query_result_row, all: true, included: true) + end + + def tax(query_result_row, all: false, included: nil) + order_ids = orders(query_result_row).map(&:id) + adjustment_ids = enterprise_fee_adjustemnt_ids(query_result_row) + query = Spree::Adjustment.tax + query = query.where(included: true) unless included.nil? + query = query.where(originator_id: tax_rate_id(query_result_row)) unless all == true + query = query.where(order_id: order_ids) + .where(adjustable_type: 'Spree::Adjustment') + .where(adjustable_id: adjustment_ids) + .pluck("sum(amount)") + + query.first || 0 + end + + def total_incl_tax(query_result_row) + total_excl_tax(query_result_row) + tax(query_result_row, all: false) + end + + def enterprise_fee_adjustemnt_ids(query_result_row) + order_ids = orders(query_result_row).map(&:id) + enterprise_fee_id = enterprise_fee_id(query_result_row) + Spree::Adjustment.enterprise_fee + .where(order_id: order_ids) + .where(originator_id: enterprise_fee_id) + .pluck(:id) + end + + def enterprise_fee(query_result_row) + first_order(query_result_row).all_adjustments + .enterprise_fee + .find_by(originator_id: enterprise_fee_id(query_result_row)) + .originator + end + + def tax_rate(query_result_row) + return nil if tax_rate_id(query_result_row).nil? + + Spree::TaxRate.find(tax_rate_id(query_result_row)) + end + + def first_order(query_result_row) + orders(query_result_row).first + end + + def tax_rate_id(query_result_row) + keys(query_result_row)[0] + end + + def supplier_id(query_result_row) + keys(query_result_row)[2] + end + + def enterprise_fee_id(query_result_row) + keys(query_result_row)[1] + end + + def keys(query_result_row) + query_result_row.first + end + + def orders(query_result_row) + query_result_row.second + end + end + end + end +end diff --git a/lib/reporting/reports/list.rb b/lib/reporting/reports/list.rb index 84e3a1ed41..3a9c1e6d2f 100644 --- a/lib/reporting/reports/list.rb +++ b/lib/reporting/reports/list.rb @@ -66,7 +66,11 @@ module Reporting [ i18n_translate('enterprise_fees_with_tax_report_by_order'), :enterprise_fees_with_tax_report_by_order - ] + ], + [ + i18n_translate('enterprise_fees_with_tax_report_by_producer'), + :enterprise_fees_with_tax_report_by_producer + ], ] end From 481b09edda87544a09dc0a07aca6380e18a92841 Mon Sep 17 00:00:00 2001 From: Mohamed ABDELLANI Date: Wed, 25 Jan 2023 14:06:30 +0100 Subject: [PATCH 02/46] test enterprise summary fee with tax report by producer Reformat/Refactor spec --- ...ry_fee_with_tax_report_by_producer_spec.rb | 216 ++++++++++++++++++ 1 file changed, 216 insertions(+) create mode 100644 spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb diff --git a/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb b/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb new file mode 100644 index 0000000000..2b8d518c5c --- /dev/null +++ b/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb @@ -0,0 +1,216 @@ +# frozen_string_literal: true + +require 'system_helper' + +describe "Enterprise Summary Fee with Tax Report By Producer" do + # 1 order cycle the has: + # - coordinator fees price 20 + # - incoming exchange fees 15 + # - outgoing exchange fees 10 + # tax + # country: 2.5% + # state: 1.5% + + let!(:table_header){ + ["Distributor", "Producer", "Producer Tax Status", "Order Cycle", "Name", "Type", "Owner", + "Tax Category", "Tax Rate Name", "Tax Rate", "Total excl. tax ($)", "Tax", + "Total incl. tax ($)"].join(" ").upcase + } + + let!(:state_zone){ create(:zone_with_state_member) } + let!(:country_zone){ create(:zone_with_member) } + let!(:tax_category){ create(:tax_category, name: 'tax_category') } + let!(:state_tax_rate){ + create(:tax_rate, zone: state_zone, tax_category: tax_category, + name: 'State', amount: 0.015) + } + let!(:country_tax_rate){ + create(:tax_rate, zone: country_zone, tax_category: tax_category, + name: 'Country', amount: 0.025) + } + let!(:ship_address){ create(:ship_address) } + + let!(:variant){ create(:variant) } + let!(:product){ variant.product } + let!(:distributor){ create(:distributor_enterprise_with_tax, name: 'Distributor') } + let!(:supplier){ create(:supplier_enterprise, name: 'Supplier', charges_sales_tax: true) } + let!(:payment_method){ create(:payment_method, :flat_rate) } + let!(:shipping_method){ create(:shipping_method, :flat_rate) } + + let!(:order){ create(:order_with_distributor, distributor: distributor) } + let!(:order_cycle){ + create(:simple_order_cycle, suppliers: [supplier], distributors: [distributor], + variants: [variant], name: "oc1") + } + + let(:admin){ create(:admin_user) } + + let!(:coordinator_fees){ + create(:enterprise_fee, :flat_rate, enterprise: distributor, amount: 20, + name: 'Adminstration', + fee_type: 'admin', + tax_category: tax_category) + } + let!(:supplier_fees){ + create(:enterprise_fee, :flat_rate, enterprise: supplier, amount: 15, + name: 'Transport', + fee_type: 'transport', + tax_category: tax_category) + } + let!(:distributor_fee){ + create(:enterprise_fee, :flat_rate, enterprise: distributor, amount: 10, + name: 'Packing', + fee_type: 'packing', + tax_category: tax_category) + } + + before do + order_cycle.coordinator_fees << coordinator_fees + order_cycle.exchanges.incoming.first.exchange_fees.create!(enterprise_fee: supplier_fees) + order_cycle.exchanges.outgoing.first.exchange_fees.create!(enterprise_fee: distributor_fee) + + distributor.shipping_methods << shipping_method + distributor.payment_methods << payment_method + + product.update!({ + tax_category_id: tax_category.id, + supplier_id: supplier.id + }) + end + + context 'added tax' do + before do + order.line_items.create({ variant: variant, quantity: 1, price: 100 }) + order.update!({ + order_cycle_id: order_cycle.id, + ship_address_id: ship_address.id + }) + # This will load the enterprise fees from the order cycle. + # This is needed because the order instance was created + # independently of the order_cycle. + order.recreate_all_fees! + while !order.completed? + break unless order.next! + end + end + + let(:coordinator_state_tax){ + ["Distributor", "Supplier", "Yes", "oc1", "Adminstration", "admin", "Distributor", + "tax_category", "State", "0.015", "20.0", "0.3", "20.3"].join(" ") + } + let(:coordinator_country_tax){ + ["Distributor", "Supplier", "Yes", "oc1", "Adminstration", "admin", "Distributor", + "tax_category", "Country", "0.025", "20.0", "0.5", "20.5"].join(" ") + } + + let(:supplier_state_tax){ + ["Distributor", "Supplier", "Yes", "oc1", "Transport", "transport", "Supplier", + "tax_category", "State", "0.015", "15.0", "0.23", "15.23"].join(" ") + } + let(:supplier_country_tax){ + ["Distributor", "Supplier", "Yes", "oc1", "Transport", "transport", "Supplier", + "tax_category", "Country", "0.025", "15.0", "0.38", "15.38"].join(" ") + } + + let(:distributor_state_tax){ + ["Distributor", "Supplier", "Yes", "oc1", "Packing", "packing", "Distributor", + "tax_category", "State", "0.015", "10.0", "0.15", "10.15"].join(" ") + } + let(:distributor_country_tax){ + ["Distributor", "Supplier", "Yes", "oc1", "Packing", "packing", "Distributor", + "tax_category", "Country", "0.025", "10.0", "0.25", "10.25"].join(" ") + } + + let(:summary_row){ + ["TOTAL", "45.0", "1.81", "46.81"].join(" ") + } + + it 'generates the report' do + login_as admin + visit admin_reports_path + click_on I18n.t("admin.reports.enterprise_fees_with_tax_report_by_producer") + + expect(page).to have_button("Go") + click_on "Go" + + expect(page.find("table.report__table thead tr")).to have_content(table_header) + + table = page.find("table.report__table tbody") + expect(table).to have_content(supplier_state_tax) + expect(table).to have_content(supplier_country_tax) + expect(table).to have_content(distributor_state_tax) + expect(table).to have_content(distributor_country_tax) + expect(table).to have_content(coordinator_state_tax) + expect(table).to have_content(coordinator_country_tax) + expect(table).to have_content(summary_row) + end + end + + context 'included tax' do + before do + state_tax_rate.update!({ included_in_price: true }) + country_tax_rate.update!({ included_in_price: true }) + + order.line_items.create({ variant: variant, quantity: 1, price: 100 }) + order.update!({ + order_cycle_id: order_cycle.id, + ship_address_id: ship_address.id + }) + order.recreate_all_fees! + while !order.completed? + break unless order.next! + end + end + + let(:coordinator_state_tax){ + ["Distributor", "Supplier", "Yes", "oc1", "Adminstration", "admin", "Distributor", + "tax_category", "State", "0.015", "19.21", "0.3", "19.51"].join(" ") + } + let(:coordinator_country_tax){ + ["Distributor", "Supplier", "Yes", "oc1", "Adminstration", "admin", "Distributor", + "tax_category", "Country", "0.025", "19.21", "0.49", "19.7"].join(" ") + } + + let(:supplier_state_tax){ + ["Distributor", "Supplier", "Yes", "oc1", "Transport", "transport", "Supplier", + "tax_category", "State", "0.015", "14.41", "0.22", "14.63"].join(" ") + } + let(:supplier_country_tax){ + ["Distributor", "Supplier", "Yes", "oc1", "Transport", "transport", "Supplier", + "tax_category", "Country", "0.025", "14.41", "0.37", "14.78"].join(" ") + } + + let(:distributor_state_tax){ + ["Distributor", "Supplier", "Yes", "oc1", "Packing", "packing", "Distributor", + "tax_category", "State", "0.015", "9.61", "0.15", "9.76"].join(" ") + } + let(:distributor_country_tax){ + ["Distributor", "Supplier", "Yes", "oc1", "Packing", "packing", "Distributor", + "tax_category", "Country", "0.025", "9.61", "0.24", "9.85"].join(" ") + } + + let(:summary_row){ + ["TOTAL", "43.23", "1.77", "45.0"].join(" ") + } + + it 'generates the report' do + login_as admin + visit admin_reports_path + click_on I18n.t("admin.reports.enterprise_fees_with_tax_report_by_producer") + + expect(page).to have_button("Go") + click_on "Go" + + expect(page.find("table.report__table thead tr")).to have_content(table_header) + + table = page.find("table.report__table tbody") + expect(table).to have_content(supplier_state_tax) + expect(table).to have_content(supplier_country_tax) + expect(table).to have_content(distributor_state_tax) + expect(table).to have_content(distributor_country_tax) + expect(table).to have_content(coordinator_state_tax) + expect(table).to have_content(coordinator_country_tax) + expect(table).to have_content(summary_row) + end + end +end From ee7668e713e3e22fd5186213671c67764be2ab77 Mon Sep 17 00:00:00 2001 From: Mohamed ABDELLANI Date: Thu, 2 Feb 2023 10:16:02 +0100 Subject: [PATCH 03/46] implement enterprise fee report filters squash Reformat/Refactor spec --- ...fees_with_tax_report_by_producer.html.haml | 27 ++++++++ ...rprise_fees_with_tax_report_by_producer.rb | 62 ++++++++++++++++--- ...ry_fee_with_tax_report_by_producer_spec.rb | 59 ++++++++++++++++++ 3 files changed, 139 insertions(+), 9 deletions(-) create mode 100644 app/views/admin/reports/filters/_enterprise_fees_with_tax_report_by_producer.html.haml diff --git a/app/views/admin/reports/filters/_enterprise_fees_with_tax_report_by_producer.html.haml b/app/views/admin/reports/filters/_enterprise_fees_with_tax_report_by_producer.html.haml new file mode 100644 index 0000000000..1c19788df6 --- /dev/null +++ b/app/views/admin/reports/filters/_enterprise_fees_with_tax_report_by_producer.html.haml @@ -0,0 +1,27 @@ +.row + .alpha.two.columns= label_tag nil, t(:report_hubs) + .omega.fourteen.columns= f.collection_select(:distributor_id_in, @data.distributors, :id, :name, {}, {class: "select2 fullwidth", multiple: true}) + +.row + .alpha.two.columns= label_tag nil, t(:report_producers) + .omega.fourteen.columns= select_tag(:supplier_id_in, options_from_collection_for_select(@data.orders_suppliers, :id, :name, params[:supplier_id_in]), {class: "select2 fullwidth", multiple: true}) + +.row + .alpha.two.columns= label_tag nil, t(:report_customers_cycle) + .omega.fourteen.columns + = f.select(:order_cycle_id_in, report_order_cycle_options(@data.order_cycles), {selected: params.dig(:q, :order_cycle_id_in)}, {class: "select2 fullwidth", multiple: true}) + +.row + .alpha.two.columns= label_tag nil, t(:fee_name) + .omega.fourteen.columns + = f.select(:enterprise_fee_id_in, fee_name_options(@report.search.result), {selected: params.dig(:q, :enterprise_fee_id_in)}, {class: "select2 fullwidth", multiple: true}) + +.row + .alpha.two.columns= label_tag nil, t(:fee_owner) + .omega.fourteen.columns + = f.select(:enterprise_fee_owner_id_in, fee_owner_options(@report.search.result), {selected: params.dig(:q, :enterprise_fee_owner_id_in)}, {class: "select2 fullwidth", multiple: true}) + +.row + .alpha.two.columns= label_tag nil, t(:report_customers) + .omega.fourteen.columns + = f.select(:customer_id_in, customer_email_options(@data.order_customers), {selected: params.dig(:q, :customer_id_in)}, {class: "select2 fullwidth", multiple: true}) diff --git a/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb b/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb index ad03abaa3b..a335572d20 100644 --- a/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb +++ b/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb @@ -1,17 +1,15 @@ # frozen_string_literal: true +# rubocop:disable Metrics/ClassLength module Reporting module Reports module EnterpriseFeeSummary class EnterpriseFeesWithTaxReportByProducer < ReportTemplate - attr_accessor :permissions, :parameters + attr_accessor :permissions def initialize(user, params = {}, render: false) super(user, params, render: render) - @parameters = Parameters.new(p || {}) - @parameters.validate! @permissions = Permissions.new(user) - @parameters.authorize!(@permissions) end def search @@ -26,9 +24,44 @@ module Reporting @report_line_items ||= Reporting::LineItems.new(order_permissions, params) end + def supplier_ids_filter(supplier_id) + return true if params[:supplier_id_in].blank? + + params[:supplier_id_in].include?(supplier_id) + end + + def enterprise_fee_filtered_ids + return @enterprise_fee_filtered_ids unless @enterprise_fee_filtered_ids.nil? + + @enterprise_fee_filtered_ids = EnterpriseFee.where(nil) + unless enterprise_fee_ids_filter.empty? + @enterprise_fee_filtered_ids = @enterprise_fee_filtered_ids.where( + id: enterprise_fee_ids_filter + ) + end + unless enterprise_fee_owner_ids_filter.empty? + @enterprise_fee_filtered_ids = @enterprise_fee_filtered_ids.where( + enterprise_id: enterprise_fee_owner_ids_filter + ) + end + @enterprise_fee_filtered_ids = @enterprise_fee_filtered_ids.pluck(:id) + end + + def enterprise_fee_filters? + enterprise_fee_ids_filter + enterprise_fee_owner_ids_filter != [] + end + + def enterprise_fee_ids_filter + ransack_params["enterprise_fee_id_in"]&.filter(&:present?) || [] + end + + def enterprise_fee_owner_ids_filter + ransack_params["enterprise_fee_owner_id_in"]&.filter(&:present?) || [] + end + def query_result # The objective is to group the orders by - # [entreprise_rate, tax_rate, supplier_id, distributor_id and order_cycle_id] + # [entreprise_fee, tax_rate, supplier_id, distributor_id and order_cycle_id] # The order.all_adjustment describes # - the enterprise fees applied on the order @@ -40,7 +73,7 @@ module Reporting # b. id of the adjustment # 2. order.all_adjustemnt.tax.where(adjustment_id: id,"Spree::Adjustment") # - this will return the tax applied on the enterprise fees - orders = search.result.to_a + orders = report_line_items.list.map(&:order).uniq orders.flat_map(&join_enterprise_fee) .flat_map(&join_tax_rate) .flat_map(&join_supplier) @@ -50,10 +83,14 @@ module Reporting def join_enterprise_fee proc do |order| - order + query = order .all_adjustments .enterprise_fee - .group('originator_id') + + if enterprise_fee_filters? + query = query.where(originator_id: enterprise_fee_filtered_ids) + end + query.group('originator_id') .pluck("originator_id", 'array_agg(id)') .map do |enterprise_fee_id, enterprise_fee_adjustment_ids| { @@ -89,6 +126,7 @@ module Reporting order .line_items .map(&:supplier_id) + .filter(&method(:supplier_ids_filter)) .map do |supplier_id| { tax_rate_id: item[:tax_rate_id], @@ -190,8 +228,13 @@ module Reporting end def enterprise_fees_for_orders(order_ids) - Spree::Adjustment.enterprise_fee + enterprise_fees = Spree::Adjustment.enterprise_fee .where(order_id: order_ids) + return enterprise_fees unless enterprise_fee_filters? + + enterprise_fees.where( + originator_id: enterprise_fee_filtered_ids + ) end def distributor(query_result_row) @@ -312,3 +355,4 @@ module Reporting end end end +# rubocop:enable Metrics/ClassLength diff --git a/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb b/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb index 2b8d518c5c..497acbae8a 100644 --- a/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb +++ b/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb @@ -144,6 +144,65 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do expect(table).to have_content(coordinator_country_tax) expect(table).to have_content(summary_row) end + + context "filtering" do + let(:fee_name_selector){ "#s2id_q_enterprise_fee_id_in" } + let(:fee_owner_selector){ "#s2id_q_enterprise_fee_owner_id_in" } + + let(:summary_row_after_filtering_by_fee_name){ + ["TOTAL", "20.0", "0.8", "20.8"].join(" ") + } + + let(:summary_row_after_filtering_by_fee_owner){ + ["TOTAL", "15.0", "0.61", "15.61"].join(" ") + } + + it "should filter by fee name" do + login_as admin + visit admin_reports_path + click_on I18n.t("admin.reports.enterprise_fees_with_tax_report_by_producer") + + page.find(fee_name_selector).click + find('li', text: coordinator_fees.name).click + + expect(page).to have_button("Go") + click_on "Go" + + expect(page.find("table.report__table thead tr")).to have_content(table_header) + + table = page.find("table.report__table tbody") + expect(table).to_not have_content(supplier_state_tax) + expect(table).to_not have_content(supplier_country_tax) + expect(table).to_not have_content(distributor_state_tax) + expect(table).to_not have_content(distributor_country_tax) + expect(table).to have_content(coordinator_state_tax) + expect(table).to have_content(coordinator_country_tax) + expect(table).to have_content(summary_row_after_filtering_by_fee_name) + end + + it "should filter by fee owner" do + login_as admin + visit admin_reports_path + click_on I18n.t("admin.reports.enterprise_fees_with_tax_report_by_producer") + + page.find(fee_owner_selector).click + find('li', text: supplier.name).click + + expect(page).to have_button("Go") + click_on "Go" + + expect(page.find("table.report__table thead tr")).to have_content(table_header) + + table = page.find("table.report__table tbody") + expect(table).to have_content(supplier_state_tax) + expect(table).to have_content(supplier_country_tax) + expect(table).to_not have_content(distributor_state_tax) + expect(table).to_not have_content(distributor_country_tax) + expect(table).to_not have_content(coordinator_state_tax) + expect(table).to_not have_content(coordinator_country_tax) + expect(table).to have_content(summary_row_after_filtering_by_fee_owner) + end + end end context 'included tax' do From cc54e2e6c7e9d4ef5cb8239084a96ee4e9972e19 Mon Sep 17 00:00:00 2001 From: David Cook Date: Thu, 9 Feb 2023 10:42:00 +1100 Subject: [PATCH 04/46] Add long report class to .rubocop_todo.yml Long classes are a problem that would be good to resolve one day. But it's hard to resolve with the current reports framework. --- .rubocop_todo.yml | 1 + .../enterprise_fees_with_tax_report_by_producer.rb | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 326b9fe003..1b76712f4b 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -234,6 +234,7 @@ Metrics/ClassLength: - 'lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_order.rb' - 'lib/reporting/reports/enterprise_fee_summary/scope.rb' - 'lib/reporting/reports/xero_invoices/base.rb' + - 'lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb' # Offense count: 34 # Configuration parameters: AllowedMethods, AllowedPatterns, Max. diff --git a/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb b/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb index a335572d20..cbe3a8ba3e 100644 --- a/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb +++ b/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb @@ -1,6 +1,5 @@ # frozen_string_literal: true -# rubocop:disable Metrics/ClassLength module Reporting module Reports module EnterpriseFeeSummary @@ -355,4 +354,3 @@ module Reporting end end end -# rubocop:enable Metrics/ClassLength From 55742f40d1b512f1166795cd13d23af440f27b3b Mon Sep 17 00:00:00 2001 From: David Cook Date: Tue, 28 Mar 2023 17:13:55 +1100 Subject: [PATCH 05/46] Show a line for cost of produce Utilising a second group_by rule, we can add a second summary_row. The cost of produce is also inserted into the TOTALS row as per requirements. --- config/locales/en.yml | 2 + ...rprise_fees_with_tax_report_by_producer.rb | 55 ++++++++++++++++++- ...ry_fee_with_tax_report_by_producer_spec.rb | 42 ++++++++++++-- 3 files changed, 90 insertions(+), 9 deletions(-) diff --git a/config/locales/en.yml b/config/locales/en.yml index 6a4be353cd..245f23ea60 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -3096,6 +3096,8 @@ See the %{link} to find out more about %{sitename}'s features and to start using report_header_transaction_fee: Transaction Fee (no tax) report_header_total_untaxable_admin: Total untaxable admin adjustments (no tax) report_header_total_taxable_admin: Total taxable admin adjustments (tax inclusive) + report_line_cost_of_produce: Cost of produce + report_line_line_items: line items report_xero_configuration: Xero Configuration initial_invoice_number: "Initial invoice number" invoice_date: "Invoice date" diff --git a/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb b/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb index cbe3a8ba3e..dc073d4ef3 100644 --- a/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb +++ b/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb @@ -177,16 +177,28 @@ module Reporting [ { group_by: :distributor }, { group_by: :producer }, - { group_by: :order_cycle, summary_row: order_cycle_totals_row } + { + # TOTAL (appear second) + group_by: :order_cycle, + summary_row: order_cycle_totals_row, + }, + { + # Cost of produce (appear first) + group_by: :order_cycle, + summary_row_class: nil, + summary_row_label: nil, + summary_row: order_cycle_line_items_row, + }, ] end def order_cycle_totals_row proc do |_key, items, _rows| order_ids = items.flat_map(&:second).map(&:id).uniq + line_items = items.flat_map(&:second).uniq.map(&:line_items).flatten - total_excl_tax = total_fees_excl_tax(order_ids) - tax = tax_for_order_ids(order_ids) + total_excl_tax = total_fees_excl_tax(order_ids) + line_items_excl_tax(line_items) + tax = tax_for_order_ids(order_ids) + tax_for_line_items(line_items) { total_excl_tax: total_excl_tax, tax: tax, @@ -195,10 +207,47 @@ module Reporting end end + def order_cycle_line_items_row + proc do |key, items, _rows| + line_items = items.flat_map(&:last).uniq.map(&:line_items).flatten + producer = producer(items.first) + + total_excl_tax = line_items_excl_tax(line_items) + tax = tax_for_line_items(line_items) + { + distributor: distributor(items.first), + producer: producer, + producer_tax_status: producer_tax_status(items.first), + order_cycle: key, + enterprise_fee_name: I18n.t('report_line_cost_of_produce'), + enterprise_fee_type: I18n.t('report_line_line_items'), + enterprise_fee_owner: producer, + total_excl_tax: total_excl_tax, + tax: tax, + total_incl_tax: total_excl_tax + tax, + } + end + end + def total_fees_excl_tax(order_ids) enterprise_fees_amount_for_orders(order_ids) - included_tax_for_order_ids(order_ids) end + def line_items_excl_tax(line_items) + cost_of_line_items(line_items) - line_items.sum(&:included_tax) + end + + def cost_of_line_items(line_items) + line_items.sum(&:amount) + end + + # This query gets called twice for each set of line_items, ideally it would be cached. + def tax_for_line_items(line_items) + line_items.map do |line_item| + line_item.adjustments.eligible.tax.sum('amount') + end.sum + end + def included_tax_for_order_ids(order_ids) Spree::Adjustment.tax .where(order: order_ids) diff --git a/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb b/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb index 497acbae8a..ac0f7d8d49 100644 --- a/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb +++ b/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb @@ -3,10 +3,11 @@ require 'system_helper' describe "Enterprise Summary Fee with Tax Report By Producer" do - # 1 order cycle the has: + # 1 order cycle has: # - coordinator fees price 20 # - incoming exchange fees 15 # - outgoing exchange fees 10 + # - cost of line items 100 # tax # country: 2.5% # state: 1.5% @@ -30,7 +31,7 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do } let!(:ship_address){ create(:ship_address) } - let!(:variant){ create(:variant) } + let!(:variant){ create(:variant, tax_category: tax_category) } let!(:product){ variant.product } let!(:distributor){ create(:distributor_enterprise_with_tax, name: 'Distributor') } let!(:supplier){ create(:supplier_enterprise, name: 'Supplier', charges_sales_tax: true) } @@ -79,6 +80,12 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do end context 'added tax' do + # 1 order cycle has: + # - coordinator fees (20) 1.5% = 0.30, 2.5% = 0.50 + # - incoming exchange (15) 1.5% = 0.23, 2.5% = 0.38 + # - outgoing exchange (10) 1.5% = 0.15, 2.5% = 0.25 + # - line items (100) 1.5% = 1.50, 2.5% = 2.50 + before do order.line_items.create({ variant: variant, quantity: 1, price: 100 }) order.update!({ @@ -121,8 +128,17 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do "tax_category", "Country", "0.025", "10.0", "0.25", "10.25"].join(" ") } + let(:cost_of_produce){ + ["Distributor", "Supplier", "Yes", "oc1", "Cost of produce", "line items", "Supplier", + "100.0", "4.0", "104.0"].join(" ") + } let(:summary_row){ - ["TOTAL", "45.0", "1.81", "46.81"].join(" ") + [ + "TOTAL", # Fees and line items + "145.0", # Tax excl: 20 + 15 + 10 + 100 + "5.81", # Tax : (0.30 + 0.50) + (0.23 + 0.38) + (0.15 + 0.25) + (1.50 + 2.50) + "150.81" # Tax incl: 145.00 + 5.81 + ].join(" ") } it 'generates the report' do @@ -142,6 +158,7 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do expect(table).to have_content(distributor_country_tax) expect(table).to have_content(coordinator_state_tax) expect(table).to have_content(coordinator_country_tax) + expect(table).to have_content(cost_of_produce) expect(table).to have_content(summary_row) end @@ -150,11 +167,11 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do let(:fee_owner_selector){ "#s2id_q_enterprise_fee_owner_id_in" } let(:summary_row_after_filtering_by_fee_name){ - ["TOTAL", "20.0", "0.8", "20.8"].join(" ") + ["TOTAL", "120.0", "4.8", "124.8"].join(" ") } let(:summary_row_after_filtering_by_fee_owner){ - ["TOTAL", "15.0", "0.61", "15.61"].join(" ") + ["TOTAL", "115.0", "4.61", "119.61"].join(" ") } it "should filter by fee name" do @@ -177,6 +194,7 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do expect(table).to_not have_content(distributor_country_tax) expect(table).to have_content(coordinator_state_tax) expect(table).to have_content(coordinator_country_tax) + expect(table).to have_content(cost_of_produce) expect(table).to have_content(summary_row_after_filtering_by_fee_name) end @@ -200,12 +218,19 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do expect(table).to_not have_content(distributor_country_tax) expect(table).to_not have_content(coordinator_state_tax) expect(table).to_not have_content(coordinator_country_tax) + expect(table).to have_content(cost_of_produce) expect(table).to have_content(summary_row_after_filtering_by_fee_owner) end end end context 'included tax' do + # 1 order cycle has: + # - coordinator fees (20) 1.5% = 0.30, 2.5% = 0.50 + # - incoming exchange (15) 1.5% = 0.23, 2.5% = 0.38 + # - outgoing exchange (10) 1.5% = 0.15, 2.5% = 0.25 + # - line items (100) 1.5% = 1.50, 2.5% = 2.50 + before do state_tax_rate.update!({ included_in_price: true }) country_tax_rate.update!({ included_in_price: true }) @@ -248,8 +273,12 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do "tax_category", "Country", "0.025", "9.61", "0.24", "9.85"].join(" ") } + let(:cost_of_produce){ + ["Distributor", "Supplier", "Yes", "oc1", "Cost of produce", "line items", "Supplier", + "96.08", "3.92", "100.0"].join(" ") + } let(:summary_row){ - ["TOTAL", "43.23", "1.77", "45.0"].join(" ") + ["TOTAL", "139.31", "5.69", "145.0"].join(" ") } it 'generates the report' do @@ -269,6 +298,7 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do expect(table).to have_content(distributor_country_tax) expect(table).to have_content(coordinator_state_tax) expect(table).to have_content(coordinator_country_tax) + expect(table).to have_content(cost_of_produce) expect(table).to have_content(summary_row) end end From 9ae65e135b782033032fb5fdabcc9dd3e2acf426 Mon Sep 17 00:00:00 2001 From: David Cook Date: Wed, 3 May 2023 10:42:00 +1000 Subject: [PATCH 06/46] Rails/Pick Prefer pick("sum(amount)") over pluck("sum(amount)").first --- .../enterprise_fees_with_tax_report_by_producer.rb | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb b/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb index dc073d4ef3..1690677828 100644 --- a/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb +++ b/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb @@ -254,8 +254,7 @@ module Reporting .where(included: true) .where(adjustable_type: 'Spree::Adjustment') .where(adjustable_id: enterprise_fee_adjustment_ids_for_orders(order_ids)) - .pluck("sum(amount)") - .first || 0 + .pick("sum(amount)") || 0 end def tax_for_order_ids(order_ids) @@ -263,8 +262,7 @@ module Reporting .where(order: order_ids) .where(adjustable_type: 'Spree::Adjustment') .where(adjustable_id: enterprise_fee_adjustment_ids_for_orders(order_ids)) - .pluck("sum(amount)") - .first || 0 + .pick("sum(amount)") || 0 end def enterprise_fee_adjustment_ids_for_orders(order_ids) @@ -272,7 +270,7 @@ module Reporting end def enterprise_fees_amount_for_orders(order_ids) - enterprise_fees_for_orders(order_ids).pluck("sum(amount)").first || 0 + enterprise_fees_for_orders(order_ids).pick("sum(amount)") || 0 end def enterprise_fees_for_orders(order_ids) @@ -294,7 +292,7 @@ module Reporting end def producer_tax_status(query_result_row) - Enterprise.where(id: supplier_id(query_result_row)).pluck(:charges_sales_tax).first + Enterprise.where(id: supplier_id(query_result_row)).pick(:charges_sales_tax) end def order_cycle(query_result_row) @@ -331,8 +329,7 @@ module Reporting amount = Spree::Adjustment.enterprise_fee .where(order_id: order_ids) .where(originator_id: enterprise_fee_id) - .pluck("sum(amount)") - .first + .pick("sum(amount)") amount - tax(query_result_row, all: true, included: true) end From 1cd0f88c1e15593bb5bb5bf3cd1a3ff9f7ecff01 Mon Sep 17 00:00:00 2001 From: Mohamed ABDELLANI Date: Thu, 8 Jun 2023 09:10:30 +0100 Subject: [PATCH 07/46] fix supplier filter --- .../enterprise_fees_with_tax_report_by_producer.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb b/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb index 1690677828..a458e95e3e 100644 --- a/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb +++ b/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb @@ -25,8 +25,8 @@ module Reporting def supplier_ids_filter(supplier_id) return true if params[:supplier_id_in].blank? - - params[:supplier_id_in].include?(supplier_id) + + params[:supplier_id_in].include?(supplier_id.to_s) end def enterprise_fee_filtered_ids From 7b0a99c652c10970c11913611745837838671bb1 Mon Sep 17 00:00:00 2001 From: Mohamed ABDELLANI Date: Fri, 9 Jun 2023 08:31:32 +0100 Subject: [PATCH 08/46] fix enterprise fees listing For every producer, we want to only show the enterprise fees that are applied to at lease one of his products. To do that, we use the order cycle to build a list of the enterprise fees for every variant. Every variant will have coordinator fee + additional fees coming from incoming/outgoing exchanges. --- ...rprise_fees_with_tax_report_by_producer.rb | 45 ++++++++++++++----- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb b/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb index a458e95e3e..95fb6aca29 100644 --- a/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb +++ b/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb @@ -23,10 +23,10 @@ module Reporting @report_line_items ||= Reporting::LineItems.new(order_permissions, params) end - def supplier_ids_filter(supplier_id) + def supplier_ids_filter(line_item) return true if params[:supplier_id_in].blank? - - params[:supplier_id_in].include?(supplier_id.to_s) + + params[:supplier_id_in].include?(line_item.supplier.id.to_s) end def enterprise_fee_filtered_ids @@ -119,24 +119,49 @@ module Reporting end end + # For every supplier, we want to show the enteprise fees + # applied to at least one of his products def join_supplier proc do |item| order = item[:order] - order - .line_items - .map(&:supplier_id) - .filter(&method(:supplier_ids_filter)) - .map do |supplier_id| + + filtered_line_items(order) + .map do |line_item| { tax_rate_id: item[:tax_rate_id], - enterprise_fee_id: item[:enterprise_fee_id], - supplier_id: supplier_id, + enterprise_fee_id: if item[:enterprise_fee_id].in?( + enterprise_fees_per_variant(order)[line_item.variant] + ) + item[:enterprise_fee_id] + end, + supplier_id: line_item.supplier.id, order: order } end + .filter do |hash| + hash[:enterprise_fee_id].present? + end end end + def filtered_line_items(order) + order + .line_items + .filter(&method(:supplier_ids_filter)) + end + + # { variant: [enterprise_fee_ids] } + def enterprise_fees_per_variant(order) + hash = {} + order.order_cycle.exchanges.each do |exchange| + exchange.variants.each do |variant| + hash[variant] ||= order.order_cycle.coordinator_fee_ids + hash[variant] += exchange.enterprise_fee_ids + end + end + hash + end + def group_keys proc do |hash| [ From 7a875723cacd00f2d974f8942811f36f8bba65ed Mon Sep 17 00:00:00 2001 From: Mohamed ABDELLANI Date: Fri, 9 Jun 2023 08:44:14 +0100 Subject: [PATCH 09/46] fix order_cycle summary row. the summary row has to only include the line items coming from the supplier used in the grouping key --- .../enterprise_fees_with_tax_report_by_producer.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb b/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb index 95fb6aca29..f474d72805 100644 --- a/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb +++ b/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb @@ -219,8 +219,12 @@ module Reporting def order_cycle_totals_row proc do |_key, items, _rows| + supplier_id = items.first.first[2] # supplier id used in the grouped line items order_ids = items.flat_map(&:second).map(&:id).uniq line_items = items.flat_map(&:second).uniq.map(&:line_items).flatten + .filter do |line_item| + line_item.supplier_id == supplier_id + end total_excl_tax = total_fees_excl_tax(order_ids) + line_items_excl_tax(line_items) tax = tax_for_order_ids(order_ids) + tax_for_line_items(line_items) From 928337c3fd6ed3b6c907044b35b6af1d6673f1bc Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Wed, 3 May 2023 14:52:06 +0100 Subject: [PATCH 10/46] Adds a second supplier and product to the setup --- ...ry_fee_with_tax_report_by_producer_spec.rb | 394 ++++++++++++------ 1 file changed, 260 insertions(+), 134 deletions(-) diff --git a/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb b/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb index ac0f7d8d49..4658e50052 100644 --- a/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb +++ b/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb @@ -31,44 +31,87 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do } let!(:ship_address){ create(:ship_address) } - let!(:variant){ create(:variant, tax_category: tax_category) } - let!(:product){ variant.product } - let!(:distributor){ create(:distributor_enterprise_with_tax, name: 'Distributor') } - let!(:supplier){ create(:supplier_enterprise, name: 'Supplier', charges_sales_tax: true) } + let!(:supplier_owner) { create(:user, enterprise_limit: 1) } + let!(:supplier2_owner) { create(:user, enterprise_limit: 1) } + let!(:supplier){ + create(:supplier_enterprise, name: 'Supplier', charges_sales_tax: true, + owner_id: supplier_owner.id) + } + let!(:supplier2){ + create(:supplier_enterprise, name: 'Supplier2', charges_sales_tax: true, + owner_id: supplier2_owner.id) + } + let!(:product){ create(:simple_product, supplier: supplier ) } + let!(:product2){ create(:simple_product, supplier: supplier2 ) } + let!(:variant){ create(:variant, product_id: product.id, tax_category: tax_category) } + let!(:variant2){ create(:variant, product_id: product2.id, tax_category: tax_category) } + let!(:distributor_owner) { create(:user, enterprise_limit: 1) } + let!(:distributor){ + create(:distributor_enterprise_with_tax, name: 'Distributor', owner_id: distributor_owner.id) + } let!(:payment_method){ create(:payment_method, :flat_rate) } let!(:shipping_method){ create(:shipping_method, :flat_rate) } - let!(:order){ create(:order_with_distributor, distributor: distributor) } let!(:order_cycle){ - create(:simple_order_cycle, suppliers: [supplier], distributors: [distributor], - variants: [variant], name: "oc1") + create(:simple_order_cycle, distributors: [distributor], name: "oc1") + } + let!(:enterprise_relationship1) { + create(:enterprise_relationship, parent: supplier, child: distributor, + permissions_list: [:add_to_order_cycle]) + } + let!(:enterprise_relationship2) { + create(:enterprise_relationship, parent: supplier2, child: distributor, + permissions_list: [:add_to_order_cycle]) } - let(:admin){ create(:admin_user) } + let(:admin) { create(:admin_user) } - let!(:coordinator_fees){ + let(:coordinator_fees){ create(:enterprise_fee, :flat_rate, enterprise: distributor, amount: 20, name: 'Adminstration', fee_type: 'admin', tax_category: tax_category) } - let!(:supplier_fees){ - create(:enterprise_fee, :flat_rate, enterprise: supplier, amount: 15, - name: 'Transport', - fee_type: 'transport', - tax_category: tax_category) + let(:supplier_fees){ + create(:enterprise_fee, :per_item, enterprise: supplier, amount: 15, + name: 'Transport', + fee_type: 'transport', + tax_category: tax_category) } - let!(:distributor_fee){ + let(:supplier_fees2){ + create(:enterprise_fee, :per_item, enterprise: supplier2, amount: 25, + name: 'Sales', + fee_type: 'sales', + tax_category: tax_category) + } + let(:distributor_fee){ create(:enterprise_fee, :flat_rate, enterprise: distributor, amount: 10, name: 'Packing', fee_type: 'packing', tax_category: tax_category) } + let!(:incoming_exchange1) { + order_cycle.exchanges.create! sender: supplier, receiver: distributor, incoming: true + } + + let!(:incoming_exchange2) { + order_cycle.exchanges.create! sender: supplier2, receiver: distributor, incoming: true + } + let(:outgoing_exchange) { + order_cycle.exchanges.create! sender: distributor, receiver: distributor, incoming: false + } + + let!(:order){ create(:order_with_distributor, distributor: distributor) } before do order_cycle.coordinator_fees << coordinator_fees order_cycle.exchanges.incoming.first.exchange_fees.create!(enterprise_fee: supplier_fees) + order_cycle.exchanges.incoming.first.exchange_variants.create!(variant: variant) + order_cycle.exchanges.incoming.second.exchange_fees.create!(enterprise_fee: supplier_fees2) + order_cycle.exchanges.incoming.second.exchange_variants.create!(variant: variant2) order_cycle.exchanges.outgoing.first.exchange_fees.create!(enterprise_fee: distributor_fee) + order_cycle.exchanges.outgoing.first.exchange_variants.create!(variant: variant) + order_cycle.exchanges.outgoing.first.exchange_variants.create!(variant: variant2) distributor.shipping_methods << shipping_method distributor.payment_methods << payment_method @@ -77,149 +120,232 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do tax_category_id: tax_category.id, supplier_id: supplier.id }) + product2.update!({ + tax_category_id: tax_category.id, + supplier_id: supplier2.id + }) end context 'added tax' do # 1 order cycle has: # - coordinator fees (20) 1.5% = 0.30, 2.5% = 0.50 - # - incoming exchange (15) 1.5% = 0.23, 2.5% = 0.38 + # - incoming exchange (15) 1.5% = 0.38, 2.5% = 0.63 # - outgoing exchange (10) 1.5% = 0.15, 2.5% = 0.25 - # - line items (100) 1.5% = 1.50, 2.5% = 2.50 + # - line items (50) 1.5% = 0.75, 2.5% = 1.25 - before do - order.line_items.create({ variant: variant, quantity: 1, price: 100 }) - order.update!({ - order_cycle_id: order_cycle.id, - ship_address_id: ship_address.id - }) - # This will load the enterprise fees from the order cycle. - # This is needed because the order instance was created - # independently of the order_cycle. - order.recreate_all_fees! - while !order.completed? - break unless order.next! + context "an order with line items from a single supplier (1)" do + before do + order.line_items.create({ variant: variant, quantity: 1, price: 100 }) + order.update!({ + order_cycle_id: order_cycle.id, + ship_address_id: ship_address.id + }) + # This will load the enterprise fees from the order cycle. + # This is needed because the order instance was created + # independently of the order_cycle. + order.recreate_all_fees! + while !order.completed? + break unless order.next! + end end - end - let(:coordinator_state_tax){ - ["Distributor", "Supplier", "Yes", "oc1", "Adminstration", "admin", "Distributor", - "tax_category", "State", "0.015", "20.0", "0.3", "20.3"].join(" ") - } - let(:coordinator_country_tax){ - ["Distributor", "Supplier", "Yes", "oc1", "Adminstration", "admin", "Distributor", - "tax_category", "Country", "0.025", "20.0", "0.5", "20.5"].join(" ") - } - - let(:supplier_state_tax){ - ["Distributor", "Supplier", "Yes", "oc1", "Transport", "transport", "Supplier", - "tax_category", "State", "0.015", "15.0", "0.23", "15.23"].join(" ") - } - let(:supplier_country_tax){ - ["Distributor", "Supplier", "Yes", "oc1", "Transport", "transport", "Supplier", - "tax_category", "Country", "0.025", "15.0", "0.38", "15.38"].join(" ") - } - - let(:distributor_state_tax){ - ["Distributor", "Supplier", "Yes", "oc1", "Packing", "packing", "Distributor", - "tax_category", "State", "0.015", "10.0", "0.15", "10.15"].join(" ") - } - let(:distributor_country_tax){ - ["Distributor", "Supplier", "Yes", "oc1", "Packing", "packing", "Distributor", - "tax_category", "Country", "0.025", "10.0", "0.25", "10.25"].join(" ") - } - - let(:cost_of_produce){ - ["Distributor", "Supplier", "Yes", "oc1", "Cost of produce", "line items", "Supplier", - "100.0", "4.0", "104.0"].join(" ") - } - let(:summary_row){ - [ - "TOTAL", # Fees and line items - "145.0", # Tax excl: 20 + 15 + 10 + 100 - "5.81", # Tax : (0.30 + 0.50) + (0.23 + 0.38) + (0.15 + 0.25) + (1.50 + 2.50) - "150.81" # Tax incl: 145.00 + 5.81 - ].join(" ") - } - - it 'generates the report' do - login_as admin - visit admin_reports_path - click_on I18n.t("admin.reports.enterprise_fees_with_tax_report_by_producer") - - expect(page).to have_button("Go") - click_on "Go" - - expect(page.find("table.report__table thead tr")).to have_content(table_header) - - table = page.find("table.report__table tbody") - expect(table).to have_content(supplier_state_tax) - expect(table).to have_content(supplier_country_tax) - expect(table).to have_content(distributor_state_tax) - expect(table).to have_content(distributor_country_tax) - expect(table).to have_content(coordinator_state_tax) - expect(table).to have_content(coordinator_country_tax) - expect(table).to have_content(cost_of_produce) - expect(table).to have_content(summary_row) - end - - context "filtering" do - let(:fee_name_selector){ "#s2id_q_enterprise_fee_id_in" } - let(:fee_owner_selector){ "#s2id_q_enterprise_fee_owner_id_in" } - - let(:summary_row_after_filtering_by_fee_name){ - ["TOTAL", "120.0", "4.8", "124.8"].join(" ") + let(:coordinator_state_tax){ + ["Distributor", "Supplier", "Yes", "oc1", "Adminstration", "admin", "Distributor", + "tax_category", "State", "0.015", "20.0", "0.3", "20.3"].join(" ") + } + let(:coordinator_country_tax){ + ["Distributor", "Supplier", "Yes", "oc1", "Adminstration", "admin", "Distributor", + "tax_category", "Country", "0.025", "20.0", "0.5", "20.5"].join(" ") } - let(:summary_row_after_filtering_by_fee_owner){ - ["TOTAL", "115.0", "4.61", "119.61"].join(" ") + let(:supplier_state_tax){ + ["Distributor", "Supplier", "Yes", "oc1", "Transport", "transport", "Supplier", + "tax_category", "State", "0.015", "15.0", "0.23", "15.23"].join(" ") + } + let(:supplier_country_tax){ + ["Distributor", "Supplier", "Yes", "oc1", "Transport", "transport", "Supplier", + "tax_category", "Country", "0.025", "15.0", "0.38", "15.38"].join(" ") } - it "should filter by fee name" do - login_as admin + let(:distributor_state_tax){ + ["Distributor", "Supplier", "Yes", "oc1", "Packing", "packing", "Distributor", + "tax_category", "State", "0.015", "10.0", "0.15", "10.15"].join(" ") + } + let(:distributor_country_tax){ + ["Distributor", "Supplier", "Yes", "oc1", "Packing", "packing", "Distributor", + "tax_category", "Country", "0.025", "10.0", "0.25", "10.25"].join(" ") + } + + let(:cost_of_produce){ + ["Distributor", "Supplier", "Yes", "oc1", "Cost of produce", "line items", "Supplier", + "100.0", "4.0", "104.0"].join(" ") + } + let(:summary_row){ + [ + "TOTAL", # Fees and line items + "145.0", # Tax excl: 20 + 15 + 10 + 100 + "5.81", # Tax : (0.30 + 0.50) + (0.23 + 0.38) + (0.15 + 0.25) + (1.50 + 2.50) + "150.81" # Tax incl: 145.00 + 5.81 + ].join(" ") + } + + it 'generates the report and displays fees for the respective supplier' do + login_as distributor_owner visit admin_reports_path click_on I18n.t("admin.reports.enterprise_fees_with_tax_report_by_producer") - page.find(fee_name_selector).click - find('li', text: coordinator_fees.name).click - expect(page).to have_button("Go") click_on "Go" - - expect(page.find("table.report__table thead tr")).to have_content(table_header) - - table = page.find("table.report__table tbody") - expect(table).to_not have_content(supplier_state_tax) - expect(table).to_not have_content(supplier_country_tax) - expect(table).to_not have_content(distributor_state_tax) - expect(table).to_not have_content(distributor_country_tax) - expect(table).to have_content(coordinator_state_tax) - expect(table).to have_content(coordinator_country_tax) - expect(table).to have_content(cost_of_produce) - expect(table).to have_content(summary_row_after_filtering_by_fee_name) - end - - it "should filter by fee owner" do - login_as admin - visit admin_reports_path - click_on I18n.t("admin.reports.enterprise_fees_with_tax_report_by_producer") - - page.find(fee_owner_selector).click - find('li', text: supplier.name).click - - expect(page).to have_button("Go") - click_on "Go" - expect(page.find("table.report__table thead tr")).to have_content(table_header) table = page.find("table.report__table tbody") expect(table).to have_content(supplier_state_tax) expect(table).to have_content(supplier_country_tax) - expect(table).to_not have_content(distributor_state_tax) - expect(table).to_not have_content(distributor_country_tax) - expect(table).to_not have_content(coordinator_state_tax) - expect(table).to_not have_content(coordinator_country_tax) + expect(table).to have_content(distributor_state_tax) + expect(table).to have_content(distributor_country_tax) + expect(table).to have_content(coordinator_state_tax) + expect(table).to have_content(coordinator_country_tax) expect(table).to have_content(cost_of_produce) - expect(table).to have_content(summary_row_after_filtering_by_fee_owner) + expect(table).to have_content(summary_row) + end + + context "filtering" do + let(:fee_name_selector){ "#s2id_q_enterprise_fee_id_in" } + let(:fee_owner_selector){ "#s2id_q_enterprise_fee_owner_id_in" } + + let(:summary_row_after_filtering_by_fee_name){ + ["TOTAL", "120.0", "4.8", "124.8"].join(" ") + } + + let(:summary_row_after_filtering_by_fee_owner){ + ["TOTAL", "115.0", "4.61", "119.61"].join(" ") + } + + it "should filter by fee name" do + login_as distributor.owner + visit admin_reports_path + click_on I18n.t("admin.reports.enterprise_fees_with_tax_report_by_producer") + + page.find(fee_name_selector).click + find('li', text: coordinator_fees.name).click + + expect(page).to have_button("Go") + click_on "Go" + + expect(page.find("table.report__table thead tr")).to have_content(table_header) + + table = page.find("table.report__table tbody") + expect(table).to_not have_content(supplier_state_tax) + expect(table).to_not have_content(supplier_country_tax) + expect(table).to_not have_content(distributor_state_tax) + expect(table).to_not have_content(distributor_country_tax) + expect(table).to have_content(coordinator_state_tax) + expect(table).to have_content(coordinator_country_tax) + expect(table).to have_content(cost_of_produce) + expect(table).to have_content(summary_row_after_filtering_by_fee_name) + end + + it "should filter by fee owner" do + login_as distributor.owner + visit admin_reports_path + click_on I18n.t("admin.reports.enterprise_fees_with_tax_report_by_producer") + + page.find(fee_owner_selector).click + find('li', text: supplier.name).click + + expect(page).to have_button("Go") + click_on "Go" + + expect(page.find("table.report__table thead tr")).to have_content(table_header) + + table = page.find("table.report__table tbody") + expect(table).to have_content(supplier_state_tax) + expect(table).to have_content(supplier_country_tax) + expect(table).to_not have_content(distributor_state_tax) + expect(table).to_not have_content(distributor_country_tax) + expect(table).to_not have_content(coordinator_state_tax) + expect(table).to_not have_content(coordinator_country_tax) + expect(table).to have_content(cost_of_produce) + expect(table).to have_content(summary_row_after_filtering_by_fee_owner) + end + end + + end + + context "an order with line items from a single supplier (2)" do + before do + order.line_items.create({ variant: variant2, quantity: 1, price: 50 }) + order.update!({ + order_cycle_id: order_cycle.id, + ship_address_id: ship_address.id + }) + # This will load the enterprise fees from the order cycle. + # This is needed because the order instance was created + # independently of the order_cycle. + order.recreate_all_fees! + while !order.completed? + break unless order.next! + end + end + + let(:coordinator_state_tax){ + ["Distributor", "Supplier2", "Yes", "oc1", "Adminstration", "admin", "Distributor", + "tax_category", "State", "0.015", "20.0", "0.3", "20.3"].join(" ") + } + let(:coordinator_country_tax){ + ["Distributor", "Supplier2", "Yes", "oc1", "Adminstration", "admin", "Distributor", + "tax_category", "Country", "0.025", "20.0", "0.5", "20.5"].join(" ") + } + + let(:supplier_state_tax){ + ["Distributor", "Supplier2", "Yes", "oc1", "Sales", "sales", "Supplier2", + "tax_category", "State", "0.015", "25.0", "0.38", "25.38"].join(" ") + } + let(:supplier_country_tax){ + ["Distributor", "Supplier2", "Yes", "oc1", "Sales", "sales", "Supplier2", + "tax_category", "Country", "0.025", "25.0", "0.63", "25.63"].join(" ") + } + + let(:distributor_state_tax){ + ["Distributor", "Supplier2", "Yes", "oc1", "Packing", "packing", "Distributor", + "tax_category", "State", "0.015", "10.0", "0.15", "10.15"].join(" ") + } + let(:distributor_country_tax){ + ["Distributor", "Supplier2", "Yes", "oc1", "Packing", "packing", "Distributor", + "tax_category", "Country", "0.025", "10.0", "0.25", "10.25"].join(" ") + } + + let(:cost_of_produce){ + ["Distributor", "Supplier2", "Yes", "oc1", "Cost of produce", "line items", "Supplier2", + "50.0", "2.0", "52.0"].join(" ") + } + let(:summary_row){ + [ + "TOTAL", # Fees and line items + "105.0", # Tax excl: 20 + 25 + 10 + 50 + "4.21", # Tax : (0.30 + 0.50) + (0.38 + 0.63) + (0.15 + 0.25) + 2 + "109.21" # Tax incl: 105 + 4.21 + ].join(" ") + } + + it 'generates the report and displays fees for the respective supplier' do + login_as distributor_owner + visit admin_reports_path + click_on I18n.t("admin.reports.enterprise_fees_with_tax_report_by_producer") + + expect(page).to have_button("Go") + click_on "Go" + expect(page.find("table.report__table thead tr")).to have_content(table_header) + + table = page.find("table.report__table tbody") + expect(table).to have_content(supplier_state_tax) + expect(table).to have_content(supplier_country_tax) + expect(table).to have_content(distributor_state_tax) + expect(table).to have_content(distributor_country_tax) + expect(table).to have_content(coordinator_state_tax) + expect(table).to have_content(coordinator_country_tax) + expect(table).to have_content(cost_of_produce) + expect(table).to have_content(summary_row) end end end From bb0f9a67580985af66b06a596e1d472ce67625f6 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Sun, 7 May 2023 23:55:24 +0100 Subject: [PATCH 11/46] Adds pending test on fees from order with line items from different suppliers Adds pending test on producer filter --- ...ry_fee_with_tax_report_by_producer_spec.rb | 556 +++++++++++++----- 1 file changed, 401 insertions(+), 155 deletions(-) diff --git a/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb b/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb index 4658e50052..b05591110b 100644 --- a/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb +++ b/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb @@ -55,6 +55,10 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do let!(:order_cycle){ create(:simple_order_cycle, distributors: [distributor], name: "oc1") } + let!(:order_cycle2){ + create(:simple_order_cycle, distributors: [distributor], name: "oc2") + } + let!(:enterprise_relationship1) { create(:enterprise_relationship, parent: supplier, child: distributor, permissions_list: [:add_to_order_cycle]) @@ -91,19 +95,34 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do tax_category: tax_category) } + # creates exchanges for oc1 let!(:incoming_exchange1) { order_cycle.exchanges.create! sender: supplier, receiver: distributor, incoming: true } - let!(:incoming_exchange2) { order_cycle.exchanges.create! sender: supplier2, receiver: distributor, incoming: true } - let(:outgoing_exchange) { + let(:outgoing_exchange1) { order_cycle.exchanges.create! sender: distributor, receiver: distributor, incoming: false } - let!(:order){ create(:order_with_distributor, distributor: distributor) } + # sets exchanges for oc2 + let!(:incoming_exchange3) { + order_cycle2.exchanges.create! sender: supplier, receiver: distributor, incoming: true + } + let!(:incoming_exchange4) { + order_cycle2.exchanges.create! sender: supplier2, receiver: distributor, incoming: true + } + let(:outgoing_exchange2) { + order_cycle2.exchanges.create! sender: distributor, receiver: distributor, incoming: false + } + + # creates orders for for oc1 and oc2 + let!(:order) { create(:order_with_distributor, distributor: distributor) } + let!(:order2) { create(:order_with_distributor, distributor: distributor) } + before do + # adds variants to exchanges on oc1 order_cycle.coordinator_fees << coordinator_fees order_cycle.exchanges.incoming.first.exchange_fees.create!(enterprise_fee: supplier_fees) order_cycle.exchanges.incoming.first.exchange_variants.create!(variant: variant) @@ -113,6 +132,16 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do order_cycle.exchanges.outgoing.first.exchange_variants.create!(variant: variant) order_cycle.exchanges.outgoing.first.exchange_variants.create!(variant: variant2) + # adds variants to exchanges on oc2 + order_cycle2.coordinator_fees << coordinator_fees + order_cycle2.exchanges.incoming.first.exchange_fees.create!(enterprise_fee: supplier_fees) + order_cycle2.exchanges.incoming.first.exchange_variants.create!(variant: variant) + order_cycle2.exchanges.incoming.second.exchange_fees.create!(enterprise_fee: supplier_fees2) + order_cycle2.exchanges.incoming.second.exchange_variants.create!(variant: variant2) + order_cycle2.exchanges.outgoing.first.exchange_fees.create!(enterprise_fee: distributor_fee) + order_cycle2.exchanges.outgoing.first.exchange_variants.create!(variant: variant) + order_cycle2.exchanges.outgoing.first.exchange_variants.create!(variant: variant2) + distributor.shipping_methods << shipping_method distributor.payment_methods << payment_method @@ -133,54 +162,71 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do # - outgoing exchange (10) 1.5% = 0.15, 2.5% = 0.25 # - line items (50) 1.5% = 0.75, 2.5% = 1.25 - context "an order with line items from a single supplier (1)" do - before do - order.line_items.create({ variant: variant, quantity: 1, price: 100 }) - order.update!({ - order_cycle_id: order_cycle.id, - ship_address_id: ship_address.id - }) - # This will load the enterprise fees from the order cycle. - # This is needed because the order instance was created - # independently of the order_cycle. - order.recreate_all_fees! - while !order.completed? - break unless order.next! - end + before do + # adds a line items to the order on oc1 + order.line_items.create({ variant: variant, quantity: 1, price: 100 }) + order.update!({ + order_cycle_id: order_cycle.id, + ship_address_id: ship_address.id + }) + # This will load the enterprise fees from the order cycle. + # This is needed because the order instance was created + # independently of the order_cycle. + order.recreate_all_fees! + while !order.completed? + break unless order.next! end - let(:coordinator_state_tax){ + # adds a line items to the order on oc2 + order2.line_items.create({ variant: variant2, quantity: 1, price: 50 }) + order2.update!({ + order_cycle_id: order_cycle2.id, + ship_address_id: ship_address.id + }) + # This will load the enterprise fees from the order cycle. + # This is needed because the order instance was created + # independently of the order_cycle. + order2.recreate_all_fees! + while !order2.completed? + break unless order2.next! + end + end + + describe "orders" do + # for supplier 1, oc1 + + let(:coordinator_state_tax_1){ ["Distributor", "Supplier", "Yes", "oc1", "Adminstration", "admin", "Distributor", "tax_category", "State", "0.015", "20.0", "0.3", "20.3"].join(" ") } - let(:coordinator_country_tax){ + let(:coordinator_country_tax_1){ ["Distributor", "Supplier", "Yes", "oc1", "Adminstration", "admin", "Distributor", "tax_category", "Country", "0.025", "20.0", "0.5", "20.5"].join(" ") } - let(:supplier_state_tax){ + let(:supplier_state_tax_1){ ["Distributor", "Supplier", "Yes", "oc1", "Transport", "transport", "Supplier", "tax_category", "State", "0.015", "15.0", "0.23", "15.23"].join(" ") } - let(:supplier_country_tax){ + let(:supplier_country_tax_1){ ["Distributor", "Supplier", "Yes", "oc1", "Transport", "transport", "Supplier", "tax_category", "Country", "0.025", "15.0", "0.38", "15.38"].join(" ") } - let(:distributor_state_tax){ + let(:distributor_state_tax_1){ ["Distributor", "Supplier", "Yes", "oc1", "Packing", "packing", "Distributor", "tax_category", "State", "0.015", "10.0", "0.15", "10.15"].join(" ") } - let(:distributor_country_tax){ + let(:distributor_country_tax_1){ ["Distributor", "Supplier", "Yes", "oc1", "Packing", "packing", "Distributor", "tax_category", "Country", "0.025", "10.0", "0.25", "10.25"].join(" ") } - let(:cost_of_produce){ + let(:cost_of_produce_1){ ["Distributor", "Supplier", "Yes", "oc1", "Cost of produce", "line items", "Supplier", "100.0", "4.0", "104.0"].join(" ") } - let(:summary_row){ + let(:summary_row_1){ [ "TOTAL", # Fees and line items "145.0", # Tax excl: 20 + 15 + 10 + 100 @@ -189,137 +235,39 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do ].join(" ") } - it 'generates the report and displays fees for the respective supplier' do - login_as distributor_owner - visit admin_reports_path - click_on I18n.t("admin.reports.enterprise_fees_with_tax_report_by_producer") - - expect(page).to have_button("Go") - click_on "Go" - expect(page.find("table.report__table thead tr")).to have_content(table_header) - - table = page.find("table.report__table tbody") - expect(table).to have_content(supplier_state_tax) - expect(table).to have_content(supplier_country_tax) - expect(table).to have_content(distributor_state_tax) - expect(table).to have_content(distributor_country_tax) - expect(table).to have_content(coordinator_state_tax) - expect(table).to have_content(coordinator_country_tax) - expect(table).to have_content(cost_of_produce) - expect(table).to have_content(summary_row) - end - - context "filtering" do - let(:fee_name_selector){ "#s2id_q_enterprise_fee_id_in" } - let(:fee_owner_selector){ "#s2id_q_enterprise_fee_owner_id_in" } - - let(:summary_row_after_filtering_by_fee_name){ - ["TOTAL", "120.0", "4.8", "124.8"].join(" ") - } - - let(:summary_row_after_filtering_by_fee_owner){ - ["TOTAL", "115.0", "4.61", "119.61"].join(" ") - } - - it "should filter by fee name" do - login_as distributor.owner - visit admin_reports_path - click_on I18n.t("admin.reports.enterprise_fees_with_tax_report_by_producer") - - page.find(fee_name_selector).click - find('li', text: coordinator_fees.name).click - - expect(page).to have_button("Go") - click_on "Go" - - expect(page.find("table.report__table thead tr")).to have_content(table_header) - - table = page.find("table.report__table tbody") - expect(table).to_not have_content(supplier_state_tax) - expect(table).to_not have_content(supplier_country_tax) - expect(table).to_not have_content(distributor_state_tax) - expect(table).to_not have_content(distributor_country_tax) - expect(table).to have_content(coordinator_state_tax) - expect(table).to have_content(coordinator_country_tax) - expect(table).to have_content(cost_of_produce) - expect(table).to have_content(summary_row_after_filtering_by_fee_name) - end - - it "should filter by fee owner" do - login_as distributor.owner - visit admin_reports_path - click_on I18n.t("admin.reports.enterprise_fees_with_tax_report_by_producer") - - page.find(fee_owner_selector).click - find('li', text: supplier.name).click - - expect(page).to have_button("Go") - click_on "Go" - - expect(page.find("table.report__table thead tr")).to have_content(table_header) - - table = page.find("table.report__table tbody") - expect(table).to have_content(supplier_state_tax) - expect(table).to have_content(supplier_country_tax) - expect(table).to_not have_content(distributor_state_tax) - expect(table).to_not have_content(distributor_country_tax) - expect(table).to_not have_content(coordinator_state_tax) - expect(table).to_not have_content(coordinator_country_tax) - expect(table).to have_content(cost_of_produce) - expect(table).to have_content(summary_row_after_filtering_by_fee_owner) - end - end - - end - - context "an order with line items from a single supplier (2)" do - before do - order.line_items.create({ variant: variant2, quantity: 1, price: 50 }) - order.update!({ - order_cycle_id: order_cycle.id, - ship_address_id: ship_address.id - }) - # This will load the enterprise fees from the order cycle. - # This is needed because the order instance was created - # independently of the order_cycle. - order.recreate_all_fees! - while !order.completed? - break unless order.next! - end - end - - let(:coordinator_state_tax){ - ["Distributor", "Supplier2", "Yes", "oc1", "Adminstration", "admin", "Distributor", + # for supplier 2, oc2 + let(:coordinator_state_tax_2){ + ["Distributor", "Supplier2", "Yes", "oc2", "Adminstration", "admin", "Distributor", "tax_category", "State", "0.015", "20.0", "0.3", "20.3"].join(" ") } - let(:coordinator_country_tax){ - ["Distributor", "Supplier2", "Yes", "oc1", "Adminstration", "admin", "Distributor", + let(:coordinator_country_tax_2){ + ["Distributor", "Supplier2", "Yes", "oc2", "Adminstration", "admin", "Distributor", "tax_category", "Country", "0.025", "20.0", "0.5", "20.5"].join(" ") } - let(:supplier_state_tax){ - ["Distributor", "Supplier2", "Yes", "oc1", "Sales", "sales", "Supplier2", + let(:supplier_state_tax_2){ + ["Distributor", "Supplier2", "Yes", "oc2", "Sales", "sales", "Supplier2", "tax_category", "State", "0.015", "25.0", "0.38", "25.38"].join(" ") } - let(:supplier_country_tax){ - ["Distributor", "Supplier2", "Yes", "oc1", "Sales", "sales", "Supplier2", + let(:supplier_country_tax_2){ + ["Distributor", "Supplier2", "Yes", "oc2", "Sales", "sales", "Supplier2", "tax_category", "Country", "0.025", "25.0", "0.63", "25.63"].join(" ") } - let(:distributor_state_tax){ - ["Distributor", "Supplier2", "Yes", "oc1", "Packing", "packing", "Distributor", + let(:distributor_state_tax_2){ + ["Distributor", "Supplier2", "Yes", "oc2", "Packing", "packing", "Distributor", "tax_category", "State", "0.015", "10.0", "0.15", "10.15"].join(" ") } - let(:distributor_country_tax){ - ["Distributor", "Supplier2", "Yes", "oc1", "Packing", "packing", "Distributor", + let(:distributor_country_tax_2){ + ["Distributor", "Supplier2", "Yes", "oc2", "Packing", "packing", "Distributor", "tax_category", "Country", "0.025", "10.0", "0.25", "10.25"].join(" ") } - let(:cost_of_produce){ - ["Distributor", "Supplier2", "Yes", "oc1", "Cost of produce", "line items", "Supplier2", + let(:cost_of_produce_2){ + ["Distributor", "Supplier2", "Yes", "oc2", "Cost of produce", "line items", "Supplier2", "50.0", "2.0", "52.0"].join(" ") } - let(:summary_row){ + let(:summary_row_2){ [ "TOTAL", # Fees and line items "105.0", # Tax excl: 20 + 25 + 10 + 50 @@ -328,24 +276,322 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do ].join(" ") } - it 'generates the report and displays fees for the respective supplier' do - login_as distributor_owner - visit admin_reports_path - click_on I18n.t("admin.reports.enterprise_fees_with_tax_report_by_producer") + context "with line items from a single supplier (1)" do + it 'generates the report and displays fees for the respective supplier' do + login_as distributor_owner + visit admin_reports_path + click_on I18n.t("admin.reports.enterprise_fees_with_tax_report_by_producer") + expect(page).to have_button("Go") + click_on "Go" - expect(page).to have_button("Go") - click_on "Go" - expect(page.find("table.report__table thead tr")).to have_content(table_header) + expect(page.find("table.report__table thead tr")).to have_content(table_header) - table = page.find("table.report__table tbody") - expect(table).to have_content(supplier_state_tax) - expect(table).to have_content(supplier_country_tax) - expect(table).to have_content(distributor_state_tax) - expect(table).to have_content(distributor_country_tax) - expect(table).to have_content(coordinator_state_tax) - expect(table).to have_content(coordinator_country_tax) - expect(table).to have_content(cost_of_produce) - expect(table).to have_content(summary_row) + table = page.find("table.report__table tbody") + expect(table).to have_content(supplier_state_tax_1) + expect(table).to have_content(supplier_country_tax_1) + expect(table).to have_content(distributor_state_tax_1) + expect(table).to have_content(distributor_country_tax_1) + expect(table).to have_content(coordinator_state_tax_1) + expect(table).to have_content(coordinator_country_tax_1) + expect(table).to have_content(cost_of_produce_1) + expect(table).to have_content(summary_row_1) + end + end + + context "with line items from a single supplier (2)" do + it 'generates the report and displays fees for the respective supplier' do + login_as distributor_owner + visit admin_reports_path + click_on I18n.t("admin.reports.enterprise_fees_with_tax_report_by_producer") + + expect(page).to have_button("Go") + click_on "Go" + expect(page.find("table.report__table thead tr")).to have_content(table_header) + + table = page.find("table.report__table tbody") + expect(table).to have_content(supplier_state_tax_2) + expect(table).to have_content(supplier_country_tax_2) + expect(table).to have_content(distributor_state_tax_2) + expect(table).to have_content(distributor_country_tax_2) + expect(table).to have_content(coordinator_state_tax_2) + expect(table).to have_content(coordinator_country_tax_2) + expect(table).to have_content(cost_of_produce_2) + expect(table).to have_content(summary_row_2) + end + end + + context "with line items from several suppliers" do + # creates oc3 and order + let!(:order_cycle3){ + create(:simple_order_cycle, distributors: [distributor], name: "oc3") + } + let!(:order3) { create(:order_with_distributor, distributor: distributor) } + + # creates exchanges on oc3 + let!(:incoming_exchange5) { + order_cycle3.exchanges.create! sender: supplier, receiver: distributor, incoming: true + } + let!(:incoming_exchange6) { + order_cycle3.exchanges.create! sender: supplier2, receiver: distributor, incoming: true + } + let(:outgoing_exchange3) { + order_cycle3.exchanges.create! sender: distributor, receiver: distributor, + incoming: false + } + + before do + # adds variants to exchanges on oc3 + order_cycle3.coordinator_fees << coordinator_fees + order_cycle3.exchanges.incoming.first.exchange_fees.create!(enterprise_fee: supplier_fees) + order_cycle3.exchanges.incoming.first.exchange_variants.create!(variant: variant) + order_cycle3.exchanges.incoming.second.exchange_fees.create!(enterprise_fee: supplier_fees2) + order_cycle3.exchanges.incoming.second.exchange_variants.create!(variant: variant2) + order_cycle3.exchanges.outgoing.first.exchange_fees.create!(enterprise_fee: distributor_fee) + order_cycle3.exchanges.outgoing.first.exchange_variants.create!(variant: variant) + order_cycle3.exchanges.outgoing.first.exchange_variants.create!(variant: variant2) + + # adds line items to the order on oc3 + order3.line_items.create({ variant: variant, quantity: 1, price: 100 }) + order3.line_items.create({ variant: variant2, quantity: 1, price: 50 }) + order3.update!({ + order_cycle_id: order_cycle3.id, + ship_address_id: ship_address.id + }) + # This will load the enterprise fees from the order cycle. + # This is needed because the order instance was created + # independently of the order_cycle. + order3.recreate_all_fees! + while !order3.completed? + break unless order3.next! + end + end + + # table lines for supplier1 + + let(:coordinator_state_tax_3){ + ["Distributor", "Supplier", "Yes", "oc3", "Adminstration", "admin", "Distributor", + "tax_category", "State", "0.015", "20.0", "0.3", "20.3"].join(" ") + } + let(:coordinator_country_tax_3){ + ["Distributor", "Supplier", "Yes", "oc3", "Adminstration", "admin", "Distributor", + "tax_category", "Country", "0.025", "20.0", "0.5", "20.5"].join(" ") + } + + let(:supplier_state_tax_3){ + ["Distributor", "Supplier", "Yes", "oc3", "Transport", "transport", "Supplier", + "tax_category", "State", "0.015", "15.0", "0.23", "15.23"].join(" ") + } + let(:supplier_country_tax_3){ + ["Distributor", "Supplier", "Yes", "oc3", "Transport", "transport", "Supplier", + "tax_category", "Country", "0.025", "15.0", "0.38", "15.38"].join(" ") + } + + let(:distributor_state_tax_3){ + ["Distributor", "Supplier", "Yes", "oc3", "Packing", "packing", "Distributor", + "tax_category", "State", "0.015", "10.0", "0.15", "10.15"].join(" ") + } + let(:distributor_country_tax_3){ + ["Distributor", "Supplier", "Yes", "oc3", "Packing", "packing", "Distributor", + "tax_category", "Country", "0.025", "10.0", "0.25", "10.25"].join(" ") + } + + let(:cost_of_produce_3){ + ["Distributor", "Supplier", "Yes", "oc3", "Cost of produce", "line items", "Supplier", + "100.0", "4.0", "104.0"].join(" ") + } + let(:summary_row_3){ + [ + "TOTAL", # Fees and line items + "145.0", # Tax excl: 20 + 15 + 10 + 100 + "5.81", # Tax : (0.30 + 0.50) + (0.23 + 0.38) + (0.15 + 0.25) + (1.50 + 2.50) + "150.81" # Tax incl: 145.00 + 5.81 + ].join(" ") + } + + # table lines for supplier2 + + let(:coordinator_state_tax_4){ + ["Distributor", "Supplier2", "Yes", "oc3", "Adminstration", "admin", "Distributor", + "tax_category", "State", "0.015", "20.0", "0.3", "20.3"].join(" ") + } + let(:coordinator_country_tax_4){ + ["Distributor", "Supplier2", "Yes", "oc3", "Adminstration", "admin", "Distributor", + "tax_category", "Country", "0.025", "20.0", "0.5", "20.5"].join(" ") + } + + let(:supplier_state_tax_4){ + ["Distributor", "Supplier2", "Yes", "oc3", "Sales", "sales", "Supplier2", + "tax_category", "State", "0.015", "25.0", "0.38", "25.38"].join(" ") + } + let(:supplier_country_tax_4){ + ["Distributor", "Supplier2", "Yes", "oc3", "Sales", "sales", "Supplier2", + "tax_category", "Country", "0.025", "25.0", "0.63", "25.63"].join(" ") + } + + let(:distributor_state_tax_4){ + ["Distributor", "Supplier2", "Yes", "oc3", "Packing", "packing", "Distributor", + "tax_category", "State", "0.015", "10.0", "0.15", "10.15"].join(" ") + } + let(:distributor_country_tax_4){ + ["Distributor", "Supplier2", "Yes", "oc3", "Packing", "packing", "Distributor", + "tax_category", "Country", "0.025", "10.0", "0.25", "10.25"].join(" ") + } + + let(:cost_of_produce_4){ + ["Distributor", "Supplier2", "Yes", "oc3", "Cost of produce", "line items", "Supplier2", + "50.0", "2.0", "52.0"].join(" ") + } + let(:summary_row_4){ + [ + "TOTAL", # Fees and line items + "105.0", # Tax excl: 20 + 25 + 10 + 50 + "4.21", # Tax : (0.30 + 0.50) + (0.38 + 0.63) + (0.15 + 0.25) + 2 + "109.21" # Tax incl: 105 + 4.21 + ].join(" ") + } + + it 'generates the report and displays fees for the respective supplier' do + pending("test case (1), see #10797") + + login_as distributor_owner + visit admin_reports_path + click_on I18n.t("admin.reports.enterprise_fees_with_tax_report_by_producer") + + expect(page).to have_button("Go") + click_on "Go" + expect(page.find("table.report__table thead tr")).to have_content(table_header) + + table = page.find("table.report__table tbody") + expect(table).to have_content(supplier_state_tax_3) + expect(table).to have_content(supplier_country_tax_3) + expect(table).to have_content(distributor_state_tax_3) + expect(table).to have_content(distributor_country_tax_3) + expect(table).to have_content(coordinator_state_tax_3) + expect(table).to have_content(coordinator_country_tax_3) + expect(table).to have_content(cost_of_produce_3) + expect(table).to have_content(summary_row_3) + + expect(table).to have_content(supplier_state_tax_4) + expect(table).to have_content(supplier_country_tax_4) + expect(table).to have_content(distributor_state_tax_4) + expect(table).to have_content(distributor_country_tax_4) + expect(table).to have_content(coordinator_state_tax_4) + expect(table).to have_content(coordinator_country_tax_4) + expect(table).to have_content(cost_of_produce_4) + expect(table).to have_content(summary_row_4) + end + + context "filtering" do + let(:fee_name_selector){ "#s2id_q_enterprise_fee_id_in" } + let(:fee_owner_selector){ "#s2id_q_enterprise_fee_owner_id_in" } + + let(:summary_row_after_filtering_by_fee_name){ + ["TOTAL", "120.0", "4.8", "124.8"].join(" ") + } + + let(:summary_row_after_filtering_by_fee_owner){ + ["TOTAL", "115.0", "4.61", "119.61"].join(" ") + } + + before do + login_as distributor_owner + visit admin_reports_path + click_on I18n.t("admin.reports.enterprise_fees_with_tax_report_by_producer") + end + + it "should filter by distributor and order cycle" do + page.find("#s2id_autogen1").click + find('li', text: distributor.name).click # selects Distributor + + page.find("#s2id_q_order_cycle_id_in").click + find('li', text: order_cycle2.name).click + + expect(page).to have_button("Go") + click_on "Go" + expect(page.find("table.report__table thead tr")).to have_content(table_header) + + table = page.find("table.report__table tbody") + expect(table).to have_content(supplier_state_tax_2) + expect(table).to have_content(supplier_country_tax_2) + expect(table).to have_content(distributor_state_tax_2) + expect(table).to have_content(distributor_country_tax_2) + expect(table).to have_content(coordinator_state_tax_2) + expect(table).to have_content(coordinator_country_tax_2) + expect(table).to have_content(cost_of_produce_2) + expect(table).to have_content(summary_row_2) + end + + it "should filter by producer" do + pending("test case (2), see #10797") + + page.find("#s2id_supplier_id_in").click + find('li', text: supplier2.name).click + + expect(page).to have_button("Go") + click_on "Go" + expect(page.find("table.report__table thead tr")).to have_content(table_header) + + table = page.find("table.report__table tbody") + + expect(table).to have_content(supplier_state_tax_2) + expect(table).to have_content(supplier_country_tax_2) + expect(table).to have_content(distributor_state_tax_2) + expect(table).to have_content(distributor_country_tax_2) + expect(table).to have_content(coordinator_state_tax_2) + expect(table).to have_content(coordinator_country_tax_2) + expect(table).to have_content(cost_of_produce_2) + expect(table).to have_content(summary_row_2) + + expect(table).to_not have_content(supplier_state_tax_1) + expect(table).to_not have_content(supplier_country_tax_1) + expect(table).to_not have_content(distributor_state_tax_1) + expect(table).to_not have_content(distributor_country_tax_1) + expect(table).to_not have_content(coordinator_state_tax_1) + expect(table).to_not have_content(coordinator_country_tax_1) + expect(table).to_not have_content(cost_of_produce_1) + expect(table).to_not have_content(summary_row_1) + end + + it "should filter by fee name" do + page.find(fee_name_selector).click + find('li', text: coordinator_fees.name).click + + expect(page).to have_button("Go") + click_on "Go" + + expect(page.find("table.report__table thead tr")).to have_content(table_header) + + table = page.find("table.report__table tbody") + + expect(table).to_not have_content(supplier_state_tax_1) + expect(table).to_not have_content(supplier_country_tax_1) + expect(table).to_not have_content(distributor_state_tax_1) + expect(table).to_not have_content(distributor_country_tax_1) + expect(table).to have_content(coordinator_state_tax_1) + expect(table).to have_content(coordinator_country_tax_1) + expect(table).to have_content(cost_of_produce_1) + expect(table).to have_content(summary_row_after_filtering_by_fee_name) + end + + it "should filter by fee owner" do + page.find(fee_owner_selector).click + find('li', text: supplier.name).click + + expect(page).to have_button("Go") + click_on "Go" + expect(page.find("table.report__table thead tr")).to have_content(table_header) + + table = page.find("table.report__table tbody") + expect(table).to have_content(supplier_state_tax_1) + expect(table).to have_content(supplier_country_tax_1) + expect(table).to_not have_content(distributor_state_tax_1) + expect(table).to_not have_content(distributor_country_tax_1) + expect(table).to_not have_content(coordinator_state_tax_1) + expect(table).to_not have_content(coordinator_country_tax_1) + expect(table).to have_content(cost_of_produce_1) + expect(table).to have_content(summary_row_after_filtering_by_fee_owner) + end + end end end end From 1b4235eb1daaf4f256d3aeb04bbca09e4972012f Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Fri, 26 May 2023 16:22:15 +0100 Subject: [PATCH 12/46] Extends tests to inclusive tax scenario --- ...ry_fee_with_tax_report_by_producer_spec.rb | 160 +++++++++++++----- 1 file changed, 113 insertions(+), 47 deletions(-) diff --git a/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb b/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb index b05591110b..6d213cc683 100644 --- a/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb +++ b/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb @@ -7,7 +7,8 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do # - coordinator fees price 20 # - incoming exchange fees 15 # - outgoing exchange fees 10 - # - cost of line items 100 + # - cost of line items 100 (supplier 1) + # - cost of line items 50 (supplier 2) # tax # country: 2.5% # state: 1.5% @@ -276,12 +277,13 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do ].join(" ") } - context "with line items from a single supplier (1)" do - it 'generates the report and displays fees for the respective supplier' do + context "with line items from a single supplier" do + it 'generates the report and displays fees for the respective suppliers' do login_as distributor_owner visit admin_reports_path click_on I18n.t("admin.reports.enterprise_fees_with_tax_report_by_producer") expect(page).to have_button("Go") + click_on "Go" expect(page.find("table.report__table thead tr")).to have_content(table_header) @@ -295,20 +297,7 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do expect(table).to have_content(coordinator_country_tax_1) expect(table).to have_content(cost_of_produce_1) expect(table).to have_content(summary_row_1) - end - end - context "with line items from a single supplier (2)" do - it 'generates the report and displays fees for the respective supplier' do - login_as distributor_owner - visit admin_reports_path - click_on I18n.t("admin.reports.enterprise_fees_with_tax_report_by_producer") - - expect(page).to have_button("Go") - click_on "Go" - expect(page.find("table.report__table thead tr")).to have_content(table_header) - - table = page.find("table.report__table tbody") expect(table).to have_content(supplier_state_tax_2) expect(table).to have_content(supplier_country_tax_2) expect(table).to have_content(distributor_state_tax_2) @@ -602,76 +591,153 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do # - incoming exchange (15) 1.5% = 0.23, 2.5% = 0.38 # - outgoing exchange (10) 1.5% = 0.15, 2.5% = 0.25 # - line items (100) 1.5% = 1.50, 2.5% = 2.50 + # - line items (50) 1.5% = 1.50, 2.5% = 2.50 before do state_tax_rate.update!({ included_in_price: true }) country_tax_rate.update!({ included_in_price: true }) + # adds a line items to the order on oc1 order.line_items.create({ variant: variant, quantity: 1, price: 100 }) order.update!({ order_cycle_id: order_cycle.id, ship_address_id: ship_address.id }) + # This will load the enterprise fees from the order cycle. + # This is needed because the order instance was created + # independently of the order_cycle. order.recreate_all_fees! while !order.completed? break unless order.next! end + + # adds a line items to the order on oc2 + order2.line_items.create({ variant: variant2, quantity: 1, price: 50 }) + order2.update!({ + order_cycle_id: order_cycle2.id, + ship_address_id: ship_address.id + }) + # This will load the enterprise fees from the order cycle. + # This is needed because the order instance was created + # independently of the order_cycle. + order2.recreate_all_fees! + while !order2.completed? + break unless order2.next! + end end - let(:coordinator_state_tax){ + let(:coordinator_state_tax_1){ ["Distributor", "Supplier", "Yes", "oc1", "Adminstration", "admin", "Distributor", - "tax_category", "State", "0.015", "19.21", "0.3", "19.51"].join(" ") + "tax_category", "State", "0.015", "19.21", "0.3", "20.0"].join(" ") } - let(:coordinator_country_tax){ + let(:coordinator_country_tax_1){ ["Distributor", "Supplier", "Yes", "oc1", "Adminstration", "admin", "Distributor", - "tax_category", "Country", "0.025", "19.21", "0.49", "19.7"].join(" ") + "tax_category", "Country", "0.025", "19.21", "0.49", "20.0"].join(" ") } - let(:supplier_state_tax){ + let(:supplier_state_tax_1){ ["Distributor", "Supplier", "Yes", "oc1", "Transport", "transport", "Supplier", - "tax_category", "State", "0.015", "14.41", "0.22", "14.63"].join(" ") + "tax_category", "State", "0.015", "14.41", "0.22", "15.0"].join(" ") } - let(:supplier_country_tax){ + let(:supplier_country_tax_1){ ["Distributor", "Supplier", "Yes", "oc1", "Transport", "transport", "Supplier", - "tax_category", "Country", "0.025", "14.41", "0.37", "14.78"].join(" ") + "tax_category", "Country", "0.025", "14.41", "0.37", "15.0"].join(" ") } - let(:distributor_state_tax){ + let(:distributor_state_tax_1){ ["Distributor", "Supplier", "Yes", "oc1", "Packing", "packing", "Distributor", - "tax_category", "State", "0.015", "9.61", "0.15", "9.76"].join(" ") + "tax_category", "State", "0.015", "9.61", "0.15", "10.0"].join(" ") } - let(:distributor_country_tax){ + let(:distributor_country_tax_1){ ["Distributor", "Supplier", "Yes", "oc1", "Packing", "packing", "Distributor", - "tax_category", "Country", "0.025", "9.61", "0.24", "9.85"].join(" ") + "tax_category", "Country", "0.025", "9.61", "0.24", "10.0"].join(" ") } - let(:cost_of_produce){ + let(:cost_of_produce_1){ ["Distributor", "Supplier", "Yes", "oc1", "Cost of produce", "line items", "Supplier", "96.08", "3.92", "100.0"].join(" ") } - let(:summary_row){ - ["TOTAL", "139.31", "5.69", "145.0"].join(" ") + let(:summary_row_1){ + [ + "TOTAL", # Fees and line items + "139.31", # Tax excl: 19.21 + 14.41 + 9.61 + 96.08 + "5.69", # Tax : (0.30 + 0.50) + (0.23 + 0.38) + (0.15 + 0.25) + (1.50 + 2.50) + "145.0" # Tax incl: 20 + 15 + 10 + 100 + ].join(" ") } - it 'generates the report' do - login_as admin - visit admin_reports_path - click_on I18n.t("admin.reports.enterprise_fees_with_tax_report_by_producer") + # for supplier 2, oc2 + let(:coordinator_state_tax_2){ + ["Distributor", "Supplier2", "Yes", "oc2", "Adminstration", "admin", "Distributor", + "tax_category", "State", "0.015", "19.21", "0.3", "20.0"].join(" ") + } + let(:coordinator_country_tax_2){ + ["Distributor", "Supplier2", "Yes", "oc2", "Adminstration", "admin", "Distributor", + "tax_category", "Country", "0.025", "19.21", "0.49", "20.0"].join(" ") + } - expect(page).to have_button("Go") - click_on "Go" + let(:supplier_state_tax_2){ + ["Distributor", "Supplier2", "Yes", "oc2", "Sales", "sales", "Supplier2", + "tax_category", "State", "0.015", "24.02", "0.37", "25.0"].join(" ") + } + let(:supplier_country_tax_2){ + ["Distributor", "Supplier2", "Yes", "oc2", "Sales", "sales", "Supplier2", + "tax_category", "Country", "0.025", "24.02", "0.61", "25.0"].join(" ") + } - expect(page.find("table.report__table thead tr")).to have_content(table_header) + let(:distributor_state_tax_2){ + ["Distributor", "Supplier2", "Yes", "oc2", "Packing", "packing", "Distributor", + "tax_category", "State", "0.015", "9.61", "0.15", "10.0"].join(" ") + } + let(:distributor_country_tax_2){ + ["Distributor", "Supplier2", "Yes", "oc2", "Packing", "packing", "Distributor", + "tax_category", "Country", "0.025", "9.61", "0.24", "10.0"].join(" ") + } - table = page.find("table.report__table tbody") - expect(table).to have_content(supplier_state_tax) - expect(table).to have_content(supplier_country_tax) - expect(table).to have_content(distributor_state_tax) - expect(table).to have_content(distributor_country_tax) - expect(table).to have_content(coordinator_state_tax) - expect(table).to have_content(coordinator_country_tax) - expect(table).to have_content(cost_of_produce) - expect(table).to have_content(summary_row) + let(:cost_of_produce_2){ + ["Distributor", "Supplier2", "Yes", "oc2", "Cost of produce", "line items", "Supplier2", + "48.04", "1.96", "50.0"].join(" ") + } + let(:summary_row_2){ + [ + "TOTAL", # Fees and line items + "100.88", # Tax excl: 19.21 + 24.02 + 9.61 + 48.04 + "4.12", # Tax : (0.30 + 0.50) + (0.38 + 0.63) + (0.15 + 0.25) + 2 + "105.0" # Tax incl: 20 + 25 + 10 + 50 + ].join(" ") + } + + context "with line items from a single supplier" do + it 'generates the report and displays fees for the respective suppliers' do + pending("test case (3), see #10797") + login_as distributor_owner + visit admin_reports_path + click_on I18n.t("admin.reports.enterprise_fees_with_tax_report_by_producer") + expect(page).to have_button("Go") + + click_on "Go" + + expect(page.find("table.report__table thead tr")).to have_content(table_header) + + table = page.find("table.report__table tbody") + expect(table).to have_content(supplier_state_tax_1) + expect(table).to have_content(supplier_country_tax_1) + expect(table).to have_content(distributor_state_tax_1) + expect(table).to have_content(distributor_country_tax_1) + expect(table).to have_content(coordinator_state_tax_1) + expect(table).to have_content(coordinator_country_tax_1) + expect(table).to have_content(cost_of_produce_1) + expect(table).to have_content(summary_row_1) + + expect(table).to have_content(supplier_state_tax_2) + expect(table).to have_content(supplier_country_tax_2) + expect(table).to have_content(distributor_state_tax_2) + expect(table).to have_content(distributor_country_tax_2) + expect(table).to have_content(coordinator_state_tax_2) + expect(table).to have_content(coordinator_country_tax_2) + expect(table).to have_content(cost_of_produce_2) + expect(table).to have_content(summary_row_2) + end end end end From 9837a4fcf2da5ad85e2a0a306011aa170726e977 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Thu, 8 Jun 2023 11:50:04 +0100 Subject: [PATCH 13/46] Removes pending (3) Reverts Included Tax values --- ...ry_fee_with_tax_report_by_producer_spec.rb | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb b/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb index 6d213cc683..7c275d04e4 100644 --- a/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb +++ b/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb @@ -440,7 +440,7 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do } it 'generates the report and displays fees for the respective supplier' do - pending("test case (1), see #10797") + # pending("test case (1), see #10797") login_as distributor_owner visit admin_reports_path @@ -448,6 +448,7 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do expect(page).to have_button("Go") click_on "Go" + expect(page.find("table.report__table thead tr")).to have_content(table_header) table = page.find("table.report__table tbody") @@ -628,29 +629,29 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do let(:coordinator_state_tax_1){ ["Distributor", "Supplier", "Yes", "oc1", "Adminstration", "admin", "Distributor", - "tax_category", "State", "0.015", "19.21", "0.3", "20.0"].join(" ") + "tax_category", "State", "0.015", "19.21", "0.3", "19.51"].join(" ") } let(:coordinator_country_tax_1){ ["Distributor", "Supplier", "Yes", "oc1", "Adminstration", "admin", "Distributor", - "tax_category", "Country", "0.025", "19.21", "0.49", "20.0"].join(" ") + "tax_category", "Country", "0.025", "19.21", "0.49", "19.7"].join(" ") } let(:supplier_state_tax_1){ ["Distributor", "Supplier", "Yes", "oc1", "Transport", "transport", "Supplier", - "tax_category", "State", "0.015", "14.41", "0.22", "15.0"].join(" ") + "tax_category", "State", "0.015", "14.41", "0.22", "14.63"].join(" ") } let(:supplier_country_tax_1){ ["Distributor", "Supplier", "Yes", "oc1", "Transport", "transport", "Supplier", - "tax_category", "Country", "0.025", "14.41", "0.37", "15.0"].join(" ") + "tax_category", "Country", "0.025", "14.41", "0.37", "14.78"].join(" ") } let(:distributor_state_tax_1){ ["Distributor", "Supplier", "Yes", "oc1", "Packing", "packing", "Distributor", - "tax_category", "State", "0.015", "9.61", "0.15", "10.0"].join(" ") + "tax_category", "State", "0.015", "9.61", "0.15", "9.76"].join(" ") } let(:distributor_country_tax_1){ ["Distributor", "Supplier", "Yes", "oc1", "Packing", "packing", "Distributor", - "tax_category", "Country", "0.025", "9.61", "0.24", "10.0"].join(" ") + "tax_category", "Country", "0.025", "9.61", "0.24", "9.85"].join(" ") } let(:cost_of_produce_1){ @@ -669,29 +670,29 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do # for supplier 2, oc2 let(:coordinator_state_tax_2){ ["Distributor", "Supplier2", "Yes", "oc2", "Adminstration", "admin", "Distributor", - "tax_category", "State", "0.015", "19.21", "0.3", "20.0"].join(" ") + "tax_category", "State", "0.015", "19.21", "0.3", "19.51"].join(" ") } let(:coordinator_country_tax_2){ ["Distributor", "Supplier2", "Yes", "oc2", "Adminstration", "admin", "Distributor", - "tax_category", "Country", "0.025", "19.21", "0.49", "20.0"].join(" ") + "tax_category", "Country", "0.025", "19.21", "0.49", "19.7"].join(" ") } let(:supplier_state_tax_2){ ["Distributor", "Supplier2", "Yes", "oc2", "Sales", "sales", "Supplier2", - "tax_category", "State", "0.015", "24.02", "0.37", "25.0"].join(" ") + "tax_category", "State", "0.015", "24.02", "0.37", "24.39"].join(" ") } let(:supplier_country_tax_2){ ["Distributor", "Supplier2", "Yes", "oc2", "Sales", "sales", "Supplier2", - "tax_category", "Country", "0.025", "24.02", "0.61", "25.0"].join(" ") + "tax_category", "Country", "0.025", "24.02", "0.61", "24.63"].join(" ") } let(:distributor_state_tax_2){ ["Distributor", "Supplier2", "Yes", "oc2", "Packing", "packing", "Distributor", - "tax_category", "State", "0.015", "9.61", "0.15", "10.0"].join(" ") + "tax_category", "State", "0.015", "9.61", "0.15", "9.76"].join(" ") } let(:distributor_country_tax_2){ ["Distributor", "Supplier2", "Yes", "oc2", "Packing", "packing", "Distributor", - "tax_category", "Country", "0.025", "9.61", "0.24", "10.0"].join(" ") + "tax_category", "Country", "0.025", "9.61", "0.24", "9.85"].join(" ") } let(:cost_of_produce_2){ @@ -709,7 +710,7 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do context "with line items from a single supplier" do it 'generates the report and displays fees for the respective suppliers' do - pending("test case (3), see #10797") + # pending("test case (3), see #10797") login_as distributor_owner visit admin_reports_path click_on I18n.t("admin.reports.enterprise_fees_with_tax_report_by_producer") From 6dd70d310c9efd62c66f240e54d9e94cd5b75526 Mon Sep 17 00:00:00 2001 From: Mohamed ABDELLANI Date: Fri, 9 Jun 2023 15:14:40 +0100 Subject: [PATCH 14/46] fix the calculation of the cost of produce we want the cost of produce to only include the items produced by the supplier used to group the rows. --- .../enterprise_fees_with_tax_report_by_producer.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb b/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb index f474d72805..f4c40a9a02 100644 --- a/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb +++ b/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb @@ -238,7 +238,11 @@ module Reporting def order_cycle_line_items_row proc do |key, items, _rows| + supplier_id = items.first.first[2] # supplier id used in the grouped line items line_items = items.flat_map(&:last).uniq.map(&:line_items).flatten + .filter do |line_item| + line_item.supplier_id == supplier_id + end producer = producer(items.first) total_excl_tax = line_items_excl_tax(line_items) From 219c581f9a86eba3c17f596d2e33badb0b18219f Mon Sep 17 00:00:00 2001 From: Mohamed ABDELLANI Date: Fri, 9 Jun 2023 15:17:19 +0100 Subject: [PATCH 15/46] remove pending from "should filter by producer" --- .../enterprise_summary_fee_with_tax_report_by_producer_spec.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb b/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb index 7c275d04e4..d9bd6f3e47 100644 --- a/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb +++ b/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb @@ -512,8 +512,6 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do end it "should filter by producer" do - pending("test case (2), see #10797") - page.find("#s2id_supplier_id_in").click find('li', text: supplier2.name).click From 44e8d2d73598a9414470e7301b21dd08f9911045 Mon Sep 17 00:00:00 2001 From: Mohamed ABDELLANI Date: Fri, 9 Jun 2023 15:52:02 +0100 Subject: [PATCH 16/46] fix pending lint issues --- .rubocop_todo.yml | 1 + ...ry_fee_with_tax_report_by_producer_spec.rb | 274 +++++++++--------- 2 files changed, 139 insertions(+), 136 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 1b76712f4b..3076bddba9 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -176,6 +176,7 @@ Metrics/BlockLength: - 'spec/support/cancan_helper.rb' - 'spec/support/matchers/select2_matchers.rb' - 'spec/support/matchers/table_matchers.rb' + - 'spec/swagger_helper.rb' - 'spec/system/consumer/shopping/checkout_spec.rb' - 'spec/system/consumer/shopping/checkout_stripe_spec.rb' - 'spec/system/consumer/shopping/variant_overrides_spec.rb' diff --git a/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb b/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb index d9bd6f3e47..ec15d22e82 100644 --- a/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb +++ b/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb @@ -196,38 +196,38 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do describe "orders" do # for supplier 1, oc1 - let(:coordinator_state_tax_1){ + let(:coordinator_state_tax1){ ["Distributor", "Supplier", "Yes", "oc1", "Adminstration", "admin", "Distributor", "tax_category", "State", "0.015", "20.0", "0.3", "20.3"].join(" ") } - let(:coordinator_country_tax_1){ + let(:coordinator_country_tax1){ ["Distributor", "Supplier", "Yes", "oc1", "Adminstration", "admin", "Distributor", "tax_category", "Country", "0.025", "20.0", "0.5", "20.5"].join(" ") } - let(:supplier_state_tax_1){ + let(:supplier_state_tax1){ ["Distributor", "Supplier", "Yes", "oc1", "Transport", "transport", "Supplier", "tax_category", "State", "0.015", "15.0", "0.23", "15.23"].join(" ") } - let(:supplier_country_tax_1){ + let(:supplier_country_tax1){ ["Distributor", "Supplier", "Yes", "oc1", "Transport", "transport", "Supplier", "tax_category", "Country", "0.025", "15.0", "0.38", "15.38"].join(" ") } - let(:distributor_state_tax_1){ + let(:distributor_state_tax1){ ["Distributor", "Supplier", "Yes", "oc1", "Packing", "packing", "Distributor", "tax_category", "State", "0.015", "10.0", "0.15", "10.15"].join(" ") } - let(:distributor_country_tax_1){ + let(:distributor_country_tax1){ ["Distributor", "Supplier", "Yes", "oc1", "Packing", "packing", "Distributor", "tax_category", "Country", "0.025", "10.0", "0.25", "10.25"].join(" ") } - let(:cost_of_produce_1){ + let(:cost_of_produce1){ ["Distributor", "Supplier", "Yes", "oc1", "Cost of produce", "line items", "Supplier", "100.0", "4.0", "104.0"].join(" ") } - let(:summary_row_1){ + let(:summary_row1){ [ "TOTAL", # Fees and line items "145.0", # Tax excl: 20 + 15 + 10 + 100 @@ -237,38 +237,38 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do } # for supplier 2, oc2 - let(:coordinator_state_tax_2){ + let(:coordinator_state_tax2){ ["Distributor", "Supplier2", "Yes", "oc2", "Adminstration", "admin", "Distributor", "tax_category", "State", "0.015", "20.0", "0.3", "20.3"].join(" ") } - let(:coordinator_country_tax_2){ + let(:coordinator_country_tax2){ ["Distributor", "Supplier2", "Yes", "oc2", "Adminstration", "admin", "Distributor", "tax_category", "Country", "0.025", "20.0", "0.5", "20.5"].join(" ") } - let(:supplier_state_tax_2){ + let(:supplier_state_tax2){ ["Distributor", "Supplier2", "Yes", "oc2", "Sales", "sales", "Supplier2", "tax_category", "State", "0.015", "25.0", "0.38", "25.38"].join(" ") } - let(:supplier_country_tax_2){ + let(:supplier_country_tax2){ ["Distributor", "Supplier2", "Yes", "oc2", "Sales", "sales", "Supplier2", "tax_category", "Country", "0.025", "25.0", "0.63", "25.63"].join(" ") } - let(:distributor_state_tax_2){ + let(:distributor_state_tax2){ ["Distributor", "Supplier2", "Yes", "oc2", "Packing", "packing", "Distributor", "tax_category", "State", "0.015", "10.0", "0.15", "10.15"].join(" ") } - let(:distributor_country_tax_2){ + let(:distributor_country_tax2){ ["Distributor", "Supplier2", "Yes", "oc2", "Packing", "packing", "Distributor", "tax_category", "Country", "0.025", "10.0", "0.25", "10.25"].join(" ") } - let(:cost_of_produce_2){ + let(:cost_of_produce2){ ["Distributor", "Supplier2", "Yes", "oc2", "Cost of produce", "line items", "Supplier2", "50.0", "2.0", "52.0"].join(" ") } - let(:summary_row_2){ + let(:summary_row2){ [ "TOTAL", # Fees and line items "105.0", # Tax excl: 20 + 25 + 10 + 50 @@ -289,23 +289,23 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do expect(page.find("table.report__table thead tr")).to have_content(table_header) table = page.find("table.report__table tbody") - expect(table).to have_content(supplier_state_tax_1) - expect(table).to have_content(supplier_country_tax_1) - expect(table).to have_content(distributor_state_tax_1) - expect(table).to have_content(distributor_country_tax_1) - expect(table).to have_content(coordinator_state_tax_1) - expect(table).to have_content(coordinator_country_tax_1) - expect(table).to have_content(cost_of_produce_1) - expect(table).to have_content(summary_row_1) + expect(table).to have_content(supplier_state_tax1) + expect(table).to have_content(supplier_country_tax1) + expect(table).to have_content(distributor_state_tax1) + expect(table).to have_content(distributor_country_tax1) + expect(table).to have_content(coordinator_state_tax1) + expect(table).to have_content(coordinator_country_tax1) + expect(table).to have_content(cost_of_produce1) + expect(table).to have_content(summary_row1) - expect(table).to have_content(supplier_state_tax_2) - expect(table).to have_content(supplier_country_tax_2) - expect(table).to have_content(distributor_state_tax_2) - expect(table).to have_content(distributor_country_tax_2) - expect(table).to have_content(coordinator_state_tax_2) - expect(table).to have_content(coordinator_country_tax_2) - expect(table).to have_content(cost_of_produce_2) - expect(table).to have_content(summary_row_2) + expect(table).to have_content(supplier_state_tax2) + expect(table).to have_content(supplier_country_tax2) + expect(table).to have_content(distributor_state_tax2) + expect(table).to have_content(distributor_country_tax2) + expect(table).to have_content(coordinator_state_tax2) + expect(table).to have_content(coordinator_country_tax2) + expect(table).to have_content(cost_of_produce2) + expect(table).to have_content(summary_row2) end end @@ -333,9 +333,11 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do order_cycle3.coordinator_fees << coordinator_fees order_cycle3.exchanges.incoming.first.exchange_fees.create!(enterprise_fee: supplier_fees) order_cycle3.exchanges.incoming.first.exchange_variants.create!(variant: variant) - order_cycle3.exchanges.incoming.second.exchange_fees.create!(enterprise_fee: supplier_fees2) + order_cycle3.exchanges.incoming.second.exchange_fees + .create!(enterprise_fee: supplier_fees2) order_cycle3.exchanges.incoming.second.exchange_variants.create!(variant: variant2) - order_cycle3.exchanges.outgoing.first.exchange_fees.create!(enterprise_fee: distributor_fee) + order_cycle3.exchanges.outgoing.first.exchange_fees + .create!(enterprise_fee: distributor_fee) order_cycle3.exchanges.outgoing.first.exchange_variants.create!(variant: variant) order_cycle3.exchanges.outgoing.first.exchange_variants.create!(variant: variant2) @@ -357,38 +359,38 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do # table lines for supplier1 - let(:coordinator_state_tax_3){ + let(:coordinator_state_tax3){ ["Distributor", "Supplier", "Yes", "oc3", "Adminstration", "admin", "Distributor", "tax_category", "State", "0.015", "20.0", "0.3", "20.3"].join(" ") } - let(:coordinator_country_tax_3){ + let(:coordinator_country_tax3){ ["Distributor", "Supplier", "Yes", "oc3", "Adminstration", "admin", "Distributor", "tax_category", "Country", "0.025", "20.0", "0.5", "20.5"].join(" ") } - let(:supplier_state_tax_3){ + let(:supplier_state_tax3){ ["Distributor", "Supplier", "Yes", "oc3", "Transport", "transport", "Supplier", "tax_category", "State", "0.015", "15.0", "0.23", "15.23"].join(" ") } - let(:supplier_country_tax_3){ + let(:supplier_country_tax3){ ["Distributor", "Supplier", "Yes", "oc3", "Transport", "transport", "Supplier", "tax_category", "Country", "0.025", "15.0", "0.38", "15.38"].join(" ") } - let(:distributor_state_tax_3){ + let(:distributor_state_tax3){ ["Distributor", "Supplier", "Yes", "oc3", "Packing", "packing", "Distributor", "tax_category", "State", "0.015", "10.0", "0.15", "10.15"].join(" ") } - let(:distributor_country_tax_3){ + let(:distributor_country_tax3){ ["Distributor", "Supplier", "Yes", "oc3", "Packing", "packing", "Distributor", "tax_category", "Country", "0.025", "10.0", "0.25", "10.25"].join(" ") } - let(:cost_of_produce_3){ + let(:cost_of_produce3){ ["Distributor", "Supplier", "Yes", "oc3", "Cost of produce", "line items", "Supplier", "100.0", "4.0", "104.0"].join(" ") } - let(:summary_row_3){ + let(:summary_row3){ [ "TOTAL", # Fees and line items "145.0", # Tax excl: 20 + 15 + 10 + 100 @@ -399,38 +401,38 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do # table lines for supplier2 - let(:coordinator_state_tax_4){ + let(:coordinator_state_tax4){ ["Distributor", "Supplier2", "Yes", "oc3", "Adminstration", "admin", "Distributor", "tax_category", "State", "0.015", "20.0", "0.3", "20.3"].join(" ") } - let(:coordinator_country_tax_4){ + let(:coordinator_country_tax4){ ["Distributor", "Supplier2", "Yes", "oc3", "Adminstration", "admin", "Distributor", "tax_category", "Country", "0.025", "20.0", "0.5", "20.5"].join(" ") } - let(:supplier_state_tax_4){ + let(:supplier_state_tax4){ ["Distributor", "Supplier2", "Yes", "oc3", "Sales", "sales", "Supplier2", "tax_category", "State", "0.015", "25.0", "0.38", "25.38"].join(" ") } - let(:supplier_country_tax_4){ + let(:supplier_country_tax4){ ["Distributor", "Supplier2", "Yes", "oc3", "Sales", "sales", "Supplier2", "tax_category", "Country", "0.025", "25.0", "0.63", "25.63"].join(" ") } - let(:distributor_state_tax_4){ + let(:distributor_state_tax4){ ["Distributor", "Supplier2", "Yes", "oc3", "Packing", "packing", "Distributor", "tax_category", "State", "0.015", "10.0", "0.15", "10.15"].join(" ") } - let(:distributor_country_tax_4){ + let(:distributor_country_tax4){ ["Distributor", "Supplier2", "Yes", "oc3", "Packing", "packing", "Distributor", "tax_category", "Country", "0.025", "10.0", "0.25", "10.25"].join(" ") } - let(:cost_of_produce_4){ + let(:cost_of_produce4){ ["Distributor", "Supplier2", "Yes", "oc3", "Cost of produce", "line items", "Supplier2", "50.0", "2.0", "52.0"].join(" ") } - let(:summary_row_4){ + let(:summary_row4){ [ "TOTAL", # Fees and line items "105.0", # Tax excl: 20 + 25 + 10 + 50 @@ -452,23 +454,23 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do expect(page.find("table.report__table thead tr")).to have_content(table_header) table = page.find("table.report__table tbody") - expect(table).to have_content(supplier_state_tax_3) - expect(table).to have_content(supplier_country_tax_3) - expect(table).to have_content(distributor_state_tax_3) - expect(table).to have_content(distributor_country_tax_3) - expect(table).to have_content(coordinator_state_tax_3) - expect(table).to have_content(coordinator_country_tax_3) - expect(table).to have_content(cost_of_produce_3) - expect(table).to have_content(summary_row_3) + expect(table).to have_content(supplier_state_tax3) + expect(table).to have_content(supplier_country_tax3) + expect(table).to have_content(distributor_state_tax3) + expect(table).to have_content(distributor_country_tax3) + expect(table).to have_content(coordinator_state_tax3) + expect(table).to have_content(coordinator_country_tax3) + expect(table).to have_content(cost_of_produce3) + expect(table).to have_content(summary_row3) - expect(table).to have_content(supplier_state_tax_4) - expect(table).to have_content(supplier_country_tax_4) - expect(table).to have_content(distributor_state_tax_4) - expect(table).to have_content(distributor_country_tax_4) - expect(table).to have_content(coordinator_state_tax_4) - expect(table).to have_content(coordinator_country_tax_4) - expect(table).to have_content(cost_of_produce_4) - expect(table).to have_content(summary_row_4) + expect(table).to have_content(supplier_state_tax4) + expect(table).to have_content(supplier_country_tax4) + expect(table).to have_content(distributor_state_tax4) + expect(table).to have_content(distributor_country_tax4) + expect(table).to have_content(coordinator_state_tax4) + expect(table).to have_content(coordinator_country_tax4) + expect(table).to have_content(cost_of_produce4) + expect(table).to have_content(summary_row4) end context "filtering" do @@ -501,14 +503,14 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do expect(page.find("table.report__table thead tr")).to have_content(table_header) table = page.find("table.report__table tbody") - expect(table).to have_content(supplier_state_tax_2) - expect(table).to have_content(supplier_country_tax_2) - expect(table).to have_content(distributor_state_tax_2) - expect(table).to have_content(distributor_country_tax_2) - expect(table).to have_content(coordinator_state_tax_2) - expect(table).to have_content(coordinator_country_tax_2) - expect(table).to have_content(cost_of_produce_2) - expect(table).to have_content(summary_row_2) + expect(table).to have_content(supplier_state_tax2) + expect(table).to have_content(supplier_country_tax2) + expect(table).to have_content(distributor_state_tax2) + expect(table).to have_content(distributor_country_tax2) + expect(table).to have_content(coordinator_state_tax2) + expect(table).to have_content(coordinator_country_tax2) + expect(table).to have_content(cost_of_produce2) + expect(table).to have_content(summary_row2) end it "should filter by producer" do @@ -521,23 +523,23 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do table = page.find("table.report__table tbody") - expect(table).to have_content(supplier_state_tax_2) - expect(table).to have_content(supplier_country_tax_2) - expect(table).to have_content(distributor_state_tax_2) - expect(table).to have_content(distributor_country_tax_2) - expect(table).to have_content(coordinator_state_tax_2) - expect(table).to have_content(coordinator_country_tax_2) - expect(table).to have_content(cost_of_produce_2) - expect(table).to have_content(summary_row_2) + expect(table).to have_content(supplier_state_tax2) + expect(table).to have_content(supplier_country_tax2) + expect(table).to have_content(distributor_state_tax2) + expect(table).to have_content(distributor_country_tax2) + expect(table).to have_content(coordinator_state_tax2) + expect(table).to have_content(coordinator_country_tax2) + expect(table).to have_content(cost_of_produce2) + expect(table).to have_content(summary_row2) - expect(table).to_not have_content(supplier_state_tax_1) - expect(table).to_not have_content(supplier_country_tax_1) - expect(table).to_not have_content(distributor_state_tax_1) - expect(table).to_not have_content(distributor_country_tax_1) - expect(table).to_not have_content(coordinator_state_tax_1) - expect(table).to_not have_content(coordinator_country_tax_1) - expect(table).to_not have_content(cost_of_produce_1) - expect(table).to_not have_content(summary_row_1) + expect(table).to_not have_content(supplier_state_tax1) + expect(table).to_not have_content(supplier_country_tax1) + expect(table).to_not have_content(distributor_state_tax1) + expect(table).to_not have_content(distributor_country_tax1) + expect(table).to_not have_content(coordinator_state_tax1) + expect(table).to_not have_content(coordinator_country_tax1) + expect(table).to_not have_content(cost_of_produce1) + expect(table).to_not have_content(summary_row1) end it "should filter by fee name" do @@ -551,13 +553,13 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do table = page.find("table.report__table tbody") - expect(table).to_not have_content(supplier_state_tax_1) - expect(table).to_not have_content(supplier_country_tax_1) - expect(table).to_not have_content(distributor_state_tax_1) - expect(table).to_not have_content(distributor_country_tax_1) - expect(table).to have_content(coordinator_state_tax_1) - expect(table).to have_content(coordinator_country_tax_1) - expect(table).to have_content(cost_of_produce_1) + expect(table).to_not have_content(supplier_state_tax1) + expect(table).to_not have_content(supplier_country_tax1) + expect(table).to_not have_content(distributor_state_tax1) + expect(table).to_not have_content(distributor_country_tax1) + expect(table).to have_content(coordinator_state_tax1) + expect(table).to have_content(coordinator_country_tax1) + expect(table).to have_content(cost_of_produce1) expect(table).to have_content(summary_row_after_filtering_by_fee_name) end @@ -570,13 +572,13 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do expect(page.find("table.report__table thead tr")).to have_content(table_header) table = page.find("table.report__table tbody") - expect(table).to have_content(supplier_state_tax_1) - expect(table).to have_content(supplier_country_tax_1) - expect(table).to_not have_content(distributor_state_tax_1) - expect(table).to_not have_content(distributor_country_tax_1) - expect(table).to_not have_content(coordinator_state_tax_1) - expect(table).to_not have_content(coordinator_country_tax_1) - expect(table).to have_content(cost_of_produce_1) + expect(table).to have_content(supplier_state_tax1) + expect(table).to have_content(supplier_country_tax1) + expect(table).to_not have_content(distributor_state_tax1) + expect(table).to_not have_content(distributor_country_tax1) + expect(table).to_not have_content(coordinator_state_tax1) + expect(table).to_not have_content(coordinator_country_tax1) + expect(table).to have_content(cost_of_produce1) expect(table).to have_content(summary_row_after_filtering_by_fee_owner) end end @@ -625,38 +627,38 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do end end - let(:coordinator_state_tax_1){ + let(:coordinator_state_tax1){ ["Distributor", "Supplier", "Yes", "oc1", "Adminstration", "admin", "Distributor", "tax_category", "State", "0.015", "19.21", "0.3", "19.51"].join(" ") } - let(:coordinator_country_tax_1){ + let(:coordinator_country_tax1){ ["Distributor", "Supplier", "Yes", "oc1", "Adminstration", "admin", "Distributor", "tax_category", "Country", "0.025", "19.21", "0.49", "19.7"].join(" ") } - let(:supplier_state_tax_1){ + let(:supplier_state_tax1){ ["Distributor", "Supplier", "Yes", "oc1", "Transport", "transport", "Supplier", "tax_category", "State", "0.015", "14.41", "0.22", "14.63"].join(" ") } - let(:supplier_country_tax_1){ + let(:supplier_country_tax1){ ["Distributor", "Supplier", "Yes", "oc1", "Transport", "transport", "Supplier", "tax_category", "Country", "0.025", "14.41", "0.37", "14.78"].join(" ") } - let(:distributor_state_tax_1){ + let(:distributor_state_tax1){ ["Distributor", "Supplier", "Yes", "oc1", "Packing", "packing", "Distributor", "tax_category", "State", "0.015", "9.61", "0.15", "9.76"].join(" ") } - let(:distributor_country_tax_1){ + let(:distributor_country_tax1){ ["Distributor", "Supplier", "Yes", "oc1", "Packing", "packing", "Distributor", "tax_category", "Country", "0.025", "9.61", "0.24", "9.85"].join(" ") } - let(:cost_of_produce_1){ + let(:cost_of_produce1){ ["Distributor", "Supplier", "Yes", "oc1", "Cost of produce", "line items", "Supplier", "96.08", "3.92", "100.0"].join(" ") } - let(:summary_row_1){ + let(:summary_row1){ [ "TOTAL", # Fees and line items "139.31", # Tax excl: 19.21 + 14.41 + 9.61 + 96.08 @@ -666,38 +668,38 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do } # for supplier 2, oc2 - let(:coordinator_state_tax_2){ + let(:coordinator_state_tax2){ ["Distributor", "Supplier2", "Yes", "oc2", "Adminstration", "admin", "Distributor", "tax_category", "State", "0.015", "19.21", "0.3", "19.51"].join(" ") } - let(:coordinator_country_tax_2){ + let(:coordinator_country_tax2){ ["Distributor", "Supplier2", "Yes", "oc2", "Adminstration", "admin", "Distributor", "tax_category", "Country", "0.025", "19.21", "0.49", "19.7"].join(" ") } - let(:supplier_state_tax_2){ + let(:supplier_state_tax2){ ["Distributor", "Supplier2", "Yes", "oc2", "Sales", "sales", "Supplier2", "tax_category", "State", "0.015", "24.02", "0.37", "24.39"].join(" ") } - let(:supplier_country_tax_2){ + let(:supplier_country_tax2){ ["Distributor", "Supplier2", "Yes", "oc2", "Sales", "sales", "Supplier2", "tax_category", "Country", "0.025", "24.02", "0.61", "24.63"].join(" ") } - let(:distributor_state_tax_2){ + let(:distributor_state_tax2){ ["Distributor", "Supplier2", "Yes", "oc2", "Packing", "packing", "Distributor", "tax_category", "State", "0.015", "9.61", "0.15", "9.76"].join(" ") } - let(:distributor_country_tax_2){ + let(:distributor_country_tax2){ ["Distributor", "Supplier2", "Yes", "oc2", "Packing", "packing", "Distributor", "tax_category", "Country", "0.025", "9.61", "0.24", "9.85"].join(" ") } - let(:cost_of_produce_2){ + let(:cost_of_produce2){ ["Distributor", "Supplier2", "Yes", "oc2", "Cost of produce", "line items", "Supplier2", "48.04", "1.96", "50.0"].join(" ") } - let(:summary_row_2){ + let(:summary_row2){ [ "TOTAL", # Fees and line items "100.88", # Tax excl: 19.21 + 24.02 + 9.61 + 48.04 @@ -719,23 +721,23 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do expect(page.find("table.report__table thead tr")).to have_content(table_header) table = page.find("table.report__table tbody") - expect(table).to have_content(supplier_state_tax_1) - expect(table).to have_content(supplier_country_tax_1) - expect(table).to have_content(distributor_state_tax_1) - expect(table).to have_content(distributor_country_tax_1) - expect(table).to have_content(coordinator_state_tax_1) - expect(table).to have_content(coordinator_country_tax_1) - expect(table).to have_content(cost_of_produce_1) - expect(table).to have_content(summary_row_1) + expect(table).to have_content(supplier_state_tax1) + expect(table).to have_content(supplier_country_tax1) + expect(table).to have_content(distributor_state_tax1) + expect(table).to have_content(distributor_country_tax1) + expect(table).to have_content(coordinator_state_tax1) + expect(table).to have_content(coordinator_country_tax1) + expect(table).to have_content(cost_of_produce1) + expect(table).to have_content(summary_row1) - expect(table).to have_content(supplier_state_tax_2) - expect(table).to have_content(supplier_country_tax_2) - expect(table).to have_content(distributor_state_tax_2) - expect(table).to have_content(distributor_country_tax_2) - expect(table).to have_content(coordinator_state_tax_2) - expect(table).to have_content(coordinator_country_tax_2) - expect(table).to have_content(cost_of_produce_2) - expect(table).to have_content(summary_row_2) + expect(table).to have_content(supplier_state_tax2) + expect(table).to have_content(supplier_country_tax2) + expect(table).to have_content(distributor_state_tax2) + expect(table).to have_content(distributor_country_tax2) + expect(table).to have_content(coordinator_state_tax2) + expect(table).to have_content(coordinator_country_tax2) + expect(table).to have_content(cost_of_produce2) + expect(table).to have_content(summary_row2) end end end From 080e81e0fe35810f3bd93fe5f281196c87b53ab1 Mon Sep 17 00:00:00 2001 From: Mohamed ABDELLANI Date: Wed, 14 Jun 2023 06:06:55 +0100 Subject: [PATCH 17/46] optimize join_supplier --- ...nterprise_fees_with_tax_report_by_producer.rb | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb b/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb index f4c40a9a02..abca741d6e 100644 --- a/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb +++ b/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb @@ -124,23 +124,21 @@ module Reporting def join_supplier proc do |item| order = item[:order] - + enterprise_fees_per_variant = enterprise_fees_per_variant(order) filtered_line_items(order) + .filter do |line_item| + item[:enterprise_fee_id].in?( + enterprise_fees_per_variant[line_item.variant] + ) + end .map do |line_item| { tax_rate_id: item[:tax_rate_id], - enterprise_fee_id: if item[:enterprise_fee_id].in?( - enterprise_fees_per_variant(order)[line_item.variant] - ) - item[:enterprise_fee_id] - end, + enterprise_fee_id: item[:enterprise_fee_id], supplier_id: line_item.supplier.id, order: order } end - .filter do |hash| - hash[:enterprise_fee_id].present? - end end end From e43661fd3c723f4a4b8754adfad3a10ee0dd7ee7 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Wed, 14 Jun 2023 12:20:54 +0100 Subject: [PATCH 18/46] Adds/corrects comments around Added tax section --- ...terprise_summary_fee_with_tax_report_by_producer_spec.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb b/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb index ec15d22e82..4d18fc4cf6 100644 --- a/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb +++ b/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb @@ -159,7 +159,8 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do context 'added tax' do # 1 order cycle has: # - coordinator fees (20) 1.5% = 0.30, 2.5% = 0.50 - # - incoming exchange (15) 1.5% = 0.38, 2.5% = 0.63 + # 1st - incoming exchange (15) 1.5% = 0.23, 2.5% = 0.38 + # 2nd - incoming exchange (25) 1.5% = 0.38, 2.5% = 0.63 # - outgoing exchange (10) 1.5% = 0.15, 2.5% = 0.25 # - line items (50) 1.5% = 0.75, 2.5% = 1.25 @@ -272,7 +273,8 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do [ "TOTAL", # Fees and line items "105.0", # Tax excl: 20 + 25 + 10 + 50 - "4.21", # Tax : (0.30 + 0.50) + (0.38 + 0.63) + (0.15 + 0.25) + 2 + "4.21", # Tax : (0.30 + 0.50) + (0.38 + 0.63) + (0.15 + 0.25) + (0.75 + 1.25) + "109.21" # Tax incl: 105 + 4.21 ].join(" ") } From 019c7b3e710716bdac2d9b06556088ed9dfc9805 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Wed, 14 Jun 2023 13:57:26 +0100 Subject: [PATCH 19/46] Splits filtering tests between orders Sets pending test case for orders with more than one supplier --- ...ry_fee_with_tax_report_by_producer_spec.rb | 93 +++++++++++-------- 1 file changed, 52 insertions(+), 41 deletions(-) diff --git a/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb b/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb index 4d18fc4cf6..e6cc9d7749 100644 --- a/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb +++ b/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb @@ -309,6 +309,37 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do expect(table).to have_content(cost_of_produce2) expect(table).to have_content(summary_row2) end + + context "filtering" do + before do + login_as distributor_owner + visit admin_reports_path + click_on I18n.t("admin.reports.enterprise_fees_with_tax_report_by_producer") + end + + it "should filter by distributor and order cycle" do + page.find("#s2id_autogen1").click + find('li', text: distributor.name).click # selects Distributor + + page.find("#s2id_q_order_cycle_id_in").click + find('li', text: order_cycle.name).click + + expect(page).to have_button("Go") + click_on "Go" + expect(page.find("table.report__table thead tr")).to have_content(table_header) + + table = page.find("table.report__table tbody") + + expect(table).to have_content(supplier_state_tax1) + expect(table).to have_content(supplier_country_tax1) + expect(table).to have_content(distributor_state_tax1) + expect(table).to have_content(distributor_country_tax1) + expect(table).to have_content(coordinator_state_tax1) + expect(table).to have_content(coordinator_country_tax1) + expect(table).to have_content(cost_of_produce1) + expect(table).to have_content(summary_row1) + end + end end context "with line items from several suppliers" do @@ -443,38 +474,6 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do ].join(" ") } - it 'generates the report and displays fees for the respective supplier' do - # pending("test case (1), see #10797") - - login_as distributor_owner - visit admin_reports_path - click_on I18n.t("admin.reports.enterprise_fees_with_tax_report_by_producer") - - expect(page).to have_button("Go") - click_on "Go" - - expect(page.find("table.report__table thead tr")).to have_content(table_header) - - table = page.find("table.report__table tbody") - expect(table).to have_content(supplier_state_tax3) - expect(table).to have_content(supplier_country_tax3) - expect(table).to have_content(distributor_state_tax3) - expect(table).to have_content(distributor_country_tax3) - expect(table).to have_content(coordinator_state_tax3) - expect(table).to have_content(coordinator_country_tax3) - expect(table).to have_content(cost_of_produce3) - expect(table).to have_content(summary_row3) - - expect(table).to have_content(supplier_state_tax4) - expect(table).to have_content(supplier_country_tax4) - expect(table).to have_content(distributor_state_tax4) - expect(table).to have_content(distributor_country_tax4) - expect(table).to have_content(coordinator_state_tax4) - expect(table).to have_content(coordinator_country_tax4) - expect(table).to have_content(cost_of_produce4) - expect(table).to have_content(summary_row4) - end - context "filtering" do let(:fee_name_selector){ "#s2id_q_enterprise_fee_id_in" } let(:fee_owner_selector){ "#s2id_q_enterprise_fee_owner_id_in" } @@ -494,25 +493,37 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do end it "should filter by distributor and order cycle" do + pending("incorrect totals for orders with more than one supplier") + page.find("#s2id_autogen1").click find('li', text: distributor.name).click # selects Distributor page.find("#s2id_q_order_cycle_id_in").click - find('li', text: order_cycle2.name).click + find('li', text: order_cycle3.name).click expect(page).to have_button("Go") click_on "Go" expect(page.find("table.report__table thead tr")).to have_content(table_header) table = page.find("table.report__table tbody") - expect(table).to have_content(supplier_state_tax2) - expect(table).to have_content(supplier_country_tax2) - expect(table).to have_content(distributor_state_tax2) - expect(table).to have_content(distributor_country_tax2) - expect(table).to have_content(coordinator_state_tax2) - expect(table).to have_content(coordinator_country_tax2) - expect(table).to have_content(cost_of_produce2) - expect(table).to have_content(summary_row2) + + expect(table).to have_content(supplier_state_tax3) + expect(table).to have_content(supplier_country_tax3) + expect(table).to have_content(distributor_state_tax3) + expect(table).to have_content(distributor_country_tax3) + expect(table).to have_content(coordinator_state_tax3) + expect(table).to have_content(coordinator_country_tax3) + expect(table).to have_content(cost_of_produce3) + expect(table).to have_content(summary_row3) + + expect(table).to have_content(supplier_state_tax4) + expect(table).to have_content(supplier_country_tax4) + expect(table).to have_content(distributor_state_tax4) + expect(table).to have_content(distributor_country_tax4) + expect(table).to have_content(coordinator_state_tax4) + expect(table).to have_content(coordinator_country_tax4) + expect(table).to have_content(cost_of_produce4) + expect(table).to have_content(summary_row4) end it "should filter by producer" do From 93cca56e6888494387a919e3e4adf8b5b5a559e5 Mon Sep 17 00:00:00 2001 From: David Cook Date: Wed, 28 Jun 2023 16:22:57 +1000 Subject: [PATCH 20/46] Style/HashSyntax --- ...rprise_fees_with_tax_report_by_producer.rb | 22 +++++----- ...ry_fee_with_tax_report_by_producer_spec.rb | 42 +++++++++---------- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb b/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb index abca741d6e..9fa638f208 100644 --- a/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb +++ b/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb @@ -7,7 +7,7 @@ module Reporting attr_accessor :permissions def initialize(user, params = {}, render: false) - super(user, params, render: render) + super(user, params, render:) @permissions = Permissions.new(user) end @@ -93,9 +93,9 @@ module Reporting .pluck("originator_id", 'array_agg(id)') .map do |enterprise_fee_id, enterprise_fee_adjustment_ids| { - enterprise_fee_id: enterprise_fee_id, - enterprise_fee_adjustment_ids: enterprise_fee_adjustment_ids, - order: order + enterprise_fee_id:, + enterprise_fee_adjustment_ids:, + order: } end end @@ -111,7 +111,7 @@ module Reporting tax_rate_ids << nil if tax_rate_ids.empty? tax_rate_ids.map do |tax_rate_id| { - tax_rate_id: tax_rate_id, + tax_rate_id:, enterprise_fee_id: item[:enterprise_fee_id], order: item[:order], } @@ -136,7 +136,7 @@ module Reporting tax_rate_id: item[:tax_rate_id], enterprise_fee_id: item[:enterprise_fee_id], supplier_id: line_item.supplier.id, - order: order + order: } end end @@ -227,8 +227,8 @@ module Reporting total_excl_tax = total_fees_excl_tax(order_ids) + line_items_excl_tax(line_items) tax = tax_for_order_ids(order_ids) + tax_for_line_items(line_items) { - total_excl_tax: total_excl_tax, - tax: tax, + total_excl_tax:, + tax:, total_incl_tax: total_excl_tax + tax } end @@ -247,14 +247,14 @@ module Reporting tax = tax_for_line_items(line_items) { distributor: distributor(items.first), - producer: producer, + producer:, producer_tax_status: producer_tax_status(items.first), order_cycle: key, enterprise_fee_name: I18n.t('report_line_cost_of_produce'), enterprise_fee_type: I18n.t('report_line_line_items'), enterprise_fee_owner: producer, - total_excl_tax: total_excl_tax, - tax: tax, + total_excl_tax:, + tax:, total_incl_tax: total_excl_tax + tax, } end diff --git a/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb b/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb index e6cc9d7749..71cc1e2c51 100644 --- a/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb +++ b/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb @@ -23,11 +23,11 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do let!(:country_zone){ create(:zone_with_member) } let!(:tax_category){ create(:tax_category, name: 'tax_category') } let!(:state_tax_rate){ - create(:tax_rate, zone: state_zone, tax_category: tax_category, + create(:tax_rate, zone: state_zone, tax_category:, name: 'State', amount: 0.015) } let!(:country_tax_rate){ - create(:tax_rate, zone: country_zone, tax_category: tax_category, + create(:tax_rate, zone: country_zone, tax_category:, name: 'Country', amount: 0.025) } let!(:ship_address){ create(:ship_address) } @@ -42,10 +42,10 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do create(:supplier_enterprise, name: 'Supplier2', charges_sales_tax: true, owner_id: supplier2_owner.id) } - let!(:product){ create(:simple_product, supplier: supplier ) } + let!(:product){ create(:simple_product, supplier: ) } let!(:product2){ create(:simple_product, supplier: supplier2 ) } - let!(:variant){ create(:variant, product_id: product.id, tax_category: tax_category) } - let!(:variant2){ create(:variant, product_id: product2.id, tax_category: tax_category) } + let!(:variant){ create(:variant, product_id: product.id, tax_category:) } + let!(:variant2){ create(:variant, product_id: product2.id, tax_category:) } let!(:distributor_owner) { create(:user, enterprise_limit: 1) } let!(:distributor){ create(:distributor_enterprise_with_tax, name: 'Distributor', owner_id: distributor_owner.id) @@ -75,25 +75,25 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do create(:enterprise_fee, :flat_rate, enterprise: distributor, amount: 20, name: 'Adminstration', fee_type: 'admin', - tax_category: tax_category) + tax_category:) } let(:supplier_fees){ create(:enterprise_fee, :per_item, enterprise: supplier, amount: 15, name: 'Transport', fee_type: 'transport', - tax_category: tax_category) + tax_category:) } let(:supplier_fees2){ create(:enterprise_fee, :per_item, enterprise: supplier2, amount: 25, name: 'Sales', fee_type: 'sales', - tax_category: tax_category) + tax_category:) } let(:distributor_fee){ create(:enterprise_fee, :flat_rate, enterprise: distributor, amount: 10, name: 'Packing', fee_type: 'packing', - tax_category: tax_category) + tax_category:) } # creates exchanges for oc1 @@ -119,28 +119,28 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do } # creates orders for for oc1 and oc2 - let!(:order) { create(:order_with_distributor, distributor: distributor) } - let!(:order2) { create(:order_with_distributor, distributor: distributor) } + let!(:order) { create(:order_with_distributor, distributor:) } + let!(:order2) { create(:order_with_distributor, distributor:) } before do # adds variants to exchanges on oc1 order_cycle.coordinator_fees << coordinator_fees order_cycle.exchanges.incoming.first.exchange_fees.create!(enterprise_fee: supplier_fees) - order_cycle.exchanges.incoming.first.exchange_variants.create!(variant: variant) + order_cycle.exchanges.incoming.first.exchange_variants.create!(variant:) order_cycle.exchanges.incoming.second.exchange_fees.create!(enterprise_fee: supplier_fees2) order_cycle.exchanges.incoming.second.exchange_variants.create!(variant: variant2) order_cycle.exchanges.outgoing.first.exchange_fees.create!(enterprise_fee: distributor_fee) - order_cycle.exchanges.outgoing.first.exchange_variants.create!(variant: variant) + order_cycle.exchanges.outgoing.first.exchange_variants.create!(variant:) order_cycle.exchanges.outgoing.first.exchange_variants.create!(variant: variant2) # adds variants to exchanges on oc2 order_cycle2.coordinator_fees << coordinator_fees order_cycle2.exchanges.incoming.first.exchange_fees.create!(enterprise_fee: supplier_fees) - order_cycle2.exchanges.incoming.first.exchange_variants.create!(variant: variant) + order_cycle2.exchanges.incoming.first.exchange_variants.create!(variant:) order_cycle2.exchanges.incoming.second.exchange_fees.create!(enterprise_fee: supplier_fees2) order_cycle2.exchanges.incoming.second.exchange_variants.create!(variant: variant2) order_cycle2.exchanges.outgoing.first.exchange_fees.create!(enterprise_fee: distributor_fee) - order_cycle2.exchanges.outgoing.first.exchange_variants.create!(variant: variant) + order_cycle2.exchanges.outgoing.first.exchange_variants.create!(variant:) order_cycle2.exchanges.outgoing.first.exchange_variants.create!(variant: variant2) distributor.shipping_methods << shipping_method @@ -166,7 +166,7 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do before do # adds a line items to the order on oc1 - order.line_items.create({ variant: variant, quantity: 1, price: 100 }) + order.line_items.create({ variant:, quantity: 1, price: 100 }) order.update!({ order_cycle_id: order_cycle.id, ship_address_id: ship_address.id @@ -347,7 +347,7 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do let!(:order_cycle3){ create(:simple_order_cycle, distributors: [distributor], name: "oc3") } - let!(:order3) { create(:order_with_distributor, distributor: distributor) } + let!(:order3) { create(:order_with_distributor, distributor:) } # creates exchanges on oc3 let!(:incoming_exchange5) { @@ -365,17 +365,17 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do # adds variants to exchanges on oc3 order_cycle3.coordinator_fees << coordinator_fees order_cycle3.exchanges.incoming.first.exchange_fees.create!(enterprise_fee: supplier_fees) - order_cycle3.exchanges.incoming.first.exchange_variants.create!(variant: variant) + order_cycle3.exchanges.incoming.first.exchange_variants.create!(variant:) order_cycle3.exchanges.incoming.second.exchange_fees .create!(enterprise_fee: supplier_fees2) order_cycle3.exchanges.incoming.second.exchange_variants.create!(variant: variant2) order_cycle3.exchanges.outgoing.first.exchange_fees .create!(enterprise_fee: distributor_fee) - order_cycle3.exchanges.outgoing.first.exchange_variants.create!(variant: variant) + order_cycle3.exchanges.outgoing.first.exchange_variants.create!(variant:) order_cycle3.exchanges.outgoing.first.exchange_variants.create!(variant: variant2) # adds line items to the order on oc3 - order3.line_items.create({ variant: variant, quantity: 1, price: 100 }) + order3.line_items.create({ variant:, quantity: 1, price: 100 }) order3.line_items.create({ variant: variant2, quantity: 1, price: 50 }) order3.update!({ order_cycle_id: order_cycle3.id, @@ -612,7 +612,7 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do country_tax_rate.update!({ included_in_price: true }) # adds a line items to the order on oc1 - order.line_items.create({ variant: variant, quantity: 1, price: 100 }) + order.line_items.create({ variant:, quantity: 1, price: 100 }) order.update!({ order_cycle_id: order_cycle.id, ship_address_id: ship_address.id From e934bc7cb9630ff1a1bae4ccf2997a64b642f79f Mon Sep 17 00:00:00 2001 From: David Cook Date: Wed, 28 Jun 2023 16:31:24 +1000 Subject: [PATCH 21/46] Ignore ClassLength I'm never quite sure the best way to deal with these, so I added a comment to at least explain my justification. --- lib/reporting/reports/list.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/reporting/reports/list.rb b/lib/reporting/reports/list.rb index 3a9c1e6d2f..2f6567a666 100644 --- a/lib/reporting/reports/list.rb +++ b/lib/reporting/reports/list.rb @@ -2,7 +2,7 @@ module Reporting module Reports - class List + class List # rubocop:disable Metrics/ClassLength # Because it's a simple class def self.all new.all end From b7e1a660c3ecfdf8e4bb4041ec6fe6311b55fd14 Mon Sep 17 00:00:00 2001 From: David Cook Date: Wed, 28 Jun 2023 16:50:55 +1000 Subject: [PATCH 22/46] Rename supplier to be more specific To ensure specs are matching the right supplier. --- ...ry_fee_with_tax_report_by_producer_spec.rb | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb b/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb index 71cc1e2c51..82afd007cf 100644 --- a/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb +++ b/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb @@ -35,7 +35,7 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do let!(:supplier_owner) { create(:user, enterprise_limit: 1) } let!(:supplier2_owner) { create(:user, enterprise_limit: 1) } let!(:supplier){ - create(:supplier_enterprise, name: 'Supplier', charges_sales_tax: true, + create(:supplier_enterprise, name: 'Supplier1', charges_sales_tax: true, owner_id: supplier_owner.id) } let!(:supplier2){ @@ -198,34 +198,34 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do # for supplier 1, oc1 let(:coordinator_state_tax1){ - ["Distributor", "Supplier", "Yes", "oc1", "Adminstration", "admin", "Distributor", + ["Distributor", "Supplier1", "Yes", "oc1", "Adminstration", "admin", "Distributor", "tax_category", "State", "0.015", "20.0", "0.3", "20.3"].join(" ") } let(:coordinator_country_tax1){ - ["Distributor", "Supplier", "Yes", "oc1", "Adminstration", "admin", "Distributor", + ["Distributor", "Supplier1", "Yes", "oc1", "Adminstration", "admin", "Distributor", "tax_category", "Country", "0.025", "20.0", "0.5", "20.5"].join(" ") } let(:supplier_state_tax1){ - ["Distributor", "Supplier", "Yes", "oc1", "Transport", "transport", "Supplier", + ["Distributor", "Supplier1", "Yes", "oc1", "Transport", "transport", "Supplier1", "tax_category", "State", "0.015", "15.0", "0.23", "15.23"].join(" ") } let(:supplier_country_tax1){ - ["Distributor", "Supplier", "Yes", "oc1", "Transport", "transport", "Supplier", + ["Distributor", "Supplier1", "Yes", "oc1", "Transport", "transport", "Supplier1", "tax_category", "Country", "0.025", "15.0", "0.38", "15.38"].join(" ") } let(:distributor_state_tax1){ - ["Distributor", "Supplier", "Yes", "oc1", "Packing", "packing", "Distributor", + ["Distributor", "Supplier1", "Yes", "oc1", "Packing", "packing", "Distributor", "tax_category", "State", "0.015", "10.0", "0.15", "10.15"].join(" ") } let(:distributor_country_tax1){ - ["Distributor", "Supplier", "Yes", "oc1", "Packing", "packing", "Distributor", + ["Distributor", "Supplier1", "Yes", "oc1", "Packing", "packing", "Distributor", "tax_category", "Country", "0.025", "10.0", "0.25", "10.25"].join(" ") } let(:cost_of_produce1){ - ["Distributor", "Supplier", "Yes", "oc1", "Cost of produce", "line items", "Supplier", + ["Distributor", "Supplier1", "Yes", "oc1", "Cost of produce", "line items", "Supplier1", "100.0", "4.0", "104.0"].join(" ") } let(:summary_row1){ @@ -393,34 +393,34 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do # table lines for supplier1 let(:coordinator_state_tax3){ - ["Distributor", "Supplier", "Yes", "oc3", "Adminstration", "admin", "Distributor", + ["Distributor", "Supplier1", "Yes", "oc3", "Adminstration", "admin", "Distributor", "tax_category", "State", "0.015", "20.0", "0.3", "20.3"].join(" ") } let(:coordinator_country_tax3){ - ["Distributor", "Supplier", "Yes", "oc3", "Adminstration", "admin", "Distributor", + ["Distributor", "Supplier1", "Yes", "oc3", "Adminstration", "admin", "Distributor", "tax_category", "Country", "0.025", "20.0", "0.5", "20.5"].join(" ") } let(:supplier_state_tax3){ - ["Distributor", "Supplier", "Yes", "oc3", "Transport", "transport", "Supplier", + ["Distributor", "Supplier1", "Yes", "oc3", "Transport", "transport", "Supplier1", "tax_category", "State", "0.015", "15.0", "0.23", "15.23"].join(" ") } let(:supplier_country_tax3){ - ["Distributor", "Supplier", "Yes", "oc3", "Transport", "transport", "Supplier", + ["Distributor", "Supplier1", "Yes", "oc3", "Transport", "transport", "Supplier1", "tax_category", "Country", "0.025", "15.0", "0.38", "15.38"].join(" ") } let(:distributor_state_tax3){ - ["Distributor", "Supplier", "Yes", "oc3", "Packing", "packing", "Distributor", + ["Distributor", "Supplier1", "Yes", "oc3", "Packing", "packing", "Distributor", "tax_category", "State", "0.015", "10.0", "0.15", "10.15"].join(" ") } let(:distributor_country_tax3){ - ["Distributor", "Supplier", "Yes", "oc3", "Packing", "packing", "Distributor", + ["Distributor", "Supplier1", "Yes", "oc3", "Packing", "packing", "Distributor", "tax_category", "Country", "0.025", "10.0", "0.25", "10.25"].join(" ") } let(:cost_of_produce3){ - ["Distributor", "Supplier", "Yes", "oc3", "Cost of produce", "line items", "Supplier", + ["Distributor", "Supplier1", "Yes", "oc3", "Cost of produce", "line items", "Supplier1", "100.0", "4.0", "104.0"].join(" ") } let(:summary_row3){ @@ -641,34 +641,34 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do end let(:coordinator_state_tax1){ - ["Distributor", "Supplier", "Yes", "oc1", "Adminstration", "admin", "Distributor", + ["Distributor", "Supplier1", "Yes", "oc1", "Adminstration", "admin", "Distributor", "tax_category", "State", "0.015", "19.21", "0.3", "19.51"].join(" ") } let(:coordinator_country_tax1){ - ["Distributor", "Supplier", "Yes", "oc1", "Adminstration", "admin", "Distributor", + ["Distributor", "Supplier1", "Yes", "oc1", "Adminstration", "admin", "Distributor", "tax_category", "Country", "0.025", "19.21", "0.49", "19.7"].join(" ") } let(:supplier_state_tax1){ - ["Distributor", "Supplier", "Yes", "oc1", "Transport", "transport", "Supplier", + ["Distributor", "Supplier1", "Yes", "oc1", "Transport", "transport", "Supplier1", "tax_category", "State", "0.015", "14.41", "0.22", "14.63"].join(" ") } let(:supplier_country_tax1){ - ["Distributor", "Supplier", "Yes", "oc1", "Transport", "transport", "Supplier", + ["Distributor", "Supplier1", "Yes", "oc1", "Transport", "transport", "Supplier1", "tax_category", "Country", "0.025", "14.41", "0.37", "14.78"].join(" ") } let(:distributor_state_tax1){ - ["Distributor", "Supplier", "Yes", "oc1", "Packing", "packing", "Distributor", + ["Distributor", "Supplier1", "Yes", "oc1", "Packing", "packing", "Distributor", "tax_category", "State", "0.015", "9.61", "0.15", "9.76"].join(" ") } let(:distributor_country_tax1){ - ["Distributor", "Supplier", "Yes", "oc1", "Packing", "packing", "Distributor", + ["Distributor", "Supplier1", "Yes", "oc1", "Packing", "packing", "Distributor", "tax_category", "Country", "0.025", "9.61", "0.24", "9.85"].join(" ") } let(:cost_of_produce1){ - ["Distributor", "Supplier", "Yes", "oc1", "Cost of produce", "line items", "Supplier", + ["Distributor", "Supplier1", "Yes", "oc1", "Cost of produce", "line items", "Supplier1", "96.08", "3.92", "100.0"].join(" ") } let(:summary_row1){ From 420494715fc7ab4f53ca3ce9d273b8ad57ba52ab Mon Sep 17 00:00:00 2001 From: David Cook Date: Wed, 28 Jun 2023 17:02:03 +1000 Subject: [PATCH 23/46] Tighten up spec I noticed that the tests don't check if the right totals are shown for each section. Now we can be certain. --- ...e_summary_fee_with_tax_report_by_producer_spec.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb b/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb index 82afd007cf..cbcf168451 100644 --- a/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb +++ b/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb @@ -230,6 +230,7 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do } let(:summary_row1){ [ + cost_of_produce1, # Ensure summary row follows the right supplier "TOTAL", # Fees and line items "145.0", # Tax excl: 20 + 15 + 10 + 100 "5.81", # Tax : (0.30 + 0.50) + (0.23 + 0.38) + (0.15 + 0.25) + (1.50 + 2.50) @@ -271,6 +272,7 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do } let(:summary_row2){ [ + cost_of_produce2, # Ensure summary row follows the right supplier "TOTAL", # Fees and line items "105.0", # Tax excl: 20 + 25 + 10 + 50 "4.21", # Tax : (0.30 + 0.50) + (0.38 + 0.63) + (0.15 + 0.25) + (0.75 + 1.25) @@ -425,6 +427,7 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do } let(:summary_row3){ [ + cost_of_produce3, # Ensure summary row follows the right supplier "TOTAL", # Fees and line items "145.0", # Tax excl: 20 + 15 + 10 + 100 "5.81", # Tax : (0.30 + 0.50) + (0.23 + 0.38) + (0.15 + 0.25) + (1.50 + 2.50) @@ -467,6 +470,7 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do } let(:summary_row4){ [ + cost_of_produce4, # Ensure summary row follows the right supplier "TOTAL", # Fees and line items "105.0", # Tax excl: 20 + 25 + 10 + 50 "4.21", # Tax : (0.30 + 0.50) + (0.38 + 0.63) + (0.15 + 0.25) + 2 @@ -479,11 +483,11 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do let(:fee_owner_selector){ "#s2id_q_enterprise_fee_owner_id_in" } let(:summary_row_after_filtering_by_fee_name){ - ["TOTAL", "120.0", "4.8", "124.8"].join(" ") + [cost_of_produce1, "TOTAL", "120.0", "4.8", "124.8"].join(" ") } let(:summary_row_after_filtering_by_fee_owner){ - ["TOTAL", "115.0", "4.61", "119.61"].join(" ") + [cost_of_produce1, "TOTAL", "115.0", "4.61", "119.61"].join(" ") } before do @@ -507,6 +511,7 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do table = page.find("table.report__table tbody") + # Supplier1 expect(table).to have_content(supplier_state_tax3) expect(table).to have_content(supplier_country_tax3) expect(table).to have_content(distributor_state_tax3) @@ -516,6 +521,7 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do expect(table).to have_content(cost_of_produce3) expect(table).to have_content(summary_row3) + # Supplier2 expect(table).to have_content(supplier_state_tax4) expect(table).to have_content(supplier_country_tax4) expect(table).to have_content(distributor_state_tax4) @@ -673,6 +679,7 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do } let(:summary_row1){ [ + cost_of_produce1, "TOTAL", # Fees and line items "139.31", # Tax excl: 19.21 + 14.41 + 9.61 + 96.08 "5.69", # Tax : (0.30 + 0.50) + (0.23 + 0.38) + (0.15 + 0.25) + (1.50 + 2.50) @@ -714,6 +721,7 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do } let(:summary_row2){ [ + cost_of_produce2, "TOTAL", # Fees and line items "100.88", # Tax excl: 19.21 + 24.02 + 9.61 + 48.04 "4.12", # Tax : (0.30 + 0.50) + (0.38 + 0.63) + (0.15 + 0.25) + 2 From f0c3d7685e8b62d388abaaa1616143da912acda0 Mon Sep 17 00:00:00 2001 From: Mohamed ABDELLANI Date: Tue, 4 Jul 2023 08:22:04 +0100 Subject: [PATCH 24/46] replace string reference with the translated string --- ...rprise_summary_fee_with_tax_report_by_producer_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb b/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb index cbcf168451..732d300d5b 100644 --- a/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb +++ b/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb @@ -285,7 +285,7 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do it 'generates the report and displays fees for the respective suppliers' do login_as distributor_owner visit admin_reports_path - click_on I18n.t("admin.reports.enterprise_fees_with_tax_report_by_producer") + click_on "Enterprise Fees With Tax Report By Producer" expect(page).to have_button("Go") click_on "Go" @@ -316,7 +316,7 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do before do login_as distributor_owner visit admin_reports_path - click_on I18n.t("admin.reports.enterprise_fees_with_tax_report_by_producer") + click_on "Enterprise Fees With Tax Report By Producer" end it "should filter by distributor and order cycle" do @@ -493,7 +493,7 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do before do login_as distributor_owner visit admin_reports_path - click_on I18n.t("admin.reports.enterprise_fees_with_tax_report_by_producer") + click_on "Enterprise Fees With Tax Report By Producer" end it "should filter by distributor and order cycle" do @@ -734,7 +734,7 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do # pending("test case (3), see #10797") login_as distributor_owner visit admin_reports_path - click_on I18n.t("admin.reports.enterprise_fees_with_tax_report_by_producer") + click_on "Enterprise Fees With Tax Report By Producer" expect(page).to have_button("Go") click_on "Go" From a3f012c9fe26242cce881c1125843f628188ccde Mon Sep 17 00:00:00 2001 From: Mohamed ABDELLANI Date: Fri, 7 Jul 2023 09:11:56 +0100 Subject: [PATCH 25/46] calculate tax total using existing rows --- .../enterprise_fees_with_tax_report_by_producer.rb | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb b/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb index 9fa638f208..822fd8da0e 100644 --- a/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb +++ b/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb @@ -216,7 +216,7 @@ module Reporting end def order_cycle_totals_row - proc do |_key, items, _rows| + proc do |_key, items, rows| supplier_id = items.first.first[2] # supplier id used in the grouped line items order_ids = items.flat_map(&:second).map(&:id).uniq line_items = items.flat_map(&:second).uniq.map(&:line_items).flatten @@ -224,8 +224,9 @@ module Reporting line_item.supplier_id == supplier_id end + tax_for_enterprise_fees = rows.map(&:tax).sum total_excl_tax = total_fees_excl_tax(order_ids) + line_items_excl_tax(line_items) - tax = tax_for_order_ids(order_ids) + tax_for_line_items(line_items) + tax = tax_for_enterprise_fees + tax_for_line_items(line_items) { total_excl_tax:, tax:, @@ -288,14 +289,6 @@ module Reporting .pick("sum(amount)") || 0 end - def tax_for_order_ids(order_ids) - Spree::Adjustment.tax - .where(order: order_ids) - .where(adjustable_type: 'Spree::Adjustment') - .where(adjustable_id: enterprise_fee_adjustment_ids_for_orders(order_ids)) - .pick("sum(amount)") || 0 - end - def enterprise_fee_adjustment_ids_for_orders(order_ids) enterprise_fees_for_orders(order_ids).pluck(:id) end From 624b4c8ad242c0f08559e5effc27f6d7c704f06a Mon Sep 17 00:00:00 2001 From: Mohamed ABDELLANI Date: Fri, 7 Jul 2023 09:38:03 +0100 Subject: [PATCH 26/46] fix calculation of the summary row's total excl tax --- ...rprise_fees_with_tax_report_by_producer.rb | 33 ++++++++++++------- ...ry_fee_with_tax_report_by_producer_spec.rb | 2 -- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb b/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb index 822fd8da0e..4ca3848346 100644 --- a/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb +++ b/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb @@ -60,7 +60,7 @@ module Reporting def query_result # The objective is to group the orders by - # [entreprise_fee, tax_rate, supplier_id, distributor_id and order_cycle_id] + # [tax_rate, entreprise_fee, supplier_id, distributor_id and order_cycle_id] # The order.all_adjustment describes # - the enterprise fees applied on the order @@ -218,14 +218,13 @@ module Reporting def order_cycle_totals_row proc do |_key, items, rows| supplier_id = items.first.first[2] # supplier id used in the grouped line items - order_ids = items.flat_map(&:second).map(&:id).uniq line_items = items.flat_map(&:second).uniq.map(&:line_items).flatten .filter do |line_item| line_item.supplier_id == supplier_id end tax_for_enterprise_fees = rows.map(&:tax).sum - total_excl_tax = total_fees_excl_tax(order_ids) + line_items_excl_tax(line_items) + total_excl_tax = total_fees_excl_tax(items) + line_items_excl_tax(line_items) tax = tax_for_enterprise_fees + tax_for_line_items(line_items) { total_excl_tax:, @@ -261,8 +260,14 @@ module Reporting end end - def total_fees_excl_tax(order_ids) - enterprise_fees_amount_for_orders(order_ids) - included_tax_for_order_ids(order_ids) + def total_fees_excl_tax(items) + order_ids = items.flat_map(&:second).map(&:id).uniq + enterprise_fee_ids = items.map(&:first).map(&:second) + enterprise_fees_amount_for_orders( + order_ids, enterprise_fee_ids + ) - included_tax_for_order_ids( + order_ids, enterprise_fee_ids + ) end def line_items_excl_tax(line_items) @@ -280,26 +285,30 @@ module Reporting end.sum end - def included_tax_for_order_ids(order_ids) + def included_tax_for_order_ids(order_ids, enterprise_fee_ids) Spree::Adjustment.tax .where(order: order_ids) .where(included: true) .where(adjustable_type: 'Spree::Adjustment') - .where(adjustable_id: enterprise_fee_adjustment_ids_for_orders(order_ids)) + .where(adjustable_id: enterprise_fee_adjustment_ids_for_orders(order_ids, + enterprise_fee_ids)) .pick("sum(amount)") || 0 end - def enterprise_fee_adjustment_ids_for_orders(order_ids) - enterprise_fees_for_orders(order_ids).pluck(:id) + def enterprise_fee_adjustment_ids_for_orders(order_ids, enterprise_fee_ids) + enterprise_fee_adjustments_for_orders(order_ids, enterprise_fee_ids).pluck(:id) end - def enterprise_fees_amount_for_orders(order_ids) - enterprise_fees_for_orders(order_ids).pick("sum(amount)") || 0 + def enterprise_fees_amount_for_orders(order_ids, enterprise_fee_ids) + enterprise_fee_adjustments_for_orders( + order_ids, enterprise_fee_ids + ).pick("sum(amount)") || 0 end - def enterprise_fees_for_orders(order_ids) + def enterprise_fee_adjustments_for_orders(order_ids, enterprise_fee_ids) enterprise_fees = Spree::Adjustment.enterprise_fee .where(order_id: order_ids) + .where(originator_id: enterprise_fee_ids) return enterprise_fees unless enterprise_fee_filters? enterprise_fees.where( diff --git a/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb b/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb index 732d300d5b..7965485340 100644 --- a/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb +++ b/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb @@ -497,8 +497,6 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do end it "should filter by distributor and order cycle" do - pending("incorrect totals for orders with more than one supplier") - page.find("#s2id_autogen1").click find('li', text: distributor.name).click # selects Distributor From 9a22cdc5e7f3bf5a4dfed5d8823c8d1f5eec9926 Mon Sep 17 00:00:00 2001 From: Mohamed ABDELLANI Date: Fri, 7 Jul 2023 11:53:36 +0100 Subject: [PATCH 27/46] test scenario: 'multiple orders, same enterprise fee, different tax rates' --- ...ry_fee_with_tax_report_by_producer_spec.rb | 269 ++++++++++++++++++ 1 file changed, 269 insertions(+) diff --git a/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb b/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb index 7965485340..ea0a0ae5c0 100644 --- a/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb +++ b/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb @@ -760,4 +760,273 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do end end end + + context 'multiple orders, same enterprise fee, different tax rates' do + let(:another_state) { + Spree::State.find_by(name: "New South Wales") + } + + let(:another_address) { + create(:address, + state: another_state, + country: another_state.country) + } + + let!(:state_zone2){ + create( + :zone, + zone_members: [Spree::ZoneMember.new(zoneable: another_state)] + ) + } + + let!(:state_tax_rate2){ + create(:tax_rate, zone: state_zone2, tax_category:, + name: 'Another State Tax', amount: 0.02) + } + + context "added tax" do + before do + # adds a line items to the order on oc1 + order.line_items.create({ variant:, quantity: 1, price: 100 }) + order.update!({ + order_cycle_id: order_cycle.id, + ship_address_id: ship_address.id + }) + order.recreate_all_fees! + while !order.completed? + break unless order.next! + end + + # adds a line items to the order on oc2 + order2.line_items.create({ variant:, quantity: 1, price: 50 }) + order2.update!({ + order_cycle_id: order_cycle.id, + ship_address_id: another_address.id + }) + order2.recreate_all_fees! + while !order2.completed? + break unless order2.next! + end + end + let(:admin_state_tax1){ + [ + "Distributor", "Supplier1", "Yes", "oc1", "Adminstration", "admin", + "Distributor", "tax_category", "State", "0.015", "20.0", "0.3", "20.3" + ].join(" ") + } + let(:admin_country_tax1){ + [ + "Distributor", "Supplier1", "Yes", "oc1", "Adminstration", "admin", + "Distributor", "tax_category", "Country", "0.025", "40.0", "1.0", "41.0" + ].join(" ") + } + let(:transport_state_tax1){ + [ + "Distributor", "Supplier1", "Yes", "oc1", "Transport", "transport", + "Supplier1", "tax_category", "State", "0.015", "15.0", "0.23", "15.23" + ].join(" ") + } + let(:transport_country_tax1){ + [ + "Distributor", "Supplier1", "Yes", "oc1", "Transport", "transport", + "Supplier1", "tax_category", "Country", "0.025", "30.0", "0.76", "30.76" + ].join(" ") + } + let(:packing_state_tax1){ + [ + "Distributor", "Supplier1", "Yes", "oc1", "Packing", "packing", + "Distributor", "tax_category", "State", "0.015", "10.0", "0.15", "10.15" + ].join(" ") + } + let(:packing_country_tax1){ + [ + "Distributor", "Supplier1", "Yes", "oc1", "Packing", "packing", + "Distributor", "tax_category", "Country", "0.025", "20.0", "0.5", "20.5" + ].join(" ") + } + + let(:admin_state_tax2){ + [ + "Distributor", "Supplier1", "Yes", "oc1", "Adminstration", "admin", + "Distributor", "tax_category", "Another State Tax", "0.02", "20.0", "0.4", "20.4" + ].join(" ") + } + let(:transport_state_tax2){ + [ + "Distributor", "Supplier1", "Yes", "oc1", "Transport", "transport", + "Supplier1", "tax_category", "Another State Tax", "0.02", "15.0", "0.3", "15.3" + ].join(" ") + } + let(:packing_state_tax2){ + [ + "Distributor", "Supplier1", "Yes", "oc1", "Packing", "packing", + "Distributor", "tax_category", "Another State Tax", "0.02", "10.0", "0.2", "10.2" + ].join(" ") + } + + let(:supplier1_cost_of_produce_line_items){ + [ + "Distributor", "Supplier1", "Yes", "oc1", "Cost of produce line items", + "Supplier1", "150.0", "6.25", "156.25" + ].join(" ") + } + + let(:summary_row){ + [ + "TOTAL", "240.0", "10.09", "250.09" + ].join(" ") + } + + it 'should list all the tax rates' do + login_as distributor_owner + visit admin_reports_path + click_on "Enterprise Fees With Tax Report By Producer" + expect(page).to have_button("Go") + + click_on "Go" + + expect(page.find("table.report__table thead tr")).to have_content(table_header) + + table = page.find("table.report__table tbody") + expect(table).to have_content(admin_state_tax1) + expect(table).to have_content(admin_country_tax1) + expect(table).to have_content(transport_state_tax1) + expect(table).to have_content(transport_country_tax1) + expect(table).to have_content(packing_state_tax1) + expect(table).to have_content(packing_country_tax1) + + expect(table).to have_content(admin_state_tax2) + expect(table).to have_content(transport_state_tax2) + expect(table).to have_content(packing_state_tax2) + + expect(table).to have_content(supplier1_cost_of_produce_line_items) + expect(table).to have_content(summary_row) + end + end + + context "included tax" do + before do + state_tax_rate.update!({ included_in_price: true }) + country_tax_rate.update!({ included_in_price: true }) + state_tax_rate2.update!({ included_in_price: true }) + + order.line_items.create({ variant:, quantity: 1, price: 100 }) + order.update!({ + order_cycle_id: order_cycle.id, + ship_address_id: ship_address.id + }) + order.recreate_all_fees! + while !order.completed? + break unless order.next! + end + + # adds a line items to the order on oc2 + order2.line_items.create({ variant:, quantity: 1, price: 50 }) + order2.update!({ + order_cycle_id: order_cycle.id, + ship_address_id: another_address.id + }) + + order2.recreate_all_fees! + while !order2.completed? + break unless order2.next! + end + end + + let(:admin_state_tax1){ + [ + "Distributor", "Supplier1", "Yes", "oc1", "Adminstration", "admin", + "Distributor", "tax_category", "State", "0.015", "19.21", "0.3", "19.51" + ].join(" ") + } + let(:admin_country_tax1){ + [ + "Distributor", "Supplier1", "Yes", "oc1", "Adminstration", "admin", + "Distributor", "tax_category", "Country", "0.025", "38.33", "0.98", "39.31" + ].join(" ") + } + let(:transport_state_tax1){ + [ + "Distributor", "Supplier1", "Yes", "oc1", "Transport", "transport", + "Supplier1", "tax_category", "State", "0.015", "14.41", "0.22", "14.63" + ].join(" ") + } + let(:transport_country_tax1){ + [ + "Distributor", "Supplier1", "Yes", "oc1", "Transport", "transport", + "Supplier1", "tax_category", "Country", "0.025", "28.75", "0.74", "29.49" + ].join(" ") + } + let(:packing_state_tax1){ + [ + "Distributor", "Supplier1", "Yes", "oc1", "Packing", "packing", + "Distributor", "tax_category", "State", "0.015", "9.61", "0.15", "9.76" + ].join(" ") + } + let(:packing_country_tax1){ + [ + "Distributor", "Supplier1", "Yes", "oc1", "Packing", "packing", + "Distributor", "tax_category", "Country", "0.025", "19.17", "0.48", "19.65" + ].join(" ") + } + + let(:admin_state_tax2){ + [ + "Distributor", "Supplier1", "Yes", "oc1", "Adminstration", "admin", + "Distributor", "tax_category", "Another State Tax", "0.02", "19.12", "0.39", "19.51" + ].join(" ") + } + let(:transport_state_tax2){ + [ + "Distributor", "Supplier1", "Yes", "oc1", "Transport", "transport", + "Supplier1", "tax_category", "Another State Tax", "0.02", "14.34", "0.29", "14.63" + ].join(" ") + } + let(:packing_state_tax2){ + [ + "Distributor", "Supplier1", "Yes", "oc1", "Packing", "packing", + "Distributor", "tax_category", "Another State Tax", "0.02", "9.56", "0.2", "9.76" + ].join(" ") + } + + let(:supplier1_cost_of_produce_line_items){ + [ + "Distributor", "Supplier1", "Yes", "oc1", "Cost of produce line items", + "Supplier1", "143.88", "6.12", "150.0" + ].join(" ") + } + + let(:summary_row){ + [ + "TOTAL", "230.13", "9.87", "240.0" + ].join(" ") + } + + it 'should list all the tax rates' do + login_as distributor_owner + visit admin_reports_path + click_on "Enterprise Fees With Tax Report By Producer" + expect(page).to have_button("Go") + + click_on "Go" + + expect(page.find("table.report__table thead tr")).to have_content(table_header) + + table = page.find("table.report__table tbody") + expect(table).to have_content(admin_state_tax1) + expect(table).to have_content(admin_country_tax1) + expect(table).to have_content(transport_state_tax1) + expect(table).to have_content(transport_country_tax1) + expect(table).to have_content(packing_state_tax1) + expect(table).to have_content(packing_country_tax1) + + expect(table).to have_content(admin_state_tax2) + expect(table).to have_content(transport_state_tax2) + expect(table).to have_content(packing_state_tax2) + + expect(table).to have_content(supplier1_cost_of_produce_line_items) + expect(table).to have_content(summary_row) + end + end + end end From ce57ac65f38589d9bd59c1013e82bd13645db013 Mon Sep 17 00:00:00 2001 From: David Cook Date: Tue, 11 Jul 2023 16:12:21 +1000 Subject: [PATCH 28/46] Refactor order cycle lets It turns out the outgoing exchanges were never even used. --- ...ry_fee_with_tax_report_by_producer_spec.rb | 38 +++++++------------ 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb b/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb index ea0a0ae5c0..f19da3ed9f 100644 --- a/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb +++ b/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb @@ -54,10 +54,22 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do let!(:shipping_method){ create(:shipping_method, :flat_rate) } let!(:order_cycle){ - create(:simple_order_cycle, distributors: [distributor], name: "oc1") + order_cycle = create(:simple_order_cycle, distributors: [distributor], name: "oc1") + + # creates exchanges for oc1 + order_cycle.exchanges.create! sender: supplier, receiver: distributor, incoming: true + order_cycle.exchanges.create! sender: supplier2, receiver: distributor, incoming: true + + order_cycle } let!(:order_cycle2){ - create(:simple_order_cycle, distributors: [distributor], name: "oc2") + order_cycle2 = create(:simple_order_cycle, distributors: [distributor], name: "oc2") + + # creates exchanges for oc2 + order_cycle2.exchanges.create! sender: supplier, receiver: distributor, incoming: true + order_cycle2.exchanges.create! sender: supplier2, receiver: distributor, incoming: true + + order_cycle2 } let!(:enterprise_relationship1) { @@ -96,28 +108,6 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do tax_category:) } - # creates exchanges for oc1 - let!(:incoming_exchange1) { - order_cycle.exchanges.create! sender: supplier, receiver: distributor, incoming: true - } - let!(:incoming_exchange2) { - order_cycle.exchanges.create! sender: supplier2, receiver: distributor, incoming: true - } - let(:outgoing_exchange1) { - order_cycle.exchanges.create! sender: distributor, receiver: distributor, incoming: false - } - - # sets exchanges for oc2 - let!(:incoming_exchange3) { - order_cycle2.exchanges.create! sender: supplier, receiver: distributor, incoming: true - } - let!(:incoming_exchange4) { - order_cycle2.exchanges.create! sender: supplier2, receiver: distributor, incoming: true - } - let(:outgoing_exchange2) { - order_cycle2.exchanges.create! sender: distributor, receiver: distributor, incoming: false - } - # creates orders for for oc1 and oc2 let!(:order) { create(:order_with_distributor, distributor:) } let!(:order2) { create(:order_with_distributor, distributor:) } From bf2298829f67b77eccdf5aae9b5b326d641390b8 Mon Sep 17 00:00:00 2001 From: David Cook Date: Tue, 11 Jul 2023 16:15:51 +1000 Subject: [PATCH 29/46] Refactor order cycle setup more Moving more code out of before blocks which will help us reduce duplication in following commits. --- ...ry_fee_with_tax_report_by_producer_spec.rb | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb b/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb index f19da3ed9f..52cbe9dee0 100644 --- a/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb +++ b/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb @@ -60,6 +60,16 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do order_cycle.exchanges.create! sender: supplier, receiver: distributor, incoming: true order_cycle.exchanges.create! sender: supplier2, receiver: distributor, incoming: true + # adds variants to exchanges on oc1 + order_cycle.coordinator_fees << coordinator_fees + order_cycle.exchanges.incoming.first.exchange_fees.create!(enterprise_fee: supplier_fees) + order_cycle.exchanges.incoming.first.exchange_variants.create!(variant:) + order_cycle.exchanges.incoming.second.exchange_fees.create!(enterprise_fee: supplier_fees2) + order_cycle.exchanges.incoming.second.exchange_variants.create!(variant: variant2) + order_cycle.exchanges.outgoing.first.exchange_fees.create!(enterprise_fee: distributor_fee) + order_cycle.exchanges.outgoing.first.exchange_variants.create!(variant:) + order_cycle.exchanges.outgoing.first.exchange_variants.create!(variant: variant2) + order_cycle } let!(:order_cycle2){ @@ -69,6 +79,16 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do order_cycle2.exchanges.create! sender: supplier, receiver: distributor, incoming: true order_cycle2.exchanges.create! sender: supplier2, receiver: distributor, incoming: true + # adds variants to exchanges on oc2 + order_cycle2.coordinator_fees << coordinator_fees + order_cycle2.exchanges.incoming.first.exchange_fees.create!(enterprise_fee: supplier_fees) + order_cycle2.exchanges.incoming.first.exchange_variants.create!(variant:) + order_cycle2.exchanges.incoming.second.exchange_fees.create!(enterprise_fee: supplier_fees2) + order_cycle2.exchanges.incoming.second.exchange_variants.create!(variant: variant2) + order_cycle2.exchanges.outgoing.first.exchange_fees.create!(enterprise_fee: distributor_fee) + order_cycle2.exchanges.outgoing.first.exchange_variants.create!(variant:) + order_cycle2.exchanges.outgoing.first.exchange_variants.create!(variant: variant2) + order_cycle2 } @@ -113,26 +133,6 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do let!(:order2) { create(:order_with_distributor, distributor:) } before do - # adds variants to exchanges on oc1 - order_cycle.coordinator_fees << coordinator_fees - order_cycle.exchanges.incoming.first.exchange_fees.create!(enterprise_fee: supplier_fees) - order_cycle.exchanges.incoming.first.exchange_variants.create!(variant:) - order_cycle.exchanges.incoming.second.exchange_fees.create!(enterprise_fee: supplier_fees2) - order_cycle.exchanges.incoming.second.exchange_variants.create!(variant: variant2) - order_cycle.exchanges.outgoing.first.exchange_fees.create!(enterprise_fee: distributor_fee) - order_cycle.exchanges.outgoing.first.exchange_variants.create!(variant:) - order_cycle.exchanges.outgoing.first.exchange_variants.create!(variant: variant2) - - # adds variants to exchanges on oc2 - order_cycle2.coordinator_fees << coordinator_fees - order_cycle2.exchanges.incoming.first.exchange_fees.create!(enterprise_fee: supplier_fees) - order_cycle2.exchanges.incoming.first.exchange_variants.create!(variant:) - order_cycle2.exchanges.incoming.second.exchange_fees.create!(enterprise_fee: supplier_fees2) - order_cycle2.exchanges.incoming.second.exchange_variants.create!(variant: variant2) - order_cycle2.exchanges.outgoing.first.exchange_fees.create!(enterprise_fee: distributor_fee) - order_cycle2.exchanges.outgoing.first.exchange_variants.create!(variant:) - order_cycle2.exchanges.outgoing.first.exchange_variants.create!(variant: variant2) - distributor.shipping_methods << shipping_method distributor.payment_methods << payment_method From 6e150497280bfdd6488a6d565b76fd9c990ca842 Mon Sep 17 00:00:00 2001 From: David Cook Date: Tue, 11 Jul 2023 16:34:02 +1000 Subject: [PATCH 30/46] Refactor distributor --- ...se_summary_fee_with_tax_report_by_producer_spec.rb | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb b/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb index 52cbe9dee0..95c59c9c01 100644 --- a/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb +++ b/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb @@ -48,7 +48,13 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do let!(:variant2){ create(:variant, product_id: product2.id, tax_category:) } let!(:distributor_owner) { create(:user, enterprise_limit: 1) } let!(:distributor){ - create(:distributor_enterprise_with_tax, name: 'Distributor', owner_id: distributor_owner.id) + distributor = create(:distributor_enterprise_with_tax, name: 'Distributor', + owner_id: distributor_owner.id) + + distributor.shipping_methods << shipping_method + distributor.payment_methods << payment_method + + distributor } let!(:payment_method){ create(:payment_method, :flat_rate) } let!(:shipping_method){ create(:shipping_method, :flat_rate) } @@ -133,9 +139,6 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do let!(:order2) { create(:order_with_distributor, distributor:) } before do - distributor.shipping_methods << shipping_method - distributor.payment_methods << payment_method - product.update!({ tax_category_id: tax_category.id, supplier_id: supplier.id From b574e71fc9418d908945d6d76715186fc3a76c66 Mon Sep 17 00:00:00 2001 From: David Cook Date: Tue, 11 Jul 2023 16:55:18 +1000 Subject: [PATCH 31/46] Refactor: set included_in_price once This saves the need for an update, and more importantly moves setup out of the before block which means we can finally deduplicate order setup. --- ...ary_fee_with_tax_report_by_producer_spec.rb | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb b/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb index 95c59c9c01..c5017d0aa6 100644 --- a/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb +++ b/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb @@ -22,13 +22,14 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do let!(:state_zone){ create(:zone_with_state_member) } let!(:country_zone){ create(:zone_with_member) } let!(:tax_category){ create(:tax_category, name: 'tax_category') } + let(:included_in_price) { false } let!(:state_tax_rate){ create(:tax_rate, zone: state_zone, tax_category:, - name: 'State', amount: 0.015) + name: 'State', amount: 0.015, included_in_price:) } let!(:country_tax_rate){ create(:tax_rate, zone: country_zone, tax_category:, - name: 'Country', amount: 0.025) + name: 'Country', amount: 0.025, included_in_price:) } let!(:ship_address){ create(:ship_address) } @@ -604,10 +605,9 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do # - line items (100) 1.5% = 1.50, 2.5% = 2.50 # - line items (50) 1.5% = 1.50, 2.5% = 2.50 - before do - state_tax_rate.update!({ included_in_price: true }) - country_tax_rate.update!({ included_in_price: true }) + let(:included_in_price) { true } + before do # adds a line items to the order on oc1 order.line_items.create({ variant:, quantity: 1, price: 100 }) order.update!({ @@ -774,7 +774,7 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do let!(:state_tax_rate2){ create(:tax_rate, zone: state_zone2, tax_category:, - name: 'Another State Tax', amount: 0.02) + name: 'Another State Tax', amount: 0.02, included_in_price:) } context "added tax" do @@ -898,11 +898,9 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do end context "included tax" do - before do - state_tax_rate.update!({ included_in_price: true }) - country_tax_rate.update!({ included_in_price: true }) - state_tax_rate2.update!({ included_in_price: true }) + let(:included_in_price) { true } + before do order.line_items.create({ variant:, quantity: 1, price: 100 }) order.update!({ order_cycle_id: order_cycle.id, From 8c514b2fe9b62e3172af67391c3ae9cf351ecfe3 Mon Sep 17 00:00:00 2001 From: David Cook Date: Tue, 11 Jul 2023 16:40:34 +1000 Subject: [PATCH 32/46] Deduplicate order setup --- ...ry_fee_with_tax_report_by_producer_spec.rb | 65 +++++-------------- 1 file changed, 15 insertions(+), 50 deletions(-) diff --git a/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb b/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb index c5017d0aa6..48faca241f 100644 --- a/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb +++ b/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb @@ -136,7 +136,21 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do } # creates orders for for oc1 and oc2 - let!(:order) { create(:order_with_distributor, distributor:) } + let!(:order) { + order = create(:order_with_distributor, distributor:, order_cycle_id: order_cycle.id, + ship_address_id: ship_address.id) + + order.line_items.create({ variant:, quantity: 1, price: 100 }) + + # This will load the enterprise fees from the order cycle. + # This is needed because the order instance was created + # independently of the order_cycle. + order.recreate_all_fees! + while !order.completed? + break unless order.next! + end + order + } let!(:order2) { create(:order_with_distributor, distributor:) } before do @@ -159,20 +173,6 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do # - line items (50) 1.5% = 0.75, 2.5% = 1.25 before do - # adds a line items to the order on oc1 - order.line_items.create({ variant:, quantity: 1, price: 100 }) - order.update!({ - order_cycle_id: order_cycle.id, - ship_address_id: ship_address.id - }) - # This will load the enterprise fees from the order cycle. - # This is needed because the order instance was created - # independently of the order_cycle. - order.recreate_all_fees! - while !order.completed? - break unless order.next! - end - # adds a line items to the order on oc2 order2.line_items.create({ variant: variant2, quantity: 1, price: 50 }) order2.update!({ @@ -608,20 +608,6 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do let(:included_in_price) { true } before do - # adds a line items to the order on oc1 - order.line_items.create({ variant:, quantity: 1, price: 100 }) - order.update!({ - order_cycle_id: order_cycle.id, - ship_address_id: ship_address.id - }) - # This will load the enterprise fees from the order cycle. - # This is needed because the order instance was created - # independently of the order_cycle. - order.recreate_all_fees! - while !order.completed? - break unless order.next! - end - # adds a line items to the order on oc2 order2.line_items.create({ variant: variant2, quantity: 1, price: 50 }) order2.update!({ @@ -779,17 +765,6 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do context "added tax" do before do - # adds a line items to the order on oc1 - order.line_items.create({ variant:, quantity: 1, price: 100 }) - order.update!({ - order_cycle_id: order_cycle.id, - ship_address_id: ship_address.id - }) - order.recreate_all_fees! - while !order.completed? - break unless order.next! - end - # adds a line items to the order on oc2 order2.line_items.create({ variant:, quantity: 1, price: 50 }) order2.update!({ @@ -901,16 +876,6 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do let(:included_in_price) { true } before do - order.line_items.create({ variant:, quantity: 1, price: 100 }) - order.update!({ - order_cycle_id: order_cycle.id, - ship_address_id: ship_address.id - }) - order.recreate_all_fees! - while !order.completed? - break unless order.next! - end - # adds a line items to the order on oc2 order2.line_items.create({ variant:, quantity: 1, price: 50 }) order2.update!({ From 47d5fe909ed4cb1cdb0ac15c9495271cf6b9cfa5 Mon Sep 17 00:00:00 2001 From: David Cook Date: Tue, 11 Jul 2023 16:58:54 +1000 Subject: [PATCH 33/46] Deduplicate order2 setup --- ...ry_fee_with_tax_report_by_producer_spec.rb | 93 +++++++------------ 1 file changed, 34 insertions(+), 59 deletions(-) diff --git a/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb b/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb index 48faca241f..c789930387 100644 --- a/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb +++ b/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb @@ -151,7 +151,23 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do end order } - let!(:order2) { create(:order_with_distributor, distributor:) } + + let!(:order2) { + order2 = create(:order_with_distributor, distributor:, order_cycle_id: order_cycle2.id, + ship_address_id: ship_address.id) + + order2.line_items.create({ variant: variant2, quantity: 1, price: 50 }) + + # This will load the enterprise fees from the order cycle. + # This is needed because the order instance was created + # independently of the order_cycle. + order2.recreate_all_fees! + while !order2.completed? + break unless order2.next! + end + + order2 + } before do product.update!({ @@ -172,22 +188,6 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do # - outgoing exchange (10) 1.5% = 0.15, 2.5% = 0.25 # - line items (50) 1.5% = 0.75, 2.5% = 1.25 - before do - # adds a line items to the order on oc2 - order2.line_items.create({ variant: variant2, quantity: 1, price: 50 }) - order2.update!({ - order_cycle_id: order_cycle2.id, - ship_address_id: ship_address.id - }) - # This will load the enterprise fees from the order cycle. - # This is needed because the order instance was created - # independently of the order_cycle. - order2.recreate_all_fees! - while !order2.completed? - break unless order2.next! - end - end - describe "orders" do # for supplier 1, oc1 @@ -607,22 +607,6 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do let(:included_in_price) { true } - before do - # adds a line items to the order on oc2 - order2.line_items.create({ variant: variant2, quantity: 1, price: 50 }) - order2.update!({ - order_cycle_id: order_cycle2.id, - ship_address_id: ship_address.id - }) - # This will load the enterprise fees from the order cycle. - # This is needed because the order instance was created - # independently of the order_cycle. - order2.recreate_all_fees! - while !order2.completed? - break unless order2.next! - end - end - let(:coordinator_state_tax1){ ["Distributor", "Supplier1", "Yes", "oc1", "Adminstration", "admin", "Distributor", "tax_category", "State", "0.015", "19.21", "0.3", "19.51"].join(" ") @@ -763,19 +747,24 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do name: 'Another State Tax', amount: 0.02, included_in_price:) } - context "added tax" do - before do - # adds a line items to the order on oc2 - order2.line_items.create({ variant:, quantity: 1, price: 50 }) - order2.update!({ - order_cycle_id: order_cycle.id, - ship_address_id: another_address.id - }) - order2.recreate_all_fees! - while !order2.completed? - break unless order2.next! - end + let!(:order2) { + # Ensure tax rates set up first + state_tax_rate2 + + order2 = create(:order_with_distributor, distributor:, order_cycle_id: order_cycle.id, + ship_address_id: another_address.id) + + # adds a line items to the order on oc2 + order2.line_items.create({ variant:, quantity: 1, price: 50 }) + order2.recreate_all_fees! + while !order2.completed? + break unless order2.next! end + + order2 + } + + context "added tax" do let(:admin_state_tax1){ [ "Distributor", "Supplier1", "Yes", "oc1", "Adminstration", "admin", @@ -875,20 +864,6 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do context "included tax" do let(:included_in_price) { true } - before do - # adds a line items to the order on oc2 - order2.line_items.create({ variant:, quantity: 1, price: 50 }) - order2.update!({ - order_cycle_id: order_cycle.id, - ship_address_id: another_address.id - }) - - order2.recreate_all_fees! - while !order2.completed? - break unless order2.next! - end - end - let(:admin_state_tax1){ [ "Distributor", "Supplier1", "Yes", "oc1", "Adminstration", "admin", From d8501e7d838d43a6fb8ad30ded9617d23b6839a7 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Mon, 17 Jul 2023 12:31:06 +0100 Subject: [PATCH 34/46] Updates test case generates the report and displays fees for the respective suppliers --- ...ry_fee_with_tax_report_by_producer_spec.rb | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb b/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb index c789930387..670e287e42 100644 --- a/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb +++ b/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb @@ -226,9 +226,9 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do [ cost_of_produce1, # Ensure summary row follows the right supplier "TOTAL", # Fees and line items - "145.0", # Tax excl: 20 + 15 + 10 + 100 - "5.81", # Tax : (0.30 + 0.50) + (0.23 + 0.38) + (0.15 + 0.25) + (1.50 + 2.50) - "150.81" # Tax incl: 145.00 + 5.81 + "115.0", # Tax excl: 15 + 100 + "4.61", # Tax : (0.23 + 0.38) + (1.50 + 2.50) + "119.61" # Tax incl: 100.00 + 15 + (0.23 + 0.38) + (1.50 + 2.50) ].join(" ") } @@ -268,40 +268,41 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do [ cost_of_produce2, # Ensure summary row follows the right supplier "TOTAL", # Fees and line items - "105.0", # Tax excl: 20 + 25 + 10 + 50 - "4.21", # Tax : (0.30 + 0.50) + (0.38 + 0.63) + (0.15 + 0.25) + (0.75 + 1.25) - - "109.21" # Tax incl: 105 + 4.21 + "75.0", # Tax excl: 25 + 50 + "3.01", # Tax : (0.38 + 0.63) + 2 + "78.01" # Tax incl: 25 + 50 + 4.21 ].join(" ") } context "with line items from a single supplier" do it 'generates the report and displays fees for the respective suppliers' do + pending "removal from distributor and coordinator fees from results" + login_as distributor_owner visit admin_reports_path click_on "Enterprise Fees With Tax Report By Producer" expect(page).to have_button("Go") click_on "Go" - + expect(page.find("table.report__table thead tr")).to have_content(table_header) table = page.find("table.report__table tbody") expect(table).to have_content(supplier_state_tax1) expect(table).to have_content(supplier_country_tax1) - expect(table).to have_content(distributor_state_tax1) - expect(table).to have_content(distributor_country_tax1) - expect(table).to have_content(coordinator_state_tax1) - expect(table).to have_content(coordinator_country_tax1) + expect(table).not_to have_content(distributor_state_tax1) + expect(table).not_to have_content(distributor_country_tax1) + expect(table).not_to have_content(coordinator_state_tax1) + expect(table).not_to have_content(coordinator_country_tax1) expect(table).to have_content(cost_of_produce1) expect(table).to have_content(summary_row1) expect(table).to have_content(supplier_state_tax2) expect(table).to have_content(supplier_country_tax2) - expect(table).to have_content(distributor_state_tax2) - expect(table).to have_content(distributor_country_tax2) - expect(table).to have_content(coordinator_state_tax2) - expect(table).to have_content(coordinator_country_tax2) + expect(table).not_to have_content(distributor_state_tax2) + expect(table).not_to have_content(distributor_country_tax2) + expect(table).not_to have_content(coordinator_state_tax2) + expect(table).not_to have_content(coordinator_country_tax2) expect(table).to have_content(cost_of_produce2) expect(table).to have_content(summary_row2) end From d7a6db3eb0a1a21a960bf75c089eacf37ef28f14 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Mon, 17 Jul 2023 16:42:41 +0100 Subject: [PATCH 35/46] Updates test case should filter by distributor and order cycle --- ...ise_summary_fee_with_tax_report_by_producer_spec.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb b/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb index 670e287e42..76ffc123e8 100644 --- a/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb +++ b/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb @@ -315,6 +315,8 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do end it "should filter by distributor and order cycle" do + pending "removal from distributor and coordinator fees from results" + page.find("#s2id_autogen1").click find('li', text: distributor.name).click # selects Distributor @@ -329,10 +331,10 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do expect(table).to have_content(supplier_state_tax1) expect(table).to have_content(supplier_country_tax1) - expect(table).to have_content(distributor_state_tax1) - expect(table).to have_content(distributor_country_tax1) - expect(table).to have_content(coordinator_state_tax1) - expect(table).to have_content(coordinator_country_tax1) + expect(table).not_to have_content(distributor_state_tax1) + expect(table).not_to have_content(distributor_country_tax1) + expect(table).not_to have_content(coordinator_state_tax1) + expect(table).not_to have_content(coordinator_country_tax1) expect(table).to have_content(cost_of_produce1) expect(table).to have_content(summary_row1) end From 7734b0417d5e2d31987384ccc994bf79ad535817 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Mon, 17 Jul 2023 17:03:11 +0100 Subject: [PATCH 36/46] Updates test case should filter by distributor and order cycle (2) --- ...ry_fee_with_tax_report_by_producer_spec.rb | 37 ++++++++++--------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb b/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb index 76ffc123e8..cb6f6a074c 100644 --- a/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb +++ b/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb @@ -391,6 +391,8 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do # table lines for supplier1 + # for supplier 1, oc3 + let(:coordinator_state_tax3){ ["Distributor", "Supplier1", "Yes", "oc3", "Adminstration", "admin", "Distributor", "tax_category", "State", "0.015", "20.0", "0.3", "20.3"].join(" ") @@ -426,14 +428,13 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do [ cost_of_produce3, # Ensure summary row follows the right supplier "TOTAL", # Fees and line items - "145.0", # Tax excl: 20 + 15 + 10 + 100 - "5.81", # Tax : (0.30 + 0.50) + (0.23 + 0.38) + (0.15 + 0.25) + (1.50 + 2.50) - "150.81" # Tax incl: 145.00 + 5.81 + "115.0", # Tax excl: 15 + 100 + "4.61", # Tax : (0.23 + 0.38) + (1.50 + 2.50) + "119.61" # Tax incl: 100.00 + 15 + (0.23 + 0.38) + (1.50 + 2.50) ].join(" ") } - # table lines for supplier2 - + # for supplier 2, oc3 let(:coordinator_state_tax4){ ["Distributor", "Supplier2", "Yes", "oc3", "Adminstration", "admin", "Distributor", "tax_category", "State", "0.015", "20.0", "0.3", "20.3"].join(" ") @@ -469,9 +470,9 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do [ cost_of_produce4, # Ensure summary row follows the right supplier "TOTAL", # Fees and line items - "105.0", # Tax excl: 20 + 25 + 10 + 50 - "4.21", # Tax : (0.30 + 0.50) + (0.38 + 0.63) + (0.15 + 0.25) + 2 - "109.21" # Tax incl: 105 + 4.21 + "75.0", # Tax excl: 25 + 50 + "3.01", # Tax : (0.38 + 0.63) + 2 + "78.01" # Tax incl: 25 + 50 + 4.21 ].join(" ") } @@ -494,6 +495,8 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do end it "should filter by distributor and order cycle" do + pending "removal from distributor and coordinator fees from results" + page.find("#s2id_autogen1").click find('li', text: distributor.name).click # selects Distributor @@ -509,20 +512,20 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do # Supplier1 expect(table).to have_content(supplier_state_tax3) expect(table).to have_content(supplier_country_tax3) - expect(table).to have_content(distributor_state_tax3) - expect(table).to have_content(distributor_country_tax3) - expect(table).to have_content(coordinator_state_tax3) - expect(table).to have_content(coordinator_country_tax3) + expect(table).not_to have_content(distributor_state_tax3) + expect(table).not_to have_content(distributor_country_tax3) + expect(table).not_to have_content(coordinator_state_tax3) + expect(table).not_to have_content(coordinator_country_tax3) expect(table).to have_content(cost_of_produce3) expect(table).to have_content(summary_row3) # Supplier2 expect(table).to have_content(supplier_state_tax4) expect(table).to have_content(supplier_country_tax4) - expect(table).to have_content(distributor_state_tax4) - expect(table).to have_content(distributor_country_tax4) - expect(table).to have_content(coordinator_state_tax4) - expect(table).to have_content(coordinator_country_tax4) + expect(table).not_to have_content(distributor_state_tax4) + expect(table).not_to have_content(distributor_country_tax4) + expect(table).not_to have_content(coordinator_state_tax4) + expect(table).not_to have_content(coordinator_country_tax4) expect(table).to have_content(cost_of_produce4) expect(table).to have_content(summary_row4) end @@ -651,7 +654,7 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do ].join(" ") } - # for supplier 2, oc2 + # for supplier 2, oc3 let(:coordinator_state_tax2){ ["Distributor", "Supplier2", "Yes", "oc2", "Adminstration", "admin", "Distributor", "tax_category", "State", "0.015", "19.21", "0.3", "19.51"].join(" ") From 86e6697723c8bb8c8cf3e27644231419aff29df1 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Mon, 17 Jul 2023 17:14:01 +0100 Subject: [PATCH 37/46] Updates test case should filter by producer --- ...ummary_fee_with_tax_report_by_producer_spec.rb | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb b/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb index cb6f6a074c..384efe444c 100644 --- a/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb +++ b/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb @@ -531,10 +531,13 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do end it "should filter by producer" do + pending "removal from distributor and coordinator fees from results" + page.find("#s2id_supplier_id_in").click find('li', text: supplier2.name).click expect(page).to have_button("Go") + click_on "Go" expect(page.find("table.report__table thead tr")).to have_content(table_header) @@ -542,19 +545,15 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do expect(table).to have_content(supplier_state_tax2) expect(table).to have_content(supplier_country_tax2) - expect(table).to have_content(distributor_state_tax2) - expect(table).to have_content(distributor_country_tax2) - expect(table).to have_content(coordinator_state_tax2) - expect(table).to have_content(coordinator_country_tax2) + expect(table).not_to have_content(distributor_state_tax2) + expect(table).not_to have_content(distributor_country_tax2) + expect(table).not_to have_content(coordinator_state_tax2) + expect(table).not_to have_content(coordinator_country_tax2) expect(table).to have_content(cost_of_produce2) expect(table).to have_content(summary_row2) expect(table).to_not have_content(supplier_state_tax1) expect(table).to_not have_content(supplier_country_tax1) - expect(table).to_not have_content(distributor_state_tax1) - expect(table).to_not have_content(distributor_country_tax1) - expect(table).to_not have_content(coordinator_state_tax1) - expect(table).to_not have_content(coordinator_country_tax1) expect(table).to_not have_content(cost_of_produce1) expect(table).to_not have_content(summary_row1) end From fc9826b44ac9ca58946509d68f46e1bc8abe8136 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Mon, 17 Jul 2023 17:35:50 +0100 Subject: [PATCH 38/46] Updates test case should filter by fee name --- ...ry_fee_with_tax_report_by_producer_spec.rb | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb b/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb index 384efe444c..aa5d8e45bf 100644 --- a/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb +++ b/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb @@ -537,7 +537,6 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do find('li', text: supplier2.name).click expect(page).to have_button("Go") - click_on "Go" expect(page.find("table.report__table thead tr")).to have_content(table_header) @@ -559,8 +558,9 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do end it "should filter by fee name" do + page.find(fee_name_selector).click - find('li', text: coordinator_fees.name).click + find('li', text: supplier_fees.name).click expect(page).to have_button("Go") click_on "Go" @@ -569,14 +569,23 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do table = page.find("table.report__table tbody") - expect(table).to_not have_content(supplier_state_tax1) - expect(table).to_not have_content(supplier_country_tax1) + expect(table).to have_content(supplier_state_tax1) + expect(table).to have_content(supplier_country_tax1) expect(table).to_not have_content(distributor_state_tax1) expect(table).to_not have_content(distributor_country_tax1) - expect(table).to have_content(coordinator_state_tax1) - expect(table).to have_content(coordinator_country_tax1) + expect(table).to_not have_content(coordinator_state_tax1) + expect(table).to_not have_content(coordinator_country_tax1) expect(table).to have_content(cost_of_produce1) - expect(table).to have_content(summary_row_after_filtering_by_fee_name) + expect(table).to have_content(summary_row1) + + expect(table).to have_content(supplier_state_tax3) + expect(table).to have_content(supplier_country_tax3) + expect(table).to_not have_content(distributor_state_tax3) + expect(table).to_not have_content(distributor_country_tax3) + expect(table).to_not have_content(coordinator_state_tax3) + expect(table).to_not have_content(coordinator_country_tax3) + expect(table).to have_content(cost_of_produce3) + expect(table).to have_content(summary_row3) end it "should filter by fee owner" do From 57f058eeb2aefe2d79acd9b00120e63cc534eaeb Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Mon, 17 Jul 2023 18:54:15 +0100 Subject: [PATCH 39/46] Updates test case should list all the tax rates --- ...ry_fee_with_tax_report_by_producer_spec.rb | 47 ++++++++++--------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb b/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb index aa5d8e45bf..a98ec3fec6 100644 --- a/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb +++ b/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb @@ -656,9 +656,9 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do [ cost_of_produce1, "TOTAL", # Fees and line items - "139.31", # Tax excl: 19.21 + 14.41 + 9.61 + 96.08 - "5.69", # Tax : (0.30 + 0.50) + (0.23 + 0.38) + (0.15 + 0.25) + (1.50 + 2.50) - "145.0" # Tax incl: 20 + 15 + 10 + 100 + "110.49", # Tax excl: 14.41 + 96.08 + "4.51", # Tax : (0.22 + 0.37) + 3.92 + "115.0" # Tax incl: 15 + 100 ].join(" ") } @@ -698,15 +698,16 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do [ cost_of_produce2, "TOTAL", # Fees and line items - "100.88", # Tax excl: 19.21 + 24.02 + 9.61 + 48.04 - "4.12", # Tax : (0.30 + 0.50) + (0.38 + 0.63) + (0.15 + 0.25) + 2 - "105.0" # Tax incl: 20 + 25 + 10 + 50 + "72.06", # Tax excl: 24.02 + 48.04 + "2.94", # Tax : (0.37 + 0.61) + 1.96 + "75.0" # Tax incl: 25 + 50 ].join(" ") } context "with line items from a single supplier" do it 'generates the report and displays fees for the respective suppliers' do - # pending("test case (3), see #10797") + pending "removal from distributor and coordinator fees from results" + login_as distributor_owner visit admin_reports_path click_on "Enterprise Fees With Tax Report By Producer" @@ -719,19 +720,19 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do table = page.find("table.report__table tbody") expect(table).to have_content(supplier_state_tax1) expect(table).to have_content(supplier_country_tax1) - expect(table).to have_content(distributor_state_tax1) - expect(table).to have_content(distributor_country_tax1) - expect(table).to have_content(coordinator_state_tax1) - expect(table).to have_content(coordinator_country_tax1) + expect(table).not_to have_content(distributor_state_tax1) + expect(table).not_to have_content(distributor_country_tax1) + expect(table).not_to have_content(coordinator_state_tax1) + expect(table).not_to have_content(coordinator_country_tax1) expect(table).to have_content(cost_of_produce1) expect(table).to have_content(summary_row1) expect(table).to have_content(supplier_state_tax2) expect(table).to have_content(supplier_country_tax2) - expect(table).to have_content(distributor_state_tax2) - expect(table).to have_content(distributor_country_tax2) - expect(table).to have_content(coordinator_state_tax2) - expect(table).to have_content(coordinator_country_tax2) + expect(table).not_to have_content(distributor_state_tax2) + expect(table).not_to have_content(distributor_country_tax2) + expect(table).not_to have_content(coordinator_state_tax2) + expect(table).not_to have_content(coordinator_country_tax2) expect(table).to have_content(cost_of_produce2) expect(table).to have_content(summary_row2) end @@ -844,11 +845,13 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do let(:summary_row){ [ - "TOTAL", "240.0", "10.09", "250.09" + "TOTAL", "180.0", "7.54", "187.54" ].join(" ") } it 'should list all the tax rates' do + pending "removal from distributor and coordinator fees from results" + login_as distributor_owner visit admin_reports_path click_on "Enterprise Fees With Tax Report By Producer" @@ -859,16 +862,16 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do expect(page.find("table.report__table thead tr")).to have_content(table_header) table = page.find("table.report__table tbody") - expect(table).to have_content(admin_state_tax1) - expect(table).to have_content(admin_country_tax1) + expect(table).not_to have_content(admin_state_tax1) + expect(table).not_to have_content(admin_country_tax1) expect(table).to have_content(transport_state_tax1) expect(table).to have_content(transport_country_tax1) - expect(table).to have_content(packing_state_tax1) - expect(table).to have_content(packing_country_tax1) + expect(table).not_to have_content(packing_state_tax1) + expect(table).not_to have_content(packing_country_tax1) - expect(table).to have_content(admin_state_tax2) + expect(table).not_to have_content(admin_state_tax2) expect(table).to have_content(transport_state_tax2) - expect(table).to have_content(packing_state_tax2) + expect(table).not_to have_content(packing_state_tax2) expect(table).to have_content(supplier1_cost_of_produce_line_items) expect(table).to have_content(summary_row) From 131474e91d58e78e200293bb674bced1aec664a7 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Mon, 17 Jul 2023 18:54:15 +0100 Subject: [PATCH 40/46] Updates test case should list all the tax rates (2) --- ...ary_fee_with_tax_report_by_producer_spec.rb | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb b/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb index a98ec3fec6..0102def430 100644 --- a/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb +++ b/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb @@ -946,31 +946,33 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do let(:summary_row){ [ - "TOTAL", "230.13", "9.87", "240.0" + "TOTAL", "172.63", "7.37", "180.0" ].join(" ") } it 'should list all the tax rates' do + pending "removal from distributor and coordinator fees from results" + login_as distributor_owner visit admin_reports_path click_on "Enterprise Fees With Tax Report By Producer" - expect(page).to have_button("Go") + expect(page).to have_button("Go") click_on "Go" expect(page.find("table.report__table thead tr")).to have_content(table_header) table = page.find("table.report__table tbody") - expect(table).to have_content(admin_state_tax1) - expect(table).to have_content(admin_country_tax1) + expect(table).not_to have_content(admin_state_tax1) + expect(table).not_to have_content(admin_country_tax1) expect(table).to have_content(transport_state_tax1) expect(table).to have_content(transport_country_tax1) - expect(table).to have_content(packing_state_tax1) - expect(table).to have_content(packing_country_tax1) + expect(table).not_to have_content(packing_state_tax1) + expect(table).not_to have_content(packing_country_tax1) - expect(table).to have_content(admin_state_tax2) + expect(table).not_to have_content(admin_state_tax2) expect(table).to have_content(transport_state_tax2) - expect(table).to have_content(packing_state_tax2) + expect(table).not_to have_content(packing_state_tax2) expect(table).to have_content(supplier1_cost_of_produce_line_items) expect(table).to have_content(summary_row) From af525f9f7f6f2597371d2dddb03e385f92cc5c88 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Mon, 17 Jul 2023 19:16:28 +0100 Subject: [PATCH 41/46] Fixes rubocop issues --- ...se_summary_fee_with_tax_report_by_producer_spec.rb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb b/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb index 0102def430..9407607895 100644 --- a/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb +++ b/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb @@ -269,7 +269,7 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do cost_of_produce2, # Ensure summary row follows the right supplier "TOTAL", # Fees and line items "75.0", # Tax excl: 25 + 50 - "3.01", # Tax : (0.38 + 0.63) + 2 + "3.01", # Tax : (0.38 + 0.63) + 2 "78.01" # Tax incl: 25 + 50 + 4.21 ].join(" ") } @@ -277,14 +277,14 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do context "with line items from a single supplier" do it 'generates the report and displays fees for the respective suppliers' do pending "removal from distributor and coordinator fees from results" - + login_as distributor_owner visit admin_reports_path click_on "Enterprise Fees With Tax Report By Producer" expect(page).to have_button("Go") click_on "Go" - + expect(page.find("table.report__table thead tr")).to have_content(table_header) table = page.find("table.report__table tbody") @@ -471,7 +471,7 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do cost_of_produce4, # Ensure summary row follows the right supplier "TOTAL", # Fees and line items "75.0", # Tax excl: 25 + 50 - "3.01", # Tax : (0.38 + 0.63) + 2 + "3.01", # Tax : (0.38 + 0.63) + 2 "78.01" # Tax incl: 25 + 50 + 4.21 ].join(" ") } @@ -558,7 +558,6 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do end it "should filter by fee name" do - page.find(fee_name_selector).click find('li', text: supplier_fees.name).click @@ -707,7 +706,7 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do context "with line items from a single supplier" do it 'generates the report and displays fees for the respective suppliers' do pending "removal from distributor and coordinator fees from results" - + login_as distributor_owner visit admin_reports_path click_on "Enterprise Fees With Tax Report By Producer" From 4cb91da8b228340518424799853d06ffdde327bb Mon Sep 17 00:00:00 2001 From: Mohamed ABDELLANI Date: Wed, 2 Aug 2023 18:25:38 +0100 Subject: [PATCH 42/46] load only enterprise fees connected to incoming exchanges on the OC --- .../enterprise_fees_with_tax_report_by_producer.rb | 10 ++++++++++ ...summary_fee_with_tax_report_by_producer_spec.rb | 14 -------------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb b/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb index 4ca3848346..d7aa97d9b2 100644 --- a/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb +++ b/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb @@ -85,6 +85,7 @@ module Reporting query = order .all_adjustments .enterprise_fee + .where(originator_id: enterprise_fees_related_to_incoming_exchanges_ids(order)) if enterprise_fee_filters? query = query.where(originator_id: enterprise_fee_filtered_ids) @@ -101,6 +102,15 @@ module Reporting end end + def enterprise_fees_related_to_incoming_exchanges_ids(order) + order + .order_cycle + .exchanges + .incoming + .flat_map(&:enterprise_fee_ids) + .uniq + end + def join_tax_rate proc do |item| tax_rate_ids = item[:order].all_adjustments.tax.where( diff --git a/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb b/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb index 9407607895..2250fdde0a 100644 --- a/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb +++ b/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb @@ -276,8 +276,6 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do context "with line items from a single supplier" do it 'generates the report and displays fees for the respective suppliers' do - pending "removal from distributor and coordinator fees from results" - login_as distributor_owner visit admin_reports_path click_on "Enterprise Fees With Tax Report By Producer" @@ -315,8 +313,6 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do end it "should filter by distributor and order cycle" do - pending "removal from distributor and coordinator fees from results" - page.find("#s2id_autogen1").click find('li', text: distributor.name).click # selects Distributor @@ -495,8 +491,6 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do end it "should filter by distributor and order cycle" do - pending "removal from distributor and coordinator fees from results" - page.find("#s2id_autogen1").click find('li', text: distributor.name).click # selects Distributor @@ -531,8 +525,6 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do end it "should filter by producer" do - pending "removal from distributor and coordinator fees from results" - page.find("#s2id_supplier_id_in").click find('li', text: supplier2.name).click @@ -705,8 +697,6 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do context "with line items from a single supplier" do it 'generates the report and displays fees for the respective suppliers' do - pending "removal from distributor and coordinator fees from results" - login_as distributor_owner visit admin_reports_path click_on "Enterprise Fees With Tax Report By Producer" @@ -849,8 +839,6 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do } it 'should list all the tax rates' do - pending "removal from distributor and coordinator fees from results" - login_as distributor_owner visit admin_reports_path click_on "Enterprise Fees With Tax Report By Producer" @@ -950,8 +938,6 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do } it 'should list all the tax rates' do - pending "removal from distributor and coordinator fees from results" - login_as distributor_owner visit admin_reports_path click_on "Enterprise Fees With Tax Report By Producer" From db8392ce81800bf4592ee1e010cfa9d0353a242c Mon Sep 17 00:00:00 2001 From: David Cook Date: Fri, 8 Sep 2023 10:32:56 +1000 Subject: [PATCH 43/46] Temporarily hide report --- lib/reporting/reports/list.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/reporting/reports/list.rb b/lib/reporting/reports/list.rb index 2f6567a666..ebb0a86fe1 100644 --- a/lib/reporting/reports/list.rb +++ b/lib/reporting/reports/list.rb @@ -2,7 +2,7 @@ module Reporting module Reports - class List # rubocop:disable Metrics/ClassLength # Because it's a simple class + class List def self.all new.all end @@ -67,10 +67,11 @@ module Reporting i18n_translate('enterprise_fees_with_tax_report_by_order'), :enterprise_fees_with_tax_report_by_order ], - [ - i18n_translate('enterprise_fees_with_tax_report_by_producer'), - :enterprise_fees_with_tax_report_by_producer - ], + # Hidden from view until report specifics are finalised. + # [ + # i18n_translate('enterprise_fees_with_tax_report_by_producer'), + # :enterprise_fees_with_tax_report_by_producer + # ], ] end From ef1ccca4fa72b607273f4926f8c51e194847d0e9 Mon Sep 17 00:00:00 2001 From: David Cook Date: Tue, 12 Sep 2023 16:10:08 +1000 Subject: [PATCH 44/46] Temporarily 'hide' report The reports framework doesn't currently support hidden reports, but we can mark it with a strike-through at least. --- lib/reporting/reports/list.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/reporting/reports/list.rb b/lib/reporting/reports/list.rb index ebb0a86fe1..5874b70c70 100644 --- a/lib/reporting/reports/list.rb +++ b/lib/reporting/reports/list.rb @@ -2,7 +2,7 @@ module Reporting module Reports - class List + class List # rubocop:disable Metrics/ClassLength # Because it's a simple class def self.all new.all end @@ -67,11 +67,11 @@ module Reporting i18n_translate('enterprise_fees_with_tax_report_by_order'), :enterprise_fees_with_tax_report_by_order ], - # Hidden from view until report specifics are finalised. - # [ - # i18n_translate('enterprise_fees_with_tax_report_by_producer'), - # :enterprise_fees_with_tax_report_by_producer - # ], + [ + i18n_translate('enterprise_fees_with_tax_report_by_producer'), + :enterprise_fees_with_tax_report_by_producer, + { deprecated: true }, # Not supported until specific details are finalised. + ], ] end From b27f63fa60ad1cab46c4f91284b23cac4f25853d Mon Sep 17 00:00:00 2001 From: David Cook Date: Fri, 8 Sep 2023 12:01:05 +1000 Subject: [PATCH 45/46] Refactor: DRY up init code --- ...ry_fee_with_tax_report_by_producer_spec.rb | 39 +++++++------------ 1 file changed, 13 insertions(+), 26 deletions(-) diff --git a/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb b/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb index 2250fdde0a..b71cc59dde 100644 --- a/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb +++ b/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb @@ -276,11 +276,7 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do context "with line items from a single supplier" do it 'generates the report and displays fees for the respective suppliers' do - login_as distributor_owner - visit admin_reports_path - click_on "Enterprise Fees With Tax Report By Producer" - expect(page).to have_button("Go") - + visit_report click_on "Go" expect(page.find("table.report__table thead tr")).to have_content(table_header) @@ -307,9 +303,7 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do context "filtering" do before do - login_as distributor_owner - visit admin_reports_path - click_on "Enterprise Fees With Tax Report By Producer" + visit_report end it "should filter by distributor and order cycle" do @@ -485,9 +479,7 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do } before do - login_as distributor_owner - visit admin_reports_path - click_on "Enterprise Fees With Tax Report By Producer" + visit_report end it "should filter by distributor and order cycle" do @@ -697,11 +689,7 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do context "with line items from a single supplier" do it 'generates the report and displays fees for the respective suppliers' do - login_as distributor_owner - visit admin_reports_path - click_on "Enterprise Fees With Tax Report By Producer" - expect(page).to have_button("Go") - + visit_report click_on "Go" expect(page.find("table.report__table thead tr")).to have_content(table_header) @@ -839,11 +827,7 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do } it 'should list all the tax rates' do - login_as distributor_owner - visit admin_reports_path - click_on "Enterprise Fees With Tax Report By Producer" - expect(page).to have_button("Go") - + visit_report click_on "Go" expect(page.find("table.report__table thead tr")).to have_content(table_header) @@ -938,11 +922,7 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do } it 'should list all the tax rates' do - login_as distributor_owner - visit admin_reports_path - click_on "Enterprise Fees With Tax Report By Producer" - - expect(page).to have_button("Go") + visit_report click_on "Go" expect(page.find("table.report__table thead tr")).to have_content(table_header) @@ -964,4 +944,11 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do end end end + + def visit_report + login_as distributor_owner + visit admin_reports_path + click_on "Enterprise Fees With Tax Report By Producer" + expect(page).to have_button("Go") + end end From ee2520a1f667f9ab6e68bbed0e6ff8099e7e34b4 Mon Sep 17 00:00:00 2001 From: David Cook Date: Fri, 8 Sep 2023 12:02:33 +1000 Subject: [PATCH 46/46] Visit page directly to save time Shaved a couple of seconds off, 35->33 sec. And make it easier to hide from the list. --- ...terprise_summary_fee_with_tax_report_by_producer_spec.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb b/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb index b71cc59dde..8fb6731421 100644 --- a/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb +++ b/spec/system/admin/reports/enterprise_summary_fees/enterprise_summary_fee_with_tax_report_by_producer_spec.rb @@ -947,8 +947,10 @@ describe "Enterprise Summary Fee with Tax Report By Producer" do def visit_report login_as distributor_owner - visit admin_reports_path - click_on "Enterprise Fees With Tax Report By Producer" + visit admin_report_path( + report_type: :enterprise_fee_summary, + report_subtype: :enterprise_fees_with_tax_report_by_producer + ) expect(page).to have_button("Go") end end