comee_core 0.2.13 → 0.2.14

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5a4ecd52efb335b2688fb0fd381163d594b81de592ed48dcd5701ee28c00d10f
4
- data.tar.gz: 53ef139383420c858b4ce5afcb52974af1051cdb2086a83bcd28256311724a76
3
+ metadata.gz: dac759817de32ff973fe059159a63dd455821779c29124d8cc40763ee85e37f1
4
+ data.tar.gz: b848191c7faf98be197912ef1709617441aa229e501d09051d2cf05a3255e9a9
5
5
  SHA512:
6
- metadata.gz: aea590ef7c2567f4f8014bd7d18f4e77e81b735afb9fb64444d680b419d0548d20edbf62308d7f3bd5904fa4a225cabaf5b47649955934976183e6ffcb9a63e2
7
- data.tar.gz: 1a44e91626c5e3c1b3d5d37574bea1ab19fbf10c2993a31436bede678660d96862f6029735b70988eebbb39107039fb843b0a1c58f29045b983a733eee4c4386
6
+ metadata.gz: 51f9017b7fe3286c0d6968f6e46c970d7dc4dbcb613ab74abdc14cbd1e4dadd97888a45facfdbb9e9bcdebc5c1c0cb981faf80cb0070a253ba848910582bfb07
7
+ data.tar.gz: b98b538ddb7c0ca35870d1bf03557f035aacc15315cd17ec6814e3082d4f2c37055ebef011286dc66821b1d58e461262bcd7cc630d677d32318ee772ebac54bd
@@ -16,7 +16,7 @@ module Comee
16
16
 
17
17
  def suggest_values
18
18
  service = CustomerOrderService.new
19
- result = service.suggest_values(params[:id], params[:unit_id])
19
+ result = service.suggest_values(params[:id], suggest_params[:quantity], suggest_params[:unit_id])
20
20
  render json: {success: true, data: result}
21
21
  end
22
22
 
@@ -33,6 +33,10 @@ module Comee
33
33
 
34
34
  private
35
35
 
36
+ def suggest_params
37
+ params.require(:payload).permit(:unit_id, :quantity)
38
+ end
39
+
36
40
  def model_params
37
41
  params.require(:payload).permit(:sales_order_id, :customer_order_item_id, :product_id, :unit_id, :quantity, :quantity_delivered,
38
42
  :customer_item_no, :customer_item_description, :price, :handover_date, :delivery_date,
@@ -71,12 +71,14 @@ module Comee
71
71
  (quantity / conversion.factor).round
72
72
  end
73
73
 
74
- def suggest_values(item_id, new_unit_id)
74
+ def suggest_values(item_id, new_quantity, new_unit_id)
75
75
  item = CustomerOrderItem.includes(:customer_order).find_by(id: item_id)
76
76
  raise(StandardError, "Order item with id `#{item_id}` not found.") unless item
77
77
 
78
- quantity = convert_quantity(item.quantity, item.unit_id, new_unit_id)
79
- client_price = ClientPrice.find_by(product_id: item.product_id, client_id: item.customer_order.client_id)
78
+ quantity = convert_quantity(new_quantity, item.unit_id, new_unit_id)
79
+ client = Client.find(item.customer_order.client_id)
80
+ client_id = client.parent_id || client.id
81
+ client_price = ClientPrice.find_by(product_id: item.product_id, client_id: client_id)
80
82
  if client_price
81
83
  price = convert_price(client_price.price, client_price.unit_id, new_unit_id)
82
84
  else
data/config/routes.rb CHANGED
@@ -112,7 +112,7 @@ Comee::Core::Engine.routes.draw do
112
112
  end
113
113
  resources :sales_order_items, except: [:index] do
114
114
  member do
115
- get "suggest", controller: :sales_order_items, action: :suggest_values
115
+ post "suggest", controller: :sales_order_items, action: :suggest_values
116
116
  post "cancel"
117
117
  end
118
118
  end
@@ -1,5 +1,5 @@
1
1
  module Comee
2
2
  module Core
3
- VERSION = "0.2.13".freeze
3
+ VERSION = "0.2.14".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: comee_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.13
4
+ version: 0.2.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henock L.