diff --git a/app/helpers/order_helper.rb b/app/helpers/order_helper.rb index feeff9ebb..4b2e023f8 100644 --- a/app/helpers/order_helper.rb +++ b/app/helpers/order_helper.rb @@ -63,6 +63,10 @@ def format_order_crm_key(order) crm_order_link(order) end + def format_order_crm_key_with_name(order) + crm_order_link(order, order.crm_key_with_label) + end + def format_order_billability(value) content_tag(:span, f(value), class: order_report_billability_class(value)) end @@ -72,7 +76,10 @@ def format_order_average_rate(value) end def format_order_additional_crm_orders(order) - simple_list(order.additional_crm_orders.map(&method(:crm_order_link))) + names = order.additional_crm_orders.map do |crm_order| + crm_order_link(crm_order, crm_order.crm_key_with_label) + end + simple_list(names) end def format_major_chance(order) diff --git a/app/models/additional_crm_order.rb b/app/models/additional_crm_order.rb index 9bb2e4ac6..e39d9aaa1 100644 --- a/app/models/additional_crm_order.rb +++ b/app/models/additional_crm_order.rb @@ -28,6 +28,10 @@ def to_s name end + def crm_key_with_label + [crm_key, name].compact.join(': ') + end + private def sync_name diff --git a/app/models/order.rb b/app/models/order.rb index 9f2ef025f..b51bc4e74 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -119,6 +119,10 @@ def label name end + def crm_key_with_label + [crm_key, name].compact.join(': ') + end + def default_billing_address_id billing_address_id || client.billing_addresses.list.pick(:id) end diff --git a/app/views/orders/show.html.haml b/app/views/orders/show.html.haml index 71e553035..a82916018 100644 --- a/app/views/orders/show.html.haml +++ b/app/views/orders/show.html.haml @@ -15,7 +15,7 @@ = labeled_attr entry.work_item, :shortname = labeled_attr entry.work_item, :description - if Crm.instance - = labeled(Crm.instance.crm_key_name, format_attr(entry, :crm_key)) + = labeled(Crm.instance.crm_key_name, format_attr(entry, :crm_key_with_label)) = labeled("Weitere #{Crm.instance.crm_key_name_plural}", format_attr(entry, :additional_crm_orders)) = render_attrs entry, :order_contacts diff --git a/test/integration/show_order_test.rb b/test/integration/show_order_test.rb index 43996bda2..0d934c5d5 100644 --- a/test/integration/show_order_test.rb +++ b/test/integration/show_order_test.rb @@ -22,10 +22,13 @@ class ShowOrder < ActionDispatch::IntegrationTest assert_empty additional_crm_links.all(:link, wait: false) # create some objects and reload page - AdditionalCrmOrder.create!(order_id: order.id, crm_key: 'hello-world') + AdditionalCrmOrder.create!(order_id: order.id, crm_key: 'hello-world', name: '123') AdditionalCrmOrder.create!(order_id: order.id, crm_key: '42') visit current_path + assert page.has_selector?('.orders-cockpit dd.value ul li a', text: 'hello-world: 123') + assert page.has_selector?('.orders-cockpit dd.value ul li a', text: '42') + additional_crm_links.all(:link, count: 2, wait: false) additional_crm_links.all(:link, href: /hello-world/, count: 1, wait: false) additional_crm_links.all(:link, href: /42/, count: 1, wait: false) diff --git a/test/models/additional_crm_order_test.rb b/test/models/additional_crm_order_test.rb index 98e58726f..77792d50b 100644 --- a/test/models/additional_crm_order_test.rb +++ b/test/models/additional_crm_order_test.rb @@ -34,6 +34,12 @@ class AdditionalCrmOrderTest < ActiveSupport::TestCase end end + test 'crm key with label' do + add = orders(:puzzletime).additional_crm_orders.create!(crm_key: '123', name: 'Foo') + + assert_equal '123: Foo', add.crm_key_with_label + end + private def setup_crm diff --git a/test/models/order_test.rb b/test/models/order_test.rb index 6f47176ea..847771cee 100644 --- a/test/models/order_test.rb +++ b/test/models/order_test.rb @@ -172,4 +172,10 @@ class OrderTest < ActiveSupport::TestCase assert_equal :high, Order.new(major_chance_value: 12).major_chance assert_equal :high, Order.new(major_chance_value: 16).major_chance end + + test 'crm key with label' do + order = Fabricate(:order, work_item: Fabricate(:work_item, parent: clients(:swisstopo).work_item, name: 'Foo'), crm_key: '123') + + assert_equal '123: Foo', order.crm_key_with_label + end end