Skip to content
Open
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
9 changes: 8 additions & 1 deletion app/helpers/order_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions app/models/additional_crm_order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ def to_s
name
end

def crm_key_with_label
[crm_key, name].compact.join(': ')
end

private

def sync_name
Expand Down
4 changes: 4 additions & 0 deletions app/models/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/views/orders/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion test/integration/show_order_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions test/models/additional_crm_order_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions test/models/order_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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