From 60c0c54eb29303093dae0d4797d5785ed917bede Mon Sep 17 00:00:00 2001 From: Gaetan Craig-Riou Date: Mon, 26 Jun 2023 14:26:23 +1000 Subject: [PATCH] Update create_adjustment to create with an amount of 0 Amount calculation is handled by VoucherAdjustmentService.calculate --- app/models/voucher.rb | 7 +++---- spec/models/voucher_spec.rb | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/app/models/voucher.rb b/app/models/voucher.rb index 1199ad0820..60bf1b8cf2 100644 --- a/app/models/voucher.rb +++ b/app/models/voucher.rb @@ -21,12 +21,11 @@ class Voucher < ApplicationRecord # but vouchers have complicated calculation so we can't easily use Spree::Calculator. We keep # the same method to stay as consistent as possible. # - # Creates a new voucher adjustment for the given order + # Creates a new voucher adjustment for the given order with an amount of 0 + # The amount will be calculated via VoucherAdjustmentsService.calculate def create_adjustment(label, order) - amount = compute_amount(order) - adjustment_attributes = { - amount: amount, + amount: 0, originator: self, order: order, label: label, diff --git a/spec/models/voucher_spec.rb b/spec/models/voucher_spec.rb index a41ec65812..0c62a81496 100644 --- a/spec/models/voucher_spec.rb +++ b/spec/models/voucher_spec.rb @@ -45,8 +45,8 @@ describe Voucher do let(:voucher) { create(:voucher, code: 'new_code', enterprise: enterprise, amount: 25) } let(:order) { create(:order_with_line_items, line_items_count: 3, distributor: enterprise) } - it 'includes the full voucher amount' do - expect(adjustment.amount.to_f).to eq(-25.0) + it 'includes an amount of 0' do + expect(adjustment.amount.to_f).to eq(0.0) end it 'has no included_tax' do