comee_core 0.3.21 → 0.3.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ef62a4650cf347d3276dede12a8c429757c5261df0697d3632a73b907c1c27a
|
4
|
+
data.tar.gz: 30d1511ab8a333c92730ccd98f16ced09d5c29aff58e7692fdbf908475ad2370
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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(
|
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(:
|
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,
|
83
|
-
item =
|
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
|
-
|
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
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
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
|
-
|
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)
|
data/lib/comee/core/version.rb
CHANGED
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.
|
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-
|
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
|