bravo 1.0.0.rc1 → 1.0.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,4 +1,7 @@
1
- # Bravo ![Travis status](https://travis-ci.org/leanucci/bravo.png)
1
+ # Bravo
2
+ ![Travis status](https://travis-ci.org/leanucci/bravo.png)
3
+ [![Gem Version](https://badge.fury.io/rb/bravo.png)](http://badge.fury.io/rb/bravo)
4
+ [![Code Climate](https://codeclimate.com/repos/5292a01e89af7e473304513a/badges/4a29fbaff3d74a23e634/gpa.png)](https://codeclimate.com/repos/5292a01e89af7e473304513a/feed)
2
5
 
3
6
  [~~Bravo~~](http://images.coveralia.com/audio/b/Bravo-Desierto_Sin_Amor-Frontal.jpg) Bravo permite la obtención del [~~C.A.E~~](http://www.muevamueva.com/masmusica/latina/cae/images/fotos.5.gif) C.A.E. (Código de Autorización Electrónico) por medio del Web Service de Facturación Electrónica provisto por AFIP.
4
7
 
@@ -2,7 +2,6 @@ require 'bundler/setup'
2
2
  require 'bravo/version'
3
3
  require 'bravo/constants'
4
4
  require 'savon'
5
- require 'bravo/core_ext/float'
6
5
  require 'bravo/core_ext/hash'
7
6
  require 'bravo/core_ext/string'
8
7
 
@@ -20,14 +19,13 @@ module Bravo
20
19
  # This class handles the logging options
21
20
  #
22
21
  class Logger < Struct.new(:log, :pretty_xml, :level)
23
- # @param log [Boolean] wether to log or not.
24
- # @param pretty_xml [Boolean] pass true to format xml in a readable way.
25
- # @param level [Symbol] one of `:debug`, `:info`, `:warn`, `:error`, `:fatal`.
22
+ # @param opts [Hash] receives a hash with keys `log`, `pretty_xml` (both
23
+ # boolean) or the desired log level as `level`
26
24
 
27
- def initialize(log = false, level = :debug, pretty_xml = true)
28
- self.log = log
29
- self.pretty_xml = pretty_xml
30
- self.level = level
25
+ def initialize(opts = {})
26
+ self.log = opts[:log] || false
27
+ self.pretty_xml = opts[:pretty_xml] || self.log
28
+ self.level = opts[:level] || :debug
31
29
  end
32
30
 
33
31
  # @return [Hash] returns a hash with the proper logging optios for Savon.
@@ -14,8 +14,8 @@ module Bravo
14
14
 
15
15
  def initialize(attrs = {})
16
16
  Bravo::AuthData.fetch
17
- opts = { wsdl: Bravo::AuthData.wsfe_url}.merge! Bravo.logger_options
18
- @client = Savon.client(opts)
17
+ opts = { wsdl: Bravo::AuthData.wsfe_url }.merge! Bravo.logger_options
18
+ @client ||= Savon.client(opts)
19
19
  @body = { 'Auth' => Bravo::AuthData.auth_hash }
20
20
  self.iva_cond = attrs[:iva_cond]
21
21
  @net = attrs[:net] || 0
@@ -50,8 +50,8 @@ module Bravo
50
50
  # TODO: fix this
51
51
  #
52
52
  def iva_sum
53
- @iva_sum = net * Bravo::ALIC_IVA[aliciva_id][1]
54
- @iva_sum.round_up_with_precision(2)
53
+ @iva_sum = net * applicable_iva_multiplier
54
+ @iva_sum.round(2)
55
55
  end
56
56
 
57
57
  # Files the authorization request to AFIP
@@ -88,7 +88,7 @@ module Bravo
88
88
  'ImpTrib' => 0.00,
89
89
  'Iva' => {
90
90
  'AlicIva' => {
91
- 'Id' => '5',
91
+ 'Id' => applicable_iva_code,
92
92
  'BaseImp' => net,
93
93
  'Importe' => iva_sum } } } } } }
94
94
 
@@ -162,5 +162,18 @@ module Bravo
162
162
  keys, values = response_hash.to_a.transpose
163
163
  self.response = (defined?(Struct::Response) ? Struct::Response : Struct.new('Response', *keys)).new(*values)
164
164
  end
165
+
166
+ def applicable_iva
167
+ index = Bravo::APPLICABLE_IVA[Bravo.own_iva_cond][iva_cond]
168
+ Bravo::ALIC_IVA[index]
169
+ end
170
+
171
+ def applicable_iva_code
172
+ applicable_iva[0]
173
+ end
174
+
175
+ def applicable_iva_multiplier
176
+ applicable_iva[1]
177
+ end
165
178
  end
166
179
  end
@@ -59,7 +59,16 @@ module Bravo
59
59
  #
60
60
  ALIC_IVA = [['03', 0], ['04', 0.105], ['05', 0.21], ['06', 0.27]]
61
61
 
62
-
62
+ # Applicable tax according to buyer and seller's iva condition.
63
+ #
64
+ APPLICABLE_IVA = {
65
+ :responsable_inscripto => {
66
+ responsable_inscripto: 02,
67
+ consumidor_final: 00,
68
+ exento: 00,
69
+ responsable_monotributo: 00
70
+ }
71
+ }
63
72
 
64
73
  # This hash keeps the codes for A document types by operation
65
74
  #
@@ -96,4 +105,4 @@ module Bravo
96
105
 
97
106
  :production => { :wsaa => 'https://wsaa.afip.gov.ar/ws/services/LoginCms',
98
107
  :wsfe => 'https://servicios1.afip.gov.ar/wsfev1/service.asmx' } }
99
- end
108
+ end
@@ -1,5 +1,5 @@
1
1
  module Bravo
2
2
  # Gem version
3
3
  #
4
- VERSION = '1.0.0.rc1'
4
+ VERSION = '1.0.0.rc2'
5
5
  end
@@ -55,8 +55,8 @@ describe 'Bill' do
55
55
  bill.net = 100.89
56
56
  bill.aliciva_id = 2
57
57
 
58
- bill.iva_sum.should be_within(0.05).of(21.18)
59
- bill.total.should be_within(0.05).of(122.07)
58
+ bill.iva_sum.should be_within(0.005).of(21.19)
59
+ bill.total.should be_within(0.005).of(122.08)
60
60
  end
61
61
  end
62
62
 
@@ -101,7 +101,7 @@ describe 'Bill' do
101
101
  Bravo::BILL_TYPE[Bravo.own_iva_cond][target_iva_cond].keys.each do |bill_type|
102
102
  vcr_options = { cassette_name: "#{ target_iva_cond.to_s }_and_#{ bill_type }" }
103
103
  it "authorizes bill type #{ bill_type }", vcr: vcr_options do
104
- bill.net = 10000.00
104
+ bill.net = 10000.88
105
105
  bill.aliciva_id = 2
106
106
  bill.doc_num = '30710151543'
107
107
  bill.iva_cond = target_iva_cond
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bravo
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.rc1
4
+ version: 1.0.0.rc2
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -157,7 +157,6 @@ files:
157
157
  - LICENSE.txt
158
158
  - README.md
159
159
  - Rakefile
160
- - VERSION
161
160
  - autotest/discover.rb
162
161
  - bin/bravo
163
162
  - bravo.gemspec
@@ -165,7 +164,6 @@ files:
165
164
  - lib/bravo/auth_data.rb
166
165
  - lib/bravo/bill.rb
167
166
  - lib/bravo/constants.rb
168
- - lib/bravo/core_ext/float.rb
169
167
  - lib/bravo/core_ext/hash.rb
170
168
  - lib/bravo/core_ext/string.rb
171
169
  - lib/bravo/reference.rb
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.3.6
@@ -1,14 +0,0 @@
1
- # Float monkeypatching.
2
- #
3
- class Float
4
- # Should be removed.
5
- #
6
- def round_with_precision(precision = nil)
7
- precision.nil? ? round : (self * (10 ** precision)).round / (10 ** precision).to_f
8
- end
9
- # Should be removed.
10
- #
11
- def round_up_with_precision(precision = nil)
12
- precision.nil? ? round : ((self * (10 ** precision)).round + 1) / (10 ** precision).to_f
13
- end
14
- end