mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-06 22:36:07 +00:00
Fix sample product creation and use bang methods
Mistakes like the missing fee when creating product distributions were hidden, because I didn't use the bang methods to create records.
This commit is contained in:
@@ -15,7 +15,7 @@ module Addressing
|
||||
|
||||
def zone
|
||||
zone = Spree::Zone.find_or_create_by_name!("Australia")
|
||||
zone.members.create(zonable: country)
|
||||
zone.members.create!(zonable: country)
|
||||
zone
|
||||
end
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ class InventoryFactory
|
||||
enterprise: shop,
|
||||
variant: product.variants.first,
|
||||
visible: true
|
||||
).find_or_create_by_variant_id(product.variants.first.id)
|
||||
).find_or_create_by_variant_id!(product.variants.first.id)
|
||||
create_override(shop, product)
|
||||
end
|
||||
|
||||
@@ -29,6 +29,6 @@ class InventoryFactory
|
||||
price: 12,
|
||||
on_demand: false,
|
||||
count_on_hand: 5
|
||||
).find_or_create_by_variant_id(product.variants.first.id)
|
||||
).find_or_create_by_variant_id!(product.variants.first.id)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -76,15 +76,18 @@ class ProductFactory
|
||||
unit_value: 1,
|
||||
on_demand: true
|
||||
)
|
||||
create_product_with_distribution(params)
|
||||
create_product_with_distribution(params, hash[:supplier])
|
||||
end
|
||||
|
||||
def create_product_with_distribution(params)
|
||||
product = Spree::Product.create_with(params).find_or_create_by_name(params[:name])
|
||||
ProductDistribution.create(
|
||||
product: product,
|
||||
distributor: params[:distributor]
|
||||
)
|
||||
def create_product_with_distribution(params, supplier)
|
||||
product = Spree::Product.create_with(params).find_or_create_by_name!(params[:name])
|
||||
|
||||
distribution_params = {
|
||||
distributor_id: params[:distributor].id,
|
||||
enterprise_fee_id: supplier.enterprise_fees.first.id
|
||||
}
|
||||
ProductDistribution.create_with(distribution_params).find_or_create_by_product_id!(product.id)
|
||||
|
||||
product
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user