mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
12890: add cities and countries data
This commit is contained in:
@@ -12,7 +12,11 @@ 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_city],
|
||||
item[:supplier_country]
|
||||
)],
|
||||
suppliedProducts: [build_product],
|
||||
)
|
||||
end
|
||||
@@ -20,7 +24,11 @@ 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_city],
|
||||
item[:distributor_country]
|
||||
)],
|
||||
)
|
||||
end
|
||||
|
||||
@@ -89,9 +97,11 @@ class AffiliateSalesDataRowBuilder < DfcBuilder
|
||||
)
|
||||
end
|
||||
|
||||
def build_address(postcode)
|
||||
def build_address(postcode, city, country)
|
||||
DataFoodConsortium::Connector::Address.new(
|
||||
nil,
|
||||
city:,
|
||||
country:,
|
||||
postalCode: postcode,
|
||||
)
|
||||
end
|
||||
|
||||
@@ -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,11 @@ class AffiliateSalesQuery
|
||||
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
|
||||
@@ -68,7 +74,11 @@ class AffiliateSalesQuery
|
||||
spree_variants.unit_presentation,
|
||||
spree_line_items.price,
|
||||
distributor_postcode,
|
||||
supplier_postcode
|
||||
supplier_postcode,
|
||||
distributor_city,
|
||||
supplier_city,
|
||||
distributor_country,
|
||||
supplier_country
|
||||
SQL
|
||||
end
|
||||
|
||||
@@ -82,7 +92,11 @@ class AffiliateSalesQuery
|
||||
unit_presentation
|
||||
price
|
||||
distributor_postcode
|
||||
distributor_city
|
||||
distributor_country
|
||||
supplier_postcode
|
||||
supplier_city
|
||||
supplier_country
|
||||
quantity_sold
|
||||
]
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user