comee_core 0.1.16 → 0.1.18

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: 79192d2994ff3a9aa6f58ed0369421fdf38d7a089dd28a8d88b05664634ad2df
4
- data.tar.gz: 59bc3b2bb2c636132602985e5bc165ee17866809522e3137d5dd8c9433972d80
3
+ metadata.gz: eee3ab42e5f0909fdd7de5f6d1fc073a4fc79b34a606e3d87e4580b3770ebfb7
4
+ data.tar.gz: 44bc512432f7732f9b2e447d2a2cf0e2d3b54f73f93d6224622957c6c6b874d2
5
5
  SHA512:
6
- metadata.gz: 8820af598fd97f4d0755ac480ee05a7c728c954bc316c1e43ddd9db5023233f595836a7181fdf37aed885de0d94869816fc2c0cd7facfd483bddf0b90d4f3ac7
7
- data.tar.gz: 6e9b291a3c46742340f05adb192264855291fd3cf39f8ca581d40f1f8e9f66078e485e1e05101a3c5122e551d6cc64e57c83b5f683e5cd83917d059cb2a51382
6
+ metadata.gz: 8afe5c968f62a1ce3b4831d6f76fec04818b085f28c8ef14853c84dbdee92768e429757362bf246993387aa0dbedbacac2106444e58497fd60b8f99373c1462f
7
+ data.tar.gz: bd830637c78c8bca22da8bd19baf3e3470c1e7e123fb5f4afb4711a459e0ebd71b28f1e7894af61387a88fe222110efbb127f4c5a822cca8b587c50a443c9a75
@@ -8,6 +8,7 @@ module Comee
8
8
 
9
9
  validates :valid_from, :valid_to, :price, :status, presence: true
10
10
  validates :price, numericality: {greater_than: 0}
11
+ validates :discount, presence: true, numericality: {greater_than_or_equal_to: 0, less_than_or_equal_to: 100}
11
12
  validates :product_id, uniqueness: {scope: [:client_id, :previous_price_id]}
12
13
  validate :validate_price_validity_dates
13
14
 
@@ -13,7 +13,7 @@ module Comee
13
13
  def validate_primary_price
14
14
  return unless product && primary
15
15
 
16
- count = MasterPrice.where(product:, primary: true).count
16
+ count = MasterPrice.where(product:, primary: true, active: true).count
17
17
  errors.add(:base, "There is already a primary supplier for item '#{product.code}'") if count.positive?
18
18
  end
19
19
 
@@ -7,6 +7,18 @@ module Comee
7
7
  @finish = finish
8
8
  end
9
9
 
10
+ def ==(other)
11
+ self.class == other.class && @start == other.start && @finish == other.finish
12
+ end
13
+
14
+ def <(other)
15
+ instance_of?(other.class) && @start < other.start && @finish < other.finish
16
+ end
17
+
18
+ def >(other)
19
+ instance_of?(other.class) && @start > other.start && @finish > other.finish
20
+ end
21
+
10
22
  def valid?
11
23
  finish > start
12
24
  end
@@ -23,13 +35,25 @@ module Comee
23
35
  false
24
36
  end
25
37
 
38
+ def disjoint?(period)
39
+ @finish < period.start || period.finish < @start
40
+ end
41
+
26
42
  def overlaps?(period)
27
- return true if period.start <= start && start <= period.finish
43
+ return true if period.start <= @start && @start <= period.finish
28
44
 
29
- return true if start <= period.start && period.start <= finish
45
+ return true if @start <= period.start && period.start <= @finish
30
46
 
31
47
  false
32
48
  end
49
+
50
+ def self.compute_next_valid_period(period1, period2)
51
+ return period2 if period1.disjoint?(period2) && period1 < period2
52
+
53
+ return nil if period1 > period2 || period1.contains?(period2)
54
+
55
+ Period.new(period1.finish.advance(days: 1), period2.finish)
56
+ end
33
57
  end
34
58
  end
35
59
  end
@@ -5,6 +5,7 @@ class CreateComeeCoreClientPrices < ActiveRecord::Migration[7.0]
5
5
  t.date :valid_to, null: false
6
6
  t.float :price, null: false
7
7
  t.float :status, null: false, default: 0
8
+ t.integer :discount, null: false
8
9
  t.references :product,
9
10
  null: false,
10
11
  index: {name: "product_on_cccp_indx"},
@@ -1,5 +1,5 @@
1
1
  module Comee
2
2
  module Core
3
- VERSION = "0.1.16"
3
+ VERSION = "0.1.18"
4
4
  end
5
5
  end
@@ -2,7 +2,7 @@ FactoryBot.define do
2
2
  factory :back_order, class: "Comee::Core::BackOrder" do
3
3
  order_number { Faker::Alphanumeric.alpha(number: 10) }
4
4
  order_date { Date.current }
5
- delivery_date { Date.current.advance(month: 1) }
5
+ delivery_date { Date.current.advance(months: 1) }
6
6
  supplier
7
7
  terms { {payment_terms: "NET 30 days", currency: "Euro", freight_terms: "FOB"} }
8
8
  delivery_address { Faker::Address.full_address }
@@ -6,5 +6,6 @@ FactoryBot.define do
6
6
  price { 100 }
7
7
  product
8
8
  client
9
+ discount { 0 }
9
10
  end
10
11
  end
@@ -5,5 +5,6 @@ FactoryBot.define do
5
5
  name { Faker::Name.name }
6
6
  address { Faker::Address.full_address }
7
7
  locale { "en" }
8
+ discount { 0 }
8
9
  end
9
10
  end
@@ -4,6 +4,6 @@ FactoryBot.define do
4
4
  product
5
5
  quantity { 100 }
6
6
  price { 50 }
7
- delivery_date { Date.current.advance(month: 1) }
7
+ delivery_date { Date.current.advance(months: 1) }
8
8
  end
9
9
  end
@@ -2,7 +2,7 @@ FactoryBot.define do
2
2
  factory :sales_order, class: "Comee::Core::SalesOrder" do
3
3
  order_number { Faker::Alphanumeric.alpha(number: 10) }
4
4
  order_date { Date.current }
5
- expected_delivery_date { Date.current.advance(month: 1) }
5
+ expected_delivery_date { Date.current.advance(months: 1) }
6
6
  client
7
7
  client_terms { Faker::Lorem.sentence }
8
8
  payment_no_of_days { 7 }
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.16
4
+ version: 0.1.18
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-10-05 00:00:00.000000000 Z
11
+ date: 2023-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers