comee_core 0.1.28 → 0.1.30

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: 4584d0f6f728f6ab957e59500e8a8af4564e0922558df83cb7562e9d9b094603
4
- data.tar.gz: 5404312320bbcf4d482e5261a6c960dc1418d1e9051c1cfa810419cd872fef7b
3
+ metadata.gz: db5eb1e3ada88d6d43262f34c3524023af78b0488327494cb104896c513567b6
4
+ data.tar.gz: 62809e1252a790952c9940267c0337150f5b70dc485adb697e0d21fc2087939b
5
5
  SHA512:
6
- metadata.gz: 86745d97fac73d6fc66de542291014f4c1b6b57fb61bac5c8c31f523b7be03728b3109fad94750100ad40c6cbdca0305e448baaa5d399c52208ddb14ff2921a0
7
- data.tar.gz: d4013f260e88c21628dc3eb1434718e949f3132e77b77d1daa58554fe6f33339da882772c43e6f6efc45d5d07230b0255b08b4fffa96cf7a91a179b0f6f6ab9c
6
+ metadata.gz: 10d651c16317a4daa58d15f6cc2acd6f239c23da54c6776ffb202682352b36b287f814bd1c9c469ceaffb3890041e072c63dbd84b45e71f9f652a05526f00c00
7
+ data.tar.gz: b5b2c66426c595d3d710beeac3a4d72f81152c0f20578525ba2c7c9281f07fbe6623df956cff56d9cb4052d59eafff5f1eeaa22a3196b45cadf531289a7d5f06
@@ -1,6 +1,8 @@
1
1
  module Comee
2
2
  module Core
3
3
  class ApplicationController < ActionController::API
4
+ include Comee::Core::Pagination
5
+
4
6
  before_action :authenticate
5
7
 
6
8
  def current_user
@@ -3,6 +3,13 @@ module Comee
3
3
  class ClientPricesController < ApplicationController
4
4
  include Comee::Core::Common
5
5
 
6
+ def index
7
+ super do
8
+ client_prices = Comee::Core::ClientPrice.all
9
+ client_prices.then(&paginate)
10
+ end
11
+ end
12
+
6
13
  def filter
7
14
  @client_prices = Comee::Core::ClientPrice.ransack(params[:q]).result
8
15
  render json: {success: true, data: serialize(@client_prices)}
@@ -0,0 +1,35 @@
1
+ module Comee
2
+ module Core
3
+ module Pagination
4
+ extend ActiveSupport::Concern
5
+
6
+ def default_per_page
7
+ 25
8
+ end
9
+
10
+ def page_no
11
+ params[:page]&.to_i || 1
12
+ end
13
+
14
+ def per_page
15
+ params[:per_page]&.to_i || default_per_page
16
+ end
17
+
18
+ def paginate_offset
19
+ (page_no - 1) * per_page
20
+ end
21
+
22
+ def order_by
23
+ params.fetch(:order_by, :id)
24
+ end
25
+
26
+ def order_direction
27
+ params.fetch(:order_direction, :asc)
28
+ end
29
+
30
+ def paginate
31
+ ->(it) { it.limit(per_page).offset(paginate_offset).order("#{order_by}": order_direction) }
32
+ end
33
+ end
34
+ end
35
+ end
@@ -6,7 +6,7 @@ module Comee
6
6
  belongs_to :back_order
7
7
  belongs_to :product
8
8
 
9
- validates :item_status, :from, :to, presence: true
9
+ validates :item_status, :from, :to, :delivery_date, presence: true
10
10
  validates :requested_quantity, :requested_unit_price, :supplier_quantity, :supplier_unit_price,
11
11
  presence: true, numericality: {greater_than: 0}
12
12
 
@@ -14,8 +14,11 @@ module Comee
14
14
  def validate_primary_price
15
15
  return unless product && primary
16
16
 
17
- count = MasterPrice.where(product: product, primary: true, active: true).count
18
- errors.add(:base, "There is already a primary supplier for item '#{product.code}'") if count.positive?
17
+ count = MasterPrice.where(product: product, primary: true, status: MasterPrice.statuses[:current]).count
18
+ return unless count.positive? && primary && MasterPrice.statuses[status] == MasterPrice.statuses[:current]
19
+
20
+ errors.add(:base,
21
+ "There is already a primary supplier for item '#{product.code}'")
19
22
  end
20
23
 
21
24
  def validate_purchase_price_validity_dates
@@ -15,6 +15,7 @@ class CreateComeeCoreBackOrderItems < ActiveRecord::Migration[7.0]
15
15
  t.float :supplier_unit_price, null: false
16
16
  t.date :from, null: false
17
17
  t.date :to, null: false
18
+ t.date :delivery_date, null: false
18
19
  t.integer :item_status, null: false, default: 0
19
20
  t.string :remark
20
21
 
@@ -1,5 +1,5 @@
1
1
  module Comee
2
2
  module Core
3
- VERSION = "0.1.28".freeze
3
+ VERSION = "0.1.30".freeze
4
4
  end
5
5
  end
@@ -6,6 +6,7 @@ FactoryBot.define do
6
6
  requested_unit_price { 50 }
7
7
  supplier_quantity { 5 }
8
8
  supplier_unit_price { 55 }
9
+ delivery_date { Date.current.advance(days: 6) }
9
10
  from { Date.current }
10
11
  to { Date.current.advance(months: 1) }
11
12
  item_status { Comee::Core::BackOrderItem.item_statuses[:available] }
@@ -1,7 +1,7 @@
1
1
  FactoryBot.define do
2
2
  factory :client, class: "Comee::Core::Client" do
3
3
  user
4
- code { Faker::Alphanumeric.alpha(number: 8) }
4
+ code { Faker::Alphanumeric.unique.alpha(number: 8) }
5
5
  name { Faker::Name.name }
6
6
  address { Faker::Address.full_address }
7
7
  locale { "en" }
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.28
4
+ version: 0.1.30
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-28 00:00:00.000000000 Z
11
+ date: 2023-11-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers
@@ -150,6 +150,20 @@ dependencies:
150
150
  - - ">="
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: rubocop-rspec
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
153
167
  - !ruby/object:Gem::Dependency
154
168
  name: shoulda-matchers
155
169
  requirement: !ruby/object:Gem::Requirement
@@ -243,6 +257,7 @@ files:
243
257
  - app/controllers/comee/core/units_controller.rb
244
258
  - app/controllers/comee/core/users_controller.rb
245
259
  - app/controllers/concerns/comee/core/common.rb
260
+ - app/controllers/concerns/comee/core/pagination.rb
246
261
  - app/jobs/comee_core/application_job.rb
247
262
  - app/mailers/comee/core/application_mailer.rb
248
263
  - app/mailers/comee/core/supplier_mailer.rb