comee_core 0.3.21 → 0.3.22

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: 1fab2298e1068d07c363f1b68294580c1083674dd2b8e39c138a9915a66e95c5
4
- data.tar.gz: 28eee2c59364a03df98d8e8dcf64f5cd1077f6b1c3bd787a27c668ead48bbda2
3
+ metadata.gz: 4ef62a4650cf347d3276dede12a8c429757c5261df0697d3632a73b907c1c27a
4
+ data.tar.gz: 30d1511ab8a333c92730ccd98f16ced09d5c29aff58e7692fdbf908475ad2370
5
5
  SHA512:
6
- metadata.gz: 786348f507b5a0c8ac4908c07fa36d946dbd938a56fdca4e2f197677532b8ceca183b8228d004ba2c43c825261542439921f26bb05b8221d63b7930fbd20ebb3
7
- data.tar.gz: 3fe9e3c69f795418bcc608571c0ef8ea1270e0154d43dd7cf88481d00a527883786f8fe58d5ba3c05fd83fb5193251f5e91d5b51068bae3cded9e31c6d4d01f7
6
+ metadata.gz: e9d3e24823a44a19181692cb570c04bb78e7ff6632022fa1e76fbd5ef330bb06be7770c2589b49d19b6613d406199f81f5e6c4c9359675a18621a719d0b5224e
7
+ data.tar.gz: 28e92974cd248a841c25dac76b5dd93f89416159b16dde9778a1d51628daece86eb13d332965816e835ffce6550236bd8fc4bfd76b754ea0af43c4669957c099
@@ -52,7 +52,12 @@ module Comee
52
52
 
53
53
  def suggest_values
54
54
  service = CustomerOrderService.new
55
- result = service.suggest_values(params[:id], suggest_params[:unit_id])
55
+ result = service.suggest_values(
56
+ params[:id],
57
+ suggest_params[:from_id],
58
+ suggest_params[:to_id],
59
+ suggest_params[:quantity]
60
+ )
56
61
  render json: {success: true, data: result}
57
62
  end
58
63
 
@@ -88,7 +93,7 @@ module Comee
88
93
  private
89
94
 
90
95
  def suggest_params
91
- params.permit(:unit_id, :quantity)
96
+ params.permit(:from_id, :to_id, :quantity)
92
97
  end
93
98
 
94
99
  def model_params
@@ -79,23 +79,30 @@ module Comee
79
79
  (quantity / conversion.factor).round
80
80
  end
81
81
 
82
- def suggest_values(item_id, new_unit_id)
83
- item = CustomerOrderItem.includes(:customer_order).find_by(id: item_id)
82
+ def suggest_values(item_id, from_id, to_id, quantity, old_price = nil)
83
+ item = SalesOrderItem.includes(:product, sales_order: :client)
84
+ .find_by(id: item_id)
84
85
  raise(StandardError, "Order item with id `#{item_id}` not found.") unless item
85
86
 
86
- quantity = convert_quantity(item.quantity, item.unit_id, new_unit_id)
87
- client = Client.find(item.customer_order.client_id)
87
+ client = item.sales_order.client
88
88
  client_id = client.parent_id || client.id
89
- client_price = ClientPrice.find_by(product_id: item.product_id, client_id: client_id)
90
- if client_price
91
- price = convert_price(client_price.price, client_price.unit_id, new_unit_id)
92
- else
93
- master_price = MasterPrice.find_by(product_id: item.product_id, primary: true)
94
- raise(StandardError, "No price entry could be found for product `#{item.product.code}`.") unless master_price
95
-
96
- price = convert_price(master_price.selling_price, master_price.unit_id, new_unit_id)
89
+
90
+ client_price = old_price
91
+ unless client_price
92
+ client_price = ClientPrice.find_by(product_id: item.product_id, client_id: client_id)
93
+ if client_price
94
+ client_price = convert_price(client_price.price, client_price.unit_id, from_id)
95
+ else
96
+ master_price = MasterPrice.find_by(product_id: item.product_id, primary: true)
97
+ raise(StandardError, "No price entry could be found for product `#{item.product.code}`.") unless master_price
98
+
99
+ client_price = convert_price(master_price.selling_price, master_price.unit_id, from_id)
100
+ end
97
101
  end
98
- {quantity: quantity, price: price, total_price: quantity * price}
102
+
103
+ price = convert_price(client_price, from_id, to_id)
104
+ new_quantity = convert_quantity(quantity, from_id, to_id)
105
+ {quantity: new_quantity, price: price, total_price: (new_quantity * price).round(2)}
99
106
  end
100
107
 
101
108
  def submit(id)
@@ -1,5 +1,5 @@
1
1
  module Comee
2
2
  module Core
3
- VERSION = "0.3.21".freeze
3
+ VERSION = "0.3.22".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: comee_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.21
4
+ version: 0.3.22
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henock L.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-07-05 00:00:00.000000000 Z
11
+ date: 2024-07-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers