magelex 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -0
- data/bin/anonymize +61 -0
- data/lib/magelex/bill_modifier.rb +2 -2
- data/lib/magelex/lexware_bill.rb +1 -1
- data/lib/magelex/lexware_csv.rb +16 -3
- data/lib/magelex/version.rb +1 -1
- data/lib/magelex.rb +0 -3
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0184b857c2eff1981ea6684932358aa778e174ce
|
4
|
+
data.tar.gz: ccd7cf2ea42949c582ed42fae44ae04cc4a803e1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ff3635bffbe4d5b17728ae27608cd49b8f19aa896955e43fde788a7062ed6e1a44fa6026dc96a682e791504eee0964773f1d8895bf614a32f5aa5ec752bbc4f
|
7
|
+
data.tar.gz: 4b802c922f790b677016b7f781e4fbb3ffee3e8dfa6f754711dd62e2fa8ebde00637f60ae8161fee09ad606eabddedfb75e15b76175a6b9c8b7c9a290e41cf6e
|
data/README.md
CHANGED
@@ -38,6 +38,10 @@ By default, `magelex` will log to `STDERR`, but you can pass the path to a log f
|
|
38
38
|
|
39
39
|
It consumes a single file (given as argument, as in `magelex magento_orders.csv`) or a directory of files. `magelex` will create a file with same filename in the path `lexware` (can be changed with the `--out-dir` option).
|
40
40
|
|
41
|
+
### magelex_debug
|
42
|
+
|
43
|
+
To play around with data, `magelex_debug` can help you. Nothing that couldnt be done with some proper application of shell scripting foo, but more convenient. Run `magelex_debug --help` to get an overview over possible options and arguments.
|
44
|
+
|
41
45
|
### Configuration
|
42
46
|
|
43
47
|
Configure magento MySQL database access in `magelex.conf` . An example configuration comes shipped with the gem (`magelex.conf.example`).
|
@@ -63,6 +67,11 @@ Quite something
|
|
63
67
|
|
64
68
|
## Changes
|
65
69
|
|
70
|
+
- 0.1.6:
|
71
|
+
fixed discounts in lexware output (have to be negative)\
|
72
|
+
skip rounding when consuming shipping costs
|
73
|
+
- 0.1.5:
|
74
|
+
respect existence of incorrect tax assignments when considering whether a split booking has to be done.
|
66
75
|
- 0.1.4:
|
67
76
|
respect per-item discounts
|
68
77
|
|
data/bin/anonymize
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "magelex"
|
4
|
+
|
5
|
+
def print_usage
|
6
|
+
STDOUT.puts "#{$PROGRAM_NAME} INFILE [OUTFILE]"
|
7
|
+
STDOUT.puts "Anonymizes a magento csv, outputs to STDOUT "
|
8
|
+
STDOUT.puts "if no OUTFILE is given."
|
9
|
+
end
|
10
|
+
|
11
|
+
if ARGV.length < 1
|
12
|
+
print_usage
|
13
|
+
STDERR.puts "Need an FILE argument"
|
14
|
+
exit 1
|
15
|
+
end
|
16
|
+
|
17
|
+
if ARGV.length > 1
|
18
|
+
outfile = ARGV[1]
|
19
|
+
else
|
20
|
+
outfile = "-"
|
21
|
+
end
|
22
|
+
|
23
|
+
if File.file?(outfile) && File.exist?(outfile)
|
24
|
+
print_usage
|
25
|
+
STDERR.puts "Output file #{outfile} already exists."
|
26
|
+
exit 2
|
27
|
+
end
|
28
|
+
|
29
|
+
# CSV read. Keep fields. Change fields. CSV write.
|
30
|
+
|
31
|
+
KEEP_FIELDS = ["Order Number","Order Date","Order Status","Order Subtotal","Order Tax","Order Shipping","Order Discount","Order Grand Total","Order Base Grand Total","Customer Name","Shipping Country","Shipping Country Name","Billing Name","Billing Country","Billing Country Name","Item Name","Item Status","Item Original Price","Item Price","Item Qty Ordered","Item Qty Invoiced","Item Tax","Item Discount","Item Total"]
|
32
|
+
|
33
|
+
out_rows = []
|
34
|
+
CSV::foreach(ARGV[0], headers: :first_row) do |row|
|
35
|
+
out_rows << KEEP_FIELDS.map{|f| row[f]}
|
36
|
+
end
|
37
|
+
|
38
|
+
order_nr_idx = KEEP_FIELDS.index('Order Number')
|
39
|
+
customer_name_idx = KEEP_FIELDS.index('Customer Name')
|
40
|
+
billing_name_idx = KEEP_FIELDS.index('Billing Name')
|
41
|
+
|
42
|
+
# 'Anonymisation'
|
43
|
+
out_rows.each do |r|
|
44
|
+
r[customer_name_idx] = "Ano Sno#{r[order_nr_idx]}den Mous"
|
45
|
+
r[billing_name_idx] = "Ano Sno#{r[order_nr_idx]}den Mous"
|
46
|
+
end
|
47
|
+
|
48
|
+
csv_s = CSV::generate do |csv|
|
49
|
+
csv << KEEP_FIELDS
|
50
|
+
out_rows.each do |r|
|
51
|
+
csv << r
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
if outfile == "-"
|
56
|
+
puts csv_s
|
57
|
+
else
|
58
|
+
File.open(outfile, 'w') do |f|
|
59
|
+
f.write csv_s
|
60
|
+
end
|
61
|
+
end
|
@@ -14,10 +14,10 @@ module Magelex
|
|
14
14
|
|
15
15
|
def self.process_shipping_costs bill
|
16
16
|
if bill.swiss?
|
17
|
-
bill.total_0 +=
|
17
|
+
bill.total_0 += bill.shipping_cost
|
18
18
|
else
|
19
19
|
bill.tax_19 += bill.shipping_cost * 0.19
|
20
|
-
bill.total_19 +=
|
20
|
+
bill.total_19 += (bill.shipping_cost * 1.19)
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
data/lib/magelex/lexware_bill.rb
CHANGED
data/lib/magelex/lexware_csv.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
module Magelex
|
2
2
|
module LexwareCSV
|
3
|
+
# Writes(renders) to file.
|
3
4
|
def self.write file, bills
|
4
5
|
File.open(file, 'w') do |f|
|
5
6
|
f.write render(bills).gsub("\n", "\r\n").encode(
|
@@ -11,13 +12,12 @@ module Magelex
|
|
11
12
|
rows = []
|
12
13
|
rows << [bill.date.strftime("%d.%m.%Y"),
|
13
14
|
bill.order_nr,
|
14
|
-
# Replace , by dash
|
15
15
|
bill.customer_name,
|
16
16
|
bill.total.round(2),
|
17
17
|
Magelex::AccountNumber.for_customer(bill),
|
18
18
|
0]
|
19
|
-
# subs
|
20
|
-
[:total_0, :total_7, :total_19, :incorrect_tax
|
19
|
+
# subs, refactoring needed.
|
20
|
+
[:total_0, :total_7, :total_19, :incorrect_tax].each do |part|
|
21
21
|
if (amount = bill.send(part)) != 0
|
22
22
|
rows << [
|
23
23
|
bill.date.strftime("%d.%m.%Y"),
|
@@ -29,6 +29,18 @@ module Magelex
|
|
29
29
|
]
|
30
30
|
end
|
31
31
|
end
|
32
|
+
[:discount_7, :discount_19].each do |part|
|
33
|
+
if (amount = bill.send(part)) != 0
|
34
|
+
rows << [
|
35
|
+
bill.date.strftime("%d.%m.%Y"),
|
36
|
+
bill.order_nr,
|
37
|
+
bill.customer_name,
|
38
|
+
- amount.round(2),
|
39
|
+
0,
|
40
|
+
Magelex::AccountNumber.for(bill, part),
|
41
|
+
]
|
42
|
+
end
|
43
|
+
end
|
32
44
|
rows
|
33
45
|
end
|
34
46
|
|
@@ -53,6 +65,7 @@ module Magelex
|
|
53
65
|
end
|
54
66
|
end
|
55
67
|
|
68
|
+
# Renders into String
|
56
69
|
def self.render bills
|
57
70
|
CSV.generate(encoding: 'utf-8') do |csv|
|
58
71
|
bills.each do |b|
|
data/lib/magelex/version.rb
CHANGED
data/lib/magelex.rb
CHANGED
@@ -35,9 +35,6 @@ module Magelex
|
|
35
35
|
"(0: #{bill.total_0} + 7: #{bill.total_7} "\
|
36
36
|
"+ 19: #{bill.total_19} "\
|
37
37
|
"= #{bill.total_0 + bill.total_7 + bill.total_19})")
|
38
|
-
if bill.discount_19 != 0 || bill.discount_7 != 0
|
39
|
-
Magelex.logger.info(bill.inspect)
|
40
|
-
end
|
41
38
|
else
|
42
39
|
if bill.swiss?
|
43
40
|
Magelex.logger.info("#{bill.order_nr}: swiss")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: magelex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Felix Wolfsteller
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mysql2
|
@@ -84,6 +84,7 @@ description:
|
|
84
84
|
email:
|
85
85
|
- felix.wolfsteller@gmail.com
|
86
86
|
executables:
|
87
|
+
- anonymize
|
87
88
|
- magelex
|
88
89
|
- magelex_debug
|
89
90
|
extensions: []
|
@@ -95,6 +96,7 @@ files:
|
|
95
96
|
- Gemfile
|
96
97
|
- README.md
|
97
98
|
- Rakefile
|
99
|
+
- bin/anonymize
|
98
100
|
- bin/magelex
|
99
101
|
- bin/magelex_debug
|
100
102
|
- lib/magelex.rb
|