comee_core 0.1.51 → 0.1.52

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: 8507c4dd25c1bcfa029f438953fe12ec069c715c4bec5783f0653e4a87b77332
4
- data.tar.gz: 474a2d3f78b9f0961130e2ace5dc66074b39d430c4c610b6b5a4ef0e2574c86b
3
+ metadata.gz: ff1dfff0aa073499bc32fea5072e424c330b9615d213dc26270262438b26e9e5
4
+ data.tar.gz: a87394329564dc44da058bbc4205f28abdb5a50e34d3ebe424cf2dc591877f87
5
5
  SHA512:
6
- metadata.gz: e65a2a474b37e891703e2f55b6c763b3ba8510c243d6cf8266fa987b7949b487c8086a29c8b5d49fda223d406ed5b6ae552a30c82e8e07a38e80bcaa4e02884c
7
- data.tar.gz: 6573cf6978274afeafb4467e74e9fe34340244bd08dca739115fd07fabca16974b083f100029ebb77534cabb686775bb586725aaee37e6ca9085b23bdd4001f3
6
+ metadata.gz: adf59f0b900a8d46b84a029c69208e71e135a2d9d8992f616474898129859178c1c524ec1558459ff8c0b43fcc4a685df54b2fd32b7855c98a580d3eb135617c
7
+ data.tar.gz: e93a6583da3c90075e23b7e71a488bae640908a8ee1281bab2db02157b7855bbca65a8151bec3bd7d494eace4aba3ae22dedc7178db21b178856f6d9efb84507
@@ -17,11 +17,25 @@ module Comee
17
17
  end
18
18
  end
19
19
 
20
+ def master_prices
21
+ data = MasterPrice.where(product_id: price_params[:product_ids])
22
+ render json: {success: true, data: serialize(data)}
23
+ end
24
+
25
+ def client_prices
26
+ data = ClientPrice.where(product_id: price_params[:product_ids])
27
+ render json: {success: true, data: serialize(data)}
28
+ end
29
+
20
30
  private
21
31
 
22
32
  def model_params
23
33
  params.required(:payload).permit(:code, :name, :description, :parent_id, :thumbnail_image, :preferred_units, images: [])
24
34
  end
35
+
36
+ def price_params
37
+ params.require(:payload).permit(product_ids: [])
38
+ end
25
39
  end
26
40
  end
27
41
  end
@@ -0,0 +1,9 @@
1
+ module Comee
2
+ module Core
3
+ class MasterPriceSerializer < ActiveModel::Serializer
4
+ attributes :id, :purchase_price, :selling_price, :valid_from, :valid_to, :primary, :margin
5
+ belongs_to :product
6
+ belongs_to :supplier
7
+ end
8
+ end
9
+ end
@@ -44,7 +44,7 @@ module Comee
44
44
  .or(UnitConversion.where("from_id = ? AND to_id = ?", new_unit_id, unit_id))
45
45
 
46
46
  unless conversions.count.positive?
47
- units = Unit.where(id: [unit_id, new_unit_id]).select(:code)
47
+ units = Unit.where(id: [unit_id, new_unit_id])
48
48
  raise(StandardError, "There is no conversion factor between #{units[0].code} and #{units[1].code}.")
49
49
  end
50
50
 
@@ -112,7 +112,10 @@ module Comee
112
112
  raise(StandardError, "Customer order should be in submitted or awaiting confirmation state.")
113
113
  end
114
114
 
115
- raise(StandardError, "Customer order does not have any items.") if order.customer_order_items.count.zero?
115
+ if order.customer_order_items.count.zero? ||
116
+ order.customer_order_items.all?(&:canceled?)
117
+ raise(StandardError, "Customer order does not have any items.")
118
+ end
116
119
 
117
120
  sales_order = nil
118
121
  CustomerOrder.transaction do
@@ -60,8 +60,24 @@ module Comee
60
60
  raise(StandardError, "RFQ should be in awaiting_confirmation state.")
61
61
  end
62
62
 
63
- rfq.status = QuotationRequest.statuses[:confirmed]
64
- rfq.save!
63
+ data = rfq.quotation_request_items.each_with_object([]) do |item, res|
64
+ res << {
65
+ client_id: rfq.client_id,
66
+ product_id: item.product_id,
67
+ unit_id: item.unit_id,
68
+ price: item.price,
69
+ discount: 0,
70
+ valid_from: item.valid_from,
71
+ valid_to: item.valid_to,
72
+ status: ClientPrice.statuses[:current]
73
+ }
74
+ end
75
+
76
+ ClientPrice.transaction do
77
+ ClientPrice.insert_all!(data)
78
+ rfq.status = QuotationRequest.statuses[:confirmed]
79
+ rfq.save!
80
+ end
65
81
  rfq
66
82
  end
67
83
  end
data/config/routes.rb CHANGED
@@ -9,7 +9,12 @@ Comee::Core::Engine.routes.draw do
9
9
  end
10
10
  end
11
11
  resources :suppliers
12
- resources :products
12
+ resources :products do
13
+ collection do
14
+ post "master_prices"
15
+ post "client_prices"
16
+ end
17
+ end
13
18
  resources :lookups
14
19
  resources :quotation_requests do
15
20
  collection do
@@ -1,5 +1,5 @@
1
1
  module Comee
2
2
  module Core
3
- VERSION = "0.1.51".freeze
3
+ VERSION = "0.1.52".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: comee_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.51
4
+ version: 0.1.52
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henock L.
@@ -353,6 +353,7 @@ files:
353
353
  - app/serializers/comee/core/external_rfq_serializer.rb
354
354
  - app/serializers/comee/core/item_status_serializer.rb
355
355
  - app/serializers/comee/core/lookup_serializer.rb
356
+ - app/serializers/comee/core/master_price_serializer.rb
356
357
  - app/serializers/comee/core/product_serializer.rb
357
358
  - app/serializers/comee/core/product_type_serializer.rb
358
359
  - app/serializers/comee/core/purchase_order_item_serializer.rb