Skip to content

Commit

Permalink
close #2096 filter order by vendor (#2097)
Browse files Browse the repository at this point in the history
  • Loading branch information
LengTech11 authored Nov 28, 2024
1 parent bd30198 commit 57d1bee
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/models/spree_cm_commissioner/line_item_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def self.prepended(base) # rubocop:disable Metrics/MethodLength
base.validate :ensure_not_exceed_max_quantity_per_order, if: -> { variant&.max_quantity_per_order.present? }

base.whitelisted_ransackable_associations |= %w[guests]
base.whitelisted_ransackable_attributes |= %w[number to_date from_date]
base.whitelisted_ransackable_attributes |= %w[number to_date from_date vendor_id]

base.delegate :delivery_required?, :permanent_stock?, :high_demand,
to: :variant
Expand Down
4 changes: 4 additions & 0 deletions app/models/spree_cm_commissioner/order_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ def self.prepended(base) # rubocop:disable Metrics/MethodLength,Metrics/AbcSize
)
}

base.scope :filter_by_vendor, lambda { |vendor|
joins(:line_items).where(spree_line_items: { vendor_id: vendor }).distinct
}

base.before_create :link_by_phone_number
base.before_create :associate_customer

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!-- insert_before "[data-hook='admin_orders_index_search'] .row:nth-child(5) .col-12.col-lg-4:nth-child(3)" -->

<div class="col-12 col-lg-4">
<div class="form-group">
<%= label_tag :q_line_items_vendor_id_eq, Spree.t(:vendor) %>
<%= f.select :line_items_vendor_id_eq, Spree::Vendor.pluck(:name, :id), { include_blank: true }, class: 'select2-clear js-filterable' %>
</div>
</div>
2 changes: 1 addition & 1 deletion spec/models/spree/line_item_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
expect(described_class.whitelisted_ransackable_attributes).to match_array([
"variant_id", "order_id", "tax_category_id", "quantity", "price", "cost_price", "cost_currency", "adjustment_total",
"additional_tax_total", "promo_total", "included_tax_total", "pre_tax_amount", "taxable_adjustment_total",
"non_taxable_adjustment_total", "number", "to_date", "from_date"
"non_taxable_adjustment_total", "number", "to_date", "from_date", "vendor_id"
])
end
end
Expand Down

0 comments on commit 57d1bee

Please sign in to comment.