Skip to content

Commit

Permalink
[Shared dev] [#162175] Show price group in orders table (#4289)
Browse files Browse the repository at this point in the history
* Show price group in order details table

* Add specs

* Fix translations

* Fix specs

* Add comment

* Add method in presenter and use it

* Use I18n in spec
  • Loading branch information
LeticiaErrandonea authored May 29, 2024
1 parent 399ceb6 commit 1198ec7
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 9 deletions.
8 changes: 8 additions & 0 deletions app/models/order_detail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,14 @@ def user_for_order
end
end

def estimated_price_group_name
return if account && !product.facility.can_pay_with_account?(account)

estimated_price_policy = product.cheapest_price_policy(self, fulfilled_at || Time.current)

estimated_price_policy&.price_group&.name
end

private

# Is there enough information to move an associated order to complete/problem?
Expand Down
4 changes: 4 additions & 0 deletions app/presenters/order_detail_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ def show_order_path
facility_order_path(facility, order)
end

def price_group_name
price_group&.name || estimated_price_group_name
end

private

# Is a fulfilled order detail nearing the end of the 90 day reconcile period?
Expand Down
9 changes: 7 additions & 2 deletions app/views/facility_orders/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,29 @@
%th.nowrap= sortable "status"
- # OrderDetail.human_attribute_name(:actual_cost) returns "Price". Despite the :actual_ prefix, these order details are new/in process, so most will have estimated costs, but could be actual or unassigned.
%th.nowrap.currency= OrderDetail.human_attribute_name(:actual_cost)
- if cross_core_order_view_enabled
%th.nowrap= PriceGroup.model_name.human
%tbody
- @order_details.each do |od|
%tr
- order_detail = OrderDetailPresenter.new(od)
%td.centered= check_box_tag("order_detail_ids[]", od.id, false, {class: "toggle", id: nil })
%td.centered= link_to od.order_id, facility_order_path(current_facility, od.order)
%td.centered= link_to od.id, manage_order_detail_path(od), class: "manage-order-detail"
- if cross_core_order_view_enabled
%td= od.order.created_by_user.full_name
%td= od.order.user.full_name
%td= format_usa_datetime(od.ordered_at)
%td.centered= OrderDetailPresenter.new(od).wrapped_quantity
%td.centered= order_detail.wrapped_quantity
= render partial: "shared/order_detail_cell", locals: { od: od }
- if cross_core_order_view_enabled
%td= render "shared/cross_core_facility_abbreviation_order_details", order_detail: od, current_facility: current_facility
%td= od.assigned_user
%td= od.order_status
%td.currency
= OrderDetailPresenter.new(od).wrapped_total
= order_detail.wrapped_total
- if cross_core_order_view_enabled
%td= order_detail.price_group_name
= render partial: "table_controls"

= will_paginate(@order_details)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
module Projects

class CrossCoreFacilitySearcher < TransactionSearch::BaseSearcher
include TextHelpers::Translation

def self.key
:cross_core_facilties
Expand Down Expand Up @@ -31,11 +32,18 @@ def label_method
end

def label
I18n.t("projects.projects.cross_core_orders.filter_label")
text("projects.projects.cross_core_orders.filter_label")
end

def input_type
:select
end

# Translation scope cannot be inferred, so we need to specify it.
# Returns empty string because label includes the complete path.
def translation_scope
""
end
end

end
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,24 @@
%th.nowrap= Projects::Project.model_name.human
%th.nowrap= sortable "status"
%th.nowrap.currency= OrderDetail.human_attribute_name(:actual_cost)
%th.nowrap= PriceGroup.model_name.human
%tbody
- @order_details.each do |od|
%tr
- order_detail = OrderDetailPresenter.new(od)
%td= od
%td= od.order.created_by_user.full_name
%td= od.order.user.full_name
%td= format_usa_datetime(od.ordered_at)
%td.centered= OrderDetailPresenter.new(od).wrapped_quantity
%td.centered= order_detail.wrapped_quantity
= render partial: "shared/order_detail_cell", locals: { od: od }
%td= od.order.facility.abbreviation.truncate(6)
-# TODO: This should be a link when we have the project page
%td= od.order.cross_core_project&.name
%td= od.order_status
%td.currency
= OrderDetailPresenter.new(od).wrapped_total
= order_detail.wrapped_total
%td= order_detail.price_group_name

= will_paginate(@order_details)
= render partial: "/price_display_footnote", locals: { admin: true }
Expand Down
3 changes: 1 addition & 2 deletions vendor/engines/projects/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ en:
projects:
projects:
cross_core_orders:
# TODO: This should use the preferred term for "facility" (e.g. "facility" or "core")
filter_label: "Participating Facilities"
filter_label: "Participating !facilities_downcase!"
head: "Cross Core Orders"
no_orders: There are no orders for your Cross Core projects.
edit:
Expand Down
12 changes: 10 additions & 2 deletions vendor/engines/projects/spec/system/cross_core_orders_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@

context "when selecting All" do
before do
select "All", from: "Participating Facilities"
select "All", from: "Participating #{I18n.t("facilities_downcase")}"
click_button "Filter"
end

Expand All @@ -78,12 +78,20 @@

expect(page).to have_content(cross_core_order_originating_facility2.order_details.first)
expect(page).to have_content(cross_core_order_originating_facility.order_details.first)

item_price_group = item.price_policies.first.price_group.name
facility2_item_price_group = facility2_item.price_policies.first.price_group.name
facility3_item_price_group = facility3_item.price_policies.first.price_group.name

expect(page).to have_content(item_price_group, count: 2)
expect(page).to have_content(facility2_item_price_group, count: 2)
expect(page).to have_content(facility3_item_price_group, count: 2)
end
end

context "when selecting Current" do
before do
select "Current", from: "Participating Facilities"
select "Current", from: "Participating #{I18n.t("facilities_downcase")}"
click_button "Filter"
end

Expand Down

0 comments on commit 1198ec7

Please sign in to comment.