mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-01-17 06:52:27 +01:00
[bug] accounting export: on subscription + reservation invoice, the subscription item is exported twice
This commit is contained in:
parent
354c660c0e
commit
19a125bd67
@ -1,3 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# Machine is an hardware equipment hosted in the fablab that is available for reservation to the members
|
||||
class Machine < ActiveRecord::Base
|
||||
extend FriendlyId
|
||||
friendly_id :name, use: :slugged
|
||||
@ -7,12 +10,12 @@ class Machine < ActiveRecord::Base
|
||||
has_many :machine_files, as: :viewable, dependent: :destroy
|
||||
accepts_nested_attributes_for :machine_files, allow_destroy: true, reject_if: :all_blank
|
||||
|
||||
has_and_belongs_to_many :projects, join_table: :projects_machines
|
||||
has_and_belongs_to_many :projects, join_table: 'projects_machines'
|
||||
|
||||
has_many :machines_availabilities, dependent: :destroy
|
||||
has_many :availabilities, through: :machines_availabilities
|
||||
|
||||
has_and_belongs_to_many :trainings, join_table: :trainings_machines
|
||||
has_and_belongs_to_many :trainings, join_table: 'trainings_machines'
|
||||
|
||||
validates :name, presence: true, length: { maximum: 50 }
|
||||
validates :description, presence: true
|
||||
@ -39,18 +42,20 @@ class Machine < ActiveRecord::Base
|
||||
|
||||
def create_statistic_subtype
|
||||
index = StatisticIndex.where(es_type_key: 'machine')
|
||||
StatisticSubType.create!({statistic_types: index.first.statistic_types, key: self.slug, label: self.name})
|
||||
StatisticSubType.create!(statistic_types: index.first.statistic_types, key: slug, label: name)
|
||||
end
|
||||
|
||||
def update_statistic_subtype
|
||||
index = StatisticIndex.where(es_type_key: 'machine')
|
||||
subtype = StatisticSubType.joins(statistic_type_sub_types: :statistic_type).where(key: self.slug, statistic_types: { statistic_index_id: index.first.id }).first
|
||||
subtype.label = self.name
|
||||
subtype = StatisticSubType.joins(statistic_type_sub_types: :statistic_type)
|
||||
.where(key: slug, statistic_types: { statistic_index_id: index.first.id })
|
||||
.first
|
||||
subtype.label = name
|
||||
subtype.save!
|
||||
end
|
||||
|
||||
def remove_statistic_subtype
|
||||
subtype = StatisticSubType.where(key: self.slug).first
|
||||
subtype = StatisticSubType.where(key: slug).first
|
||||
subtype.destroy!
|
||||
end
|
||||
|
||||
|
@ -1,3 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# Plan is a generic description of a subscription plan, which can be subscribed by a member to benefit from advantageous prices.
|
||||
# Subscribers can also get some Credits for some reservable items
|
||||
class Plan < ActiveRecord::Base
|
||||
belongs_to :group
|
||||
|
||||
@ -106,7 +110,7 @@ class Plan < ActiveRecord::Base
|
||||
if !stat_type.nil? && !stat_subtype.nil?
|
||||
StatisticTypeSubType.create!(statistic_type: stat_type, statistic_sub_type: stat_subtype)
|
||||
else
|
||||
puts 'ERROR: Unable to create the statistics association for the new plan. '+
|
||||
puts 'ERROR: Unable to create the statistics association for the new plan. ' \
|
||||
'Possible causes: the type or the subtype were not created successfully.'
|
||||
end
|
||||
end
|
||||
|
@ -63,7 +63,8 @@ class AccountingExportService
|
||||
def items_rows(invoice)
|
||||
rows = invoice.subscription_invoice? ? "#{subscription_row(invoice)}\n" : ''
|
||||
if invoice.invoiced_type == 'Reservation'
|
||||
invoice.invoice_items.each do |item|
|
||||
items = invoice.invoice_items.select { |ii| ii.subscription.nil? }
|
||||
items.each do |item|
|
||||
rows << "#{reservation_row(invoice, item)}\n"
|
||||
end
|
||||
elsif invoice.invoiced_type == 'WalletTransaction'
|
||||
|
Loading…
x
Reference in New Issue
Block a user