comee_core 0.1.31 → 0.1.33
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/comee/core/client_prices_controller.rb +2 -1
- data/app/controllers/comee/core/products_controller.rb +7 -0
- data/app/models/comee/core/client_price.rb +12 -14
- data/app/models/comee/core/master_price.rb +21 -18
- data/app/models/comee/core/price.rb +37 -0
- data/app/models/comee/core/user.rb +1 -1
- data/app/serializers/comee/core/client_price_serializer.rb +4 -1
- data/app/serializers/comee/core/supplier_serializer.rb +1 -1
- data/app/utils/comee/core/period.rb +18 -0
- data/db/migrate/20230813235946_create_comee_core_master_prices.rb +11 -8
- data/db/migrate/20230814151601_create_comee_core_client_prices.rb +4 -0
- data/lib/comee/core/version.rb +1 -1
- data/spec/factories/comee/core/client_prices.rb +11 -0
- data/spec/factories/comee/core/master_prices.rb +14 -6
- data/spec/factories/comee/core/products.rb +1 -1
- data/spec/factories/comee/core/suppliers.rb +1 -1
- data/spec/factories/comee/core/units.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 89be0ab79ac6789639448aaafa19ca5845e08e132d0d99c34eef619b97ece546
|
4
|
+
data.tar.gz: f62cdbb0af85b33c2322d17d9289cdd12c2021cd28b1fa06332cc63c39847a01
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5fca168ac18ac7ceef8614bdb8792f4395e21107cb62adfc9b9ac1d7b4301f8b418e3bdb5968f9b8fd4c4ebcebaf3517cb13fcda854ef1c36bb059943ac42b59
|
7
|
+
data.tar.gz: 6369177eb65524a12f58c1f2469b9fc3114a587edc0bdc7b6b64dc98e1655433910325fa4d3864fce8f861dbb866694f3079171e91f18d9a5d48c9d1c01a9e16
|
@@ -18,7 +18,8 @@ module Comee
|
|
18
18
|
private
|
19
19
|
|
20
20
|
def model_params
|
21
|
-
params.require(:payload).permit(:valid_from, :valid_to, :price, :status, :product_id, :discount, :client_id, :previous_price
|
21
|
+
params.require(:payload).permit(:valid_from, :valid_to, :price, :status, :product_id, :discount, :client_id, :previous_price,
|
22
|
+
:unit_id)
|
22
23
|
end
|
23
24
|
end
|
24
25
|
end
|
@@ -1,30 +1,28 @@
|
|
1
1
|
module Comee
|
2
2
|
module Core
|
3
|
-
class ClientPrice <
|
4
|
-
enum :status, {old: 0, current: 1, future: 2}
|
5
|
-
belongs_to :product
|
3
|
+
class ClientPrice < Price
|
6
4
|
belongs_to :client
|
7
5
|
belongs_to :previous_price, class_name: "Comee::Core::ClientPrice", optional: true
|
8
6
|
|
9
|
-
validates :
|
7
|
+
validates :price, presence: true
|
10
8
|
validates :price, numericality: {greater_than: 0}
|
11
9
|
validates :discount, presence: true, numericality: {greater_than_or_equal_to: 0, less_than_or_equal_to: 100}
|
12
10
|
validates :product_id, uniqueness: {scope: %i[client_id previous_price_id]}
|
13
|
-
validate :validate_price_validity_dates
|
14
|
-
|
15
|
-
def validate_price_validity_dates
|
16
|
-
return unless valid_from && valid_to
|
17
|
-
|
18
|
-
period = Period.new(valid_from, valid_to)
|
19
|
-
errors.add(:base, "Price validity date range is not correct.") unless period.valid?
|
20
|
-
end
|
21
11
|
|
22
12
|
def self.ransackable_attributes(_auth_object = nil)
|
23
|
-
%w[
|
13
|
+
%w[
|
14
|
+
valid_from
|
15
|
+
valid_to
|
16
|
+
price
|
17
|
+
status
|
18
|
+
product_id
|
19
|
+
client_id
|
20
|
+
previous_price_id
|
21
|
+
]
|
24
22
|
end
|
25
23
|
|
26
24
|
def self.ransackable_associations(_auth_object = nil)
|
27
|
-
[]
|
25
|
+
%w[product client]
|
28
26
|
end
|
29
27
|
end
|
30
28
|
end
|
@@ -1,38 +1,41 @@
|
|
1
1
|
module Comee
|
2
2
|
module Core
|
3
|
-
class MasterPrice <
|
4
|
-
enum :status, {old: 0, current: 1, future: 2}
|
3
|
+
class MasterPrice < Price
|
5
4
|
belongs_to :supplier
|
6
|
-
belongs_to :product
|
7
5
|
belongs_to :previous_price, class_name: "Comee::Core::MasterPrice", optional: true
|
8
6
|
|
9
|
-
validates :purchase_price, :
|
7
|
+
validates :purchase_price, :selling_price, presence: true
|
10
8
|
validates :margin, presence: true, numericality: {greater_than_or_equal_to: 0, less_than_or_equal_to: 100}
|
11
9
|
validates :product_id, uniqueness: {scope: %i[supplier_id previous_price_id]}
|
12
|
-
validate :validate_primary_price
|
10
|
+
validate :validate_primary_price
|
11
|
+
|
12
|
+
scope :current_primary, -> { where(primary: true).current }
|
13
|
+
scope :unapplied, -> { where(propagated_to_client: false).current_primary }
|
13
14
|
|
14
15
|
def validate_primary_price
|
15
16
|
return unless product && primary
|
16
17
|
|
17
|
-
count = MasterPrice.where(product: product, primary: true, status:
|
18
|
+
count = MasterPrice.where(product: product, primary: true, status: Price.statuses[:current]).count
|
18
19
|
return unless count.positive? && primary && MasterPrice.statuses[status] == MasterPrice.statuses[:current]
|
19
20
|
|
20
|
-
errors.add(:base,
|
21
|
-
"There is already a primary supplier for item '#{product.code}'")
|
21
|
+
errors.add(:base, "There is already a primary price entry for item '#{product.code}'")
|
22
22
|
end
|
23
23
|
|
24
|
-
def
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
24
|
+
def self.ransackable_attributes(_auth_object = nil)
|
25
|
+
%w[
|
26
|
+
valid_from
|
27
|
+
valid_to
|
28
|
+
purchase_price
|
29
|
+
selling_price
|
30
|
+
status
|
31
|
+
product_id
|
32
|
+
supplier_id
|
33
|
+
previous_price_id
|
34
|
+
]
|
29
35
|
end
|
30
36
|
|
31
|
-
def
|
32
|
-
|
33
|
-
|
34
|
-
period = Period.new(sp_valid_from, sp_valid_to)
|
35
|
-
errors.add(:base, "Selling price validity date range is not correct.") unless period.valid?
|
37
|
+
def self.ransackable_associations(_auth_object = nil)
|
38
|
+
%w[product supplier]
|
36
39
|
end
|
37
40
|
end
|
38
41
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Comee
|
2
|
+
module Core
|
3
|
+
class Price < ApplicationRecord
|
4
|
+
self.abstract_class = true
|
5
|
+
before_save :compute_status
|
6
|
+
|
7
|
+
enum :status, {past: 0, current: 1, future: 2}
|
8
|
+
|
9
|
+
scope :current, -> { where(status: Price.statuses[:current]) }
|
10
|
+
scope :future, -> { where(status: Price.statuses[:future]) }
|
11
|
+
|
12
|
+
belongs_to :product
|
13
|
+
belongs_to :unit
|
14
|
+
|
15
|
+
validates :valid_from, :valid_to, presence: true
|
16
|
+
validate :validate_price_validity_dates
|
17
|
+
|
18
|
+
def validate_price_validity_dates
|
19
|
+
return unless valid_from && valid_to
|
20
|
+
|
21
|
+
period = Period.new(valid_from, valid_to)
|
22
|
+
errors.add(:base, "Price validity date range is not correct.") unless period.valid?
|
23
|
+
end
|
24
|
+
|
25
|
+
def compute_status
|
26
|
+
period = Period.new(valid_from, valid_to)
|
27
|
+
if period.past?
|
28
|
+
self.status = Price.statuses[:past]
|
29
|
+
elsif period.current?
|
30
|
+
self.status = Price.statuses[:current]
|
31
|
+
elsif period.future?
|
32
|
+
self.status = Price.statuses[:future]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -1,7 +1,10 @@
|
|
1
1
|
module Comee
|
2
2
|
module Core
|
3
3
|
class ClientPriceSerializer < ActiveModel::Serializer
|
4
|
-
attributes :id, :valid_from, :valid_to, :price, :status, :
|
4
|
+
attributes :id, :valid_from, :valid_to, :price, :status, :previous_price
|
5
|
+
belongs_to :product
|
6
|
+
belongs_to :client
|
7
|
+
belongs_to :unit
|
5
8
|
end
|
6
9
|
end
|
7
10
|
end
|
@@ -24,6 +24,24 @@ module Comee
|
|
24
24
|
finish > start
|
25
25
|
end
|
26
26
|
|
27
|
+
def past?
|
28
|
+
raise(StandardError, "Period must be valid.") unless valid?
|
29
|
+
|
30
|
+
finish < Date.current
|
31
|
+
end
|
32
|
+
|
33
|
+
def current?
|
34
|
+
raise(StandardError, "Period must be valid.") unless valid?
|
35
|
+
|
36
|
+
start <= Date.current && finish > Date.current
|
37
|
+
end
|
38
|
+
|
39
|
+
def future?
|
40
|
+
raise(StandardError, "Period must be valid.") unless valid?
|
41
|
+
|
42
|
+
start > Date.current
|
43
|
+
end
|
44
|
+
|
27
45
|
def contains?(period)
|
28
46
|
return true if start <= period.start && finish >= period.finish
|
29
47
|
|
@@ -3,29 +3,32 @@ class CreateComeeCoreMasterPrices < ActiveRecord::Migration[7.0]
|
|
3
3
|
create_table :comee_core_master_prices do |t|
|
4
4
|
t.float :purchase_price, null: false
|
5
5
|
t.float :selling_price, null: false
|
6
|
-
t.date :
|
7
|
-
t.date :
|
8
|
-
t.date :sp_valid_from, null: false
|
6
|
+
t.date :valid_from, null: false
|
7
|
+
t.date :valid_to, null: false
|
9
8
|
t.float :status, null: false, default: 0
|
10
|
-
t.
|
11
|
-
t.boolean :active, null: false
|
12
|
-
t.boolean :primary, null: false
|
9
|
+
t.boolean :primary, null: false, default: false
|
13
10
|
t.integer :margin, null: false
|
14
11
|
t.references :product,
|
15
12
|
null: false,
|
16
|
-
index: {name: "
|
13
|
+
index: {name: "product_on_ccmp_indx"},
|
17
14
|
foreign_key: {to_table: :comee_core_products}
|
18
15
|
t.references :supplier,
|
19
16
|
null: false,
|
20
|
-
index: {name: "
|
17
|
+
index: {name: "supplier_on_ccmp_indx"},
|
21
18
|
foreign_key: {to_table: :comee_core_suppliers}
|
19
|
+
t.references :unit,
|
20
|
+
null: false,
|
21
|
+
index: {name: "unit_on_ccmp_indx"},
|
22
|
+
foreign_key: {to_table: :comee_core_units}
|
22
23
|
t.references :previous_price,
|
23
24
|
null: true,
|
24
25
|
index: {name: "previous_price_on_ccsp_indx"},
|
25
26
|
foreign_key: {to_table: :comee_core_master_prices}
|
27
|
+
t.boolean :propagated_to_client, null: false, default: false
|
26
28
|
|
27
29
|
t.timestamps
|
28
30
|
end
|
31
|
+
|
29
32
|
add_index :comee_core_master_prices,
|
30
33
|
%i[product_id supplier_id previous_price_id],
|
31
34
|
unique: true,
|
@@ -14,6 +14,10 @@ class CreateComeeCoreClientPrices < ActiveRecord::Migration[7.0]
|
|
14
14
|
null: false,
|
15
15
|
index: {name: "client_on_cccp_indx"},
|
16
16
|
foreign_key: {to_table: :comee_core_clients}
|
17
|
+
t.references :unit,
|
18
|
+
null: false,
|
19
|
+
index: {name: "unit_on_cccp_indx"},
|
20
|
+
foreign_key: {to_table: :comee_core_units}
|
17
21
|
t.references :previous_price,
|
18
22
|
null: true,
|
19
23
|
index: {name: "previous_price_on_cccp_indx"},
|
data/lib/comee/core/version.rb
CHANGED
@@ -6,7 +6,18 @@ FactoryBot.define do
|
|
6
6
|
price { 100 }
|
7
7
|
product
|
8
8
|
client
|
9
|
+
unit
|
9
10
|
discount { 0 }
|
10
11
|
previous_price { nil }
|
12
|
+
|
13
|
+
trait :past do
|
14
|
+
valid_from { Date.current.advance(months: -2) }
|
15
|
+
valid_to { Date.current.advance(months: -1) }
|
16
|
+
end
|
17
|
+
|
18
|
+
trait :future do
|
19
|
+
valid_from { Date.current.advance(months: 1) }
|
20
|
+
valid_to { Date.current.advance(months: 2) }
|
21
|
+
end
|
11
22
|
end
|
12
23
|
end
|
@@ -2,16 +2,24 @@ FactoryBot.define do
|
|
2
2
|
factory :master_price, class: "Comee::Core::MasterPrice" do
|
3
3
|
purchase_price { 100.0 }
|
4
4
|
selling_price { 90.0 }
|
5
|
-
|
6
|
-
|
7
|
-
sp_valid_from { Date.current.advance(months: -1) }
|
8
|
-
sp_valid_to { Date.current.advance(months: 1) }
|
9
|
-
active { true }
|
5
|
+
valid_from { Date.current.advance(months: -1) }
|
6
|
+
valid_to { Date.current.advance(months: 1) }
|
10
7
|
primary { false }
|
11
8
|
margin { 10.0 }
|
12
9
|
product
|
13
10
|
supplier
|
11
|
+
unit
|
14
12
|
previous_price { nil }
|
15
|
-
|
13
|
+
propagated_to_client { false }
|
14
|
+
|
15
|
+
trait :past do
|
16
|
+
valid_from { Date.current.advance(months: -2) }
|
17
|
+
valid_to { Date.current.advance(months: -1) }
|
18
|
+
end
|
19
|
+
|
20
|
+
trait :future do
|
21
|
+
valid_from { Date.current.advance(months: 1) }
|
22
|
+
valid_to { Date.current.advance(months: 2) }
|
23
|
+
end
|
16
24
|
end
|
17
25
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
FactoryBot.define do
|
2
2
|
factory :product, class: "Comee::Core::Product" do
|
3
|
-
code { Faker::Alphanumeric.alpha(number: 6) }
|
3
|
+
sequence(:code) { |n| "#{Faker::Alphanumeric.unique.alpha(number: 6)}-#{n}" }
|
4
4
|
name { Faker::Name.name }
|
5
5
|
description { Faker::Lorem.sentence }
|
6
6
|
metadata { {} }
|
@@ -1,6 +1,6 @@
|
|
1
1
|
FactoryBot.define do
|
2
2
|
factory :supplier, class: "Comee::Core::Supplier" do
|
3
|
-
code { Faker::Alphanumeric.alpha(number: 8) }
|
3
|
+
sequence(:code) { |n| "#{Faker::Alphanumeric.alpha(number: 8)}-#{n}" }
|
4
4
|
name { Faker::Name.name }
|
5
5
|
address { Faker::Address.full_address }
|
6
6
|
locale { "en" }
|
@@ -1,6 +1,6 @@
|
|
1
1
|
FactoryBot.define do
|
2
2
|
factory :unit, class: "Comee::Core::Unit" do
|
3
|
-
code { Faker::Alphanumeric.alpha(number: 2) }
|
3
|
+
sequence(:code) { |n| "#{Faker::Alphanumeric.alpha(number: 2)}-#{n}" }
|
4
4
|
name { Faker::Name.name }
|
5
5
|
unit_type { Comee::Core::Unit.unit_types[:weight] }
|
6
6
|
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.1.
|
4
|
+
version: 0.1.33
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Henock L.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-11-
|
11
|
+
date: 2023-11-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_model_serializers
|
@@ -276,6 +276,7 @@ files:
|
|
276
276
|
- app/models/comee/core/master_price.rb
|
277
277
|
- app/models/comee/core/notification.rb
|
278
278
|
- app/models/comee/core/order_source.rb
|
279
|
+
- app/models/comee/core/price.rb
|
279
280
|
- app/models/comee/core/product.rb
|
280
281
|
- app/models/comee/core/product_lookup.rb
|
281
282
|
- app/models/comee/core/product_type.rb
|