mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-04-09 07:56:58 +00:00
Merge pull request #2574 from luisramos0/bulk_line_items_controller_spec_fix
Spree2 - Bulk line items controller spec fix
This commit is contained in:
@@ -1,16 +0,0 @@
|
||||
module Spree
|
||||
InventoryUnit.class_eval do
|
||||
def self.assign_opening_inventory(order)
|
||||
return [] unless order.completed?
|
||||
|
||||
#increase inventory to meet initial requirements
|
||||
scoper = OpenFoodNetwork::ScopeVariantToHub.new(order.distributor)
|
||||
order.line_items.each do |line_item|
|
||||
# Scope variant to hub so that stock levels may be subtracted from VariantOverride.
|
||||
scoper.scope(line_item.variant)
|
||||
|
||||
increase(order, line_item.variant, line_item.quantity)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -110,34 +110,6 @@ Spree::LineItem.class_eval do
|
||||
final_weight_volume / quantity
|
||||
end
|
||||
|
||||
# MONKEYPATCH of Spree method
|
||||
# Enables scoping of variant to hub/shop, stock drawn down from inventory
|
||||
def update_inventory
|
||||
return true unless order.completed?
|
||||
|
||||
scoper.scope(variant) # this line added
|
||||
|
||||
if new_record?
|
||||
Spree::InventoryUnit.increase(order, variant, quantity)
|
||||
elsif old_quantity = self.changed_attributes['quantity']
|
||||
if old_quantity < quantity
|
||||
Spree::InventoryUnit.increase(order, variant, (quantity - old_quantity))
|
||||
elsif old_quantity > quantity
|
||||
Spree::InventoryUnit.decrease(order, variant, (old_quantity - quantity))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# MONKEYPATCH of Spree method
|
||||
# Enables scoping of variant to hub/shop, stock replaced to inventory
|
||||
def remove_inventory
|
||||
return true unless order.completed?
|
||||
|
||||
scoper.scope(variant) # this line added
|
||||
|
||||
Spree::InventoryUnit.decrease(order, variant, quantity)
|
||||
end
|
||||
|
||||
# MONKEYPATCH of Spree method
|
||||
# Enables scoping of variant to hub/shop, so we check stock against relevant overrides if they exist
|
||||
# Also skips stock check if requested quantity is zero
|
||||
|
||||
@@ -2,6 +2,7 @@ module Spree
|
||||
Shipment.class_eval do
|
||||
def ensure_correct_adjustment_with_included_tax
|
||||
ensure_correct_adjustment_without_included_tax
|
||||
return unless adjustment
|
||||
|
||||
if Config.shipment_inc_vat && (order.distributor.nil? || order.distributor.charges_sales_tax)
|
||||
adjustment.set_included_tax! Config.shipping_tax_rate
|
||||
|
||||
@@ -11,10 +11,13 @@ describe Admin::BulkLineItemsController, type: :controller do
|
||||
let!(:order1) { FactoryBot.create(:order, state: 'complete', completed_at: 1.day.ago, distributor: dist1, billing_address: FactoryBot.create(:address) ) }
|
||||
let!(:order2) { FactoryBot.create(:order, state: 'complete', completed_at: Time.zone.now, distributor: dist1, billing_address: FactoryBot.create(:address) ) }
|
||||
let!(:order3) { FactoryBot.create(:order, state: 'complete', completed_at: Time.zone.now, distributor: dist1, billing_address: FactoryBot.create(:address) ) }
|
||||
let!(:line_item1) { FactoryBot.create(:line_item, order: order1) }
|
||||
let!(:line_item2) { FactoryBot.create(:line_item, order: order2) }
|
||||
let!(:line_item3) { FactoryBot.create(:line_item, order: order2) }
|
||||
let!(:line_item4) { FactoryBot.create(:line_item, order: order3) }
|
||||
let(:shipment1) { FactoryBot.create(:shipment, order:order1) }
|
||||
let(:shipment2) { FactoryBot.create(:shipment, order:order2) }
|
||||
let(:shipment3) { FactoryBot.create(:shipment, order:order3) }
|
||||
let!(:line_item1) { FactoryBot.create(:line_item, order: order1, target_shipment: shipment1) }
|
||||
let!(:line_item2) { FactoryBot.create(:line_item, order: order2, target_shipment: shipment2) }
|
||||
let!(:line_item3) { FactoryBot.create(:line_item, order: order2, target_shipment: shipment2) }
|
||||
let!(:line_item4) { FactoryBot.create(:line_item, order: order3, target_shipment: shipment3) }
|
||||
|
||||
context "as a normal user" do
|
||||
before { controller.stub spree_current_user: create_enterprise_user }
|
||||
@@ -83,10 +86,12 @@ describe Admin::BulkLineItemsController, type: :controller do
|
||||
let(:coordinator) { create(:distributor_enterprise) }
|
||||
let(:order_cycle) { create(:simple_order_cycle, coordinator: coordinator) }
|
||||
let!(:order1) { FactoryBot.create(:order, order_cycle: order_cycle, state: 'complete', completed_at: Time.zone.now, distributor: distributor1, billing_address: FactoryBot.create(:address) ) }
|
||||
let!(:line_item1) { FactoryBot.create(:line_item, order: order1, product: FactoryBot.create(:product, supplier: supplier)) }
|
||||
let!(:line_item2) { FactoryBot.create(:line_item, order: order1, product: FactoryBot.create(:product, supplier: supplier)) }
|
||||
let(:shipment1) { FactoryBot.create(:shipment, order:order1) }
|
||||
let(:shipment2) { FactoryBot.create(:shipment, order:order2) }
|
||||
let!(:line_item1) { FactoryBot.create(:line_item, order: order1, target_shipment: shipment1, product: FactoryBot.create(:product, supplier: supplier)) }
|
||||
let!(:line_item2) { FactoryBot.create(:line_item, order: order1, target_shipment: shipment1, product: FactoryBot.create(:product, supplier: supplier)) }
|
||||
let!(:order2) { FactoryBot.create(:order, order_cycle: order_cycle, state: 'complete', completed_at: Time.zone.now, distributor: distributor2, billing_address: FactoryBot.create(:address) ) }
|
||||
let!(:line_item3) { FactoryBot.create(:line_item, order: order2, product: FactoryBot.create(:product, supplier: supplier)) }
|
||||
let!(:line_item3) { FactoryBot.create(:line_item, order: order2, target_shipment: shipment2, product: FactoryBot.create(:product, supplier: supplier)) }
|
||||
|
||||
context "producer enterprise" do
|
||||
before do
|
||||
@@ -131,7 +136,12 @@ describe Admin::BulkLineItemsController, type: :controller do
|
||||
let(:coordinator) { create(:distributor_enterprise) }
|
||||
let(:order_cycle) { create(:simple_order_cycle, coordinator: coordinator) }
|
||||
let!(:order1) { FactoryBot.create(:order, order_cycle: order_cycle, state: 'complete', completed_at: Time.zone.now, distributor: distributor1, billing_address: FactoryBot.create(:address) ) }
|
||||
let!(:line_item1) { FactoryBot.create(:line_item, order: order1, product: FactoryBot.create(:product, supplier: supplier)) }
|
||||
let(:shipment1) { FactoryBot.create(:shipment, order:order1) }
|
||||
let!(:line_item1) {
|
||||
line_item1 = FactoryBot.create(:line_item, order: order1, target_shipment: shipment1, product: FactoryBot.create(:product, supplier: supplier))
|
||||
# make sure target_shipment is available through db reloads of this line_item
|
||||
line_item1.tap(&:save!)
|
||||
}
|
||||
let(:line_item_params) { { quantity: 3, final_weight_volume: 3000, price: 3.00 } }
|
||||
let(:params) { { id: line_item1.id, order_id: order1.number, line_item: line_item_params } }
|
||||
|
||||
@@ -227,7 +237,8 @@ describe Admin::BulkLineItemsController, type: :controller do
|
||||
let(:coordinator) { create(:distributor_enterprise) }
|
||||
let(:order_cycle) { create(:simple_order_cycle, coordinator: coordinator) }
|
||||
let!(:order1) { FactoryBot.create(:order, order_cycle: order_cycle, state: 'complete', completed_at: Time.zone.now, distributor: distributor1, billing_address: FactoryBot.create(:address) ) }
|
||||
let!(:line_item1) { FactoryBot.create(:line_item, order: order1, product: FactoryBot.create(:product, supplier: supplier)) }
|
||||
let(:shipment1) { FactoryBot.create(:shipment, order:order1) }
|
||||
let!(:line_item1) { FactoryBot.create(:line_item, order: order1, target_shipment: shipment1, product: FactoryBot.create(:product, supplier: supplier)) }
|
||||
let(:params) { { id: line_item1.id, order_id: order1.number } }
|
||||
|
||||
before do
|
||||
|
||||
Reference in New Issue
Block a user