From 3b641c1c8f2fc0bb1a92856d0051e3b58a21a175 Mon Sep 17 00:00:00 2001 From: puppe1990 Date: Fri, 15 Dec 2023 16:04:48 -0300 Subject: [PATCH 1/2] create a filter for pending products --- app/controllers/orders_control_controller.rb | 16 +++++++++++++++- app/jobs/update_items_bling_order_items.rb | 8 ++++++++ app/models/bling_order_item.rb | 9 ++++++++- .../orders_control/show_pending_orders.html.erb | 15 +++++++++++++++ 4 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 app/jobs/update_items_bling_order_items.rb diff --git a/app/controllers/orders_control_controller.rb b/app/controllers/orders_control_controller.rb index 5711bc58..55b87a3d 100644 --- a/app/controllers/orders_control_controller.rb +++ b/app/controllers/orders_control_controller.rb @@ -20,8 +20,22 @@ def show_orders_products_stock .order(custom_id: :desc) end + def show_pending_orders - @pending_order_items = BlingOrderItem.where(situation_id: BlingOrderItem::Status::PENDING) + situation_id = params[:situation_id] + store_id = params[:store_id] + + if situation_id.present? + cleaned_situation_ids = situation_id.split(',').map(&:to_i) + else + cleaned_situation_ids = BlingOrderItem::Status::PENDING + end + + if store_id.present? + @pending_order_items = BlingOrderItem.where(situation_id: cleaned_situation_ids, store_id: store_id) + else + @pending_order_items = BlingOrderItem.where(situation_id: cleaned_situation_ids) + end end def show_orders_business_day diff --git a/app/jobs/update_items_bling_order_items.rb b/app/jobs/update_items_bling_order_items.rb new file mode 100644 index 00000000..17c51719 --- /dev/null +++ b/app/jobs/update_items_bling_order_items.rb @@ -0,0 +1,8 @@ +class UpdateItemsBlingOrderItem < ApplicationJob + queue_as :default + + def perform(store_id, situation_id, current_tenant_id) + bling_order_ids = BlingOrderItem.where(store_id: store_id, situation_id: situation_id, items: nil).pluck(:bling_order_id) + Services::Bling::FindOrders.call(order_command: 'find_orders', tenant: current_tenant_id, ids: bling_order_ids) + end +end diff --git a/app/models/bling_order_item.rb b/app/models/bling_order_item.rb index 20c07f27..02a2e69e 100644 --- a/app/models/bling_order_item.rb +++ b/app/models/bling_order_item.rb @@ -48,7 +48,14 @@ class BlingOrderItem < ApplicationRecord "24" => 'Verificado', "94871" => 'Pendente', "95745" => 'Impresso', - "12" => 'Cancelado' + "12" => 'Cancelado', + }.freeze + + STATUS_PENDING_NAME_KEY_VALUE = { + "15, 94871, 95745" => 'Pedidos Pagos Pendentes', + "94871" => 'Pendente', + "15" => 'Em andamento', + "95745" => 'Impresso', }.freeze class Status diff --git a/app/views/orders_control/show_pending_orders.html.erb b/app/views/orders_control/show_pending_orders.html.erb index 229b30ac..da2f149c 100644 --- a/app/views/orders_control/show_pending_orders.html.erb +++ b/app/views/orders_control/show_pending_orders.html.erb @@ -5,6 +5,21 @@
+ <%= form_with(url: show_pending_orders_path, method: :get, local: true) do |form| %> +
+ <%= form.label :situation_id, 'Filtro por Status' %> + <%= form.select :situation_id, BlingOrderItem::STATUS_PENDING_NAME_KEY_VALUE.invert, + { include_blank: 'Select Status', selected: params[:situation_id] }, + { class: 'form-control' } %> +
+
+ <%= form.label :store_id, 'Filtro por Loja' %> + <%= form.select :store_id, BlingOrderItem::STORE_ID_NAME_KEY_VALUE.invert, + { include_blank: 'Todas', selected: params[:store_id] }, + { class: 'form-control' } %> +
+ <%= form.submit 'Filtro', class: 'btn btn-primary' %> + <% end %>
<% if @pending_order_items.present? %> From e9c7daf2899ee2d88d031d52b987d820233e55e3 Mon Sep 17 00:00:00 2001 From: puppe1990 Date: Fri, 15 Dec 2023 16:17:08 -0300 Subject: [PATCH 2/2] fix name --- ...ing_order_items.rb => update_items_bling_order_items_job.rb} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename app/jobs/{update_items_bling_order_items.rb => update_items_bling_order_items_job.rb} (86%) diff --git a/app/jobs/update_items_bling_order_items.rb b/app/jobs/update_items_bling_order_items_job.rb similarity index 86% rename from app/jobs/update_items_bling_order_items.rb rename to app/jobs/update_items_bling_order_items_job.rb index 17c51719..964c71f3 100644 --- a/app/jobs/update_items_bling_order_items.rb +++ b/app/jobs/update_items_bling_order_items_job.rb @@ -1,4 +1,4 @@ -class UpdateItemsBlingOrderItem < ApplicationJob +class UpdateItemsBlingOrderItemsJob < ApplicationJob queue_as :default def perform(store_id, situation_id, current_tenant_id)