Skip to content

Commit

Permalink
close #760 show request booking order when payment_state is not paid
Browse files Browse the repository at this point in the history
  • Loading branch information
panhachom committed Oct 27, 2023
1 parent d1fcbce commit f871fd0
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 9 deletions.
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

0 comments on commit f871fd0

Please sign in to comment.