comee_core 0.3.0 → 0.3.1

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: fc0763d813df0b1e3ddf87c6a4212f0c0bf6f85e60744ade8f1d216fb2eefb9e
4
+ data.tar.gz: 664f56499508ef5699bdeb95543f442d9dcc58f43d0cb05bdafa5eda0c4868a1
5
5
  SHA512:
6
- metadata.gz: 7f3df1fafcd3c7284ea6854b88edb63c3a8c8ae4b6d1ce01059e9c3599c6e76c153eeed696f13450b754e13d3f7d9b2c04b1ac87eed61bd9cefacde55ee0666c
7
- data.tar.gz: c68b224fc40c934f93c8ae85c84f40de3d71a32d1f7f0b9f89ccb737fbb37576b0df39f51bbfa93e7da705623d224e006fe39061fb5b66af8a7c54deb021a8f8
6
+ metadata.gz: 828cfd039c47d92f5cbb4c1039cb84006227a74e2dfc908b8003e9531eae83afb61f6d8fcac7ac3786b4b69199a36c68e31c53aa38684fcdbb29b7d259d241fb
7
+ data.tar.gz: 3876f53bbb1c93e16eeff25e49f9b8e6d398797bc553ffeaf76af572a277da90eded3932d41e813004d7d620d07b8fcf47623dbd207649d3d01b22183e43f55b
@@ -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
@@ -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
7
7
  belongs_to :sales_order
8
8
  belongs_to :customer_order_item
9
9
  belongs_to :source
@@ -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
@@ -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
@@ -1,5 +1,5 @@
1
1
  module Comee
2
2
  module Core
3
- VERSION = "0.3.0".freeze
3
+ VERSION = "0.3.1".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.1
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-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers