ecom_core 1.1.17 → 1.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: 7bdf3745639577dacd60d41eb82831de69cd41040b71411628f17be1a8397b42
4
- data.tar.gz: 21fd30d003500d6648d42eb6be7e5d073eff6b7810148cd00aed1fd2496363ec
3
+ metadata.gz: cbaba2b0f521af3d18d5636be2e3be40c6de15aa9f3951b5c3d8b57bdc634e83
4
+ data.tar.gz: 24ab07446617733ce416002684e0565f4bb04e66ad0a30d0b28d1f1cd79cf9a2
5
5
  SHA512:
6
- metadata.gz: 769ccb1b054f0b6faf9421e323e562053d3fe7770fb3abed2af5e0535be3f61f39803deff27b4816d4b58efcb07419b46519c73906ff44c7480ee4b03e9ac099
7
- data.tar.gz: 6d852af57207ad9cfbc6f30d7eaadf239c338b6c4796198e5ec8f833b69b16fba2d790d555b64b37279583e87edb8a517a7dfe0811e74b66fc21f1e0659c3b9c
6
+ metadata.gz: 88dc9269297366e77f415c768da3bb457414b57143f3aef34df98cbbc3923ac7a125f4bec6005f0f46ff071a64dfabb2295c91931b1033ad872f02cfc5100e04
7
+ data.tar.gz: cec52dafb2589e7711300bd0322425be7c670ee83bc440def6f26ee6663f10edf6fd1b4231327e28603e9e6bcea95e09e1635c6ce97dda774f69cdea736f58e7
@@ -10,19 +10,24 @@ module Ecom
10
10
 
11
11
  has_many :attendance_sheet_entries
12
12
 
13
- scope :open, -> { find_by(status: OPEN) }
14
- scope :current_open, -> { where(status: OPEN, date: Date.today) }
13
+ scope :open, -> { where(status: OPEN) }
14
+ scope :current, -> { where(date: Date.today) }
15
+ scope :current_open, -> { open.current }
16
+
17
+ def self.open_for_date(date)
18
+ AttendanceSheet.find_by(status: OPEN, date: date)
19
+ end
15
20
 
16
21
  def self.open_exists?
17
- AttendanceSheet.where(status: OPEN).exists?
22
+ AttendanceSheet.open.exists?
18
23
  end
19
24
 
20
25
  def self.exists_for_today?
21
- AttendanceSheet.where(date: Date.today).exists?
26
+ AttendanceSheet.current.exists?
22
27
  end
23
28
 
24
29
  def self.open_exists_for_today?
25
- where(status: OPEN, date: Date.today).exists?
30
+ AttendanceSheet.current_open.exists?
26
31
  end
27
32
 
28
33
  # Attendance sheet should be created using the
@@ -53,13 +58,14 @@ module Ecom
53
58
  # to submit the attendance sheet after the date has
54
59
  # passed. Normally, timekeepers need to open and close
55
60
  # an attendance sheet of a date on the specific date.
56
- def submit
57
- raise 'This attendance sheet is not open. Therefore it cannot be submitted' unless status == OPEN
61
+ def self.submit(date)
62
+ sheet = AttendanceSheet.open_for_date(date)
63
+ raise 'There is no open attendance sheet to submit for the selected day.' unless sheet
58
64
 
59
- self.closed_at = Time.now
60
- self.status = SUBMITTED
61
- save
62
- self
65
+ sheet.closed_at = Time.now
66
+ sheet.status = SUBMITTED
67
+ sheet.save
68
+ sheet
63
69
  end
64
70
  end
65
71
  end
@@ -6,7 +6,7 @@ module Ecom
6
6
  belongs_to :revision_to, class_name: 'Ecom::Core::CrewOvertime', optional: true
7
7
  belongs_to :created_by, class_name: 'Ecom::Core::User'
8
8
 
9
- has_one :revision, class_name: 'Ecom::Core::CrewOvertime'
9
+ has_one :revision, class_name: 'Ecom::Core::CrewOvertime', foreign_key: :revision_to_id
10
10
 
11
11
  validates :hours, :converted_hours, presence: true
12
12
 
@@ -10,10 +10,15 @@ module Ecom
10
10
 
11
11
  has_many :overtime_sheet_entries
12
12
 
13
- scope :open, -> { find_by(status: OPEN) }
13
+ scope :open, -> { where(status: OPEN) }
14
+ scope :for_date, ->(date) { where(date: date) }
14
15
 
15
16
  def self.open_exists?
16
- OvertimeSheet.where(status: OPEN).exists?
17
+ OvertimeSheet.open.exists?
18
+ end
19
+
20
+ def self.open_for_date_exists?(date)
21
+ OvertimeSheet.open.for_date(date).exists?
17
22
  end
18
23
 
19
24
  # Overtime sheet should be created using the
@@ -22,6 +27,10 @@ module Ecom
22
27
  # and also that we have only one open overtime
23
28
  # sheet at a time.
24
29
  def self.create_new(date)
30
+ if OvertimeSheet.open_for_date_exists?(date)
31
+ raise 'There is already an open overtime sheet for the selected date.'
32
+ end
33
+
25
34
  if OvertimeSheet.open_exists?
26
35
  raise 'There is already an open overtime sheet. It has to be submitted before creating a new one.'
27
36
  end
@@ -3,6 +3,7 @@ module Ecom
3
3
  class OvertimeSheetEntry < ApplicationRecord
4
4
  belongs_to :overtime_sheet
5
5
  belongs_to :crew
6
+ has_many :crew_overtimes
6
7
  end
7
8
  end
8
9
  end
@@ -6,7 +6,7 @@ module Ecom
6
6
  has_and_belongs_to_many :user_roles, join_table: 'ecom_core_users_user_roles'
7
7
 
8
8
  VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i.freeze
9
- validates :first_name, :last_name, :active, presence: true
9
+ validates :first_name, :last_name, presence: true
10
10
  validates :email, presence: true, format: { with: VALID_EMAIL_REGEX }, uniqueness: { case_sensitive: false }
11
11
  validates :password, presence: true, length: { minimum: 6 }, confirmation: true, if: :password
12
12
 
@@ -1,5 +1,5 @@
1
1
  module Ecom
2
2
  module Core
3
- VERSION = '1.1.17'.freeze
3
+ VERSION = '1.1.18'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ecom_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.17
4
+ version: 1.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: 2020-04-10 00:00:00.000000000 Z
11
+ date: 2020-04-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aasm