Skip to content

Commit

Permalink
12890: add cities and countries data
Browse files Browse the repository at this point in the history
  • Loading branch information
chahmedejaz authored and RachL committed Nov 21, 2024
1 parent d0dcc92 commit 3b86315
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,23 @@ def initialize(row)
def build_supplier
DataFoodConsortium::Connector::Enterprise.new(
nil,
localizations: [build_address(item[:supplier_postcode])],
localizations: [build_address(
item[:supplier_postcode],
item[:supplier_city],
item[:supplier_country]
)],
suppliedProducts: [build_product],
)
end

def build_distributor
DataFoodConsortium::Connector::Enterprise.new(
nil,
localizations: [build_address(item[:distributor_postcode])],
localizations: [build_address(
item[:distributor_postcode],
item[:distributor_city],
item[:distributor_country]
)],
)
end

Expand Down Expand Up @@ -89,9 +97,11 @@ def build_price
)
end

def build_address(postcode)
def build_address(postcode, city, country)
DataFoodConsortium::Connector::Address.new(
nil,
city:,
country:,
postalCode: postcode,
)
end
Expand Down
16 changes: 15 additions & 1 deletion engines/dfc_provider/app/services/affiliate_sales_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ def tables
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

Expand All @@ -53,7 +55,11 @@ def fields
spree_variants.unit_presentation,
spree_line_items.price,
distributor_addresses.zipcode AS distributor_postcode,
distributor_addresses.city AS distributor_city,
distributor_countries.name AS distributor_country,
supplier_addresses.zipcode AS supplier_postcode,
supplier_addresses.city AS supplier_city,
supplier_countries.name AS supplier_country,
SUM(spree_line_items.quantity) AS quantity_sold
SQL
Expand All @@ -68,7 +74,11 @@ def key_fields
spree_variants.unit_presentation,
spree_line_items.price,
distributor_postcode,
supplier_postcode
supplier_postcode,
distributor_city,
supplier_city,
distributor_country,
supplier_country
SQL
end

Expand All @@ -82,7 +92,11 @@ def labels
unit_presentation
price
distributor_postcode
distributor_city
distributor_country
supplier_postcode
supplier_city
supplier_country
quantity_sold
]
end
Expand Down

0 comments on commit 3b86315

Please sign in to comment.