-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add historical data to financial metrics
- Loading branch information
1 parent
f4a1051
commit fa09b20
Showing
13 changed files
with
193 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,31 @@ | ||
# This configuration was generated by | ||
# `rubocop --auto-gen-config` | ||
# on 2023-12-13 18:57:39 UTC using RuboCop version 1.56.2. | ||
# on 2023-12-13 21:43:07 UTC using RuboCop version 1.56.2. | ||
# The point is for the user to remove these configuration records | ||
# one by one as the offenses are removed from the code base. | ||
# Note that changes in the inspected code, or installation of new | ||
# versions of RuboCop, may require this file to be generated again. | ||
|
||
# Offense count: 4 | ||
# Offense count: 5 | ||
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes. | ||
Metrics/AbcSize: | ||
Max: 24 | ||
Max: 29 | ||
|
||
# Offense count: 4 | ||
# Offense count: 5 | ||
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns. | ||
Metrics/MethodLength: | ||
Max: 16 | ||
Max: 19 | ||
|
||
# Offense count: 1 | ||
# Configuration parameters: AllowedMethods. | ||
# AllowedMethods: respond_to_missing? | ||
Style/OptionalBooleanParameter: | ||
Exclude: | ||
- 'app/utils/analytics/finances/models/financial_statements_of_work.rb' | ||
|
||
# Offense count: 2 | ||
# This cop supports safe autocorrection (--autocorrect). | ||
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns. | ||
# URISchemes: http, https | ||
Layout/LineLength: | ||
Max: 124 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# frozen_string_literal: true | ||
|
||
# == Schema Information | ||
# | ||
# Table name: statement_of_work_financial_reports | ||
# | ||
# id :bigint not null, primary key | ||
# end_date :datetime | ||
# start_date :datetime | ||
# total_executed_income :float | ||
# created_at :datetime not null | ||
# updated_at :datetime not null | ||
# statement_of_work_id :integer not null | ||
# | ||
# Indexes | ||
# | ||
# index_sow_financial_reports_on_sow_id (statement_of_work_id) | ||
# | ||
class StatementOfWorkFinancialReport < ApplicationRecord | ||
belongs_to :statement_of_work | ||
|
||
scope :ending_on, lambda { |filter| | ||
where(end_date: filter.to_date) | ||
} | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# frozen_string_literal: true | ||
|
||
class UpdateStatementOfWorkFinancialReports | ||
def self.update! | ||
initial_date = 2.years.ago.beginning_of_day.to_date | ||
today = Time.zone.now.end_of_day.to_date | ||
|
||
StatementOfWorkFinancialReport.destroy_all | ||
|
||
Project.find(2).statement_of_works.active_in_period(initial_date, today).each do |statement_of_work| | ||
start_date = [initial_date, statement_of_work.start_date].max.to_date | ||
|
||
(start_date..today).each do |end_date| | ||
previous_period_model_calculator = | ||
Analytics::Finances::Calculators::CalculatorBuilder.build(statement_of_work, | ||
start_date, end_date) | ||
executed_income_to_start_date = previous_period_model_calculator.total_executed_income | ||
|
||
StatementOfWorkFinancialReport.create!(statement_of_work:, start_date:, | ||
end_date:, total_executed_income: executed_income_to_start_date) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
db/migrate/20231213195743_create_statement_of_work_financial_reports.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
class CreateStatementOfWorkFinancialReports < ActiveRecord::Migration[7.0] | ||
def change | ||
create_table :statement_of_work_financial_reports do |t| | ||
# Remove index: true from here | ||
t.integer :statement_of_work_id, null: false | ||
t.datetime :start_date | ||
t.datetime :end_date | ||
t.float :total_executed_income | ||
|
||
t.timestamps | ||
end | ||
|
||
# Add the index after the create_table block | ||
# You can provide a custom shorter name if needed | ||
add_index :statement_of_work_financial_reports, :statement_of_work_id, name: 'index_sow_financial_reports_on_sow_id' | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# frozen_string_literal: true | ||
|
||
# == Schema Information | ||
# | ||
# Table name: statement_of_work_financial_reports | ||
# | ||
# id :bigint not null, primary key | ||
# end_date :datetime | ||
# start_date :datetime | ||
# total_executed_income :float | ||
# created_at :datetime not null | ||
# updated_at :datetime not null | ||
# statement_of_work_id :integer not null | ||
# | ||
# Indexes | ||
# | ||
# index_sow_financial_reports_on_sow_id (statement_of_work_id) | ||
# | ||
FactoryBot.define do | ||
factory :statement_of_work_financial_report do | ||
statement_of_work { nil } | ||
start_date { '2023-12-13 19:57:44' } | ||
end_date { '2023-12-13 19:57:44' } | ||
total_executed_income { 1.5 } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# frozen_string_literal: true | ||
|
||
# == Schema Information | ||
# | ||
# Table name: statement_of_work_financial_reports | ||
# | ||
# id :bigint not null, primary key | ||
# end_date :datetime | ||
# start_date :datetime | ||
# total_executed_income :float | ||
# created_at :datetime not null | ||
# updated_at :datetime not null | ||
# statement_of_work_id :integer not null | ||
# | ||
# Indexes | ||
# | ||
# index_sow_financial_reports_on_sow_id (statement_of_work_id) | ||
# | ||
require 'rails_helper' | ||
|
||
RSpec.describe StatementOfWorkFinancialReport, type: :model do | ||
pending "add some examples to (or delete) #{__FILE__}" | ||
end |