comee_core 0.1.96 → 0.1.98

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/comee/core/agents_controller.rb +13 -0
  3. data/app/controllers/comee/core/application_controller.rb +15 -2
  4. data/app/controllers/comee/core/back_orders_controller.rb +2 -2
  5. data/app/controllers/comee/core/client_prices_controller.rb +3 -10
  6. data/app/controllers/comee/core/client_warehouses_controller.rb +13 -0
  7. data/app/controllers/comee/core/clients_controller.rb +42 -9
  8. data/app/controllers/comee/core/contacts_controller.rb +13 -0
  9. data/app/controllers/comee/core/customer_order_items_controller.rb +3 -2
  10. data/app/controllers/comee/core/customer_orders_controller.rb +3 -3
  11. data/app/controllers/comee/core/item_statuses_controller.rb +2 -2
  12. data/app/controllers/comee/core/notifications_controller.rb +4 -4
  13. data/app/controllers/comee/core/product_lookups_controller.rb +2 -2
  14. data/app/controllers/comee/core/products_controller.rb +7 -9
  15. data/app/controllers/comee/core/purchase_order_items_controller.rb +2 -2
  16. data/app/controllers/comee/core/purchase_orders_controller.rb +2 -2
  17. data/app/controllers/comee/core/quotation_request_items_controller.rb +2 -2
  18. data/app/controllers/comee/core/quotation_requests_controller.rb +8 -9
  19. data/app/controllers/comee/core/sales_order_items_controller.rb +1 -1
  20. data/app/controllers/comee/core/sales_orders_controller.rb +13 -7
  21. data/app/controllers/comee/core/shipment_items_controller.rb +13 -13
  22. data/app/controllers/comee/core/suppliers_controller.rb +4 -6
  23. data/app/controllers/comee/core/unit_conversions_controller.rb +1 -1
  24. data/app/controllers/comee/core/units_controller.rb +1 -1
  25. data/app/controllers/concerns/comee/core/common.rb +33 -7
  26. data/app/models/comee/core/agent.rb +7 -0
  27. data/app/models/comee/core/client.rb +4 -1
  28. data/app/models/comee/core/client_warehouse.rb +8 -0
  29. data/app/models/comee/core/contact.rb +7 -0
  30. data/app/models/comee/core/customer_order_item.rb +6 -0
  31. data/app/models/comee/core/master_price.rb +1 -0
  32. data/app/models/comee/core/price.rb +2 -1
  33. data/app/models/comee/core/sales_order.rb +1 -2
  34. data/app/models/comee/core/sales_order_item.rb +6 -1
  35. data/app/models/comee/core/supplier.rb +2 -0
  36. data/app/serializers/comee/core/agent_serializer.rb +7 -0
  37. data/app/serializers/comee/core/client_serializer.rb +4 -1
  38. data/app/serializers/comee/core/client_warehouse_serializer.rb +8 -0
  39. data/app/serializers/comee/core/contact_serializer.rb +7 -0
  40. data/app/serializers/comee/core/product_serializer.rb +2 -2
  41. data/app/serializers/comee/core/sales_order_item_serializer.rb +1 -1
  42. data/app/serializers/comee/core/supplier_serializer.rb +1 -0
  43. data/app/services/comee/core/customer_order_service.rb +7 -2
  44. data/config/routes.rb +7 -1
  45. data/db/migrate/20230728122618_create_comee_core_suppliers.rb +4 -0
  46. data/db/migrate/20230728123039_create_comee_core_clients.rb +4 -0
  47. data/db/migrate/20230728123458_create_comee_core_agents.rb +23 -0
  48. data/db/migrate/20230728123559_create_comee_core_contacts.rb +34 -0
  49. data/db/migrate/20230811102708_create_comee_core_customer_order_items.rb +1 -0
  50. data/db/migrate/20230812212844_create_comee_core_sales_order_items.rb +1 -0
  51. data/db/migrate/20230813235946_create_comee_core_master_prices.rb +2 -1
  52. data/db/migrate/20230814151601_create_comee_core_client_prices.rb +2 -1
  53. data/db/migrate/20240119100125_create_comee_core_client_warehouses.rb +15 -0
  54. data/lib/comee/core/version.rb +1 -1
  55. data/spec/factories/comee/core/agents.rb +8 -0
  56. data/spec/factories/comee/core/client_prices.rb +1 -1
  57. data/spec/factories/comee/core/client_warehouses.rb +8 -0
  58. data/spec/factories/comee/core/clients.rb +2 -1
  59. data/spec/factories/comee/core/contacts.rb +8 -0
  60. data/spec/factories/comee/core/customer_order_items.rb +1 -0
  61. data/spec/factories/comee/core/fulfillment_centers.rb +1 -1
  62. data/spec/factories/comee/core/master_prices.rb +1 -0
  63. data/spec/factories/comee/core/sales_order_items.rb +1 -0
  64. data/spec/factories/comee/core/suppliers.rb +1 -0
  65. metadata +35 -12
  66. data/app/models/comee/core/warehouse_shipment.rb +0 -70
  67. data/app/models/comee/core/warehouse_shipment_item.rb +0 -37
  68. data/db/migrate/20231003080017_create_comee_core_warehouse_shipments.rb +0 -17
  69. data/db/migrate/20231004105455_create_comee_core_warehouse_shipment_items.rb +0 -17
  70. data/spec/factories/comee/core/warehouse_shipment_items.rb +0 -7
  71. data/spec/factories/comee/core/warehouse_shipments.rb +0 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '09b9b7bd296564a11541c134cdcea60a4e948cfb0a6635c19c069c62a1f86eda'
4
- data.tar.gz: 386ef21d5cdc2d86207be07dc0afd4fae421c859058d6d74083edf45bd0c0b68
3
+ metadata.gz: 7b02327a6f7076613d6072fc19df00c3c19b8256dfba0e90d254d4c63f21cd87
4
+ data.tar.gz: eab3d691391e6aa77b95074449704f65f2b7320f3a920b00ef645b651351bec4
5
5
  SHA512:
6
- metadata.gz: f7c5fbfb2d819845e756a023cb93aa23c0c1ea0f21a0ee6b229c4592e458872c732b24fe1386c58284a9f4ee47ac4078e49dbfb05b887d0e2717e4d36402e8bd
7
- data.tar.gz: e6f301d17d9704b52f429f371748da640a53ca0d5b20ff31be22b0ab47c11400edc5cdf1fc635144ab39e6520f8d5369039ae58e5b14b3ce1a5ac110d3b24c73
6
+ metadata.gz: bb5963d8249beac05dc28de793a53c970168f0da7f20f289e0bbb2c81562b633e85be1eb77befe79f268535b3b23174fda847b15e940e21575f1fd0502de977a
7
+ data.tar.gz: c5ceac445d220ed100a80ce759f62ac5537bb862e357dfb855552b49aa5b94880163baaae8f371a16f96db07d30491d92fa04043420c9f4084154e5f34003904
@@ -0,0 +1,13 @@
1
+ module Comee
2
+ module Core
3
+ class AgentsController < ApplicationController
4
+ include Common
5
+
6
+ private
7
+
8
+ def model_params
9
+ params.require(:payload).permit(:name, :address, :email, :telephone)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -5,6 +5,19 @@ module Comee
5
5
 
6
6
  before_action :authenticate
7
7
 
8
+ def render_content(data, options = {})
9
+ result = {success: true}
10
+ if params[:page]
11
+ total = data.count
12
+ data = data.then(&paginate)
13
+ result[:page] = params[:page].to_i
14
+ result[:total] = total
15
+ end
16
+ result[:data] = options.key?(:fields) ? serialize(data, include: options[:fields]) : serialize(data)
17
+
18
+ render json: result
19
+ end
20
+
8
21
  def current_user
9
22
  return if token.nil?
10
23
 
@@ -27,8 +40,8 @@ module Comee
27
40
 
28
41
  private
29
42
 
30
- def serialize(data)
31
- ActiveModelSerializers::SerializableResource.new(data)
43
+ def serialize(data, options = {})
44
+ ActiveModelSerializers::SerializableResource.new(data, options)
32
45
  end
33
46
 
34
47
  def token
@@ -21,8 +21,8 @@ module Comee
21
21
  end
22
22
 
23
23
  def filter
24
- query = Comee::Core::BackOrder.ransack(params[:q])
25
- render json: {success: true, data: serialize(query.result.includes(:back_order_items, :supplier))}
24
+ data = BackOrder.includes(:back_order_items, :supplier).ransack(params[:q]).result
25
+ render_content(data)
26
26
  end
27
27
 
28
28
  def model_params
@@ -5,8 +5,7 @@ module Comee
5
5
 
6
6
  def index
7
7
  super do
8
- client_prices = ClientPrice.all
9
- client_prices.then(&paginate)
8
+ ClientPrice.includes(:client, :product, :unit, :product_lookup).all
10
9
  end
11
10
  end
12
11
 
@@ -15,19 +14,13 @@ module Comee
15
14
  client_id = client.parent_id || client.id
16
15
  prices = ClientPrice.includes(:client, :product, :unit, :product_lookup)
17
16
  .where(client_id: client_id)
18
- total = prices.count
19
- prices = prices.then(&paginate)
20
-
21
- render json: {success: true, data: serialize(prices), page: params[:page], total: total}
17
+ render_content(prices)
22
18
  end
23
19
 
24
20
  def filter
25
21
  prices = ClientPrice.includes(:client, :product, :unit, :product_lookup)
26
22
  .ransack(params[:q]).result
27
- total = prices.count
28
- prices = prices.then(&paginate)
29
-
30
- render json: {success: true, data: serialize(prices), page: params[:page], total: total}
23
+ render_content(prices)
31
24
  end
32
25
 
33
26
  private
@@ -0,0 +1,13 @@
1
+ module Comee
2
+ module Core
3
+ class ClientWarehousesController < ApplicationController
4
+ include Common
5
+
6
+ private
7
+
8
+ def model_params
9
+ params.require(:payload).permit(:name, :description, :address, :client_id)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -4,28 +4,61 @@ module Comee
4
4
  include Common
5
5
 
6
6
  def filter
7
- @clients = Comee::Core::Client.ransack(params[:q]).result
8
- render json: {success: true, data: serialize(@clients)}
7
+ clients = Client.includes(:parent, :agents, :contacts, :client_warehouses).ransack(params[:q]).result
8
+ render_content(clients)
9
9
  end
10
10
 
11
11
  def consignees
12
- client = Comee::Core::Client.find(params[:id])
12
+ client = Client.find(params[:id])
13
13
  render json: {success: true, data: client.consignees}
14
14
  rescue StandardError => e
15
- render json: {success: false, error: e.message}
15
+ render json: {success: false, error: e.message}, status: :unprocessable_entity
16
16
  end
17
17
 
18
- def shipment_addresses
19
- client = Comee::Core::Client.find(params[:id])
20
- render json: {success: true, data: client.shipment_addresses}
18
+ def create_agent
19
+ client = Client.includes(:parent, :agents, :contacts, :client_warehouses).find(params[:id])
20
+ agent = Agent.new(agent_params)
21
+ if agent.save
22
+ client.agents << agent
23
+ client.save!
24
+ render_content(client)
25
+ else
26
+ render json: {success: false, error: agent.errors.full_messages[0]}, status: :unprocessable_entity
27
+ end
28
+ end
29
+
30
+ def create_contact
31
+ client = Client.includes(:parent, :agents, :contacts, :client_warehouses).find(params[:id])
32
+ contact = Contact.new(contact_params)
33
+ if contact.save
34
+ client.contacts << contact
35
+ client.save!
36
+ render_content(client)
37
+ else
38
+ render json: {success: false, error: contact.errors.full_messages[0]}, status: :unprocessable_entity
39
+ end
40
+ end
41
+
42
+ def agents
43
+ client = Client.find(params[:id])
44
+ render_content(client.agents)
21
45
  rescue StandardError => e
22
- render json: {success: false, error: e.message}
46
+ render json: {success: false, error: e.message}, status: :unprocessable_entity
23
47
  end
24
48
 
25
49
  private
26
50
 
27
51
  def model_params
28
- params.require(:payload).permit(:code, :name, :address, :locale, :user_id, :parent_id, consignees: [], shipment_addresses: [])
52
+ params.require(:payload).permit(:code, :name, :address, :locale, :user_id, :parent_id, :currency,
53
+ consignees: [])
54
+ end
55
+
56
+ def agent_params
57
+ params.require(:payload).permit(:name, :address, :email, :telephone)
58
+ end
59
+
60
+ def contact_params
61
+ params.require(:payload).permit(:first_name, :last_name, :email, :telephone)
29
62
  end
30
63
  end
31
64
  end
@@ -0,0 +1,13 @@
1
+ module Comee
2
+ module Core
3
+ class ContactsController < ApplicationController
4
+ include Common
5
+
6
+ private
7
+
8
+ def model_params
9
+ params.require(:payload).permit(:first_name, :last_name, :email, :telephone)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -9,8 +9,8 @@ module Comee
9
9
  end
10
10
 
11
11
  def filter
12
- query = CustomerOrderItem.ransack(params[:q])
13
- render json: {success: true, data: serialize(query.result.includes(:product))}
12
+ data = CustomerOrderItem.includes(:product, :unit).ransack(params[:q]).result
13
+ render_content(data)
14
14
  end
15
15
 
16
16
  def destroy
@@ -32,6 +32,7 @@ module Comee
32
32
  :customer_item_no,
33
33
  :quantity,
34
34
  :price,
35
+ :total_price,
35
36
  :delivery_date,
36
37
  :canceled,
37
38
  :product_id,
@@ -39,8 +39,8 @@ module Comee
39
39
  end
40
40
 
41
41
  def filter
42
- @customer_orders = Comee::Core::CustomerOrder.ransack(params[:q]).result
43
- render json: {success: true, data: serialize(@customer_orders)}
42
+ orders = CustomerOrder.includes(:client, :customer_order_items).ransack(params[:q]).result
43
+ render_content(orders)
44
44
  end
45
45
 
46
46
  private
@@ -59,7 +59,7 @@ module Comee
59
59
  .permit(
60
60
  :order_number, :order_date, :order_terms, :consignee, :shipment_address, :final_destination,
61
61
  :final_delivery_date, :handover_date, :shipping_date, :delivery_address, :invoice_address, :status, :client_id,
62
- items: %i[customer_item_no product_id quantity price unit_id delivery_date]
62
+ items: %i[customer_item_no product_id quantity price total_price unit_id delivery_date]
63
63
  )
64
64
  end
65
65
 
@@ -4,8 +4,8 @@ module Comee
4
4
  include Common
5
5
 
6
6
  def filter
7
- @item_statuses = Comee::Core::ItemStatus.ransack(params[:q]).result
8
- render json: {success: true, data: serialize(@item_statuses)}
7
+ item_statuses = ItemStatus.ransack(params[:q]).result
8
+ render_content(item_statuses)
9
9
  end
10
10
 
11
11
  private
@@ -4,18 +4,18 @@ module Comee
4
4
  before_action :set_notification, only: %i[mark_as_read mark_as_unread]
5
5
 
6
6
  def index
7
- data = Comee::Core::Notification.messages(current_user.notifications.newest_first)
8
- render json: {success: true, data: data}
7
+ data = Notification.messages(current_user.notifications.newest_first)
8
+ render_content(data)
9
9
  end
10
10
 
11
11
  def read
12
12
  data = Notification.messages(current_user.notifications.read.newest_first)
13
- render json: {success: true, data: data}
13
+ render_content(data)
14
14
  end
15
15
 
16
16
  def unread
17
17
  data = Notification.messages(current_user.notifications.unread.newest_first)
18
- render json: {success: true, data: data}
18
+ render_content(data)
19
19
  end
20
20
 
21
21
  def mark_as_read
@@ -10,8 +10,8 @@ module Comee
10
10
  end
11
11
 
12
12
  def filter
13
- lookups = ProductLookup.ransack(params[:q]).result
14
- render json: {success: true, data: serialize(lookups)}
13
+ data = ProductLookup.ransack(params[:q]).result
14
+ render_content(data)
15
15
  end
16
16
 
17
17
  private
@@ -5,37 +5,35 @@ module Comee
5
5
 
6
6
  def index
7
7
  super do
8
- products = Product.leafs
9
- products.then(&paginate)
8
+ Product.leafs
10
9
  end
11
10
  end
12
11
 
13
12
  def show
14
13
  super do
15
- product = Comee::Core::Product.with_attached_images.find(params[:id])
16
- product
14
+ Comee::Core::Product.with_attached_images.find(params[:id])
17
15
  end
18
16
  end
19
17
 
20
18
  def master_prices
21
19
  data = MasterPrice.includes(:product_lookup, :supplier, :product)
22
20
  .where(product_id: price_params[:product_ids])
23
- render json: {success: true, data: serialize(data)}
21
+ render_content(data)
24
22
  end
25
23
 
26
24
  def client_prices
27
25
  data = ClientPrice.where(product_id: price_params[:product_ids])
28
- render json: {success: true, data: serialize(data)}
26
+ render_content(data)
29
27
  end
30
28
 
31
29
  def categories
32
30
  root = Product.find_by(code: "root")
33
- render json: {success: true, data: serialize(root.children)}
31
+ render_content(root.children)
34
32
  end
35
33
 
36
34
  def filter
37
- products = Product.ransack(params[:q]).result
38
- render json: {success: true, data: serialize(products)}
35
+ data = Product.ransack(params[:q]).result
36
+ render_content(data)
39
37
  end
40
38
 
41
39
  private
@@ -4,8 +4,8 @@ module Comee
4
4
  include Common
5
5
 
6
6
  def filter
7
- @purchase_order_items = Comee::Core::PurchaseOrderItem.ransack(params[:q]).result
8
- render json: {success: true, data: serialize(@purchase_order_items)}
7
+ data = PurchaseOrderItem.ransack(params[:q]).result
8
+ render_content(data)
9
9
  end
10
10
 
11
11
  private
@@ -4,8 +4,8 @@ module Comee
4
4
  include Common
5
5
 
6
6
  def filter
7
- @purchase_orders = Comee::Core::PurchaseOrder.ransack(params[:q]).result
8
- render json: {success: true, data: serialize(@purchase_orders)}
7
+ data = Comee::Core::PurchaseOrder.ransack(params[:q]).result
8
+ render_content(data)
9
9
  end
10
10
 
11
11
  private
@@ -9,8 +9,8 @@ module Comee
9
9
  end
10
10
 
11
11
  def filter
12
- query = QuotationRequestItem.ransack(params[:q])
13
- render json: {success: true, data: serialize(query.result.includes(:product))}
12
+ data = QuotationRequestItem.includes(:product, :quotation_request, :unit).ransack(params[:q]).result
13
+ render_content(data)
14
14
  end
15
15
 
16
16
  def destroy
@@ -10,9 +10,8 @@ module Comee
10
10
  end
11
11
 
12
12
  def filter
13
- query = QuotationRequest.ransack(params[:q]).result
14
- query = query.then(&paginate)
15
- render json: {success: true, data: serialize(query.includes(:client))}
13
+ data = QuotationRequest.includes(:client).ransack(params[:q]).result
14
+ render_content(data)
16
15
  end
17
16
 
18
17
  def rfq_products_for_client
@@ -20,20 +19,20 @@ module Comee
20
19
  root = Product.roots.first
21
20
  ids = root.indirect_ids - client_products
22
21
  products = Product.where(id: ids)
23
- render json: {success: true, data: serialize(products)}
22
+ render_content(products)
24
23
  end
25
24
 
26
25
  def create_request_with_items
27
26
  service = QuotationRequestService.new
28
27
  parameters = rfq_params.to_h.deep_symbolize_keys
29
28
  result = service.create_request_with_items(parameters)
30
- render json: {success: true, data: serialize(result)}
29
+ render_content(result)
31
30
  end
32
31
 
33
32
  def submit
34
33
  service = QuotationRequestService.new
35
34
  rfq = service.submit(params[:id])
36
- render json: {success: true, data: serialize(rfq)}
35
+ render_content(rfq)
37
36
  rescue StandardError => e
38
37
  render json: {success: false, error: e.message}
39
38
  end
@@ -41,7 +40,7 @@ module Comee
41
40
  def submit_for_confirmation
42
41
  service = QuotationRequestService.new
43
42
  rfq = service.submit_for_confirmation(params[:id])
44
- render json: {success: true, data: serialize(rfq)}
43
+ render_content(rfq)
45
44
  rescue StandardError => e
46
45
  render json: {success: false, error: e.message}
47
46
  end
@@ -49,7 +48,7 @@ module Comee
49
48
  def confirm
50
49
  service = QuotationRequestService.new
51
50
  rfq = service.confirm(params[:id])
52
- render json: {success: true, data: serialize(rfq)}
51
+ render_content(rfq)
53
52
  rescue StandardError => e
54
53
  render json: {success: false, error: e.message}
55
54
  end
@@ -57,7 +56,7 @@ module Comee
57
56
  def convert
58
57
  service = QuotationRequestService.new
59
58
  order = service.convert_to_order(params[:id])
60
- render json: {success: true, data: serialize(order)}
59
+ render_content(order)
61
60
  rescue StandardError => e
62
61
  render json: {success: false, error: e.message}
63
62
  end
@@ -5,7 +5,7 @@ module Comee
5
5
 
6
6
  def index
7
7
  super do
8
- Comee::Core::SalesOrderItem.includes(
8
+ SalesOrderItem.includes(
9
9
  :sales_order,
10
10
  :customer_order_item,
11
11
  :source,
@@ -6,35 +6,41 @@ module Comee
6
6
 
7
7
  def index
8
8
  super do
9
+ data = SalesOrder.includes(:customer_order, :fulfillment_center, :sales_order_items, :client).all
9
10
  [
10
- Comee::Core::SalesOrder.includes(:customer_order, :fulfillment_center, :sales_order_items).all,
11
- include: ["client", "customer_order", "sales_order_items", "sales_order_items.product", "sales_order_items.unit"]
11
+ data,
12
+ fields: ["client", "customer_order", "sales_order_items", "sales_order_items.product", "sales_order_items.unit"]
12
13
  ]
13
14
  end
14
15
  end
15
16
 
16
17
  def filter
17
- @sales_order = Comee::Core::SalesOrder.ransack(params[:q]).result
18
- render json: {success: true, data: serialize(@sales_order)}
18
+ data = SalesOrder.includes(
19
+ :customer_order,
20
+ :client,
21
+ :fulfillment_center,
22
+ :sales_order_items
23
+ ).ransack(params[:q]).result
24
+ render_content(data)
19
25
  end
20
26
 
21
27
  def submit
22
28
  order = @service.submit(params[:id])
23
- render json: {success: true, data: serialize(order)}
29
+ render_content(order)
24
30
  rescue StandardError => e
25
31
  render json: {success: false, error: e.message}
26
32
  end
27
33
 
28
34
  def confirm
29
35
  order = @service.confirm(params[:id])
30
- render json: {success: true, data: serialize(order)}
36
+ render_content(order)
31
37
  rescue StandardError => e
32
38
  render json: {success: false, error: e.message}
33
39
  end
34
40
 
35
41
  def cancel
36
42
  order = @service.cancel(params[:id])
37
- render json: {success: true, data: serialize(order)}
43
+ render_content(order)
38
44
  rescue StandardError => e
39
45
  render json: {success: false, error: e.message}
40
46
  end
@@ -7,27 +7,27 @@ module Comee
7
7
  super do
8
8
  [
9
9
  ShipmentItem.includes(sales_order_item: [sales_order: :client]).all,
10
- include: ["sales_order_item.sales_order.client"]
10
+ fields: ["sales_order_item.sales_order.client"]
11
11
  ]
12
12
  end
13
13
  end
14
14
 
15
15
  def filter
16
- @shipment_item = Comee::Core::ShipmentItem.ransack(params[:q]).result
17
- options = {include: ["sales_order_item.sales_order.client"]}
18
- render json: {success: true, data: serialize(@shipment_item, options)}
16
+ shipment_item = ShipmentItem.includes(:sales_order_item).ransack(params[:q]).result
17
+ options = {fields: ["sales_order_item.sales_order.client"]}
18
+ render_content(shipment_item, options)
19
19
  end
20
20
 
21
21
  def filter_for_client
22
- shipment_items = Comee::Core::ShipmentItem.joins(sales_order_item: :sales_order)
23
- .where(
24
- comee_core_sales_order_items: {
25
- comee_core_sales_orders: {
26
- client_id: params[:id]
27
- }
28
- }
29
- )
30
- render json: {success: true, data: serialize(shipment_items)}
22
+ shipment_items = ShipmentItem.joins(sales_order_item: :sales_order)
23
+ .where(
24
+ comee_core_sales_order_items: {
25
+ comee_core_sales_orders: {
26
+ client_id: params[:id]
27
+ }
28
+ }
29
+ )
30
+ render_content(shipment_items)
31
31
  end
32
32
 
33
33
  def filter_with_status
@@ -5,21 +5,19 @@ module Comee
5
5
 
6
6
  def index
7
7
  super do
8
- Supplier.all.then(&paginate)
8
+ Supplier.includes(:currency).all
9
9
  end
10
10
  end
11
11
 
12
12
  def filter
13
- suppliers = Comee::Core::Supplier.ransack(params[:q]).result
14
- total = suppliers.count
15
- suppliers = suppliers.then(&paginate)
16
- render json: {success: true, data: serialize(suppliers), page: params[:page], total: total}
13
+ suppliers = Supplier.includes(:currency).ransack(params[:q]).result
14
+ render_content(suppliers)
17
15
  end
18
16
 
19
17
  private
20
18
 
21
19
  def model_params
22
- params.require(:payload).permit(:code, :name, :address, :locale)
20
+ params.require(:payload).permit(:code, :name, :address, :locale, :currency_id)
23
21
  end
24
22
  end
25
23
  end
@@ -5,7 +5,7 @@ module Comee
5
5
 
6
6
  def index
7
7
  super do
8
- Comee::Core::UnitConversion.includes(:from, :to).all
8
+ UnitConversion.includes(:from, :to).all
9
9
  end
10
10
  end
11
11
 
@@ -5,7 +5,7 @@ module Comee
5
5
 
6
6
  def filter
7
7
  units = Unit.ransack(params[:q]).result
8
- render json: {success: true, data: serialize(units)}
8
+ render_content(units)
9
9
  end
10
10
 
11
11
  private
@@ -2,6 +2,7 @@ module Comee
2
2
  module Core
3
3
  module Common
4
4
  extend ActiveSupport::Concern
5
+ include Pagination
5
6
 
6
7
  included do
7
8
  before_action :set_clazz
@@ -15,23 +16,48 @@ module Comee
15
16
  incoming = yield
16
17
  if incoming.instance_of?(Array)
17
18
  data, options = incoming
19
+ elsif incoming.instance_of?(Hash)
20
+ options = incoming
18
21
  else
19
22
  data = incoming
20
23
  end
21
24
  else
22
25
  data = @clazz.all
23
26
  end
24
-
25
- page = params[:page]
26
- if page
27
- render json: {success: true, data: serialize(data, options), page: page, total: @clazz.count}
28
- else
29
- render json: {success: true, data: serialize(data, options)}
27
+ total = data.count
28
+ data = data.then(&paginate) if params[:page]
29
+ result = {
30
+ success: true,
31
+ data: options.key?(:fields) ? serialize(data, include: options[:fields]) : serialize(data)
32
+ }
33
+ if params[:page]
34
+ result[:page] = params[:page]
35
+ result[:total] = total
30
36
  end
37
+
38
+ render json: result
31
39
  end
32
40
 
33
41
  def show
34
- render json: {success: true, data: serialize(@obj)}
42
+ data = nil
43
+ options = {}
44
+ if block_given?
45
+ incoming = yield
46
+ if incoming.instance_of?(Array)
47
+ data, options = incoming
48
+ elsif incoming.instance_of?(Hash)
49
+ options = incoming
50
+ else
51
+ data = incoming
52
+ end
53
+ else
54
+ data = @obj
55
+ end
56
+ result = {
57
+ success: true,
58
+ data: options.key?(:fields) ? serialize(data, include: options[:fields]) : serialize(data)
59
+ }
60
+ render json: result
35
61
  end
36
62
 
37
63
  def create
@@ -0,0 +1,7 @@
1
+ module Comee
2
+ module Core
3
+ class Agent < ApplicationRecord
4
+ validates :name, :email, :telephone, presence: true
5
+ end
6
+ end
7
+ end