magelex 0.1.3 → 0.1.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: de06fc18a480aa62a7229eb17dd1039513345fd3
4
- data.tar.gz: 2c47cad6e86d40495ddd67c32a6533ab5e2d4e77
3
+ metadata.gz: 3265c8e33e2ad6890d52621525e0c1bd5dd413be
4
+ data.tar.gz: 155eeb146e499ce591d689fc234800ccacc0667d
5
5
  SHA512:
6
- metadata.gz: 07b259c2f497d0345b89ec13819b6717e2c64293bc212d7fe1a805214270aacf77f80fec7d0478462c2002cfd2a55b81741d6f171a971933aa1e924846873026
7
- data.tar.gz: 7efba0085ec0ecfe48693fd2b0e71af54f7f4351769d943338d9bd8e39a2a339af03c9ab7e199b12f5ddd748318300778f5b8ccca1e43a543c78e71be301baea
6
+ metadata.gz: 3c15c967d7f20bdf9eedaf4f4cf333dbccfcd3c0fa7486a06b10a73fc78c52ef8f61cccb8757aa93cd8135fdf83314ae9c6eb65be44387d9705251149b4fe35c
7
+ data.tar.gz: b9263bc21038c81c2d33e69b9410a62a8df4db0a9324491e34e70db3c087456c93dc8e66fa04af3a44cf99079cb0d642f2498c388cd712fbb35c4c9a9b4e18bf
data/README.md CHANGED
@@ -57,6 +57,11 @@ Swiss orders require some special attention, so steps are undertaken to adjust t
57
57
 
58
58
  Finally the `LexwareBill`s that conform to the rules (`LexwareBill#check`) can be exported to be imported to Lexware (`Magelex::LexwareCSV`).
59
59
 
60
+ ## Changes
61
+
62
+ - 0.1.4:
63
+ respect per-item discounts
64
+
60
65
  ## Development
61
66
 
62
67
  After checking out the repo, run `rake spec` to run the tests. You can also run `bundle console` for an interactive prompt that will allow you to experiment. Run `bundle exec magelex` to use the gem in this directory, ignoring other installed copies of this gem.
data/bin/magelex_debug CHANGED
@@ -48,8 +48,7 @@ def main options
48
48
 
49
49
  # Import/Read file.
50
50
  bills = Magelex::MagentoCSV.read ARGV[0]
51
- bills.each(&:swissify)
52
- bills.each(&:process_shipping_costs)
51
+ Magelex::BillModifier.process bills
53
52
  bill_rows = bills.map do |bill|
54
53
  [
55
54
  bill.order_nr,
@@ -1,10 +1,15 @@
1
1
  module Magelex
2
2
  module BillModifier
3
- def self.process bill
4
- # 'Trick' around with bill
5
- swissify bill
6
- process_shipping_costs bill
7
- adjust_order_number bill
3
+ # shifts to total_0 for swiss orders,
4
+ # consumes the shipping cost (19)
5
+ # and adjusts the order number
6
+ # takes single bill or list of bills
7
+ def self.process bills
8
+ [*bills].each do |bill|
9
+ swissify bill
10
+ process_shipping_costs bill
11
+ adjust_order_number bill
12
+ end
8
13
  end
9
14
 
10
15
  def self.process_shipping_costs bill
@@ -23,6 +23,10 @@ module Magelex
23
23
  return for_19 bill
24
24
  elsif tax_kind == :incorrect_tax
25
25
  return for_incorrect_tax bill
26
+ elsif tax_kind == :discount_7
27
+ return for_discount_7 bill
28
+ elsif tax_kind == :discount_19
29
+ return for_discount_19 bill
26
30
  else
27
31
  raise "unknown tax_kind (#{tax_kind})"
28
32
  end
@@ -43,5 +47,13 @@ module Magelex
43
47
  def self.for_incorrect_tax bill
44
48
  '1783'
45
49
  end
50
+
51
+ def self.for_discount_7 bill
52
+ '8780'
53
+ end
54
+
55
+ def self.for_discount_19 bill
56
+ '8790'
57
+ end
46
58
  end
47
59
  end
@@ -6,8 +6,13 @@ module Magelex
6
6
  'IE','IT','CY','LV','LT','LU','HU','MT',
7
7
  'NL','AT','PL','PT','RO','SI','SK','FI','SE','UK']
8
8
 
9
- attr_accessor :order_nr, :customer_name, :country_code,
10
- :date, :status, :shipping_cost, :total, :total_0, :total_7, :total_19, :has_problems, :tax_7, :tax_19, :incorrect_tax
9
+ attr_accessor :order_nr, :customer_name,
10
+ :country_code,
11
+ :date, :status, :shipping_cost,
12
+ :total, :total_0, :total_7, :total_19,
13
+ :discount_7, :discount_19,
14
+ :total, :total_0, :total_7, :total_19,
15
+ :has_problems, :tax_7, :tax_19, :incorrect_tax
11
16
 
12
17
  def initialize values={}
13
18
  @total_0, @total_7, @total_19, @total = 0, 0, 0, 0
@@ -22,8 +27,10 @@ module Magelex
22
27
  @tax_19 = values.delete(:tax_19) || 0
23
28
  @incorrect_tax = values.delete(:incorrect_tax) || 0
24
29
  @status = values.delete(:status) || nil
25
- @shipping_cost = values.delete(:shipping_cost) || nil
30
+ @shipping_cost = values.delete(:shipping_cost) || 0
26
31
  @country_code = values.delete(:country_code) || nil
32
+ @discount_7 = values.delete(:discount_7) || 0
33
+ @discount_19 = values.delete(:discount_19) || 0
27
34
  @has_problems = false
28
35
  if !values.empty?
29
36
  raise "Unknown values for bill: #{values.inspect}"
@@ -36,21 +43,24 @@ module Magelex
36
43
 
37
44
  # Add item values to corresponding total_ and tax_ attributes
38
45
  # depending on discount, include or exclude taxes.
39
- def add_item amount, tax, name, discount=0
46
+ # TODO full_amount shall not be 0 if discount is not zero
47
+ def add_item amount, tax, name, discount=0, full_amount=0
40
48
  begin
41
49
  case TaxGuess.guess(amount, tax)
42
50
  when :tax0
43
51
  @total_0 += amount.round(2)
44
52
  when :tax7
45
53
  if discount != 0
46
- @total_7 += (amount.round(2) * 1.07)
54
+ @total_7 += full_amount.round(2)
55
+ @discount_7 += discount
47
56
  else
48
57
  @total_7 += amount.round(2)
49
58
  end
50
59
  @tax_7 += tax
51
60
  when :tax19
52
61
  if discount != 0
53
- @total_19 += (amount.round(2) * 1.18)
62
+ @total_19 += full_amount.round(2)
63
+ @discount_19 += discount
54
64
  else
55
65
  @total_19 += amount.round(2)
56
66
  end
@@ -76,7 +86,12 @@ module Magelex
76
86
  end
77
87
 
78
88
  def check_diff
79
- @total.round(2) - (@total_0.round(2) + @total_7.round(2) + @total_19.round(2) + @incorrect_tax.round(2)).round(2)
89
+ @total.round(2) - (@total_0.round(2) + \
90
+ + @total_7.round(2) + \
91
+ + @total_19.round(2) + \
92
+ + @incorrect_tax.round(2) + \
93
+ - @discount_7.round(2) + \
94
+ - @discount_19.round(2)).round(2)
80
95
  end
81
96
 
82
97
  def check
@@ -16,7 +16,7 @@ module Magelex
16
16
  Magelex::AccountNumber.for_customer(bill),
17
17
  0]
18
18
  # subs
19
- [:total_0, :total_7, :total_19, :incorrect_tax].each do |part|
19
+ [:total_0, :total_7, :total_19, :incorrect_tax, :discount_7, :discount_19].each do |part|
20
20
  if (amount = bill.send(part)) != 0
21
21
  rows << [
22
22
  bill.date.strftime("%d.%m.%Y"),
@@ -3,7 +3,7 @@ require 'csv'
3
3
  module Magelex
4
4
  module MagentoCSV
5
5
  MONEY_FIELDS = ['Order Shipping', 'Order Grand Total',
6
- 'Item Total', 'Item Tax', 'Item Discount']
6
+ 'Item Original Price', 'Item Total', 'Item Tax', 'Item Discount']
7
7
 
8
8
  CSV::Converters[:german_money_amount] = lambda do |value, info|
9
9
  if MONEY_FIELDS.include? info[:header]
@@ -31,7 +31,7 @@ module Magelex
31
31
  bill = Magelex::LexwareBill.new
32
32
 
33
33
  # TODO: defining a attribute|colum- map would be nicer
34
- bill.order_nr = row['Order Number']
34
+ bill.order_nr = row['Order Number']
35
35
  bill.customer_name = row['Billing Name']
36
36
  bill.country_code = row['Shipping Country']
37
37
  bill.date = row['Order Date']
@@ -65,7 +65,8 @@ module Magelex
65
65
  current_bill.add_item(row['Item Total'],
66
66
  row['Item Tax'],
67
67
  row['Item Name'],
68
- row['Item Discount'])
68
+ row['Item Discount'],
69
+ row['Item Original Price'].to_f * row['Item Qty Ordered'].to_i)
69
70
 
70
71
  if !bills.include? (current_bill)
71
72
  bills << current_bill
@@ -1,3 +1,3 @@
1
1
  module Magelex
2
- VERSION = "0.1.3".freeze
2
+ VERSION = "0.1.4".freeze
3
3
  end
data/lib/magelex.rb CHANGED
@@ -27,15 +27,24 @@ module Magelex
27
27
  else # complete!
28
28
  Magelex::BillModifier.process bill
29
29
  if !bill.check
30
+ if bill.discount_7 != 0 || bill.discount_19 != 0
31
+ Magelex.logger.info("#{bill.order_nr}: discounted")
32
+ end
30
33
  Magelex.logger.info("Skip order #{bill.order_nr}#{bill.swiss? ? ' (swiss)' : ''} #{bill.has_problems ? ' (broken item)': '' }")
31
- Magelex.logger.info(" (totals do not match #{bill.total} != "\
34
+ Magelex.logger.info(" (totals do not match [#{bill.check_diff}] #{bill.total} != "\
32
35
  "(0: #{bill.total_0} + 7: #{bill.total_7} "\
33
36
  "+ 19: #{bill.total_19} "\
34
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
35
41
  else
36
42
  if bill.swiss?
37
43
  Magelex.logger.info("#{bill.order_nr}: swiss")
38
44
  end
45
+ if bill.discount_7 != 0 || bill.discount_19 != 0
46
+ Magelex.logger.info("#{bill.order_nr}: discounted")
47
+ end
39
48
  Magelex.logger.debug("Handle #{bill.order_nr}")
40
49
  bills_export << bill
41
50
  end
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.3
4
+ version: 0.1.4
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-02-23 00:00:00.000000000 Z
11
+ date: 2016-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mysql2