comee_core 0.3.0 → 0.3.2

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: 521259eb0c767a6dddab837b5d613c06cb8acb2fd5ce3ad6db25baab15699d63
4
- data.tar.gz: a8de0c041aac3c4f9e45edd953d4d88ace6867a7f15e3a9c8b5217f6542387e4
3
+ metadata.gz: b5679f8f8d4ed8da5747d3f1f63e4b9b0621d5204e821241ed126ed4148701d7
4
+ data.tar.gz: 007bd33cf75d023854a2b4b35974065bee2e405f1c7d9830413b5c57fbe061f5
5
5
  SHA512:
6
- metadata.gz: 7f3df1fafcd3c7284ea6854b88edb63c3a8c8ae4b6d1ce01059e9c3599c6e76c153eeed696f13450b754e13d3f7d9b2c04b1ac87eed61bd9cefacde55ee0666c
7
- data.tar.gz: c68b224fc40c934f93c8ae85c84f40de3d71a32d1f7f0b9f89ccb737fbb37576b0df39f51bbfa93e7da705623d224e006fe39061fb5b66af8a7c54deb021a8f8
6
+ metadata.gz: 84538ddee22dcff3353d894c017f812d7b5beb4e7c81bbf532f0b558f1071350ef71b4b3ce698bc07e905195668166b49e9497c0e485f5b458b26a407e066ea4
7
+ data.tar.gz: 20a4c722dcdd2bc4a6d075c0f0c886ae810f3977950236c069d4af995b629ab7011eea011ef359e8d8fbeae155b81e6da9a468e908830471dd217aeeebd87482
@@ -9,7 +9,7 @@ module Comee
9
9
  end
10
10
 
11
11
  def send_customs_details
12
- service = BeoService.new(params[:id])
12
+ service = BeoService.new(publish_params[:ids])
13
13
  data = service.send_customs_details
14
14
  render json: {success: true, data: data}
15
15
  rescue StandardError => e
@@ -18,6 +18,12 @@ module Comee
18
18
 
19
19
  private
20
20
 
21
+ def publish_params
22
+ params.require(:payload).permit(
23
+ ids: []
24
+ )
25
+ end
26
+
21
27
  def model_params
22
28
  params.require(:payload).permit(
23
29
  :registration_type,
@@ -3,8 +3,26 @@ module Comee
3
3
  class UsersController < ApplicationController
4
4
  include Common
5
5
 
6
+ def change_password
7
+ @user = current_user
8
+ if @user.authenticate(change_password_params[:old_password])
9
+ if @user.update(password: change_password_params[:new_password],
10
+ password_confirmation: change_password_params[:new_password_confirmation])
11
+ render json: @user, serializer: UserSerializer, status: :ok
12
+ else
13
+ render json: {errors: @user.errors.full_messages}, status: 422
14
+ end
15
+ else
16
+ render json: {error: "Old password is incorrect"}, status: :unauthorized
17
+ end
18
+ end
19
+
6
20
  private
7
21
 
22
+ def change_password_params
23
+ params.require(:payload).permit(:old_password, :new_password, :new_password_confirmation)
24
+ end
25
+
8
26
  def model_params
9
27
  params.require(:payload).permit(:name, :email, :active, :password, :password_confirmation)
10
28
  end
@@ -10,10 +10,6 @@ module Comee
10
10
  def self.ransackable_associations(_auth_object = nil)
11
11
  %w[sales_order]
12
12
  end
13
-
14
- validates :registration_type, :export_declaration_type, :participant_constellation, :mode_of_transport_type, :destination_country,
15
- :additional_identifier, :packaging_type, :export_customs_office, :customs_office_of_exit, :mode_of_transport,
16
- :delivery_term_code, presence: true
17
13
  end
18
14
  end
19
15
  end
@@ -6,6 +6,14 @@ module Comee
6
6
 
7
7
  validates :gin_number, :stock_transfer_request, uniqueness: true
8
8
  validates :date_issued, :gin_number, presence: true
9
+
10
+ def self.ransackable_attributes(_auth_object = nil)
11
+ %w[gin_number date_issued stock_transfer_request_id]
12
+ end
13
+
14
+ def self.ransackable_associations(_auth_object = nil)
15
+ %w[stock_transfer_request]
16
+ end
9
17
  end
10
18
  end
11
19
  end
@@ -8,6 +8,14 @@ module Comee
8
8
  validates :report_date, presence: true
9
9
  validates :reference_number, uniqueness: true
10
10
 
11
+ def self.ransackable_attributes(_auth_object = nil)
12
+ %w[reference_number report_date store_id]
13
+ end
14
+
15
+ def self.ransackable_associations(_auth_object = nil)
16
+ %w[store]
17
+ end
18
+
11
19
  private
12
20
 
13
21
  def set_reference_number
@@ -3,7 +3,7 @@ module Comee
3
3
  class SalesOrderItemSerializer < ActiveModel::Serializer
4
4
  attributes :id, :serial_no, :customer_item_no, :customer_item_description, :quantity, :quantity_delivered, :quantity_canceled,
5
5
  :price, :handover_date, :delivery_date, :eb_number, :lead_time, :comment, :action_note, :purchase_order_item_id,
6
- :total_price, :canceled, :processing_status
6
+ :total_price, :canceled, :processing_status, :additional_details, :created_at
7
7
  belongs_to :sales_order
8
8
  belongs_to :customer_order_item
9
9
  belongs_to :source
@@ -4,7 +4,7 @@ module Comee
4
4
  attributes :id, :order_number, :order_date, :order_terms, :shipment_address, :delivery_address, :invoice_address,
5
5
  :destination, :handover_date, :shipping_date, :delivery_date, :consignee, :parent_client_name, :payment_term,
6
6
  :delivery_term, :payment_penalty, :status, :purchase_status, :total_price, :amount_paid, :pallete_note,
7
- :remark, :created_by, :files_url
7
+ :remark, :created_by, :files_url, :created_at
8
8
  belongs_to :customer_order
9
9
  belongs_to :client
10
10
  belongs_to :fulfillment_center
@@ -3,54 +3,83 @@ require "httparty"
3
3
  module Comee
4
4
  module Core
5
5
  class BeoService
6
- def initialize(id)
6
+ def initialize(ids)
7
7
  @atlas_token = ENV.fetch("ATLAS_TOKEN")
8
8
  @atlas_base_url = ENV.fetch("ATLAS_BASE_URL")
9
9
  @encoded_auth = ENV.fetch("ENCODED_AUTH")
10
- @customs_detail = Comee::Core::CustomsDetail.includes(sales_order: :customer_order).find_by(sales_order_id: id)
11
- @line_items = Comee::Core::SalesOrderItem.includes(:product, :unit, :customer_order_item, :source,
12
- :purchase_order_item).where(sales_order_id: id)
13
- @transportation_routes = []
14
- @position_data = []
15
- raise(StandardError, "No customs detail filed for sales order") unless @customs_detail.present?
16
-
17
- @address = @customs_detail.sales_order.customer_order.client.address.split(", ")
18
- @customs_detail.transportation_route.each do |tr|
19
- @transportation_routes << tr["route"][0, 2]
10
+ @ids = ids
11
+ end
12
+
13
+ def pre_process_data
14
+ @ids.each do |id|
15
+ @line_items = Comee::Core::ShipmentInstructionItem.includes(shipment_item: {sales_order_item: :sales_order})
16
+ .where(shipment_instruction_id: id)
17
+ sales_order_ids = @line_items.map(&:shipment_item).map(&:sales_order_item).map(&:sales_order).map(&:id)
18
+ @customs_details = Comee::Core::CustomsDetail.includes(sales_order: :customer_order).where(sales_order_id: sales_order_ids)
19
+ @transportation_routes = []
20
+ @position_data = []
21
+
22
+ packaging_types = @line_items.map { |line_item| line_item.shipment_item.package_type.split(" ")[0] }.uniq
23
+
24
+ @no_of_packages = packaging_types.count
25
+ @package_type = packaging_types.count == 1 && packaging_types.first == "PX" ? "PX" : "PK"
26
+ @total_weight = @line_items.sum do |line_item|
27
+ line_item.shipment_item.sales_order_item.quantity * line_item.shipment_item.sales_order_item.product.weight
28
+ end
29
+
30
+ raise(StandardError, "No customs detail filed for sales order") unless @customs_details.present?
31
+
32
+ @address = @customs_details[0].sales_order.customer_order.client.address.split(", ")
33
+ @customs_details[0].transportation_route.each do |tr|
34
+ @transportation_routes << tr["route"][0, 2]
35
+ end
36
+
37
+ prepare_data
20
38
  end
39
+
40
+ JSON(@data)
21
41
  end
22
42
 
23
- def prepare_data
24
- @line_items.each do |line_item, index|
25
- mp = Comee::Core::MasterPrice.includes(:country_of_origin).find_by(primary: true, product_id: line_item.product.id)
26
- sii = Comee::Core::ShipmentItem.find_by(sales_order_item_id: line_item.id)
27
- @position_data << {
28
- "warePositionsnummer": index,
29
- "wareWarennummerKN8": line_item.product.hs_code,
30
- "wareWarenbezeichnung": line_item.product.hs_description,
31
- "wareRegistriernummerFremdsystem": @customs_detail.sales_order.order_number,
43
+ def position_data
44
+ position_items = []
45
+ @line_items.each_with_index do |line_item, index|
46
+ customs_detail = @customs_details.find_by(sales_order_id: line_item.shipment_item.sales_order_item.sales_order_id)
47
+ mp = Comee::Core::MasterPrice.includes(:country_of_origin).find_by(primary: true,
48
+ product_id: line_item.shipment_item
49
+ .sales_order_item.product.id)
50
+ line_item.shipment_item
51
+ position_items << {
52
+ "warePositionsnummer": index + 1,
53
+ "wareWarennummerKN8": line_item.shipment_item.sales_order_item.product.hs_code,
54
+ "wareWarenbezeichnung": line_item.shipment_item.sales_order_item.product.hs_description,
55
+ "wareRegistriernummerFremdsystem": customs_detail.sales_order.customer_order.order_number,
32
56
  "wareUrsprungsbundesland": mp.state_of_origin,
33
- "wareEigenmasse": line_item.product.weight * line_item.quantity,
34
- "wareRohmasse": line_item.product.weight * line_item.quantity,
57
+ "wareEigenmasse": line_item.shipment_item.sales_order_item.product.weight * line_item.shipment_item.sales_order_item.quantity,
58
+ "wareRohmasse": index.zero? ? @total_weight : 0,
35
59
  "ausfuhrLand": "DE",
36
60
  "ursprungsland": mp.country_of_origin.code,
37
61
  "beantragtesVerfahren": "10",
38
62
  "vorhergehendesVerfahren": "00",
39
63
  "zusatzlichesVerfahren": "F61",
40
- "aussenhandelsstatistikMenge": line_item.quantity,
41
- "aussenhandelsstatistikWert": line_item.quantity * line_item.price,
64
+ "aussenhandelsstatistikMenge": line_item.shipment_item.sales_order_item.quantity,
65
+ "aussenhandelsstatistikWert": (line_item.shipment_item.sales_order_item.quantity *
66
+ line_item.shipment_item.sales_order_item.price * 1.05).round(2),
42
67
  "packstuck": [
43
68
  {
44
- "packstuckNummer": "1",
45
- "packstuckAnzahl": sii.pallet_no,
46
- "packstuckVerpackungsart": sii.package_type.split(" ")[0],
47
- "packstuckZeichenNummern": @customs_detail.sales_order.order_number
69
+ "packstuckNummer": index + 1,
70
+ "packstuckAnzahl": index.zero? ? @no_of_packages : 0,
71
+ "packstuckVerpackungsart": @package_type,
72
+ "packstuckZeichenNummern": customs_detail.sales_order.customer_order.order_number
48
73
  }
49
74
  ]
50
75
  }
51
76
  end
52
77
 
53
- data = {
78
+ position_items
79
+ end
80
+
81
+ def prepare_data
82
+ @data = {
54
83
  "dataIdentifier": "",
55
84
  "kundenNumber": "",
56
85
  "mandantId": "",
@@ -67,43 +96,43 @@ module Comee
67
96
  {
68
97
  "kopf": {
69
98
  "eoriNiederlassungsnummer": "DE47897410000",
70
- "dienststellennummer": "DE014851",
71
- "artderAnmeldung": @customs_detail.registration_type.split(" ")[0],
72
- "artderAnmeldungAusfuhr": @customs_detail.export_declaration_type,
99
+ "artderAnmeldung": @customs_details[0].registration_type.split(" ")[0],
100
+ "artderAnmeldungAusfuhr": @customs_details[0].export_declaration_type,
73
101
  "ausfuhrLand": "DE",
74
- "beteiligtenKonstellation": @customs_detail.participant_constellation.split(" ")[0],
75
- "sicherheit": @customs_detail.registration_type.split(" ")[0] == "CO" ? 0 : 2,
76
- "container": @customs_detail.containerized == true ? 1 : 0,
77
- "bestimmungsLand": @customs_detail.destination_country,
78
- "referenznummerUCR": @customs_detail.sales_order.customer_order.consignee,
79
- "lrn": @customs_detail.sales_order.order_number,
80
- "beforderungsmittelImInlandVerkehrszweig": @customs_detail.mode_of_transport,
81
- "beforderungsmittelderGrenzeVerkehrszweig": @customs_detail.mode_of_transport_at_border,
82
- "beforderungsmittelderGrenzeArt": @customs_detail.mode_of_transport_type,
102
+ "beteiligtenKonstellation": @customs_details[0].participant_constellation.split(" ")[0],
103
+ "sicherheit": @customs_details[0].registration_type.split(" ")[0] == "CO" ? 0 : 2,
104
+ "container": @customs_details[0].containerized == true ? 1 : 0,
105
+ "bestimmungsLand": @customs_details[0].destination_country,
106
+ "referenznummerUCR": @customs_details.map(&:sales_order).map(&:customer_order).map(&:consignee).join(" "),
107
+ "lrn": @customs_details.map(&:sales_order).map(&:customer_order).map(&:order_number).join(" "),
108
+ "beforderungsmittelImInlandVerkehrszweig": @customs_details[0].mode_of_transport,
109
+ "beforderungsmittelderGrenzeVerkehrszweig": @customs_details[0].mode_of_transport_at_border,
110
+ "beforderungsmittelderGrenzeArt": @customs_details[0].mode_of_transport_type,
83
111
  "beforderungsmittelderGrenzeKennzeichen": "UNBEKANNT",
84
- "beforderungsmittelderGrenzeStaatszugehorigkeit": @customs_detail.mode_of_transport_nationality.split(" ")[0],
112
+ "beforderungsmittelderGrenzeStaatszugehorigkeit": @customs_details[0].mode_of_transport_nationality.split(" ")[0],
113
+ "gesamtRohmasse": @total_weight,
85
114
  "beforderungsmittelBeimAbgang": [
86
115
  {
87
116
  "sequenznummer": "1",
88
- "artderIdentifikation": @customs_detail.type_of_identification.split(" ")[0],
89
- "kennzeichen": @customs_detail.additional_identifier.split(" ")[0],
90
- "staatszugehorigkeit": @customs_detail.nationality.split(" ")[0]
117
+ "artderIdentifikation": @customs_details[0].type_of_identification.split(" ")[0],
118
+ "kennzeichen": @customs_details[0].additional_identifier.split(" ")[0],
119
+ "staatszugehorigkeit": @customs_details[0].nationality.split(" ")[0]
91
120
  }
92
121
  ],
93
- "ausfuhrzollstelleDienststellennummer": @customs_detail.export_customs_office.split(" ")[0],
94
- "vorgeseheneAusgangszollstelleDienststellennummer": @customs_detail.customs_office_of_exit.split(" ")[0],
122
+ "ausfuhrzollstelleDienststellennummer": @customs_details[0].export_customs_office.split(" ")[0],
123
+ "vorgeseheneAusgangszollstelleDienststellennummer": @customs_details[0].customs_office_of_exit.split(" ")[0],
95
124
  "geschaftsvorgangArt": "11",
96
- "geschaftsvorgangRechnungspreis": @customs_detail.sales_order.total_price,
125
+ "geschaftsvorgangRechnungspreis": @customs_details[0].sales_order.total_price.round(2),
97
126
  "geschaftsvorgangWahrung": "EUR",
98
127
  "beforderungsroute": {
99
128
  "ausgewahlteLander": @transportation_routes,
100
- "beforderungsVon": @customs_detail.transportation_route[0]["route"].split(" ")[0],
101
- "beforderungsBis": @customs_detail.transportation_route[-1]["route"].split(" ")[0]
129
+ "beforderungsVon": @customs_details[0].transportation_route[0]["route"].split(" ")[0],
130
+ "beforderungsBis": @customs_details[0].transportation_route[-1]["route"].split(" ")[0]
102
131
  },
103
132
  "empfanger": {
104
133
  "tin": "",
105
134
  "niederlassungsNummer": "",
106
- "name": @customs_detail.sales_order.customer_order.client.name,
135
+ "name": @customs_details[0].sales_order.customer_order.client.name,
107
136
  "strasse": @address[0],
108
137
  "plz": @address[-1],
109
138
  "ort": "#{@address[1].split(' ')[-3]} #{@address[1].split(' ')[-2]}",
@@ -111,24 +140,22 @@ module Comee
111
140
  },
112
141
  "warenortArtdesOrtes": "B",
113
142
  "warenortArtDerOrtsbestimmung": "Y",
114
- "warenortZusatzlicheKennung": @customs_detail.additional_identifier.split(" ")[0],
115
- "lieferbedingungIncotermCode": @customs_detail.delivery_term_code[0, 3],
143
+ "warenortZusatzlicheKennung": @customs_details[0].additional_identifier.split(" ")[0],
144
+ "lieferbedingungIncotermCode": @customs_details[0].delivery_term_code[0, 3],
116
145
  "lieferbedingungOrt": "Hamburg"
117
146
  },
118
- "position": @position_data
147
+ "position": position_data
119
148
  }
120
149
  ]
121
150
  }
122
151
  }
123
152
  }
124
-
125
- JSON(data)
126
153
  end
127
154
 
128
155
  def send_customs_details
129
156
  response = HTTParty.post("#{@atlas_base_url}/PutData", headers: {'Content-Type': "application/json",
130
157
  'token': @atlas_token,
131
- 'bearertoken': bearer_token}, body: prepare_data)
158
+ 'bearertoken': bearer_token}, body: pre_process_data)
132
159
  unless [200, 201].include?(response.code)
133
160
  raise(StandardError,
134
161
  "Failed to send POST request with token: #{response.code} - #{response.body}")
@@ -169,7 +169,18 @@ module Comee
169
169
  product_id: order_items.map(&:product_id),
170
170
  status: ClientPrice.statuses[:current]
171
171
  )
172
- master_prices = MasterPrice.where(primary: true, status: Price.statuses[:current], product: order_items.map(&:product))
172
+ master_prices = MasterPrice.includes(:supplier).where(primary: true, status: Price.statuses[:current],
173
+ product: order_items.map(&:product))
174
+ main_query = ProductLookup.includes(:itemable).where(itemable_type: "Comee::Core::Supplier")
175
+ queries = master_prices.each_with_object([]) do |obj, res|
176
+ res << {
177
+ product_id: obj.product_id,
178
+ itemable_id: obj.supplier_id
179
+ }
180
+ end
181
+ product_lookups = queries.inject(main_query) do |conditions, condition|
182
+ conditions.or(ProductLookup.where(condition))
183
+ end
173
184
  items = order_items.each_with_object([]) do |item, res|
174
185
  next if item.canceled?
175
186
 
@@ -178,13 +189,16 @@ module Comee
178
189
  quantity = convert_quantity(item.quantity, item.unit_id, unit_id)
179
190
  client_price = client_prices.find { |price| price.product_id == item.product_id }
180
191
  master_price = master_prices.find { |price| price.product_id == item.product_id }
181
- if client_price
182
- price = convert_price(client_price.price, client_price.unit_id, unit_id)
183
- else
184
- raise(StandardError, "No price entry could be found for product `#{item.product.code}`.") unless master_price
185
-
186
- price = convert_price(master_price.selling_price, master_price.unit_id, unit_id)
192
+ product_lookup = product_lookups.find do |lookup|
193
+ lookup.product_id == master_price.product_id && lookup.itemable_id == master_price.supplier_id
187
194
  end
195
+ raise(StandardError, "No primary supplier found for product #{item.customer_item_no}") unless master_price
196
+
197
+ price = if client_price
198
+ convert_price(client_price.price, client_price.unit_id, unit_id)
199
+ else
200
+ convert_price(master_price.selling_price, master_price.unit_id, unit_id)
201
+ end
188
202
 
189
203
  res << {
190
204
  sales_order_id: sales_order.id,
@@ -199,7 +213,13 @@ module Comee
199
213
  total_price: quantity * price,
200
214
  delivery_date: item.delivery_date,
201
215
  handover_date: order.handover_date,
202
- lead_time: master_price&.lead_time
216
+ lead_time: master_price&.lead_time,
217
+ additional_details: {
218
+ supplier_id: master_price.supplier_id,
219
+ supplier_name: master_price.supplier.name,
220
+ supplier_item_no: product_lookup.code,
221
+ supplier_description: product_lookup.item_description
222
+ }
203
223
  }
204
224
  end
205
225
  SalesOrderItem.insert_all!(items)
data/config/routes.rb CHANGED
@@ -83,7 +83,11 @@ Comee::Core::Engine.routes.draw do
83
83
  end
84
84
  end
85
85
  resources :unit_conversions
86
- resources :users
86
+ resources :users do
87
+ member do
88
+ patch "change_password"
89
+ end
90
+ end
87
91
  resources :client_addresses
88
92
  resources :clients do
89
93
  member do
@@ -153,9 +157,6 @@ Comee::Core::Engine.routes.draw do
153
157
  resources :customs_details do
154
158
  collection do
155
159
  post "filter"
156
- end
157
-
158
- member do
159
160
  post "send", action: :send_customs_details
160
161
  end
161
162
  end
@@ -41,6 +41,7 @@ class CreateComeeCoreSalesOrderItems < ActiveRecord::Migration[7.0]
41
41
  t.string :comment
42
42
  t.string :action_note
43
43
  t.integer :processing_status, null: false, default: 0
44
+ t.jsonb :additional_details, default: {}
44
45
 
45
46
  t.timestamps
46
47
  end
@@ -5,18 +5,18 @@ class CreateComeeCoreCustomsDetails < ActiveRecord::Migration[7.1]
5
5
  null: false,
6
6
  index: {name: "soi_on_cccd_indx"},
7
7
  foreign_key: {to_table: :comee_core_sales_orders}
8
- t.string :registration_type, null: false
9
- t.string :export_declaration_type, null: false
10
- t.string :participant_constellation, null: false
11
- t.string :mode_of_transport_type, null: false
12
- t.string :destination_country, null: false
13
- t.boolean :containerized, null: false, default: false
14
- t.string :additional_identifier, null: false
15
- t.string :packaging_type, null: false
16
- t.string :export_customs_office, null: false
17
- t.string :customs_office_of_exit, null: false
18
- t.string :mode_of_transport, null: false
19
- t.string :delivery_term_code, null: false
8
+ t.string :registration_type
9
+ t.string :export_declaration_type
10
+ t.string :participant_constellation
11
+ t.string :mode_of_transport_type
12
+ t.string :destination_country
13
+ t.boolean :containerized, default: false
14
+ t.string :additional_identifier
15
+ t.string :packaging_type
16
+ t.string :export_customs_office
17
+ t.string :customs_office_of_exit
18
+ t.string :mode_of_transport
19
+ t.string :delivery_term_code
20
20
  t.string :mrn
21
21
  t.string :office_number
22
22
  t.float :quantity
@@ -1,5 +1,5 @@
1
1
  module Comee
2
2
  module Core
3
- VERSION = "0.3.0".freeze
3
+ VERSION = "0.3.2".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.0
4
+ version: 0.3.2
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-06-22 00:00:00.000000000 Z
11
+ date: 2024-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers