comee_core 0.1.32 → 0.1.33

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: a9b8f42b3900f864a1225399177186948e42ae9e67c48fe9b3248eb45675ad71
4
- data.tar.gz: c487c5e62ef7c83ba1442773f7a19dae1a32fb40fe966e41bcce7b21c7eb80ca
3
+ metadata.gz: 89be0ab79ac6789639448aaafa19ca5845e08e132d0d99c34eef619b97ece546
4
+ data.tar.gz: f62cdbb0af85b33c2322d17d9289cdd12c2021cd28b1fa06332cc63c39847a01
5
5
  SHA512:
6
- metadata.gz: a7079cd5b10f8b9cf68fd7ba3c764f875fd09fc827b1f67b006f91dc52b78bee029616a335664becb6f30c1b9305cf9660fafcf5e3dc493b59175f666034b539
7
- data.tar.gz: 48ab1f0e3bb54c08830e73f3ce76e472f85afe5f2683d967b8c726197083b7c9a3856faedcdca5ed65edf9fa98dade94b5e78ee355e003811b1062bac5f736c4
6
+ metadata.gz: 5fca168ac18ac7ceef8614bdb8792f4395e21107cb62adfc9b9ac1d7b4301f8b418e3bdb5968f9b8fd4c4ebcebaf3517cb13fcda854ef1c36bb059943ac42b59
7
+ data.tar.gz: 6369177eb65524a12f58c1f2469b9fc3114a587edc0bdc7b6b64dc98e1655433910325fa4d3864fce8f861dbb866694f3079171e91f18d9a5d48c9d1c01a9e16
@@ -3,6 +3,13 @@ module Comee
3
3
  class ProductsController < ApplicationController
4
4
  include Common
5
5
 
6
+ def index
7
+ super do
8
+ products = Comee::Core::Product.all
9
+ products.then(&paginate)
10
+ end
11
+ end
12
+
6
13
  private
7
14
 
8
15
  def model_params
@@ -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, {old: 0, current: 1, future: 2}
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.old?
29
- self.status = Price.statuses[:old]
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?
@@ -1,7 +1,7 @@
1
1
  module Comee
2
2
  module Core
3
3
  class User < ApplicationRecord
4
- enum :user_type, {supplier: 0, admin: 1}
4
+ enum :user_type, {supplier: 0, admin: 1, client: 2, worker: 3}
5
5
 
6
6
  has_secure_password
7
7
  has_many :notifications, as: :recipient, dependent: :destroy
@@ -1,7 +1,7 @@
1
1
  module Comee
2
2
  module Core
3
3
  class SupplierSerializer < ActiveModel::Serializer
4
- attributes :id, :code, :name, :address, :locale
4
+ attributes :id, :code, :name, :address, :locale, :user_id
5
5
  end
6
6
  end
7
7
  end
@@ -24,16 +24,16 @@ module Comee
24
24
  finish > start
25
25
  end
26
26
 
27
- def current?
27
+ def past?
28
28
  raise(StandardError, "Period must be valid.") unless valid?
29
29
 
30
- start <= Date.current && finish > Date.current
30
+ finish < Date.current
31
31
  end
32
32
 
33
- def old?
33
+ def current?
34
34
  raise(StandardError, "Period must be valid.") unless valid?
35
35
 
36
- finish < Date.current
36
+ start <= Date.current && finish > Date.current
37
37
  end
38
38
 
39
39
  def future?
@@ -1,5 +1,5 @@
1
1
  module Comee
2
2
  module Core
3
- VERSION = "0.1.32".freeze
3
+ VERSION = "0.1.33".freeze
4
4
  end
5
5
  end
@@ -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
@@ -12,7 +12,7 @@ FactoryBot.define do
12
12
  previous_price { nil }
13
13
  propagated_to_client { false }
14
14
 
15
- trait :old do
15
+ trait :past do
16
16
  valid_from { Date.current.advance(months: -2) }
17
17
  valid_to { Date.current.advance(months: -1) }
18
18
  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.32
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-09 00:00:00.000000000 Z
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