comee_core 0.1.32 → 0.1.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/controllers/comee/core/products_controller.rb +7 -0
- data/app/models/comee/core/master_price.rb +1 -32
- data/app/models/comee/core/price.rb +3 -4
- data/app/models/comee/core/user.rb +1 -1
- data/app/serializers/comee/core/supplier_serializer.rb +1 -1
- data/app/utils/comee/core/period.rb +4 -4
- data/lib/comee/core/version.rb +1 -1
- data/spec/factories/comee/core/client_prices.rb +10 -0
- data/spec/factories/comee/core/master_prices.rb +1 -1
- metadata +2 -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
|
@@ -9,6 +9,7 @@ module Comee
|
|
9
9
|
validates :product_id, uniqueness: {scope: %i[supplier_id previous_price_id]}
|
10
10
|
validate :validate_primary_price
|
11
11
|
|
12
|
+
scope :current_primary, -> { where(primary: true).current }
|
12
13
|
scope :unapplied, -> { where(propagated_to_client: false).current_primary }
|
13
14
|
|
14
15
|
def validate_primary_price
|
@@ -20,38 +21,6 @@ module Comee
|
|
20
21
|
errors.add(:base, "There is already a primary price entry for item '#{product.code}'")
|
21
22
|
end
|
22
23
|
|
23
|
-
# def update_price(new_price, from, to, margin = nil)
|
24
|
-
# raise(StandardError, "Future prices cannot be updated.") if Price.statuses[status] == Price.statuses[:future]
|
25
|
-
|
26
|
-
# margin ||= self.margin
|
27
|
-
# raise(StandardError, "No changes detected. Update failed!") if purchase_price == new_price && self.margin == margin
|
28
|
-
|
29
|
-
# period = Period.new(from, to)
|
30
|
-
# raise(StandardError, "Validity date range is not correct.") unless period.valid?
|
31
|
-
|
32
|
-
# old_period = Period.new(valid_from, valid_to)
|
33
|
-
# new_period = Period.compute_next_valid_period(old_period, period)
|
34
|
-
# raise(StandardError, "No valid validity period could be computed for the given validity date range.") unless new_period
|
35
|
-
|
36
|
-
# price = dup
|
37
|
-
# price.assign_attributes(
|
38
|
-
# purchase_price: new_price,
|
39
|
-
# valid_from: new_period.start,
|
40
|
-
# valid_to: new_period.finish,
|
41
|
-
# margin: margin,
|
42
|
-
# previous_price: self,
|
43
|
-
# selling_price: (new_price * (1 + margin / 100.0)).round(2)
|
44
|
-
# )
|
45
|
-
|
46
|
-
# ActiveRecord::Base.transaction do
|
47
|
-
# price.previous_price.save!
|
48
|
-
# price.save!
|
49
|
-
# end
|
50
|
-
# price
|
51
|
-
# rescue StandardError
|
52
|
-
# raise
|
53
|
-
# end
|
54
|
-
|
55
24
|
def self.ransackable_attributes(_auth_object = nil)
|
56
25
|
%w[
|
57
26
|
valid_from
|
@@ -4,11 +4,10 @@ module Comee
|
|
4
4
|
self.abstract_class = true
|
5
5
|
before_save :compute_status
|
6
6
|
|
7
|
-
enum :status, {
|
7
|
+
enum :status, {past: 0, current: 1, future: 2}
|
8
8
|
|
9
9
|
scope :current, -> { where(status: Price.statuses[:current]) }
|
10
10
|
scope :future, -> { where(status: Price.statuses[:future]) }
|
11
|
-
scope :current_primary, -> { where(primary: true).current }
|
12
11
|
|
13
12
|
belongs_to :product
|
14
13
|
belongs_to :unit
|
@@ -25,8 +24,8 @@ module Comee
|
|
25
24
|
|
26
25
|
def compute_status
|
27
26
|
period = Period.new(valid_from, valid_to)
|
28
|
-
if period.
|
29
|
-
self.status = Price.statuses[:
|
27
|
+
if period.past?
|
28
|
+
self.status = Price.statuses[:past]
|
30
29
|
elsif period.current?
|
31
30
|
self.status = Price.statuses[:current]
|
32
31
|
elsif period.future?
|
@@ -24,16 +24,16 @@ module Comee
|
|
24
24
|
finish > start
|
25
25
|
end
|
26
26
|
|
27
|
-
def
|
27
|
+
def past?
|
28
28
|
raise(StandardError, "Period must be valid.") unless valid?
|
29
29
|
|
30
|
-
|
30
|
+
finish < Date.current
|
31
31
|
end
|
32
32
|
|
33
|
-
def
|
33
|
+
def current?
|
34
34
|
raise(StandardError, "Period must be valid.") unless valid?
|
35
35
|
|
36
|
-
finish
|
36
|
+
start <= Date.current && finish > Date.current
|
37
37
|
end
|
38
38
|
|
39
39
|
def future?
|
data/lib/comee/core/version.rb
CHANGED
@@ -9,5 +9,15 @@ FactoryBot.define do
|
|
9
9
|
unit
|
10
10
|
discount { 0 }
|
11
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
|
12
22
|
end
|
13
23
|
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
|