ydim 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitattributes +1 -0
- data/.gitignore +6 -0
- data/.travis.yml +26 -0
- data/Gemfile +11 -0
- data/History.txt +7 -2
- data/Rakefile +16 -23
- data/bin/migrate_to_utf_8 +201 -0
- data/bin/ydim-edit +7 -1
- data/bin/ydim-inject +2 -1
- data/bin/ydimd +4 -2
- data/lib/pdfinvoice/config.rb +53 -0
- data/lib/pdfinvoice/invoice.rb +203 -0
- data/lib/ydim/config.rb +1 -1
- data/lib/ydim/factory.rb +1 -0
- data/lib/ydim/invoice.rb +22 -1
- data/lib/ydim/odba.rb +1 -0
- data/lib/ydim/root_session.rb +12 -5
- data/lib/ydim/server.rb +6 -3
- data/lib/ydim/version.rb +3 -0
- data/readme.md +29 -0
- data/set_initial_ydim_db.sql +440 -0
- data/test/data/config.yml +44 -0
- data/test/data/logo.png +0 -0
- data/test/suite.rb +9 -4
- data/test/test_autoinvoicer.rb +3 -3
- data/test/test_currency_converter.rb +3 -2
- data/test/test_currency_updater.rb +3 -3
- data/test/test_debitor.rb +3 -3
- data/test/test_factory.rb +5 -6
- data/test/test_invoice.rb +69 -23
- data/test/test_item.rb +6 -4
- data/test/test_mail.rb +10 -5
- data/test/test_root_session.rb +15 -15
- data/test/test_root_user.rb +3 -2
- data/test/test_server.rb +7 -14
- data/ydim.gemspec +40 -0
- metadata +302 -72
- data/README.txt +0 -21
@@ -0,0 +1,44 @@
|
|
1
|
+
---
|
2
|
+
# encoding: utf-8
|
3
|
+
creditor_email: zdavatz@ywesee.com
|
4
|
+
creditor_address: |
|
5
|
+
ywesee GmbH
|
6
|
+
Winterthurerstrasse 52
|
7
|
+
CH-8006 Zürich
|
8
|
+
Schweiz
|
9
|
+
creditor_bank: |
|
10
|
+
MwSt-Nummer: CHE-112.233.959 MWST
|
11
|
+
UBS-Römerhof Zürich
|
12
|
+
Kontonummer: 830024.01Z, Clearingnummer: 251
|
13
|
+
IBAN: CH870025125183002401Z
|
14
|
+
BIC: UBSWCHZH80A
|
15
|
+
due_days: "Bedingungen: zahlbar in 10 Tagen"
|
16
|
+
logo_path: /tmp/ywesee_logo.png
|
17
|
+
formats:
|
18
|
+
currency: '%1.2f'
|
19
|
+
date: '%d.%m.%Y'
|
20
|
+
invoice_number: "<b>Rechnung %s</b>"
|
21
|
+
quantity: '%1.1f'
|
22
|
+
total: 'CHF %1.2f'
|
23
|
+
logo_link:
|
24
|
+
:type: :external
|
25
|
+
:target: http://www.ywesee.com
|
26
|
+
tax: 0.080
|
27
|
+
texts:
|
28
|
+
date: Datum
|
29
|
+
description: Beschreibung
|
30
|
+
unit: Einheit
|
31
|
+
quantity: Anzahl
|
32
|
+
price: Preis
|
33
|
+
item_total: Betrag
|
34
|
+
subtotal: Zwischensumme
|
35
|
+
tax: MwSt 8.0%
|
36
|
+
thanks: |
|
37
|
+
Ohne Ihre Gegenmeldung erfolgt der Rechnungsversand nur per Email.
|
38
|
+
Thank you for your patronage!
|
39
|
+
|
40
|
+
Mit freundlichen Grüssen
|
41
|
+
Zeno Davatz
|
42
|
+
zdavatz@ywesee.com
|
43
|
+
043 540 05 50
|
44
|
+
total: Fälliger Betrag
|
data/test/data/logo.png
ADDED
Binary file
|
data/test/suite.rb
CHANGED
@@ -1,10 +1,15 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# TestSuite -- ydim -- 27.01.2005 -- hwyss@ywesee.com
|
3
|
+
require 'simplecov'
|
3
4
|
|
4
5
|
$: << File.dirname(File.expand_path(__FILE__))
|
5
|
-
|
6
|
-
|
6
|
+
SimpleCov.start :rails do
|
7
|
+
add_filter do |src|
|
8
|
+
src.filename =~ /vendo/
|
9
|
+
end
|
10
|
+
end
|
11
|
+
Dir.foreach(File.dirname(__FILE__)) do |file|
|
7
12
|
if /^test_.*\.rb$/o.match(file)
|
8
|
-
require file
|
13
|
+
require file
|
9
14
|
end
|
10
|
-
|
15
|
+
end
|
data/test/test_autoinvoicer.rb
CHANGED
@@ -3,13 +3,13 @@
|
|
3
3
|
|
4
4
|
$: << File.expand_path('../lib', File.dirname(__FILE__))
|
5
5
|
|
6
|
-
require '
|
7
|
-
require 'flexmock'
|
6
|
+
require 'minitest/autorun'
|
7
|
+
require 'flexmock/test_unit'
|
8
8
|
require 'ydim/autoinvoicer'
|
9
9
|
require 'ydim/invoice'
|
10
10
|
|
11
11
|
module YDIM
|
12
|
-
class TestAutoInvoicer < Test
|
12
|
+
class TestAutoInvoicer < Minitest::Test
|
13
13
|
include FlexMock::TestCase
|
14
14
|
def setup
|
15
15
|
@serv = flexmock('Registry')
|
@@ -3,11 +3,12 @@
|
|
3
3
|
|
4
4
|
$: << File.expand_path('../lib', File.dirname(__FILE__))
|
5
5
|
|
6
|
-
require '
|
6
|
+
require 'minitest/autorun'
|
7
|
+
require 'flexmock/test_unit'
|
7
8
|
require 'ydim/currency_converter'
|
8
9
|
|
9
10
|
module YDIM
|
10
|
-
class TestCurrencyConverter < Test
|
11
|
+
class TestCurrencyConverter < Minitest::Test
|
11
12
|
def setup
|
12
13
|
@converter = CurrencyConverter.new
|
13
14
|
end
|
@@ -4,12 +4,12 @@
|
|
4
4
|
|
5
5
|
$: << File.expand_path('../lib', File.dirname(__FILE__))
|
6
6
|
|
7
|
-
require '
|
7
|
+
require 'minitest/autorun'
|
8
|
+
require 'flexmock/test_unit'
|
8
9
|
require 'ydim/currency_updater'
|
9
|
-
require 'flexmock'
|
10
10
|
|
11
11
|
module YDIM
|
12
|
-
class TestCurrencyUpdater < Test
|
12
|
+
class TestCurrencyUpdater < Minitest::Test
|
13
13
|
include FlexMock::TestCase
|
14
14
|
def setup
|
15
15
|
@serv = flexmock('Config')
|
data/test/test_debitor.rb
CHANGED
@@ -3,13 +3,13 @@
|
|
3
3
|
|
4
4
|
$: << File.expand_path('../lib', File.dirname(__FILE__))
|
5
5
|
|
6
|
-
require '
|
6
|
+
require 'minitest/autorun'
|
7
|
+
require 'flexmock/test_unit'
|
7
8
|
require 'ydim/debitor'
|
8
|
-
require 'flexmock'
|
9
9
|
require 'date'
|
10
10
|
|
11
11
|
module YDIM
|
12
|
-
class TestDebitor < Test
|
12
|
+
class TestDebitor < Minitest::Test
|
13
13
|
include FlexMock::TestCase
|
14
14
|
def setup
|
15
15
|
@debitor = Debitor.new(1)
|
data/test/test_factory.rb
CHANGED
@@ -4,13 +4,13 @@
|
|
4
4
|
$: << File.dirname(__FILE__)
|
5
5
|
$: << File.expand_path('../lib', File.dirname(__FILE__))
|
6
6
|
|
7
|
-
require '
|
7
|
+
require 'minitest/autorun'
|
8
|
+
require 'flexmock/test_unit'
|
8
9
|
require 'stub/odba'
|
9
|
-
require 'flexmock'
|
10
10
|
require 'ydim/factory'
|
11
11
|
|
12
12
|
module YDIM
|
13
|
-
class TestFactory < Test
|
13
|
+
class TestFactory < Minitest::Test
|
14
14
|
include FlexMock::TestCase
|
15
15
|
def setup
|
16
16
|
@id_server = flexmock('IdServer')
|
@@ -39,7 +39,7 @@ module YDIM
|
|
39
39
|
dinvs
|
40
40
|
}
|
41
41
|
invoice = nil
|
42
|
-
|
42
|
+
invoice = @factory.create_invoice(debitor)
|
43
43
|
assert_instance_of(Invoice, invoice)
|
44
44
|
end
|
45
45
|
def test_create_autoinvoice
|
@@ -61,8 +61,7 @@ module YDIM
|
|
61
61
|
dinvs
|
62
62
|
}
|
63
63
|
invoice = nil
|
64
|
-
|
65
|
-
invoice = @factory.create_autoinvoice(debitor) }
|
64
|
+
invoice = @factory.create_autoinvoice(debitor)
|
66
65
|
assert_instance_of(AutoInvoice, invoice)
|
67
66
|
end
|
68
67
|
def test_generate_invoice
|
data/test/test_invoice.rb
CHANGED
@@ -1,27 +1,29 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
2
4
|
# TestInvoice -- ydim -- 11.01.2006 -- hwyss@ywesee.com
|
3
5
|
|
4
6
|
$: << File.expand_path('../lib', File.dirname(__FILE__))
|
5
7
|
|
6
|
-
require '
|
7
|
-
require 'flexmock'
|
8
|
+
require 'minitest/autorun'
|
9
|
+
require 'flexmock/test_unit'
|
8
10
|
require 'ydim/invoice'
|
9
11
|
|
10
12
|
module YDIM
|
11
|
-
class TestInvoice < Test
|
13
|
+
class TestInvoice < Minitest::Test
|
12
14
|
include FlexMock::TestCase
|
13
15
|
def setup
|
14
|
-
|
16
|
+
@invoice = Invoice.new(23)
|
15
17
|
end
|
16
18
|
def test_add_item
|
17
19
|
assert_equal([], @invoice.items)
|
18
20
|
item_id = 0
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
21
|
+
item = FlexMock.new
|
22
|
+
item.should_receive(:index=, 2).and_return { |idx|
|
23
|
+
assert_equal(item_id, idx)
|
24
|
+
item_id += 1
|
25
|
+
}
|
26
|
+
retval = @invoice.add_item(item)
|
25
27
|
assert_equal([item], @invoice.items)
|
26
28
|
assert_equal(item, retval)
|
27
29
|
retval = @invoice.add_item(item)
|
@@ -62,18 +64,52 @@ module YDIM
|
|
62
64
|
assert_nil(@invoice.due_date)
|
63
65
|
end
|
64
66
|
def test_pdf_invoice
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
67
|
+
@invoice = Invoice.new(23)
|
68
|
+
|
69
|
+
debitor = FlexMock.new
|
70
|
+
debitor.should_receive(:add_invoice, 1).and_return { |arg|
|
71
|
+
assert_equal(@invoice, arg)
|
72
|
+
}
|
73
|
+
debitor.should_receive(:address).and_return { ['address'] }
|
74
|
+
@invoice.debitor = debitor
|
75
|
+
@invoice.description = 'description'
|
76
|
+
item = flexmock('item')
|
77
|
+
item_id = 0
|
78
|
+
item.should_receive(:index=).and_return { |idx| item_id += 1 }
|
79
|
+
item.should_receive(:vat_rate).and_return(7.6)
|
80
|
+
item.should_receive(:text).and_return('item text')
|
81
|
+
item.should_receive(:unit).and_return('hours')
|
82
|
+
item.should_receive(:quantity).and_return(3)
|
83
|
+
item.should_receive(:price).and_return(13)
|
84
|
+
item.should_receive(:vat).and_return(4)
|
85
|
+
@invoice.date = Date.new(2015, 1, 30)
|
86
|
+
item.should_receive(:time).and_return( @invoice.date.to_time)
|
87
|
+
@invoice.add_item(item)
|
88
|
+
user_pdfinvoice = File.join(Dir.home, '.pdfinvoice')
|
89
|
+
FileUtils.rm_rf(user_pdfinvoice)
|
90
|
+
FileUtils.makedirs(user_pdfinvoice)
|
91
|
+
FileUtils.cp(File.join(File.dirname(__FILE__), 'data', 'config.yml'), user_pdfinvoice)
|
92
|
+
FileUtils.cp(File.join(File.dirname(__FILE__), 'data', 'logo.png'), '/tmp/ywesee_logo.png')
|
93
|
+
pdf = @invoice.pdf_invoice({})
|
94
|
+
assert_instance_of(PdfInvoice::Invoice, pdf)
|
95
|
+
pdf_output = 'tst.pdf'
|
96
|
+
pdf_as_txt = 'tst.txt'
|
97
|
+
FileUtils.rm(pdf_output) if File.exist?(pdf_output)
|
98
|
+
FileUtils.rm(pdf_as_txt) if File.exist?(pdf_as_txt)
|
99
|
+
content = pdf.to_pdf
|
100
|
+
File.open(pdf_output, 'w+') {|f| f.write content } if $VERBOSE
|
101
|
+
assert_match(/Bedingungen/, content)
|
102
|
+
assert_match(/Rechnung 23/, content)
|
103
|
+
assert_match(/30.01.2015/, content)
|
104
|
+
assert_match(/Clearing/, content)
|
105
|
+
assert_match(/Beschreibung/, content)
|
106
|
+
assert_match(/Ohne Ihre Gegenmeldung/, content)
|
107
|
+
assert_match(/Mit freundlichen/, content)
|
108
|
+
assert_match(/MwSt/, content)
|
109
|
+
assert_equal(['address'], pdf.debitor_address)
|
110
|
+
assert_equal(23, pdf.invoice_number)
|
111
|
+
assert_equal('description', pdf.description)
|
112
|
+
assert(content.size > 10000, "PDF output must be > 10 Kb, or the Logo is missing. Is #{content.size} bytes. ")
|
77
113
|
end
|
78
114
|
def test_status
|
79
115
|
@invoice.date = Date.today
|
@@ -95,9 +131,19 @@ module YDIM
|
|
95
131
|
item = flexmock('item')
|
96
132
|
@invoice.items.push(item)
|
97
133
|
assert_equal(false, @invoice.empty?)
|
134
|
+
end
|
135
|
+
def test_date_must_be_current
|
136
|
+
refute_nil(@invoice.date, 'A new invoice must have the current year by default')
|
137
|
+
assert_equal(Date.today.year, @invoice.date.year)
|
138
|
+
end
|
139
|
+
def test_date_must_be_fixed
|
140
|
+
@invoice.date= Date.new(-4712, 1, 1)
|
141
|
+
item = Item.new({:time => Time.now})
|
142
|
+
@invoice.add_item(Item.new({:time => Time.now}))
|
143
|
+
assert_equal(Date.today.year, @invoice.date.year)
|
98
144
|
end
|
99
145
|
end
|
100
|
-
class TestAutoInvoice < Test
|
146
|
+
class TestAutoInvoice < Minitest::Test
|
101
147
|
def setup
|
102
148
|
@invoice = AutoInvoice.new(23)
|
103
149
|
end
|
data/test/test_item.rb
CHANGED
@@ -1,22 +1,24 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
2
3
|
# TestItem -- ydim -- 12.01.2006 -- hwyss@ywesee.com
|
3
4
|
|
4
5
|
$: << File.expand_path('../lib', File.dirname(__FILE__))
|
5
6
|
|
6
|
-
require '
|
7
|
+
require 'minitest/autorun'
|
8
|
+
require 'flexmock/test_unit'
|
7
9
|
require 'ydim/item'
|
8
10
|
|
9
11
|
module YDIM
|
10
|
-
class TestItem < Test
|
12
|
+
class TestItem < Minitest::Test
|
11
13
|
def test_initialize
|
12
14
|
time = Time.now
|
13
15
|
data = {
|
14
|
-
:quantity => 1, :unit => '
|
16
|
+
:quantity => 1, :unit => 'Stück', :text => 'Item 1', :price => 10.00,
|
15
17
|
:vat_rate => 7.6, :data => {}, :time => time, :expiry_time => nil
|
16
18
|
}
|
17
19
|
item = Item.new(data)
|
18
20
|
assert_equal(1, item.quantity)
|
19
|
-
assert_equal('
|
21
|
+
assert_equal('Stück', item.unit)
|
20
22
|
assert_equal('Item 1', item.text)
|
21
23
|
assert_equal(10.0, item.price)
|
22
24
|
assert_equal(7.6, item.vat_rate)
|
data/test/test_mail.rb
CHANGED
@@ -3,12 +3,12 @@
|
|
3
3
|
|
4
4
|
$: << File.expand_path('../lib', File.dirname(__FILE__))
|
5
5
|
|
6
|
-
require '
|
6
|
+
require 'minitest/autorun'
|
7
|
+
require 'flexmock/test_unit'
|
7
8
|
require 'ydim/mail'
|
8
|
-
require 'flexmock'
|
9
9
|
|
10
10
|
module YDIM
|
11
|
-
class TestMail < Test
|
11
|
+
class TestMail < Minitest::Test
|
12
12
|
include FlexMock::TestCase
|
13
13
|
def setup_config
|
14
14
|
config = flexmock('Config')
|
@@ -29,6 +29,11 @@ module YDIM
|
|
29
29
|
}
|
30
30
|
config.should_receive(:smtp_from).and_return('smtp@ywesee.com')
|
31
31
|
config.should_receive(:smtp_server).and_return('localhost')
|
32
|
+
config.should_receive(:smtp_port).and_return('123')
|
33
|
+
config.should_receive(:smtp_domain).and_return('ywesee.com')
|
34
|
+
config.should_receive(:smtp_user).and_return('user')
|
35
|
+
config.should_receive(:smtp_pass).and_return('pass')
|
36
|
+
config.should_receive(:smtp_authtype).and_return('plain')
|
32
37
|
config
|
33
38
|
end
|
34
39
|
def test_body
|
@@ -57,7 +62,7 @@ module YDIM
|
|
57
62
|
invoice.should_receive(:to_pdf).times(1).and_return('pdf-document')
|
58
63
|
smtp = flexmock('SMTP')
|
59
64
|
flexstub(Net::SMTP).should_receive(:new).and_return(smtp)
|
60
|
-
smtp.should_receive(:start)
|
65
|
+
smtp.should_receive(:start)
|
61
66
|
smtp.should_receive(:sendmail).with(String,
|
62
67
|
'smtp@ywesee.com', 'cc@ywesee.com').and_return { assert(true) }
|
63
68
|
smtp.should_receive(:sendmail).with(String,
|
@@ -81,7 +86,7 @@ module YDIM
|
|
81
86
|
invoice.should_receive(:reminder_body).and_return('Reminder Body')
|
82
87
|
smtp = flexmock('SMTP')
|
83
88
|
flexstub(Net::SMTP).should_receive(:new).and_return(smtp)
|
84
|
-
smtp.should_receive(:start)
|
89
|
+
smtp.should_receive(:start)
|
85
90
|
smtp.should_receive(:sendmail).with(String,
|
86
91
|
'smtp@ywesee.com', 'cc@ywesee.com').and_return { assert(true) }
|
87
92
|
smtp.should_receive(:sendmail).with(String,
|
data/test/test_root_session.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
2
3
|
# TestRootSession -- ydim -- 10.01.2006 -- hwyss@ywesee.com
|
3
|
-
|
4
|
-
|
5
4
|
$: << File.expand_path('../lib', File.dirname(__FILE__))
|
5
|
+
$: << File.dirname(__FILE__)
|
6
6
|
|
7
|
-
require '
|
8
|
-
require '
|
7
|
+
require 'minitest/autorun'
|
8
|
+
require 'flexmock/test_unit'
|
9
|
+
require 'stub/odba'
|
9
10
|
require 'ydim/root_session'
|
10
|
-
require 'flexmock'
|
11
11
|
|
12
12
|
module YDIM
|
13
|
-
class TestRootSession < Test
|
13
|
+
class TestRootSession < Minitest::Test
|
14
14
|
include FlexMock::TestCase
|
15
15
|
def setup
|
16
16
|
@user = FlexMock.new
|
@@ -40,13 +40,13 @@ module YDIM
|
|
40
40
|
flexstub(Invoice).should_receive(:find_by_unique_id)\
|
41
41
|
.with('123').and_return(invoice)
|
42
42
|
items = [
|
43
|
-
{ :quantity => 1, :unit => '
|
43
|
+
{ :quantity => 1, :unit => 'Stück', :text => 'Item 1', :price => 10.00,
|
44
44
|
:vat_rate => 7.6, :data => {}, :time => Time.now, :expiry_time => nil},
|
45
|
-
{ :quantity => 2, :unit => '
|
45
|
+
{ :quantity => 2, :unit => 'Stück', :text => 'Item 2', :price => 20.00,
|
46
46
|
:vat_rate => 7.6, :data => {}, :time => Time.now, :expiry_time => nil},
|
47
|
-
{ :quantity => 3, :unit => '
|
47
|
+
{ :quantity => 3, :unit => 'Stück', :text => 'Item 3', :price => 30.00,
|
48
48
|
:vat_rate => 7.6, :data => {}, :time => Time.now, :expiry_time => nil},
|
49
|
-
{ :quantity => 4, :unit => '
|
49
|
+
{ :quantity => 4, :unit => 'Stück', :text => 'Item 4', :price => 40.00,
|
50
50
|
:vat_rate => 7.6, :data => {}, :time => Time.now, :expiry_time => nil},
|
51
51
|
]
|
52
52
|
added_items = []
|
@@ -134,7 +134,7 @@ module YDIM
|
|
134
134
|
'invoice created by Factory'
|
135
135
|
}
|
136
136
|
invoice = nil
|
137
|
-
|
137
|
+
invoice = @session.create_autoinvoice(2)
|
138
138
|
assert_equal('invoice created by Factory', invoice)
|
139
139
|
end
|
140
140
|
def test_create_debitor
|
@@ -171,7 +171,7 @@ module YDIM
|
|
171
171
|
'invoice created by Factory'
|
172
172
|
}
|
173
173
|
invoice = nil
|
174
|
-
|
174
|
+
invoice = @session.create_invoice(2)
|
175
175
|
assert_equal('invoice created by Factory', invoice)
|
176
176
|
end
|
177
177
|
def test_currency_converter
|
@@ -259,10 +259,10 @@ module YDIM
|
|
259
259
|
}
|
260
260
|
assert_equal(inv, res)
|
261
261
|
end
|
262
|
-
def
|
262
|
+
def test_invoice__error_raises
|
263
263
|
flexstub(Invoice).should_receive(:find_by_unique_id)
|
264
|
-
assert_logged(:debug, :error) {
|
265
264
|
assert_raises(IndexError) {
|
265
|
+
assert_logged(:debug, :error) {
|
266
266
|
@session.invoice(17)
|
267
267
|
}
|
268
268
|
}
|
@@ -312,7 +312,7 @@ module YDIM
|
|
312
312
|
flexstub(Invoice).should_receive(:find_by_unique_id)\
|
313
313
|
.with('17').and_return(inv)
|
314
314
|
@serv.should_receive(:config).and_return('cnf')
|
315
|
-
flexstub(Mail).should_receive(:send_invoice).with('cnf', inv)
|
315
|
+
flexstub(Mail).should_receive(:send_invoice).with('cnf', inv, {})
|
316
316
|
assert_logged(:info, :debug) {
|
317
317
|
@session.send_invoice(17)
|
318
318
|
}
|