From d3a41903cd4a9b4ce0238476d960ae2aae8f2371 Mon Sep 17 00:00:00 2001 From: Sylvain Date: Mon, 21 Dec 2020 17:37:58 +0100 Subject: [PATCH] WIP: exclude invoice_id from footprint in payment_schedule_item --- app/controllers/open_api/v1/invoices_controller.rb | 7 ++++--- app/models/footprintable.rb | 5 +++++ app/models/history_value.rb | 2 ++ app/models/invoice.rb | 1 + app/models/invoice_item.rb | 2 ++ app/models/payment_schedule.rb | 2 ++ app/models/payment_schedule_item.rb | 6 ++++++ app/services/footprint_service.rb | 2 +- 8 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 app/models/footprintable.rb diff --git a/app/controllers/open_api/v1/invoices_controller.rb b/app/controllers/open_api/v1/invoices_controller.rb index 3dd1e9b15..f914175f4 100644 --- a/app/controllers/open_api/v1/invoices_controller.rb +++ b/app/controllers/open_api/v1/invoices_controller.rb @@ -21,7 +21,8 @@ class OpenAPI::V1::InvoicesController < OpenAPI::V1::BaseController end private - def per_page - params[:per_page] || 20 - end + + def per_page + params[:per_page] || 20 + end end diff --git a/app/models/footprintable.rb b/app/models/footprintable.rb new file mode 100644 index 000000000..a3f6b7921 --- /dev/null +++ b/app/models/footprintable.rb @@ -0,0 +1,5 @@ +module Footprintable + def self.columns_out_of_footprint + [] + end +end diff --git a/app/models/history_value.rb b/app/models/history_value.rb index b62cf843f..e3658b623 100644 --- a/app/models/history_value.rb +++ b/app/models/history_value.rb @@ -4,6 +4,8 @@ require 'checksum' # Setting values, kept history of modifications class HistoryValue < ApplicationRecord + include Footprintable + belongs_to :setting belongs_to :invoicing_profile diff --git a/app/models/invoice.rb b/app/models/invoice.rb index 08b0f1772..389a2336d 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -5,6 +5,7 @@ require 'checksum' # Invoice correspond to a single purchase made by an user. This purchase may # include reservation(s) and/or a subscription class Invoice < ApplicationRecord + include Footprintable include NotifyWith::NotificationAttachedObject require 'fileutils' scope :only_invoice, -> { where(type: nil) } diff --git a/app/models/invoice_item.rb b/app/models/invoice_item.rb index 28590005e..f03fc8c54 100644 --- a/app/models/invoice_item.rb +++ b/app/models/invoice_item.rb @@ -4,6 +4,8 @@ require 'checksum' # A single line inside an invoice. Can be a subscription or a reservation class InvoiceItem < ApplicationRecord + include Footprintable + belongs_to :invoice belongs_to :subscription diff --git a/app/models/payment_schedule.rb b/app/models/payment_schedule.rb index ad8413f47..f59b931b6 100644 --- a/app/models/payment_schedule.rb +++ b/app/models/payment_schedule.rb @@ -3,6 +3,8 @@ # PaymentSchedule is a way for members to pay something (especially a Subscription) with multiple payment, # staged on a long period rather than with a single payment class PaymentSchedule < ApplicationRecord + include Footprintable + belongs_to :scheduled, polymorphic: true belongs_to :wallet_transaction belongs_to :coupon diff --git a/app/models/payment_schedule_item.rb b/app/models/payment_schedule_item.rb index 46e0f1741..d687a1d0a 100644 --- a/app/models/payment_schedule_item.rb +++ b/app/models/payment_schedule_item.rb @@ -2,6 +2,8 @@ # Represents a due date and the associated amount for a PaymentSchedule class PaymentScheduleItem < ApplicationRecord + include Footprintable + belongs_to :payment_schedule belongs_to :invoice after_create :chain_record @@ -23,4 +25,8 @@ class PaymentScheduleItem < ApplicationRecord def compute_footprint FootprintService.compute_footprint(PaymentScheduleItem, self) end + + def self.columns_out_of_footprint + %w[invoice_id] + end end diff --git a/app/services/footprint_service.rb b/app/services/footprint_service.rb index 425395bf0..049f05450 100644 --- a/app/services/footprint_service.rb +++ b/app/services/footprint_service.rb @@ -29,7 +29,7 @@ class FootprintService # Return an ordered array of the columns used in the footprint computation # @param klass Invoice|InvoiceItem|HistoryValue def self.footprint_columns(klass) - klass.columns.map(&:name).delete_if { |c| %w[footprint updated_at].include? c } + klass.columns.map(&:name).delete_if { |c| %w[footprint updated_at].concat(klass.columns_out_of_footprint).include? c } end # Logs a debugging message to help finding why a footprint is invalid