diff --git a/engines/dfc_provider/app/services/affiliate_sales_data_row_builder.rb b/engines/dfc_provider/app/services/affiliate_sales_data_row_builder.rb index 073097a04f..8d50508a63 100644 --- a/engines/dfc_provider/app/services/affiliate_sales_data_row_builder.rb +++ b/engines/dfc_provider/app/services/affiliate_sales_data_row_builder.rb @@ -12,7 +12,10 @@ class AffiliateSalesDataRowBuilder < DfcBuilder def build_supplier DataFoodConsortium::Connector::Enterprise.new( nil, - localizations: [build_address(item[:supplier_postcode])], + localizations: [build_address( + item[:supplier_postcode], + item[:supplier_country] + )], suppliedProducts: [build_product], ) end @@ -20,7 +23,10 @@ class AffiliateSalesDataRowBuilder < DfcBuilder def build_distributor DataFoodConsortium::Connector::Enterprise.new( nil, - localizations: [build_address(item[:distributor_postcode])], + localizations: [build_address( + item[:distributor_postcode], + item[:distributor_country] + )], ) end @@ -89,9 +95,10 @@ class AffiliateSalesDataRowBuilder < DfcBuilder ) end - def build_address(postcode) + def build_address(postcode, country) DataFoodConsortium::Connector::Address.new( nil, + country:, postalCode: postcode, ) end diff --git a/engines/dfc_provider/app/services/affiliate_sales_query.rb b/engines/dfc_provider/app/services/affiliate_sales_query.rb index 3193ed5623..a2a90ad233 100644 --- a/engines/dfc_provider/app/services/affiliate_sales_query.rb +++ b/engines/dfc_provider/app/services/affiliate_sales_query.rb @@ -38,9 +38,11 @@ class AffiliateSalesQuery JOIN spree_products ON spree_products.id = spree_variants.product_id JOIN enterprises AS suppliers ON suppliers.id = spree_variants.supplier_id JOIN spree_addresses AS supplier_addresses ON supplier_addresses.id = suppliers.address_id + JOIN spree_countries AS supplier_countries ON supplier_countries.id = supplier_addresses.country_id JOIN spree_orders ON spree_orders.id = spree_line_items.order_id JOIN enterprises AS distributors ON distributors.id = spree_orders.distributor_id JOIN spree_addresses AS distributor_addresses ON distributor_addresses.id = distributors.address_id + JOIN spree_countries AS distributor_countries ON distributor_countries.id = distributor_addresses.country_id SQL end @@ -53,7 +55,9 @@ class AffiliateSalesQuery spree_variants.unit_presentation, spree_line_items.price, distributor_addresses.zipcode AS distributor_postcode, + distributor_countries.name AS distributor_country, supplier_addresses.zipcode AS supplier_postcode, + supplier_countries.name AS supplier_country, SUM(spree_line_items.quantity) AS quantity_sold SQL @@ -68,7 +72,9 @@ class AffiliateSalesQuery spree_variants.unit_presentation, spree_line_items.price, distributor_postcode, - supplier_postcode + supplier_postcode, + distributor_country, + supplier_country SQL end @@ -82,7 +88,9 @@ class AffiliateSalesQuery unit_presentation price distributor_postcode + distributor_country supplier_postcode + supplier_country quantity_sold ] end diff --git a/engines/dfc_provider/spec/services/affiliate_sales_query_spec.rb b/engines/dfc_provider/spec/services/affiliate_sales_query_spec.rb index 4ae4b91954..7bb431cb06 100644 --- a/engines/dfc_provider/spec/services/affiliate_sales_query_spec.rb +++ b/engines/dfc_provider/spec/services/affiliate_sales_query_spec.rb @@ -53,9 +53,15 @@ RSpec.describe AffiliateSalesQuery do it "converts an array to a hash" do row = [ "Apples", - "item", "item", nil, nil, + "item", + "item", + nil, + nil, 15.50, - "3210", "3211", + "3210", + "country1", + "3211", + "country2", 3, ] expect(query.label_row(row)).to eq( @@ -67,7 +73,9 @@ RSpec.describe AffiliateSalesQuery do unit_presentation: nil, price: 15.50, distributor_postcode: "3210", + distributor_country: "country1", supplier_postcode: "3211", + supplier_country: "country2", quantity_sold: 3, } ) diff --git a/spec/system/admin/reports/pay_your_suppliers_spec.rb b/spec/system/admin/reports/pay_your_suppliers_spec.rb index a7b7ac9966..b22a094c5d 100644 --- a/spec/system/admin/reports/pay_your_suppliers_spec.rb +++ b/spec/system/admin/reports/pay_your_suppliers_spec.rb @@ -34,6 +34,8 @@ RSpec.describe "Pay Your Suppliers Report" do before do login_as owner visit admin_reports_path + + update_line_items_product_names end context "on Reports page" do @@ -138,4 +140,18 @@ RSpec.describe "Pay Your Suppliers Report" do expect(lines.last).to have_content("TOTAL 50.0 50.0 0.0 0.0 0.0 50.0") end end + + def update_line_items_product_names + n = 1 + update_product_name_proc = proc do |order| + order.line_items.each do |line_item| + product = line_item.variant.product + product.update!(name: "Product##{n}") + n += 1 + end + end + + update_product_name_proc.call(order1) + update_product_name_proc.call(order2) + end end diff --git a/swagger/dfc.yaml b/swagger/dfc.yaml index 72a3699ab5..3f325a5b73 100644 --- a/swagger/dfc.yaml +++ b/swagger/dfc.yaml @@ -97,12 +97,13 @@ paths: dfc-b:hasAddress: "@type": dfc-b:Address dfc-b:hasPostalCode: '20170' + dfc-b:hasCountry: Australia dfc-b:supplies: "@type": dfc-b:SuppliedProduct dfc-b:name: Tomato dfc-b:hasQuantity: "@type": dfc-b:QuantitativeValue - dfc-b:hasUnit: dfc-m:Gram + dfc-b:hasUnit: dfc-m:Piece dfc-b:value: 1.0 dfc-b:concernedBy: "@type": dfc-b:OrderLine @@ -124,6 +125,7 @@ paths: dfc-b:hasAddress: "@type": dfc-b:Address dfc-b:hasPostalCode: '20170' + dfc-b:hasCountry: Australia '400': description: bad request "/api/dfc/enterprises/{enterprise_id}/catalog_items":