solidus_invoice 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +15 -0
  3. data/.rspec +1 -0
  4. data/.rubocop.yml +250 -0
  5. data/.rvmrc +1 -0
  6. data/.travis.yml +18 -0
  7. data/Gemfile +10 -0
  8. data/MIT-LICENSE +20 -0
  9. data/README.md +38 -0
  10. data/Rakefile +32 -0
  11. data/app/assets/javascripts/spree/backend/solidus_invoice.js +2 -0
  12. data/app/assets/javascripts/spree/frontend/solidus_invoice.js +2 -0
  13. data/app/assets/stylesheets/spree/backend/solidus_invoice.scss +4 -0
  14. data/app/assets/stylesheets/spree/frontend/solidus_invoice.css +4 -0
  15. data/app/jobs/application_job.rb +9 -0
  16. data/app/jobs/solidus_invoice/daily_summary_job.rb +32 -0
  17. data/app/jobs/solidus_invoice/invoice_job.rb +22 -0
  18. data/app/models/concerns/solidus_invoice/line_item_concern.rb +11 -0
  19. data/app/models/concerns/solidus_invoice/order_concern.rb +44 -0
  20. data/app/models/concerns/solidus_invoice/shipment_concern.rb +11 -0
  21. data/app/models/concerns/solidus_invoice/store_concern.rb +11 -0
  22. data/app/models/spree.rb +7 -0
  23. data/app/models/spree/invoice.rb +61 -0
  24. data/app/models/spree/invoice_serial.rb +9 -0
  25. data/app/overrides/spree/line_item_override.rb +5 -0
  26. data/app/overrides/spree/order_override.rb +5 -0
  27. data/app/overrides/spree/shipment_override.rb +5 -0
  28. data/app/overrides/spree/store_override.rb +5 -0
  29. data/bin/rails +9 -0
  30. data/bin/test +7 -0
  31. data/config/locales/en.yml +5 -0
  32. data/config/routes.rb +5 -0
  33. data/db/migrate/20191107042751_create_spree_invoices.rb +14 -0
  34. data/db/migrate/20191115204118_create_spree_invoice_serials.rb +13 -0
  35. data/db/migrate/20191205205004_add_tax_uid_to_spree_addresses.rb +7 -0
  36. data/db/migrate/20191223173229_add_preferences_to_spree_invoices.rb +7 -0
  37. data/lib/generators/solidus_invoice/install/install_generator.rb +22 -0
  38. data/lib/solidus_invoice.rb +4 -0
  39. data/lib/solidus_invoice/engine.rb +22 -0
  40. data/lib/solidus_invoice/errors/invalid_serial_error.rb +6 -0
  41. data/lib/solidus_invoice/factories.rb +34 -0
  42. data/lib/solidus_invoice/railtie.rb +6 -0
  43. data/lib/solidus_invoice/version.rb +5 -0
  44. data/lib/tasks/solidus_invoice_tasks.rake +5 -0
  45. data/solidus_invoice.gemspec +37 -0
  46. data/spec/jobs/solidus_invoice/daily_summary_job_spec.rb +24 -0
  47. data/spec/jobs/solidus_invoice/invoice_job_spec.rb +76 -0
  48. data/spec/models/spree/address_spec.rb +11 -0
  49. data/spec/models/spree/invoice_serial_spec.rb +16 -0
  50. data/spec/models/spree/invoice_spec.rb +55 -0
  51. data/spec/models/spree/line_item_spec.rb +37 -0
  52. data/spec/models/spree/order_spec.rb +31 -0
  53. data/spec/models/spree/shipment_spec.rb +26 -0
  54. data/spec/models/spree/store_spec.rb +9 -0
  55. data/spec/spec_helper.rb +98 -0
  56. metadata +320 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ec74ca7d70297e617f86e4ff1a0669adeb6a1e0cc179effdeab31fda35d21033
4
+ data.tar.gz: f913a310651d186f57f0222fec66ac4549963b2c3ead9314e74f6815e7aaf56e
5
+ SHA512:
6
+ metadata.gz: b8f3841e4515c8d4066996f42ebcd3b64bee0eab6724322a75c365765fba761235a4bc47e04c414ce5f4d04998136c7f62b3ded167328f72e87efd009014f332
7
+ data.tar.gz: bea0241938e408b4c086fa39a76c375e0ee1aaaba45901cff92a8f6576c7ccb89810840d072ffdb5baa2395cb006510b41d864798cac10238fb44c863ec90375
@@ -0,0 +1,15 @@
1
+ *.gem
2
+ \#*
3
+ *~
4
+ .#*
5
+ .DS_Store
6
+ .idea
7
+ .project
8
+ .sass-cache
9
+ coverage
10
+ Gemfile.lock
11
+ tmp
12
+ nbproject
13
+ pkg
14
+ *.swp
15
+ spec/dummy
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,250 @@
1
+ # Relaxed.Ruby.Style
2
+
3
+ AllCops:
4
+ Exclude:
5
+ - 'spec/dummy/**/*'
6
+ - 'vendor/bundle/**/*'
7
+ TargetRubyVersion: 2.6
8
+
9
+ # We use class vars and will have to continue doing so for compatability
10
+ Style/ClassVars:
11
+ Enabled: false
12
+
13
+ # This has been used for customization
14
+ Style/MutableConstant:
15
+ Enabled: false
16
+
17
+ Style/ClassAndModuleChildren:
18
+ Enabled: false
19
+
20
+ Style/GuardClause:
21
+ Enabled: false
22
+
23
+ Style/WordArray:
24
+ Enabled: false
25
+
26
+ Style/ConditionalAssignment:
27
+ Enabled: false
28
+
29
+ Style/RaiseArgs:
30
+ Enabled: false
31
+
32
+ # We can use good judgement here
33
+ Style/RegexpLiteral:
34
+ Enabled: false
35
+
36
+ # Unicode comments are useful
37
+ Style/AsciiComments:
38
+ Enabled: false
39
+
40
+ Layout/EndAlignment:
41
+ Enabled: false
42
+
43
+ # From http://relaxed.ruby.style/
44
+
45
+ Style/Alias:
46
+ Enabled: false
47
+ StyleGuide: http://relaxed.ruby.style/#stylealias
48
+
49
+ Style/BeginBlock:
50
+ Enabled: false
51
+ StyleGuide: http://relaxed.ruby.style/#stylebeginblock
52
+
53
+ Style/BlockDelimiters:
54
+ Enabled: false
55
+ StyleGuide: http://relaxed.ruby.style/#styleblockdelimiters
56
+
57
+ Style/Documentation:
58
+ Enabled: false
59
+ StyleGuide: http://relaxed.ruby.style/#styledocumentation
60
+
61
+ Style/DoubleNegation:
62
+ Enabled: false
63
+ StyleGuide: http://relaxed.ruby.style/#styledoublenegation
64
+
65
+ Style/EndBlock:
66
+ Enabled: false
67
+ StyleGuide: http://relaxed.ruby.style/#styleendblock
68
+
69
+ Style/FormatString:
70
+ Enabled: false
71
+ StyleGuide: http://relaxed.ruby.style/#styleformatstring
72
+
73
+ Style/IfUnlessModifier:
74
+ Enabled: false
75
+ StyleGuide: http://relaxed.ruby.style/#styleifunlessmodifier
76
+
77
+ Style/Lambda:
78
+ Enabled: false
79
+ StyleGuide: http://relaxed.ruby.style/#stylelambda
80
+
81
+ Style/ModuleFunction:
82
+ Enabled: false
83
+ StyleGuide: http://relaxed.ruby.style/#stylemodulefunction
84
+
85
+ Style/MultilineBlockChain:
86
+ Enabled: false
87
+ StyleGuide: http://relaxed.ruby.style/#stylemultilineblockchain
88
+
89
+ Style/NegatedIf:
90
+ Enabled: false
91
+ StyleGuide: http://relaxed.ruby.style/#stylenegatedif
92
+
93
+ Style/NegatedWhile:
94
+ Enabled: false
95
+ StyleGuide: http://relaxed.ruby.style/#stylenegatedwhile
96
+
97
+ Style/ParallelAssignment:
98
+ Enabled: false
99
+ StyleGuide: http://relaxed.ruby.style/#styleparallelassignment
100
+
101
+ Style/PercentLiteralDelimiters:
102
+ Enabled: false
103
+ StyleGuide: http://relaxed.ruby.style/#stylepercentliteraldelimiters
104
+
105
+ Style/PerlBackrefs:
106
+ Enabled: false
107
+ StyleGuide: http://relaxed.ruby.style/#styleperlbackrefs
108
+
109
+ Style/Semicolon:
110
+ Enabled: false
111
+ StyleGuide: http://relaxed.ruby.style/#stylesemicolon
112
+
113
+ Style/SignalException:
114
+ Enabled: false
115
+ StyleGuide: http://relaxed.ruby.style/#stylesignalexception
116
+
117
+ Style/SingleLineBlockParams:
118
+ Enabled: false
119
+ StyleGuide: http://relaxed.ruby.style/#stylesinglelineblockparams
120
+
121
+ Style/SingleLineMethods:
122
+ Enabled: false
123
+ StyleGuide: http://relaxed.ruby.style/#stylesinglelinemethods
124
+
125
+ Style/SpecialGlobalVars:
126
+ Enabled: false
127
+ StyleGuide: http://relaxed.ruby.style/#stylespecialglobalvars
128
+
129
+ Style/StringLiterals:
130
+ Enabled: false
131
+ StyleGuide: http://relaxed.ruby.style/#stylestringliterals
132
+
133
+ Style/SymbolProc:
134
+ Enabled: false
135
+
136
+ Style/WhileUntilModifier:
137
+ Enabled: false
138
+ StyleGuide: http://relaxed.ruby.style/#stylewhileuntilmodifier
139
+
140
+ Style/ExponentialNotation:
141
+ Enabled: true
142
+
143
+ Style/HashEachMethods:
144
+ Enabled: true
145
+
146
+ Style/HashTransformKeys:
147
+ Enabled: true
148
+
149
+ Style/HashTransformValues:
150
+ Enabled: true
151
+
152
+ Lint/AmbiguousRegexpLiteral:
153
+ Enabled: false
154
+ StyleGuide: http://relaxed.ruby.style/#lintambiguousregexpliteral
155
+
156
+ Lint/AssignmentInCondition:
157
+ Enabled: false
158
+ StyleGuide: http://relaxed.ruby.style/#lintassignmentincondition
159
+
160
+ Lint/SuppressedException:
161
+ Exclude:
162
+ - 'Rakefile'
163
+
164
+ Lint/RaiseException:
165
+ Enabled: true
166
+
167
+ Lint/StructNewOverride:
168
+ Enabled: true
169
+
170
+ Metrics/AbcSize:
171
+ Enabled: false
172
+
173
+ Metrics/BlockLength:
174
+ Exclude:
175
+ - '*.gemspec'
176
+ - 'spec/**/**/*'
177
+ - 'lib/solidus_invoice/factories.rb'
178
+
179
+ Metrics/BlockNesting:
180
+ Enabled: false
181
+
182
+ Metrics/ClassLength:
183
+ Enabled: false
184
+
185
+ Metrics/ModuleLength:
186
+ Enabled: false
187
+
188
+ Metrics/CyclomaticComplexity:
189
+ Enabled: false
190
+
191
+ Layout/LineLength:
192
+ Enabled: false
193
+
194
+ Metrics/MethodLength:
195
+ Enabled: false
196
+
197
+ Metrics/ParameterLists:
198
+ Enabled: false
199
+
200
+ Metrics/PerceivedComplexity:
201
+ Enabled: false
202
+
203
+ Naming/BinaryOperatorParameterName:
204
+ Enabled: false
205
+
206
+ # We need these names for backwards compatability
207
+ Naming/PredicateName:
208
+ Enabled: false
209
+
210
+ Naming/AccessorMethodName:
211
+ Enabled: false
212
+
213
+ Layout/ElseAlignment:
214
+ Enabled: false
215
+
216
+ Layout/IndentationWidth:
217
+ Enabled: false
218
+
219
+ Layout/ParameterAlignment:
220
+ Enabled: false
221
+
222
+ Layout/ClosingParenthesisIndentation:
223
+ Enabled: false
224
+
225
+ Layout/MultilineMethodCallIndentation:
226
+ Enabled: false
227
+
228
+ Layout/FirstArrayElementIndentation:
229
+ Enabled: false
230
+
231
+ Layout/FirstHashElementIndentation:
232
+ Enabled: false
233
+
234
+ Layout/HashAlignment:
235
+ Enabled: false
236
+
237
+ Layout/DotPosition:
238
+ Enabled: false
239
+ StyleGuide: http://relaxed.ruby.style/#styledotposition
240
+
241
+ Layout/SpaceBeforeBlockBraces:
242
+ Enabled: false
243
+ StyleGuide: http://relaxed.ruby.style/#stylespacebeforeblockbraces
244
+
245
+ Layout/SpaceInsideParens:
246
+ Enabled: false
247
+ StyleGuide: http://relaxed.ruby.style/#stylespaceinsideparens
248
+
249
+ Layout/SpaceAroundMethodCallOperator:
250
+ Enabled: true
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm --create use 2.6.5@solidus_invoice
@@ -0,0 +1,18 @@
1
+ sudo: false
2
+ cache: bundler
3
+ language: ruby
4
+ bundler_args: --quiet
5
+ script:
6
+ - bundle exec rake
7
+ rvm:
8
+ - 2.6.6
9
+ env:
10
+ matrix:
11
+ - SOLIDUS_BRANCH=v2.8 DB=postgres
12
+ - SOLIDUS_BRANCH=v2.9 DB=postgres
13
+ - SOLIDUS_BRANCH=v2.10 DB=postgres
14
+ - SOLIDUS_BRANCH=master DB=postgres
15
+ - SOLIDUS_BRANCH=v2.8 DB=mysql
16
+ - SOLIDUS_BRANCH=v2.9 DB=mysql
17
+ - SOLIDUS_BRANCH=v2.10 DB=mysql
18
+ - SOLIDUS_BRANCH=master DB=mysql
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}.git" }
6
+
7
+ branch = ENV.fetch('SOLIDUS_BRANCH', 'master')
8
+ gem 'solidus', github: 'solidusio/solidus', branch: branch
9
+
10
+ gemspec
@@ -0,0 +1,20 @@
1
+ Copyright 2019 César Carruitero
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,38 @@
1
+ # SolidusInvoice
2
+
3
+ Solidus invoicing models and some SUNAT utility
4
+
5
+ Installation
6
+ ------------
7
+
8
+ Add solidus_invoice to your Gemfile:
9
+
10
+ ```ruby
11
+ gem 'solidus_invoice'
12
+ ```
13
+
14
+ Bundle your dependencies and run the installation generator:
15
+
16
+ ```shell
17
+ bundle
18
+ bundle exec rails g solidus_invoice:install
19
+ ```
20
+
21
+ Testing
22
+ -------
23
+
24
+ First bundle your dependencies, then run `rake`. `rake` will default to building the dummy app if it does not exist, then it will run specs, and [Rubocop](https://github.com/bbatsov/rubocop) static code analysis. The dummy app can be regenerated by using `rake test_app`.
25
+
26
+ ```shell
27
+ bundle
28
+ bundle exec rake
29
+ ```
30
+
31
+ When testing your applications integration with this extension you may use it's factories.
32
+ Simply add this require statement to your spec_helper:
33
+
34
+ ```ruby
35
+ require 'solidus_invoice/factories'
36
+ ```
37
+
38
+ Copyright (c) 2019 [name of extension creator], released under the New BSD License
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler'
4
+
5
+ Bundler::GemHelper.install_tasks
6
+
7
+ begin
8
+ require 'spree/testing_support/extension_rake'
9
+ require 'rubocop/rake_task'
10
+ require 'rspec/core/rake_task'
11
+
12
+ RSpec::Core::RakeTask.new(:spec)
13
+
14
+ RuboCop::RakeTask.new
15
+
16
+ task default: %i(first_run rubocop spec)
17
+ rescue LoadError
18
+ # no rspec available
19
+ end
20
+
21
+ task :first_run do
22
+ if Dir['spec/dummy'].empty?
23
+ Rake::Task[:test_app].invoke
24
+ Dir.chdir('../../')
25
+ end
26
+ end
27
+
28
+ desc 'Generates a dummy app for testing'
29
+ task :test_app do
30
+ ENV['LIB_NAME'] = 'solidus_invoice'
31
+ Rake::Task['extension:test_app'].invoke
32
+ end
@@ -0,0 +1,2 @@
1
+ // Placeholder manifest file.
2
+ // the installer will append this file to the app vendored assets here: vendor/assets/javascripts/spree/backend/all.js'
@@ -0,0 +1,2 @@
1
+ // Placeholder manifest file.
2
+ // the installer will append this file to the app vendored assets here: vendor/assets/javascripts/spree/frontend/all.js'
@@ -0,0 +1,4 @@
1
+ /*
2
+ Placeholder manifest file.
3
+ the installer will append this file to the app vendored assets here: 'vendor/assets/stylesheets/spree/backend/all.css'
4
+ */
@@ -0,0 +1,4 @@
1
+ /*
2
+ Placeholder manifest file.
3
+ the installer will append this file to the app vendored assets here: 'vendor/assets/stylesheets/spree/frontend/all.css'
4
+ */
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ApplicationJob < ActiveJob::Base
4
+ # Automatically retry jobs that encountered a deadlock
5
+ # retry_on ActiveRecord::Deadlocked
6
+
7
+ # Most jobs are safe to ignore if the underlying records are no longer available
8
+ # discard_on ActiveJob::DeserializationError
9
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ class SolidusInvoice::DailySummaryJob < ApplicationJob
4
+ queue_as :default
5
+
6
+ def perform(*args)
7
+ # find all doc_type doc without comunication
8
+ serials = Spree::InvoiceSerial.includes(:invoices).where(
9
+ doc_type: args[:doc_type],
10
+ store_id: args[:store_id]
11
+ )
12
+
13
+ lines = []
14
+
15
+ serials.each do
16
+ invoices = serials.invoices.where(communicated: false).order(doc_number: :asc)
17
+ line = SunatInvoice::SummaryLine.new(document_type: serial.doc_type,
18
+ document_serial: serial.serial,
19
+ start_document_number: invoice.first.doc_number,
20
+ end_document_number: invoice.last.doc_number,
21
+ total_amount: invoices.sum(:total),
22
+ taxable: invoice.sum(:taxable))
23
+ lines << line
24
+ end
25
+
26
+ # send to sunat
27
+ client = SunatInvoice::InvoiceClient.new
28
+ summary = SunatInvoice::DailySummary.new(reference_date: Time.with_zone.yesterday,
29
+ lines: lines)
30
+ client.dispatch(summary)
31
+ end
32
+ end