Class: PurchaseOrdersController
- Inherits:
-
CrmController
- Object
- ActionController::Base
- ApplicationController
- CrmController
- PurchaseOrdersController
- Defined in:
- app/controllers/purchase_orders_controller.rb
Overview
== Schema Information
Table name: purchase_orders
id :integer not null, primary key
legacy_reference_number :integer
company_id :integer
supplier_id :integer
carrier_id :integer
description :string(255)
order_date :date
request_date :date
promised_delivery_date :date
cancel_date :date
currency :string(255)
exchange_rate :float
creator_id :integer
updater_id :integer
created_at :datetime
updated_at :datetime
store_id :integer
total_cost :decimal(8, 2)
total_weight :float
terms :string(255)
uploads_count :integer
state :string(255)
po_type :string(255)
rma_id :integer
drop_ship :boolean
drop_ship_order_id :integer
drop_ship_delivery_id :integer
reference_number :string(20) not null
Constant Summary collapse
- TAB_ACTIONS =
Tab fragments never render standalone — non-frame hits redirect to show ?tab=.
%i[tab_receipts tab_shipments tab_line_items tab_attachments].freeze
Constants included from Controllers::ReferenceFindable
Controllers::ReferenceFindable::ID_EMBEDDED_PATTERNS
Constants included from Controllers::AnalyticsEvents
Controllers::AnalyticsEvents::MAX_QUEUED_EVENTS, Controllers::AnalyticsEvents::SESSION_KEY
Constants included from Controllers::ErrorRendering
Controllers::ErrorRendering::NON_CONTENT_PATH_PREFIXES
Instance Method Summary collapse
-
#cancel ⇒ void
Cancels the purchase order and all of its items.
-
#create ⇒ Object
POST /purchase_orders POST /purchase_orders.xml.
-
#edit ⇒ Object
GET /purchase_orders/1/edit.
-
#get_supplier_items ⇒ void
Returns the given supplier's active items as JSON, for the purchase order item-picker's autocomplete.
-
#index ⇒ Object
GET /purchase_orders GET /purchase_orders.xml.
-
#new ⇒ Object
GET /purchase_orders/new GET /purchase_orders/new.xml.
-
#print_serial_number_labels ⇒ void
Generates and redirects to a super-label PDF for the purchase order's serial numbers, if any were assigned.
-
#regenerate_pdf ⇒ void
Regenerates the purchase order's PDF and redirects to the new upload.
-
#service_fulfilled ⇒ void
Marks a service purchase order as fulfilled.
-
#ship ⇒ void
Marks the purchase order as shipped.
-
#show ⇒ Object
GET /purchase_orders/1 GET /purchase_orders/1.xml.
-
#tab_attachments ⇒ void
Renders the attachments tab fragment.
-
#tab_line_items ⇒ void
Renders the line items tab fragment.
-
#tab_receipts ⇒ Object
Tab actions for turbo-tabs lazy loading.
-
#tab_shipments ⇒ void
Renders the shipments tab fragment.
-
#transmit ⇒ void
Redirects to the new-communication form pre-filled to transmit this purchase order to its supplier.
-
#update ⇒ Object
PUT /purchase_orders/1 PUT /purchase_orders/1.xml.
Methods included from Controllers::Workflowable
#render_workflow_error_stream, #render_workflow_success_stream, #workflow_action, #workflow_action_complete
Methods included from Controllers::RequireTurboFrame
require_in_pane_tab_frames, require_turbo_frame
Methods included from Controllers::Destroyable
Methods inherited from CrmController
#access_denied, #context_id, #context_object, #crm_home_path, #current_ability, #default_url_options, #download_temp, #get_tempfile_path_for_download, #init_status_job_collector, #initialize_crm_lazy_chunks, #persist_enqueued_status_jobs, #record_not_found, #redirect_to_job_or_fallback, #render_edit_action, #set_context, #set_download_path, #stash_file_for_temp_download, #sync_admin_presence_cookie, #touch_employee_last_seen
Methods inherited from ApplicationController
#account_impersonated?, #add_to_flash, #after_sign_in_path_for, #bypass_forgery_protection?, #chat_enabled?, #cloudflare_cleared?, #default_catalog, #default_url_options, #enable_turbo_frames, #find_publication, #fix_invalid_accept_header, #init_js_utils, #is_globals_call?, #layout_by_resource, #locale_store, #redirect_to, #require_employee_for_crm, #set_base_host, #set_real_ip, #set_report_errors_for, #should_render_layout?, #skip_layout_for_turbo_frame?, #stamp_impersonation_context, #tab_frame_breakout_request?, #warmlyyours_canada_ip?, #warmlyyours_ip?, #y
Methods included from Controllers::ReturnPathHandling
#check_for_return_path, #redirect_to_return_path_or_default
Methods included from Controllers::AnalyticsEvents
#consume_queued_analytics_events, #registration_lead_type, #track_event
Methods included from Controllers::DeviceDetection
Methods included from Controllers::SubdomainDetection
#is_crm_request?, #is_www_request?, #json_request?
Methods included from Controllers::TurboSafeRedirect
Methods included from Controllers::TrackingDetection
#bot_request?, #gdpr_country?, #gdpr_country_data, #prevent_bots, #set_tracking_cookie, #track_visitor?
Methods included from Controllers::AcceleratedFileSending
#send_file_accelerated, #send_upload_accelerated
Methods included from Controllers::ErrorRendering
#excp_string, #mail_to_for_error_reporting, #render_400, #render_404, #render_406, #render_410, #render_500, #render_invalid_authenticity_token, #render_ip_spoof_error, #render_unpermitted_parameters, #safe_referer_or_fallback
Methods included from Controllers::TurnstileVerification
#load_turnstile_script_tag, #turnstile_lazy_widget, #turnstile_script_tag, #turnstile_widget, #validate_turnstile!
Methods included from Controllers::CloudflareCaching
edge_cached, #edge_cached_action?, #reset_cloudflare_cache, #set_cloudflare_cache, #skip_edge_cache!, #skip_session
Methods included from Controllers::Webpackable
#preload_webpack_fonts, #webpack_css_include, #webpack_css_url, #webpack_js_include, #wpd_is_running?
Methods included from Controllers::Localizable
#cloudflare_country_locale, #determine_request_locale, #geocoder_locale, #guest_user_locale_check, #locale_optional_www_auth_path?, #param_locale, #set_locale, #set_request_locale, #skip_localization?, #warmlyyours_ip_locale
Methods included from Controllers::Authenticable
#access_denied, #authenticate_account, #authenticate_account!, #authenticate_account_from_login_token!, #check_is_a_manager, #check_is_a_sales_manager, #check_is_an_admin, #check_is_an_employee, #check_party, #clear_mismatched_guest_user, #create_guest_user, #credentials?, #current_or_guest_user, #current_or_guest_user_id_read_only, #current_user, #devise_mapping, #fully_logged_in?, #generate_bot_id, #guest_user, #identifiable?, #init_current_user, #initialize_guest, #load_context_user, #logging_in, #resource, #resource_name, #restrict_access_for_non_employees, #scrubbed_request_path, #user_object, #warn_on_session_guest_id_leak
Methods included from UrlsHelper
#catalog_breadcrumb_links, #catalog_link, #catalog_link_for_product_line, #catalog_link_for_sku, #cms_link, #delocalized_path, #path_to_sales_product_sku, #path_to_sales_product_sku_for_product_line, #path_to_sales_product_sku_for_product_line_slug, #product_line_from_catalog_link, #protocol_neutral_url, #sanitize_external_url, #valid_external_url?
Instance Method Details
#cancel ⇒ void
This method returns an undefined value.
Cancels the purchase order and all of its items.
178 179 180 181 182 183 184 185 186 |
# File 'app/controllers/purchase_orders_controller.rb', line 178 def cancel @purchase_order.cancel_items_and_self if @purchase_order.cancelled? flash[:info] = 'Purchase Order cancelled successfully' else flash[:error] = 'Unable to cancel Purchase Order, please contact the administrator' end redirect_to(@purchase_order) end |
#create ⇒ Object
POST /purchase_orders
POST /purchase_orders.xml
121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'app/controllers/purchase_orders_controller.rb', line 121 def create @purchase_order = PurchaseOrder.new(params[:purchase_order]) respond_to do |format| if @purchase_order.save format.html { redirect_to(purchase_order_url(@purchase_order), notice: 'Purchase Order was successfully created.') } format.xml { render xml: @purchase_order, status: :created, location: @purchase_order } else @purchase_order.purchase_order_items.build if @purchase_order.purchase_order_items.empty? format.html { render action: 'new', status: :unprocessable_content } format.xml { render xml: @purchase_order.errors, status: :unprocessable_content } end end end |
#edit ⇒ Object
GET /purchase_orders/1/edit
115 116 117 |
# File 'app/controllers/purchase_orders_controller.rb', line 115 def edit @purchase_order.purchase_order_items.build if @purchase_order.purchase_order_items.empty? end |
#get_supplier_items ⇒ void
This method returns an undefined value.
Returns the given supplier's active items as JSON, for the purchase order
item-picker's autocomplete.
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'app/controllers/purchase_orders_controller.rb', line 200 def get_supplier_items supplier = Supplier.find(params[:supplier_id]) supplier_items = supplier.supplier_items.active.includes(:item, :supplier_item_prices).references(:item).where.not('items.id' => nil).map do |si| price = si.current_price { item_id: si.item_id, supplier_id: si.supplier_id, value: si.item.sku_and_name, desc: si.item.name, sku: si.item.sku, uom_cost: price&.purchasing_cost.to_s, uom: si.uom, uom_quantity: si.uom_quantity, unit_cost: price&.unit_cost.to_s, weight: si.item.base_weight, supplier_sku: si.supplier_sku, supplier_desc: si.supplier_description, stock_item: si.stock_item? ? 1 : 0, auto_receive: si.auto_receive? ? 1 : 0 } end render json: { supplier_items: supplier_items } end |
#index ⇒ Object
GET /purchase_orders
GET /purchase_orders.xml
51 52 53 54 55 |
# File 'app/controllers/purchase_orders_controller.rb', line 51 def index respond_to do |format| format.html # index.html.erb end end |
#new ⇒ Object
GET /purchase_orders/new
GET /purchase_orders/new.xml
100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'app/controllers/purchase_orders_controller.rb', line 100 def new # Pick up a draft stashed by Crm::Reports::InventoryPlanningController#generate_po # (or similar flows) when it's too large to pass via the URL. params[:purchase_order] ||= session.delete(:inventory_planning_po_draft) @purchase_order = PurchaseOrder.new(params[:purchase_order]) @purchase_order.po_type = 'purchase' if @purchase_order.po_type.nil? @purchase_order.purchase_order_items.build if @purchase_order.purchase_order_items.empty? respond_to do |format| format.html # new.html.erb format.xml { render xml: @purchase_order } end end |
#print_serial_number_labels ⇒ void
This method returns an undefined value.
Generates and redirects to a super-label PDF for the purchase order's
serial numbers, if any were assigned.
225 226 227 228 229 230 231 232 233 |
# File 'app/controllers/purchase_orders_controller.rb', line 225 def print_serial_number_labels if @purchase_order.serial_numbers.empty? flash[:info] = 'No serial numbers to print' redirect_to @purchase_order else pdf = SerialNumber.generate_super_label_pdf(@purchase_order.serial_numbers) redirect_to upload_path(pdf) end end |
#regenerate_pdf ⇒ void
This method returns an undefined value.
Regenerates the purchase order's PDF and redirects to the new upload.
153 154 155 156 |
# File 'app/controllers/purchase_orders_controller.rb', line 153 def regenerate_pdf @pdf = @purchase_order.generate_pdf redirect_to upload_path(@pdf) end |
#service_fulfilled ⇒ void
This method returns an undefined value.
Marks a service purchase order as fulfilled.
191 192 193 194 |
# File 'app/controllers/purchase_orders_controller.rb', line 191 def service_fulfilled @purchase_order.service_fulfilled! redirect_to(@purchase_order) end |
#ship ⇒ void
This method returns an undefined value.
Marks the purchase order as shipped.
170 171 172 173 |
# File 'app/controllers/purchase_orders_controller.rb', line 170 def ship @purchase_order.ship redirect_to purchase_order_path(@purchase_order) end |
#show ⇒ Object
GET /purchase_orders/1
GET /purchase_orders/1.xml
59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'app/controllers/purchase_orders_controller.rb', line 59 def show @pagy_activities, @activities = pagy(@purchase_order.activities.natural_order) @attachments = @purchase_order.uploads @pdf = @purchase_order.uploads.where(category: 'purchase_order').first respond_to do |format| format.html # show.html.erb format.xml { render xml: @purchase_order } format.pdf do pdf = PurchaseOrder::PdfGenerator.new(@purchase_order).generate send_data pdf, filename: @purchase_order.file_name, type: 'application/pdf', disposition: 'inline' end end end |
#tab_attachments ⇒ void
This method returns an undefined value.
Renders the attachments tab fragment.
249 250 251 252 253 254 255 |
# File 'app/controllers/purchase_orders_controller.rb', line 249 def :read, @purchase_order respond_to do |format| format.html { render layout: should_render_layout? } format.turbo_stream end end |
#tab_line_items ⇒ void
This method returns an undefined value.
Renders the line items tab fragment.
238 239 240 241 242 243 244 |
# File 'app/controllers/purchase_orders_controller.rb', line 238 def tab_line_items :read, @purchase_order respond_to do |format| format.html { render layout: should_render_layout? } format.turbo_stream end end |
#tab_receipts ⇒ Object
Tab actions for turbo-tabs lazy loading. Streamed pattern (PR #903) —
every tab serves both formats so in-pane interactions can target
tab_frame_id via turbo_stream.update.
77 78 79 80 81 82 83 84 |
# File 'app/controllers/purchase_orders_controller.rb', line 77 def tab_receipts :read, @purchase_order @shipment_receipts = @purchase_order.shipment_receipts.includes(shipment_receipt_items: %i[purchase_order purchase_order_item item_ledger_entries serial_numbers estimated_landed_costs actual_landed_costs]) respond_to do |format| format.html { render layout: should_render_layout? } format.turbo_stream end end |
#tab_shipments ⇒ void
This method returns an undefined value.
Renders the shipments tab fragment.
89 90 91 92 93 94 95 96 |
# File 'app/controllers/purchase_orders_controller.rb', line 89 def tab_shipments :read, @purchase_order @shipments = @purchase_order.purchase_order_shipments.includes(shipment_items_with_receipted_quantity: %i[purchase_order_item purchase_order]) respond_to do |format| format.html { render layout: should_render_layout? } format.turbo_stream end end |
#transmit ⇒ void
This method returns an undefined value.
Redirects to the new-communication form pre-filled to transmit this
purchase order to its supplier.
162 163 164 165 |
# File 'app/controllers/purchase_orders_controller.rb', line 162 def transmit redir_params = CommunicationBuilder.new(resource: @purchase_order, current_user: current_user).to_params redirect_to new_communication_path(redir_params) end |
#update ⇒ Object
PUT /purchase_orders/1
PUT /purchase_orders/1.xml
138 139 140 141 142 143 144 145 146 147 148 |
# File 'app/controllers/purchase_orders_controller.rb', line 138 def update respond_to do |format| if @purchase_order.update(params[:purchase_order]) format.html { redirect_to(purchase_order_url(@purchase_order), notice: 'Purchase Order was successfully updated.') } format.xml { head :ok } else format.html { render action: 'edit', status: :unprocessable_content } format.xml { render xml: @purchase_order.errors, status: :unprocessable_content } end end end |