More customer/project relations

This commit is contained in:
2017-11-17 10:51:25 -05:00
parent d98a8b8cc4
commit b8186e4b52
3 changed files with 14 additions and 12 deletions

View File

@@ -12,11 +12,12 @@ $(function() {
data: { selected_customer: $("input#issue_customer_id").val() } data: { selected_customer: $("input#issue_customer_id").val() }
}); });
$("input#project_customers_id").on("change", function() { $("input#project_customer_id").on("change", function() {
$.ajax({ $.ajax({
url: "/filter_vehicles_by_customer", url: "/filter_vehicles_by_customer",
type: "GET", type: "GET",
data: { selected_customer: $("input#project_customers_id").val() } data: { selected_customer: $("input#project_customer_id").val() }
});
}); });
}); });
}); });

View File

@@ -17,6 +17,7 @@ en:
field_qbo_invoice: "Invoice" field_qbo_invoice: "Invoice"
field_qbo_estimate: "Estimate" field_qbo_estimate: "Estimate"
field_vehicles: "Vehicle" field_vehicles: "Vehicle"
field_vehicle: "Vehicle"
field_vin: "VIN" field_vin: "VIN"
field_notes: "Notes" field_notes: "Notes"
field_qbo_billed: "Billed" field_qbo_billed: "Billed"

View File

@@ -15,21 +15,21 @@ class ProjectsFormHookListener < Redmine::Hook::ViewListener
f = context[:form] f = context[:form]
# Check to see if there is a quickbooks user attached to the issue # Check to see if there is a quickbooks user attached to the issue
selected_customer = context[:project].customers_id ? context[:project].customers_id : nil selected_customer = context[:project].customer ? context[:project].customer : nil
selected_vehicle = context[:project].vehicles_id ? context[:project].vehicles_id : nil selected_vehicle = context[:project].vehicle_id ? context[:project].vehicle_id : nil
# Load customer information # Load customer information
customer = Customer.find_by_id(selected_customer) if selected_customer customer = Customer.find_by_id(selected_customer) if selected_customer
search_customer = f.autocomplete_field :customers_id, autocomplete_customer_name_customers_path, :selected => selected_customer, :update_elements => {:id => '#project_customer_id', :value => '#project_customer'} search_customer = f.autocomplete_field :customer, autocomplete_customer_name_customers_path, :selected => selected_customer, :update_elements => {:id => '#project_customer_id', :value => '#project_customer'}
customer_id = f.hidden_field :customers_id, :id => "project_customer_id" customer_id = f.hidden_field :customer_id, :id => "project_customer_id"
if context[:project].customers_id if context[:project].customer
vehicles = customer.vehicles.pluck(:name, :id).sort! vehicles = customer.vehicles.pluck(:name, :id).sort!
else else
vehicles = [nil].compact vehicles = [nil].compact
end end
vehicle = f.select :vehicles_id, vehicles, :selected => selected_vehicle, include_blank: true vehicle = f.select :vehicle_id, vehicles, :selected => selected_vehicle, include_blank: true
return "<p><label for=\"project_customer\">Customer</label>#{search_customer} #{customer_id}</p> <p>#{vehicle}</p>" return "<p><label for=\"project_customer\">Customer</label>#{search_customer} #{customer_id}</p> <p>#{vehicle}</p>"
end end