Commit a157469c authored by gwendal's avatar gwendal
Browse files

do not invoice service with no chargeable item (fix #181)

parent d1bd2143
...@@ -243,6 +243,12 @@ class Service < ActiveRecord::Base ...@@ -243,6 +243,12 @@ class Service < ActiveRecord::Base
return records if self.first_invoicing_started_on.nil? return records if self.first_invoicing_started_on.nil?
return records if self.service_sale_templates.empty? return records if self.service_sale_templates.empty?
# Ensure at least one service_sale_templates is chargeable
if service_sale_templates.where(chargeable: true).empty?
errors.add(:base, :no_chargeable_item)
return records
end
# Ensure that there is no open invoice for this service # Ensure that there is no open invoice for this service
if is_there_an_open_invoice_for_this_service? if is_there_an_open_invoice_for_this_service?
errors.add(:base, :already_an_open_invoice) errors.add(:base, :already_an_open_invoice)
...@@ -256,6 +262,7 @@ class Service < ActiveRecord::Base ...@@ -256,6 +262,7 @@ class Service < ActiveRecord::Base
return records return records
end end
# For services not yet invoiced, set the last_invoicing_end_at to yesterday # For services not yet invoiced, set the last_invoicing_end_at to yesterday
# in order to bill them. # in order to bill them.
if last_invoicing_end_at.nil? if last_invoicing_end_at.nil?
......
...@@ -383,6 +383,7 @@ fr: ...@@ -383,6 +383,7 @@ fr:
already_a_pending_payment: "Il y a déjà un paiement en attente pour ce service" already_a_pending_payment: "Il y a déjà un paiement en attente pour ce service"
already_an_open_invoice: "Il y a déjà une facture en brouillon pour ce service" already_an_open_invoice: "Il y a déjà une facture en brouillon pour ce service"
last_invoicing_end_at_after_end_of_month_chargeable: "La fin de facturation de ce service est postérieur au mois de facturation en cours" last_invoicing_end_at_after_end_of_month_chargeable: "La fin de facturation de ce service est postérieur au mois de facturation en cours"
no_chargeable_item: "Le service n'a pas d'item facturable"
radio_service: radio_service:
<<: *service_errors <<: *service_errors
......
...@@ -610,6 +610,18 @@ RSpec.describe Service, type: :model do ...@@ -610,6 +610,18 @@ RSpec.describe Service, type: :model do
] ]
end end
it 'should not render anything if there is no chargeable item' do
@service = FactoryBot.create(
:dsl_service,
member: @member,
first_invoicing_started_on: Date.today - 5.month,
last_invoicing_end_at: Date.yesterday - 2.month,
)
@service.service_sale_templates.update_all(chargeable: false)
records = @service.generate_invoicing
expect(records).to be_empty
end
# it 'should use deposit account if possible' do # it 'should use deposit account if possible' do
# @service = FactoryBot.create( # @service = FactoryBot.create(
# :vpn_service, # :vpn_service,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment