Fix filtering of active ordergroups

This commit is contained in:
Harald Reingruber 2022-03-08 00:11:06 +01:00 committed by GitHub
parent 708f85a839
commit 15e715c9f3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View file

@ -20,7 +20,7 @@ class Ordergroup < Group
after_create :update_stats! after_create :update_stats!
scope :active, -> { joins(:orders).where(orders: { starts: (Time.now.months_ago(3)..) }).group(:id) } scope :active, -> { joins(:orders).where(orders: { starts: (Time.now.months_ago(3)..Time.now) }).group(:id) }
def contact def contact
"#{contact_phone} (#{contact_person})" "#{contact_phone} (#{contact_person})"

View file

@ -8,6 +8,20 @@ describe Ordergroup do
let(:ftt3) { create :financial_transaction_type, financial_transaction_class: ftc2 } let(:ftt3) { create :financial_transaction_type, financial_transaction_class: ftc2 }
let(:user) { create :user, groups: [create(:ordergroup)] } let(:user) { create :user, groups: [create(:ordergroup)] }
it 'shows no active ordergroups when all orders are older than 3 months' do
order = create :order, starts: 4.months.ago
user.ordergroup.group_orders.create!(order: order)
expect(Ordergroup.active).to be_empty
end
it 'shows active ordergroups when there are recent orders' do
order = create :order, starts: 2.days.ago
user.ordergroup.group_orders.create!(order: order)
expect(Ordergroup.active).not_to be_empty
end
context 'with financial transactions' do context 'with financial transactions' do
before do before do
og = user.ordergroup og = user.ordergroup