Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

close #760 show request booking order when payment_state is not paid #761

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def collection

def serialize_collection(collection)
options_data = collection_options(collection).merge(params: serializer_params)
options_data[:meta][:unread_count] = collection.select(&:unread?).count
options_data[:meta][:unread_count] = spree_current_user.notifications.request_notifications.where(read_at: nil).size

collection_serializer.new(
collection,
Expand Down
7 changes: 3 additions & 4 deletions app/models/spree_cm_commissioner/notification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ class Notification < SpreeCmCommissioner::Base
include Noticed::Model

scope :request_notifications, lambda {
where(
type: %w[order_requested_notification order_rejected_notification order_accepted_notification],
read_at: nil
).newest_first
select('DISTINCT ON (notificable_id) *')
.where(type: %w[order_requested_notification order_rejected_notification order_accepted_notification], read_at: nil)
.order('notificable_id, created_at DESC')
}

scope :user_notifications, lambda {
Expand Down
9 changes: 5 additions & 4 deletions app/models/spree_cm_commissioner/order_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ def self.prepended(base)
base.scope :paid, -> { where(payment_state: :paid) }

base.scope :filter_by_request_state, lambda {
where(state: :complete, payment_state: :paid)
.where.not(request_state: nil)
.order(created_at: :desc)
}
where(state: :complete)
.where.not(request_state: nil)
.where.not(payment_state: :paid)
.order(created_at: :desc)
}

base.before_create :link_by_phone_number
base.before_create :associate_customer
Expand Down
25 changes: 25 additions & 0 deletions spec/models/spree_cm_commissioner/notification_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require 'spec_helper'

RSpec.describe SpreeCmCommissioner::Notification, type: :model do

describe "request_notifications" do
it "return the latest notification if records have the same notification_id" do
notification1 = create(:notification,
type: 'order_requested_notification',
read_at: nil,
notificable_id: 1,
notificable_type: 'Spree::Order'
)
notification2 = create(:notification,
type: 'order_rejected_notification',
read_at: nil,
notificable_id: 1,
notificable_type: 'Spree::Order'
)

notifications = SpreeCmCommissioner::Notification.request_notifications

expect(notifications).to contain_exactly(notification2)
end
end
end