comee_core 0.3.20 → 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: 5800c13672eb17e44ca33d72b8793090222e15e35a1b3b006fcdbb8394e1440c
4
- data.tar.gz: d3c846baacc27f192b2bc54cb009b98bccdc9958dc3e1a617bcbf8476c6d54c5
3
+ metadata.gz: 4ef62a4650cf347d3276dede12a8c429757c5261df0697d3632a73b907c1c27a
4
+ data.tar.gz: 30d1511ab8a333c92730ccd98f16ced09d5c29aff58e7692fdbf908475ad2370
5
5
  SHA512:
6
- metadata.gz: 6c2a9a3381044970f4bc3a23459d3bb5438e226e8ff0265de16a952c9939dd6e88f369a453ab54d8398301d464b305500b4cc1c6405553437a4dd0514751ef5c
7
- data.tar.gz: 2f18c9811f6165ce75f2bfd6cd06f300043e9699ad56b282ca5c3f87e10f83f5df7bf1d1d98a00e909462fca97547a5dd27e72c5a12b358cd04948a15c6f1948
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
@@ -13,41 +13,26 @@ module Comee
13
13
  def preprocess_data(xml: false)
14
14
  @ids.each do |id|
15
15
  @line_items = if xml
16
- shipment_items = Comee::Core::ShipmentItem.includes(sales_order_item: :sales_order)
17
- .where(sales_order_item: {sales_order_id: id})
18
- sales_order_item_ids = shipment_items.map { |item| item.sales_order_item_id }
19
- Comee::Core::SalesOrderItem.where(id: sales_order_item_ids)
16
+ Comee::Core::ShipmentInstructionItem.includes(shipment_item: {sales_order_item: :sales_order})
17
+ .where(delivery_note_id: id)
20
18
  else
21
19
  Comee::Core::ShipmentInstructionItem.includes(shipment_item: {sales_order_item: :sales_order})
22
20
  .where(shipment_instruction_id: id)
23
21
  end
24
- sales_order_ids = if xml
25
- @line_items.map(&:sales_order_id)
26
- else
27
- @line_items.map { |item| item.shipment_item.sales_order_item.sales_order.id }
28
- end
22
+ sales_order_ids = @line_items.map { |item| item.shipment_item.sales_order_item.sales_order.id }
23
+
29
24
  @customs_details = Comee::Core::CustomsDetail.includes(sales_order: :customer_order).where(sales_order_id: sales_order_ids)
30
25
  @transportation_routes = []
31
26
  @position_data = []
32
27
 
33
28
  packaging_types = @line_items.map do |line_item|
34
- if xml
35
- Comee::Core::ShipmentItem.find_by(sales_order_item_id: line_item.id).package_type.split(" ")[0]
36
- else
37
- line_item.shipment_item.package_type.split(" ")[0]
38
- end
29
+ line_item.shipment_item.package_type.split(" ")[0]
39
30
  end.uniq
40
31
 
41
32
  @no_of_packages = packaging_types.count
42
33
  @package_type = packaging_types.count == 1 && packaging_types.first == "PX" ? "PX" : "PK"
43
34
  @total_weight = @line_items.sum do |line_item|
44
- if xml
45
- xml_line = Comee::Core::ShipmentInstructionItem.where(shipment_item_id: Comee::Core::ShipmentItem
46
- .find_by(sales_order_item_id: line_item.id).id).first
47
- (xml_line.quantity * xml_line.weight).round(2)
48
- else
49
- (line_item.quantity * line_item.weight).round(2)
50
- end
35
+ (line_item.quantity * line_item.weight).round(2)
51
36
  end
52
37
 
53
38
  raise(StandardError, "No customs detail filed for sales order") unless @customs_details.present?
@@ -63,7 +48,11 @@ module Comee
63
48
 
64
49
  @data = xml ? generate_xml : prepare_data
65
50
  end
66
- xml ? @data : JSON(@data)
51
+ if xml
52
+ {xml_data: @data, file_name: "#{@customs_details[0].sales_order.customer_order.order_number}_Ausfuhr"}
53
+ else
54
+ JSON(@data)
55
+ end
67
56
  end
68
57
 
69
58
  def position_data
@@ -81,7 +70,7 @@ module Comee
81
70
  "wareWarenbezeichnung": si.sales_order_item.product.customs_description,
82
71
  "wareRegistriernummerFremdsystem": customs_detail.sales_order.customer_order.order_number,
83
72
  "wareUrsprungsbundesland": mp.state_of_origin.split(" ")[0],
84
- "wareEigenmasse": line_item.weight * line_item.quantity,
73
+ "wareEigenmasse": (line_item.weight * line_item.quantity).round(2),
85
74
  "wareRohmasse": index.zero? ? @total_weight : 0,
86
75
  "ausfuhrLand": "DE",
87
76
  "ursprungsland": mp.country_of_origin.code,
@@ -193,21 +182,22 @@ module Comee
193
182
 
194
183
  def xml_position_data(xml)
195
184
  @line_items.each_with_index do |line_item, index|
196
- customs_detail = @customs_details.find_by(sales_order_id: line_item.sales_order_id)
185
+ sales_order_item = line_item.shipment_item.sales_order_item
186
+ customs_detail = @customs_details.find_by(sales_order_id: sales_order_item.sales_order_id)
197
187
  mp = Comee::Core::MasterPrice.includes(:country_of_origin).find_by(primary: true,
198
- product_id: line_item.product.id)
188
+ product_id: sales_order_item.product.id)
199
189
 
200
190
  xml.Position do
201
191
  xml.Positionsnummer (index + 1).to_s
202
- xml.Warenbezeichnung line_item.product.customs_description
192
+ xml.Warenbezeichnung sales_order_item.product.customs_description
203
193
  xml.Registriernummer_Fremdsystem customs_detail.sales_order.customer_order.order_number
204
194
  xml.Kennnummer_der_Sendung @customs_details.map(&:sales_order).map(&:customer_order).map(&:consignee).join(" ")
205
195
  xml.Ursprungsbundesland mp.state_of_origin.split(" ")[0]
206
196
  xml.Ursprungsland mp.country_of_origin.code
207
- xml.Eigenmasse line_item.product.weight * line_item.quantity
197
+ xml.Eigenmasse (sales_order_item.product.weight * sales_order_item.quantity).round(2)
208
198
  xml.Rohmasse index.zero? ? @total_weight : 0
209
199
  xml.Gefahrgutnummer_UNDG
210
- xml.Warennummer_KN8 line_item.product.hs_code
200
+ xml.Warennummer_KN8 sales_order_item.product.hs_code
211
201
  xml.Verfahren do
212
202
  xml.angemeldetes "10"
213
203
  xml.vorangegangenes "00"
@@ -215,9 +205,9 @@ module Comee
215
205
  xml.Ausfuhrerstattung
216
206
  end
217
207
  xml.Aussenhandelsstatistik do
218
- xml.Menge line_item.quantity
219
- xml.Wert (line_item.quantity *
220
- line_item.price * 1.05).round(2).to_i
208
+ xml.Menge sales_order_item.quantity
209
+ xml.Wert (sales_order_item.quantity *
210
+ sales_order_item.price * 1.05).round(2).to_i
221
211
  end
222
212
  xml.Vorpapier do
223
213
  xml.Typ
@@ -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.20".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.20
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