Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
pik
ambre
Commits
a157469c
Commit
a157469c
authored
Jan 15, 2020
by
gwendal
Browse files
do not invoice service with no chargeable item (fix #181)
parent
d1bd2143
Changes
3
Hide whitespace changes
Inline
Side-by-side
app/models/service.rb
View file @
a157469c
...
...
@@ -243,6 +243,12 @@ class Service < ActiveRecord::Base
return
records
if
self
.
first_invoicing_started_on
.
nil?
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
if
is_there_an_open_invoice_for_this_service?
errors
.
add
(
:base
,
:already_an_open_invoice
)
...
...
@@ -256,6 +262,7 @@ class Service < ActiveRecord::Base
return
records
end
# For services not yet invoiced, set the last_invoicing_end_at to yesterday
# in order to bill them.
if
last_invoicing_end_at
.
nil?
...
...
config/locales/activerecord.fr.yml
View file @
a157469c
...
...
@@ -383,6 +383,7 @@ fr:
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"
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
:
<<
:
*service_errors
...
...
spec/models/service_spec.rb
View file @
a157469c
...
...
@@ -610,6 +610,18 @@ RSpec.describe Service, type: :model do
]
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
# @service = FactoryBot.create(
# :vpn_service,
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment