comee_core 0.2.99 → 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: 6f908a911b1098420945879d34cfcea3d9d2621d45558a771fc00523f90f5c9f
4
- data.tar.gz: a5a0ba0c43e01acd881f85a99ac0913ce87863ead8528dc313095874e0af435d
3
+ metadata.gz: fc0763d813df0b1e3ddf87c6a4212f0c0bf6f85e60744ade8f1d216fb2eefb9e
4
+ data.tar.gz: 664f56499508ef5699bdeb95543f442d9dcc58f43d0cb05bdafa5eda0c4868a1
5
5
  SHA512:
6
- metadata.gz: 2ecbb6029fd90d1238167c0d9f25e855bbe4564e444f5265c9fad5419d68cf42106bc9cebf9ed6ad1b378716bd44a8c7d2205a8c930512553b962d7d2b6227dd
7
- data.tar.gz: 7a1532959dd4b0f75c9ede644ba2b5d8f2179328c7d6f4bce434a4e194e76062efe835f9c7824f1c6353b05dab7dee065df3610e82c50a8b52d6a1b11152c767
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
@@ -10,7 +10,7 @@ module Comee
10
10
  validates :order_number, :order_date, :delivery_address, :invoice_address, :status, presence: true
11
11
 
12
12
  def self.ransackable_attributes(_auth_object = nil)
13
- %w[id client_id delivery_address invoice_address order_number status]
13
+ %w[id client_id delivery_address invoice_address order_number status final_destination consignee]
14
14
  end
15
15
 
16
16
  def self.ransackable_associations(_auth_object = nil)
@@ -41,6 +41,7 @@ module Comee
41
41
  status
42
42
  purchase_status
43
43
  consignee
44
+ destination
44
45
  customer_order_id
45
46
  ]
46
47
  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.2.99".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.2.99
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-21 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