Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Added Order#pre_tax_total and Order#display_pre_tax_total
Damian Legawiec81ca4eb54b53
diff --git a/core/app/models/spree/order.rb b/core/app/models/spree/order.rbindex ad6ef9dfca..56f9337fb6 100644--- a/core/app/models/spree/order.rb+++ b/core/app/models/spree/order.rb@@ -22,7 +22,7 @@ module Spreemoney_methods :outstanding_balance, :item_total, :adjustment_total,:included_tax_total, :additional_tax_total, :tax_total,:shipment_total, :promo_total, :total,- :cart_promo_total, :pre_tax_item_amount+ :cart_promo_total, :pre_tax_item_amount, :pre_tax_totalalias display_ship_total display_shipment_totalalias_attribute :ship_total, :shipment_total@@ -177,6 +177,11 @@ module Spreeline_items.sum(:pre_tax_amount)end+ # Sum of all line item and shipment pre-tax+ def pre_tax_total+ pre_tax_item_amount + shipments.sum(:pre_tax_amount)+ end+def shipping_discountshipment_adjustments.non_tax.eligible.sum(:amount) * - 1enddiff --git a/core/spec/models/spree/order_spec.rb b/core/spec/models/spree/order_spec.rbindex 61e815b57f..5a37e4ac77 100644--- a/core/spec/models/spree/order_spec.rb+++ b/core/spec/models/spree/order_spec.rb@@ -861,6 +861,29 @@ describe Spree::Order, type: :model doendend+ describe '#pre_tax_total' do+ let(:order) { create(:order) }++ before do+ line_item = create(:line_item, order: order, price: 10, quantity: 2)+ shipment = create(:shipment, order: order, cost: 5)++ line_item.update(pre_tax_amount: 8.0)+ shipment.update(pre_tax_amount: 4.0)+ end++ it "sums all of the line items' and shipments pre tax amounts" do+ expect(order.pre_tax_total).to eq BigDecimal(12)+ end+ end++ describe '#display_pre_tax_total' do+ it 'returns the value as a spree money' do+ allow(order).to receive(:pre_tax_total).and_return(10.55)+ expect(order.display_pre_tax_total).to eq(Spree::Money.new(10.55))+ end+ end+describe '#quantity' do# Uses a persisted record, as the quantity is retrieved via a DB countlet(:order) { create :order_with_line_items, line_items_count: 3 }