dorsale 3.14.3 → 3.14.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/Rakefile +2 -0
- data/app/pdfs/dorsale/application_pdf.rb +11 -1
- data/app/pdfs/dorsale/expense_gun/expense_pdf.rb +75 -0
- data/app/views/dorsale/expense_gun/expenses/_show_actions.html.slim +2 -0
- data/app/views/dorsale/expense_gun/expenses/show.pdf.ruby +3 -0
- data/lib/dorsale/version.rb +1 -1
- metadata +125 -358
- data/features/access.feature +0 -17
- data/features/billing_machine_invoices.feature +0 -261
- data/features/billing_machine_multiple_vat.feature +0 -53
- data/features/billing_machine_payment_terms.feature +0 -19
- data/features/billing_machine_quotations.feature +0 -193
- data/features/customer_vault_activity_types.feature +0 -19
- data/features/customer_vault_corporations.feature +0 -95
- data/features/customer_vault_filters.feature +0 -14
- data/features/customer_vault_individuals.feature +0 -35
- data/features/customer_vault_invoices.feature +0 -10
- data/features/customer_vault_links.feature +0 -54
- data/features/customer_vault_origins.feature +0 -19
- data/features/customer_vault_people.feature +0 -25
- data/features/customer_vault_search.feature +0 -22
- data/features/customer_vault_tasks.feature +0 -35
- data/features/expense_gun_categories.feature +0 -19
- data/features/expense_gun_expenses.feature +0 -60
- data/features/flyboy_task_comments.feature +0 -21
- data/features/flyboy_tasks.feature +0 -122
- data/features/flyboy_tasks_summary.feature +0 -22
- data/features/step_definitions/access_steps.rb +0 -15
- data/features/step_definitions/alexandrie_steps.rb +0 -25
- data/features/step_definitions/billing_machine_invoices_steps.rb +0 -377
- data/features/step_definitions/billing_machine_multiple_vat.rb +0 -19
- data/features/step_definitions/billing_machine_payment_terms_steps.rb +0 -42
- data/features/step_definitions/billing_machine_quotations_steps.rb +0 -248
- data/features/step_definitions/common_steps.rb +0 -91
- data/features/step_definitions/customer_vault_activity_types_steps.rb +0 -42
- data/features/step_definitions/customer_vault_corporations_steps.rb +0 -218
- data/features/step_definitions/customer_vault_filters_steps.rb +0 -37
- data/features/step_definitions/customer_vault_individuals_steps.rb +0 -67
- data/features/step_definitions/customer_vault_invoices_steps.rb +0 -7
- data/features/step_definitions/customer_vault_links_steps.rb +0 -73
- data/features/step_definitions/customer_vault_origins_steps.rb +0 -42
- data/features/step_definitions/customer_vault_people_steps.rb +0 -26
- data/features/step_definitions/customer_vault_search_steps.rb +0 -48
- data/features/step_definitions/customer_vault_tasks_steps.rb +0 -34
- data/features/step_definitions/expense_gun_categories_steps.rb +0 -50
- data/features/step_definitions/expense_gun_expenses_steps.rb +0 -135
- data/features/step_definitions/flyboy_task_comments_steps.rb +0 -10
- data/features/step_definitions/flyboy_tasks_steps.rb +0 -196
- data/features/step_definitions/tasks_summary_steps.rb +0 -30
- data/features/step_definitions/users_management_step.rb +0 -29
- data/features/support/env.rb +0 -8
- data/features/users_management.feature +0 -18
- data/spec/controllers/dorsale/alexandrie/attachments_controller_spec.rb +0 -145
- data/spec/controllers/dorsale/billing_machine/invoices_controller_spec.rb +0 -153
- data/spec/controllers/dorsale/billing_machine/quotations_controller_spec.rb +0 -24
- data/spec/controllers/dorsale/comments_controller_spec.rb +0 -50
- data/spec/controllers/dorsale/customer_vault/events_controller_spec.rb +0 -42
- data/spec/controllers/dorsale/customer_vault/people_controller_spec.rb +0 -129
- data/spec/controllers/dorsale/expense_gun/expenses_controller_spec.rb +0 -45
- data/spec/controllers/dorsale/flyboy/task_comments_controller_spec.rb +0 -40
- data/spec/controllers/dorsale/flyboy/tasks_controller_spec.rb +0 -349
- data/spec/factories/alexandrie_attachment_types.rb +0 -5
- data/spec/factories/alexandrie_attachments.rb +0 -16
- data/spec/factories/billing_machine_invoice_lines.rb +0 -9
- data/spec/factories/billing_machine_invoices.rb +0 -9
- data/spec/factories/billing_machine_payment_terms.rb +0 -5
- data/spec/factories/billing_machine_quotation_lines.rb +0 -9
- data/spec/factories/billing_machine_quotations.rb +0 -9
- data/spec/factories/customer_vault_activity_types.rb +0 -5
- data/spec/factories/customer_vault_corporations.rb +0 -13
- data/spec/factories/customer_vault_event.rb +0 -13
- data/spec/factories/customer_vault_individuals.rb +0 -17
- data/spec/factories/customer_vault_links.rb +0 -7
- data/spec/factories/customer_vault_origins.rb +0 -5
- data/spec/factories/dorsale_addresses.rb +0 -9
- data/spec/factories/dorsale_comments.rb +0 -7
- data/spec/factories/expense_gun_categories.rb +0 -7
- data/spec/factories/expense_gun_expense_lines.rb +0 -10
- data/spec/factories/expense_gun_expenses.rb +0 -13
- data/spec/factories/flyboy_task_comments.rb +0 -9
- data/spec/factories/flyboy_tasks.rb +0 -8
- data/spec/files/avatar.png +0 -0
- data/spec/files/pdf.pdf +0 -0
- data/spec/mailers/user_mailer_spec.rb +0 -21
- data/spec/models/dorsale/address_spec.rb +0 -46
- data/spec/models/dorsale/alexandrie/attachment_spec.rb +0 -36
- data/spec/models/dorsale/alexandrie/attachment_type_spec.rb +0 -11
- data/spec/models/dorsale/billing_machine/invoice_line_spec.rb +0 -52
- data/spec/models/dorsale/billing_machine/invoice_spec.rb +0 -258
- data/spec/models/dorsale/billing_machine/quotation_line_spec.rb +0 -51
- data/spec/models/dorsale/billing_machine/quotation_spec.rb +0 -213
- data/spec/models/dorsale/billing_machine_spec.rb +0 -57
- data/spec/models/dorsale/comment_spec.rb +0 -24
- data/spec/models/dorsale/customer_vault/activity_type_spec.rb +0 -10
- data/spec/models/dorsale/customer_vault/corporation_spec.rb +0 -33
- data/spec/models/dorsale/customer_vault/event_spec.rb +0 -22
- data/spec/models/dorsale/customer_vault/individual_spec.rb +0 -44
- data/spec/models/dorsale/customer_vault/link_spec.rb +0 -14
- data/spec/models/dorsale/customer_vault/origin_spec.rb +0 -8
- data/spec/models/dorsale/customer_vault/person_spec.rb +0 -112
- data/spec/models/dorsale/email_spec.rb +0 -39
- data/spec/models/dorsale/expense_gun/category_spec.rb +0 -9
- data/spec/models/dorsale/expense_gun/expense_line_spec.rb +0 -59
- data/spec/models/dorsale/expense_gun/expense_spec.rb +0 -176
- data/spec/models/dorsale/flyboy/task_comment_spec.rb +0 -54
- data/spec/models/dorsale/flyboy/task_spec.rb +0 -254
- data/spec/models/dorsale/i18n_spec.rb +0 -30
- data/spec/models/dorsale/users_spec.rb +0 -65
- data/spec/pdfs/dorsale/billing_machine/invoice_multiple_vat_pdf_spec.rb +0 -42
- data/spec/pdfs/dorsale/billing_machine/invoice_single_vat_pdf_spec.rb +0 -42
- data/spec/pdfs/dorsale/billing_machine/quotation_multiple_vat_pdf_spec.rb +0 -42
- data/spec/pdfs/dorsale/billing_machine/quotation_single_vat_pdf_spec.rb +0 -55
- data/spec/rails_helper.rb +0 -55
- data/spec/routing/dorsale/alexandrie/attachments_routing_spec.rb +0 -32
- data/spec/routing/dorsale/billing_machine/invoices_routing_spec.rb +0 -67
- data/spec/routing/dorsale/billing_machine/quotations_routing_spec.rb +0 -67
- data/spec/routing/dorsale/comments_routing_spec.rb +0 -23
- data/spec/routing/dorsale/customer_vault/activity_types_routing_spec.rb +0 -40
- data/spec/routing/dorsale/customer_vault/events_routing_spec.rb +0 -12
- data/spec/routing/dorsale/customer_vault/origins_routing_spec.rb +0 -40
- data/spec/routing/dorsale/customer_vault/people_routing_spec.rb +0 -109
- data/spec/routing/dorsale/expense_gun/expenses_routing_spec.rb +0 -62
- data/spec/routing/dorsale/flyboy/task_comments_routing_spec.rb +0 -11
- data/spec/routing/dorsale/flyboy/tasks_routing_spec.rb +0 -51
- data/spec/routing/dorsale/users_routing_spec.rb +0 -38
- data/spec/services/dorsale/billing_machine/quotation/copy_spec.rb +0 -55
- data/spec/services/dorsale/billing_machine/quotation/statistics.rb +0 -23
- data/spec/services/dorsale/billing_machine/quotation/to_invoice_spec.rb +0 -46
- data/spec/services/dorsale/expense_gun/expense/copy_spec.rb +0 -83
- data/spec/services/dorsale/flyboy/task/copy_spec.rb +0 -24
- data/spec/services/dorsale/flyboy/task/snoozer_spec.rb +0 -117
- data/spec/spec_helper.rb +0 -86
- data/spec/support/devise.rb +0 -3
- data/spec/support/message_delivery.rb +0 -5
@@ -1,16 +0,0 @@
|
|
1
|
-
FactoryBot.define do
|
2
|
-
factory :alexandrie_attachment, class: ::Dorsale::Alexandrie::Attachment do
|
3
|
-
attachable {
|
4
|
-
DummyModel.create!(name: "abc")
|
5
|
-
}
|
6
|
-
|
7
|
-
sender {
|
8
|
-
create(:user)
|
9
|
-
}
|
10
|
-
|
11
|
-
file {
|
12
|
-
path = Dorsale::Engine.root.join("spec/files/pdf.pdf").to_s
|
13
|
-
Rack::Test::UploadedFile.new(path, "application/pdf")
|
14
|
-
}
|
15
|
-
end
|
16
|
-
end
|
@@ -1,9 +0,0 @@
|
|
1
|
-
FactoryBot.define do
|
2
|
-
factory :billing_machine_invoice_line, class: ::Dorsale::BillingMachine::InvoiceLine do
|
3
|
-
invoice { create(:billing_machine_invoice) }
|
4
|
-
label { "Invoice line" + Faker::Lorem.words.join(" ") }
|
5
|
-
quantity { 10 }
|
6
|
-
unit { "€" }
|
7
|
-
unit_price { 20 }
|
8
|
-
end
|
9
|
-
end
|
@@ -1,9 +0,0 @@
|
|
1
|
-
FactoryBot.define do
|
2
|
-
factory :billing_machine_invoice, class: ::Dorsale::BillingMachine::Invoice do
|
3
|
-
customer { create(:customer_vault_corporation) }
|
4
|
-
payment_term { create(:billing_machine_payment_term) }
|
5
|
-
date { "2014-02-19" }
|
6
|
-
label { "Software service" }
|
7
|
-
advance { 0 }
|
8
|
-
end
|
9
|
-
end
|
@@ -1,9 +0,0 @@
|
|
1
|
-
FactoryBot.define do
|
2
|
-
factory :billing_machine_quotation_line, class: ::Dorsale::BillingMachine::QuotationLine do
|
3
|
-
quotation { create(:billing_machine_quotation) }
|
4
|
-
label { "Quotation line" + Faker::Lorem.words.join(" ") }
|
5
|
-
quantity { 10 }
|
6
|
-
unit { "€" }
|
7
|
-
unit_price { 20 }
|
8
|
-
end
|
9
|
-
end
|
@@ -1,9 +0,0 @@
|
|
1
|
-
FactoryBot.define do
|
2
|
-
factory :billing_machine_quotation, class: ::Dorsale::BillingMachine::Quotation do
|
3
|
-
customer { create(:customer_vault_corporation) }
|
4
|
-
payment_term { create(:billing_machine_payment_term) }
|
5
|
-
date { "2014-02-19" }
|
6
|
-
label { "Software service" }
|
7
|
-
comments { "This is the quotation for the software your companie want" }
|
8
|
-
end
|
9
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
FactoryBot.define do
|
2
|
-
factory :customer_vault_corporation, class: ::Dorsale::CustomerVault::Corporation do
|
3
|
-
activity_type { create(:customer_vault_activity_type) }
|
4
|
-
origin { create(:customer_vault_origin) }
|
5
|
-
name { "#{Faker::Company.name} #{Faker::Company.suffix}" }
|
6
|
-
short_name { "SN" }
|
7
|
-
email { Faker::Internet.email }
|
8
|
-
phone { "06 xx xx xx xx" }
|
9
|
-
fax { "09 xx xx xx xx" }
|
10
|
-
www { Faker::Internet.url }
|
11
|
-
address { build(:dorsale_address) }
|
12
|
-
end
|
13
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
FactoryBot.define do
|
2
|
-
factory :customer_vault_event, class: ::Dorsale::CustomerVault::Event do
|
3
|
-
author { build(:user) }
|
4
|
-
person { build(:customer_vault_corporation) }
|
5
|
-
action { "create" }
|
6
|
-
text { "Création de la personne" }
|
7
|
-
end
|
8
|
-
|
9
|
-
factory :customer_vault_event_comment, parent: :customer_vault_event do
|
10
|
-
action { "comment" }
|
11
|
-
text { "Je suis un commentaire" }
|
12
|
-
end
|
13
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
FactoryBot.define do
|
2
|
-
factory :customer_vault_individual, class: ::Dorsale::CustomerVault::Individual do
|
3
|
-
origin { create(:customer_vault_origin) }
|
4
|
-
first_name { Faker::Name.first_name }
|
5
|
-
last_name { Faker::Name.last_name }
|
6
|
-
short_name { "SN" }
|
7
|
-
email { Faker::Internet.email("#{first_name} #{last_name}") }
|
8
|
-
title { "Individual-Title" }
|
9
|
-
twitter { "#{first_name}#{last_name}" }
|
10
|
-
www { Faker::Internet.url }
|
11
|
-
context { "Individual-Context" }
|
12
|
-
phone { "01 23 xx xx xx" }
|
13
|
-
fax { "09 xx xx xx xx" }
|
14
|
-
mobile { "06 xx xx xx xx" }
|
15
|
-
address { build(:dorsale_address) }
|
16
|
-
end
|
17
|
-
end
|
@@ -1,10 +0,0 @@
|
|
1
|
-
FactoryBot.define do
|
2
|
-
factory :expense_gun_expense_line, class: ::Dorsale::ExpenseGun::ExpenseLine do
|
3
|
-
name { Faker::Lorem.sentence(3) }
|
4
|
-
category { FactoryBot.create(:expense_gun_category) }
|
5
|
-
date { Faker::Date.backward(30) }
|
6
|
-
total_all_taxes { rand(100..1000) }
|
7
|
-
vat { rand(1..(total_all_taxes/5)) }
|
8
|
-
company_part { [25, 50, 75, 100].sample }
|
9
|
-
end
|
10
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
FactoryBot.define do
|
2
|
-
factory :expense_gun_expense, class: ::Dorsale::ExpenseGun::Expense do
|
3
|
-
name { Faker::Lorem.sentence(3) }
|
4
|
-
date { Date.current }
|
5
|
-
user { create(:user) }
|
6
|
-
|
7
|
-
after(:create) { |expense|
|
8
|
-
rand(2..5).times {
|
9
|
-
create(:expense_gun_expense_line, expense: expense)
|
10
|
-
}
|
11
|
-
}
|
12
|
-
end
|
13
|
-
end
|
@@ -1,8 +0,0 @@
|
|
1
|
-
FactoryBot.define do
|
2
|
-
factory :flyboy_task, class: ::Dorsale::Flyboy::Task do
|
3
|
-
name { "I-am-a-task#{Kernel.rand(1_000..9_999)}" }
|
4
|
-
description { "I-am-the-task-description_#{Kernel.rand(1_000..9_999)}" }
|
5
|
-
progress { Kernel.rand(0..99) }
|
6
|
-
done { false }
|
7
|
-
end
|
8
|
-
end
|
data/spec/files/avatar.png
DELETED
Binary file
|
data/spec/files/pdf.pdf
DELETED
Binary file
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require "rails_helper"
|
2
|
-
|
3
|
-
describe ::Dorsale::UserMailer do
|
4
|
-
describe "New Account" do
|
5
|
-
let(:user) { create(:user) }
|
6
|
-
let(:email) { ::Dorsale::UserMailer.new_account(user, user.password) }
|
7
|
-
|
8
|
-
it "should send to the right person" do
|
9
|
-
expect(email.to).to eq([user.email])
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should have the right sender" do
|
13
|
-
expect(email.from).to eq(["example@example.org"])
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should contain user_type, login and password" do
|
17
|
-
expect(email.body).to include user.email
|
18
|
-
expect(email.body).to include user.password
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
require "rails_helper"
|
2
|
-
|
3
|
-
module Dorsale
|
4
|
-
RSpec.describe Address, :type => :model do
|
5
|
-
it { should belong_to :addressable }
|
6
|
-
it { should validate_presence_of :addressable }
|
7
|
-
|
8
|
-
describe "#one_line" do
|
9
|
-
it "should build a one line address" do
|
10
|
-
address = Address.new(
|
11
|
-
street: "3 Rue Marx Dormoy",
|
12
|
-
street_bis: "L'atelier",
|
13
|
-
zip: "13004",
|
14
|
-
city: "Marseille",
|
15
|
-
country: "France",
|
16
|
-
)
|
17
|
-
|
18
|
-
expect(address.one_line).to eq("3 Rue Marx Dormoy, L'atelier, 13004 Marseille, France")
|
19
|
-
end
|
20
|
-
|
21
|
-
it "should remove useless commas" do
|
22
|
-
address = Address.new(
|
23
|
-
street: "3 Rue Marx Dormoy",
|
24
|
-
street_bis: "",
|
25
|
-
zip: "13004",
|
26
|
-
city: "Marseille",
|
27
|
-
country: "",
|
28
|
-
)
|
29
|
-
|
30
|
-
expect(address.one_line).to eq("3 Rue Marx Dormoy, 13004 Marseille")
|
31
|
-
end
|
32
|
-
|
33
|
-
it "should remove useless commas" do
|
34
|
-
address = Address.new(
|
35
|
-
street: "3 Rue Marx Dormoy",
|
36
|
-
street_bis: "",
|
37
|
-
zip: "",
|
38
|
-
city: "Marseille",
|
39
|
-
country: "",
|
40
|
-
)
|
41
|
-
|
42
|
-
expect(address.one_line).to eq("3 Rue Marx Dormoy, Marseille")
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
require "rails_helper"
|
2
|
-
|
3
|
-
describe ::Dorsale::Alexandrie::Attachment, type: :model do
|
4
|
-
it { is_expected.to belong_to :attachable }
|
5
|
-
it { is_expected.to belong_to :sender }
|
6
|
-
it { is_expected.to belong_to :attachment_type }
|
7
|
-
|
8
|
-
it { is_expected.to validate_presence_of :attachable }
|
9
|
-
it { is_expected.to validate_presence_of :file }
|
10
|
-
|
11
|
-
it { is_expected.to_not validate_presence_of :attachment_type }
|
12
|
-
it { is_expected.to_not validate_presence_of :sender }
|
13
|
-
|
14
|
-
it "factory should be valid" do
|
15
|
-
expect(create(:alexandrie_attachment)).to be_valid
|
16
|
-
end
|
17
|
-
|
18
|
-
it "should assign default name" do
|
19
|
-
attachment = create(:alexandrie_attachment, name: nil)
|
20
|
-
expect(attachment.name).to eq "pdf.pdf"
|
21
|
-
end
|
22
|
-
|
23
|
-
it "download_filename should be valid" do
|
24
|
-
attachment = create(:alexandrie_attachment)
|
25
|
-
expect(attachment.download_filename).to eq "pdf.pdf"
|
26
|
-
|
27
|
-
attachment = create(:alexandrie_attachment, name: "hello")
|
28
|
-
expect(attachment.download_filename).to eq "hello.pdf"
|
29
|
-
|
30
|
-
attachment = create(:alexandrie_attachment, name: "hello.pdf")
|
31
|
-
expect(attachment.download_filename).to eq "hello.pdf"
|
32
|
-
|
33
|
-
attachment = create(:alexandrie_attachment, name: "hello.xls")
|
34
|
-
expect(attachment.download_filename).to eq "hello-xls.pdf"
|
35
|
-
end
|
36
|
-
end
|
@@ -1,11 +0,0 @@
|
|
1
|
-
require "rails_helper"
|
2
|
-
|
3
|
-
describe ::Dorsale::Alexandrie::AttachmentType, type: :model do
|
4
|
-
it { is_expected.to have_many(:attachments).dependent(:nullify) }
|
5
|
-
|
6
|
-
it { is_expected.to validate_presence_of :name }
|
7
|
-
|
8
|
-
it "factory should be valid" do
|
9
|
-
expect(create(:alexandrie_attachment_type)).to be_valid
|
10
|
-
end
|
11
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
require "rails_helper"
|
2
|
-
|
3
|
-
describe Dorsale::BillingMachine::InvoiceLine, type: :model do
|
4
|
-
it { is_expected.to belong_to :invoice }
|
5
|
-
it { is_expected.to validate_presence_of :invoice }
|
6
|
-
|
7
|
-
it { is_expected.to respond_to :quantity }
|
8
|
-
it { is_expected.to respond_to :label }
|
9
|
-
it { is_expected.to respond_to :vat_rate }
|
10
|
-
it { is_expected.to respond_to :total }
|
11
|
-
it { is_expected.to respond_to :unit }
|
12
|
-
it { is_expected.to respond_to :unit_price }
|
13
|
-
|
14
|
-
it "should have a valid factory" do
|
15
|
-
expect(build(:billing_machine_invoice_line)).to be_valid
|
16
|
-
end
|
17
|
-
|
18
|
-
describe "default values" do
|
19
|
-
it "quantity should be 0" do
|
20
|
-
expect(described_class.new.quantity).to eq 0
|
21
|
-
end
|
22
|
-
|
23
|
-
it "unit_price should be 0" do
|
24
|
-
expect(described_class.new.unit_price).to eq 0
|
25
|
-
end
|
26
|
-
|
27
|
-
it "vat_rate should be 0" do
|
28
|
-
expect(described_class.new.vat_rate).to eq Dorsale::BillingMachine.default_vat_rate
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should be sorted by created_at" do
|
33
|
-
line1 = create(:billing_machine_invoice_line, :created_at => Time.zone.now + 1.minute)
|
34
|
-
line2 = create(:billing_machine_invoice_line, :created_at => Time.zone.now + 2.minutes)
|
35
|
-
line3 = create(:billing_machine_invoice_line, :created_at => Time.zone.now + 3.minutes)
|
36
|
-
line4 = create(:billing_machine_invoice_line, :created_at => Time.zone.now + 4.minutes)
|
37
|
-
line3.update!(:created_at => Time.zone.now + 5.minutes)
|
38
|
-
|
39
|
-
lines = described_class.all
|
40
|
-
expect(lines).to eq [line1, line2, line4, line3]
|
41
|
-
end
|
42
|
-
|
43
|
-
it "should update the total upon save" do
|
44
|
-
line = create(:billing_machine_invoice_line, quantity: 12.34, unit_price: 12.34, total: 0)
|
45
|
-
expect(line.total.to_f).to eq 152.28
|
46
|
-
end
|
47
|
-
|
48
|
-
it "should update the total gracefully with invalid data" do
|
49
|
-
line = create(:billing_machine_invoice_line, quantity: nil, unit_price: nil, total: 0)
|
50
|
-
expect(line.total.to_f).to eq 0
|
51
|
-
end
|
52
|
-
end
|
@@ -1,258 +0,0 @@
|
|
1
|
-
require "rails_helper"
|
2
|
-
|
3
|
-
describe Dorsale::BillingMachine::Invoice, type: :model do
|
4
|
-
# Reset to default mode before each test
|
5
|
-
before :each do
|
6
|
-
::Dorsale::BillingMachine.vat_mode = :single
|
7
|
-
end
|
8
|
-
|
9
|
-
it { is_expected.to belong_to :customer }
|
10
|
-
it { is_expected.to belong_to :payment_term }
|
11
|
-
it { is_expected.to have_many(:lines).dependent(:destroy) }
|
12
|
-
|
13
|
-
it { is_expected.to validate_presence_of :date }
|
14
|
-
|
15
|
-
it { is_expected.to respond_to :date }
|
16
|
-
it { is_expected.to respond_to :label }
|
17
|
-
it { is_expected.to respond_to :vat_amount }
|
18
|
-
it { is_expected.to respond_to :unique_index }
|
19
|
-
it { is_expected.to respond_to :commercial_discount }
|
20
|
-
|
21
|
-
it { is_expected.to respond_to :total_excluding_taxes }
|
22
|
-
it { is_expected.to respond_to :total_including_taxes }
|
23
|
-
|
24
|
-
it { is_expected.to respond_to :advance }
|
25
|
-
|
26
|
-
it "should have a valid factory" do
|
27
|
-
expect(create(:billing_machine_invoice)).to be_valid
|
28
|
-
end
|
29
|
-
|
30
|
-
it "should return document_type" do
|
31
|
-
expect(described_class.new.document_type).to eq :invoice
|
32
|
-
end
|
33
|
-
|
34
|
-
describe "unique_index" do
|
35
|
-
context "when unique index is 69" do
|
36
|
-
it "should be assigned upon creation" do
|
37
|
-
invoice1 = create(:billing_machine_invoice, date: "2014-02-01", unique_index: 69)
|
38
|
-
invoice2 = create(:billing_machine_invoice, date: "2014-02-01")
|
39
|
-
expect(invoice2.unique_index).to eq(70)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
context "when unique index is nil" do
|
44
|
-
it "should be assigned upon creation" do
|
45
|
-
described_class.destroy_all
|
46
|
-
invoice1 = create(:billing_machine_invoice, date: "2014-02-01")
|
47
|
-
expect(invoice1.unique_index).to eq(1)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
describe "tracking_id" do
|
53
|
-
it "should return correct tracking_id" do
|
54
|
-
invoice = create(:billing_machine_invoice, date: "2014-02-01")
|
55
|
-
expect(invoice.tracking_id).to eq("2014-01")
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
describe "payment_status" do
|
60
|
-
it "should be pending if nothing special" do
|
61
|
-
invoice = create(:billing_machine_invoice,
|
62
|
-
:due_date => Date.current,
|
63
|
-
:date => Date.current,
|
64
|
-
:paid => false,
|
65
|
-
)
|
66
|
-
expect(invoice.payment_status).to eq(:pending)
|
67
|
-
end
|
68
|
-
|
69
|
-
it "should be late if a bit late" do
|
70
|
-
invoice = create(:billing_machine_invoice,
|
71
|
-
:due_date => Date.current-1,
|
72
|
-
:date => Date.current-1,
|
73
|
-
:paid => false,
|
74
|
-
)
|
75
|
-
expect(invoice.payment_status).to eq(:late)
|
76
|
-
end
|
77
|
-
|
78
|
-
it "should be on_alert if a too late" do
|
79
|
-
invoice = create(:billing_machine_invoice,
|
80
|
-
:due_date => Date.current-16,
|
81
|
-
:date => Date.current-16,
|
82
|
-
:paid => false,
|
83
|
-
)
|
84
|
-
expect(invoice.payment_status).to eq(:on_alert)
|
85
|
-
end
|
86
|
-
|
87
|
-
it "should be paid if paid" do
|
88
|
-
invoice = create(:billing_machine_invoice,
|
89
|
-
:due_date => Date.current-16,
|
90
|
-
:date => Date.current-16,
|
91
|
-
:paid => true,
|
92
|
-
)
|
93
|
-
expect(invoice.payment_status).to eq(:paid)
|
94
|
-
end
|
95
|
-
|
96
|
-
it "should be on_alert if no due date is defined" do
|
97
|
-
invoice = create(:billing_machine_invoice, due_date: nil, date: Date.current, paid: false)
|
98
|
-
expect(invoice.payment_status).to eq(:on_alert)
|
99
|
-
end
|
100
|
-
|
101
|
-
it "should be on_alert if no due date is defined" do
|
102
|
-
invoice = create(:billing_machine_invoice, due_date: nil, date: Date.current, paid: true)
|
103
|
-
expect(invoice.payment_status).to eq(:paid)
|
104
|
-
end
|
105
|
-
|
106
|
-
it "should work fine upon creation" do
|
107
|
-
invoice = build(:billing_machine_invoice)
|
108
|
-
invoice.lines << ::Dorsale::BillingMachine::InvoiceLine.new(quantity: 1, unit_price: 10)
|
109
|
-
invoice.lines << ::Dorsale::BillingMachine::InvoiceLine.new(quantity: 1, unit_price: 10)
|
110
|
-
invoice.save!
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
describe "paid" do
|
115
|
-
it "should be false by default" do
|
116
|
-
invoice = create(:billing_machine_invoice)
|
117
|
-
expect(invoice.paid).to eq(false)
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
describe "vat rate" do
|
122
|
-
it "default vat rate should be 20" do
|
123
|
-
expect(described_class.new.vat_rate).to eq ::Dorsale::BillingMachine.default_vat_rate
|
124
|
-
end
|
125
|
-
|
126
|
-
it "it should be specified vat rate" do
|
127
|
-
expect(build(:billing_machine_invoice, vat_rate: 12).vat_rate).to eq 12
|
128
|
-
end
|
129
|
-
|
130
|
-
it "it should be first line vat rate" do
|
131
|
-
invoice = create(:billing_machine_invoice)
|
132
|
-
line1 = create(:billing_machine_invoice_line, invoice: invoice, vat_rate: 10)
|
133
|
-
line2 = create(:billing_machine_invoice_line, invoice: invoice, vat_rate: 10)
|
134
|
-
expect(invoice.vat_rate).to eq 10
|
135
|
-
end
|
136
|
-
|
137
|
-
it "it should raise if multiple vat_rates" do
|
138
|
-
invoice = create(:billing_machine_invoice)
|
139
|
-
line1 = create(:billing_machine_invoice_line, invoice: invoice, vat_rate: 10)
|
140
|
-
|
141
|
-
expect {
|
142
|
-
line2 = create(:billing_machine_invoice_line, invoice: invoice, vat_rate: 15)
|
143
|
-
}.to raise_error(RuntimeError)
|
144
|
-
end
|
145
|
-
|
146
|
-
it "it should raise when vat mode is multiple" do
|
147
|
-
::Dorsale::BillingMachine.vat_mode = :multiple
|
148
|
-
invoice = build(:billing_machine_invoice)
|
149
|
-
expect { invoice.vat_rate }.to raise_error(RuntimeError)
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
describe "totals" do
|
154
|
-
it "should be calculated upon saving with advance" do
|
155
|
-
invoice = create(:billing_machine_invoice,
|
156
|
-
:commercial_discount => 10,
|
157
|
-
:advance => 40,
|
158
|
-
)
|
159
|
-
|
160
|
-
create(:billing_machine_invoice_line,
|
161
|
-
:quantity => 10,
|
162
|
-
:unit_price => 5,
|
163
|
-
:vat_rate => 20,
|
164
|
-
:invoice => invoice,
|
165
|
-
) # total 50
|
166
|
-
|
167
|
-
create(:billing_machine_invoice_line,
|
168
|
-
:quantity => 10,
|
169
|
-
:unit_price => 5,
|
170
|
-
:vat_rate => 20,
|
171
|
-
:invoice => invoice,
|
172
|
-
) # total 50
|
173
|
-
|
174
|
-
expect(invoice.total_excluding_taxes).to eq(90.0)
|
175
|
-
expect(invoice.vat_amount).to eq(18)
|
176
|
-
expect(invoice.total_including_taxes).to eq(108)
|
177
|
-
expect(invoice.balance).to eq(68)
|
178
|
-
end
|
179
|
-
|
180
|
-
it "should be calculated upon saving without advance" do
|
181
|
-
invoice = create(:billing_machine_invoice,
|
182
|
-
:commercial_discount => 10,
|
183
|
-
)
|
184
|
-
|
185
|
-
create(:billing_machine_invoice_line,
|
186
|
-
:quantity => 10,
|
187
|
-
:unit_price => 5,
|
188
|
-
:vat_rate => 20,
|
189
|
-
:invoice => invoice,
|
190
|
-
) # total 50
|
191
|
-
|
192
|
-
create(:billing_machine_invoice_line,
|
193
|
-
:quantity => 10,
|
194
|
-
:unit_price => 5,
|
195
|
-
:vat_rate => 20,
|
196
|
-
:invoice => invoice,
|
197
|
-
) # total 50
|
198
|
-
|
199
|
-
expect(invoice.total_excluding_taxes).to eq(90.0)
|
200
|
-
expect(invoice.vat_amount).to eq(18)
|
201
|
-
expect(invoice.total_including_taxes).to eq(108)
|
202
|
-
expect(invoice.balance).to eq(108)
|
203
|
-
end
|
204
|
-
|
205
|
-
describe "VAT round" do
|
206
|
-
let(:invoice) {
|
207
|
-
invoice = create(:billing_machine_invoice,
|
208
|
-
:commercial_discount => 0,
|
209
|
-
)
|
210
|
-
|
211
|
-
create(:billing_machine_invoice_line,
|
212
|
-
:quantity => 12.34,
|
213
|
-
:unit_price => 12.34,
|
214
|
-
:vat_rate => 20,
|
215
|
-
:invoice => invoice,
|
216
|
-
) # vat 30.45512 / total 152.2756
|
217
|
-
|
218
|
-
create(:billing_machine_invoice_line,
|
219
|
-
:quantity => 12.34,
|
220
|
-
:unit_price => 12.34,
|
221
|
-
:vat_rate => 20,
|
222
|
-
:invoice => invoice,
|
223
|
-
) # vat 30.45512 / total 152.2756
|
224
|
-
|
225
|
-
invoice
|
226
|
-
}
|
227
|
-
|
228
|
-
after { Dorsale::BillingMachine.vat_round_by_line = nil }
|
229
|
-
|
230
|
-
it "should round VAT by line" do
|
231
|
-
Dorsale::BillingMachine.vat_round_by_line = true
|
232
|
-
expect(invoice.total_excluding_taxes.to_f).to eq(304.56)
|
233
|
-
expect(invoice.vat_amount.to_f).to eq(60.92)
|
234
|
-
expect(invoice.total_including_taxes.to_f).to eq(365.48)
|
235
|
-
expect(invoice.balance.to_f).to eq(365.48)
|
236
|
-
end
|
237
|
-
|
238
|
-
it "should round VAT globally" do
|
239
|
-
Dorsale::BillingMachine.vat_round_by_line = false
|
240
|
-
expect(invoice.total_excluding_taxes.to_f).to eq(304.56)
|
241
|
-
expect(invoice.vat_amount.to_f).to eq(60.91)
|
242
|
-
expect(invoice.total_including_taxes.to_f).to eq(365.47)
|
243
|
-
expect(invoice.balance.to_f).to eq(365.47)
|
244
|
-
end
|
245
|
-
end # describe "VAT round"
|
246
|
-
|
247
|
-
it "should work fine even with empty lines" do
|
248
|
-
invoice = create(:billing_machine_invoice)
|
249
|
-
|
250
|
-
create(:billing_machine_invoice_line, invoice: invoice, quantity: nil, unit_price: nil)
|
251
|
-
|
252
|
-
expect(invoice.total_excluding_taxes).to eq(0.0)
|
253
|
-
expect(invoice.vat_amount).to eq(0)
|
254
|
-
expect(invoice.total_including_taxes).to eq(0)
|
255
|
-
expect(invoice.balance).to eq(0)
|
256
|
-
end
|
257
|
-
end
|
258
|
-
end
|