spree_invoice 1.1.3 → 1.1.10

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -8,7 +8,7 @@ Basic Installation
8
8
 
9
9
  1. Add the following to your Gemfile
10
10
  <pre>
11
- gem 'spree_invoice', '~> 1.1.2'
11
+ gem 'spree_invoice', '~> 1.1.0'
12
12
  </pre>
13
13
  2. Run `bundle install`
14
14
  3. To copy and apply migrations run:
@@ -1,15 +1,15 @@
1
1
  module Spree
2
2
  class InvoiceController < BaseController
3
-
3
+
4
4
  def show
5
- @order = Order.find_by_id(params[:order_id])
6
- #@order.create_invoice(:user => @order.user)
5
+ order_id = params[:order_id].to_i
6
+ @order = Order.find_by_id(order_id)
7
7
  @address = @order.bill_address
8
- @invoice_print = current_user.has_role?(:admin) ? Spree::Invoice.find_or_create_by_order_id_and_user_id(@order.id, (@order ? @order.user_id : nil)) : current_user.invoices.find_or_create_by_order_id(@order.id)
8
+ @invoice_print = current_user.has_role?(:admin) ? Spree::Invoice.find_or_create_by_order_id({:order_id => order_id, :user_id => @order ? @order.user_id : nil}) : current_user.invoices.find_or_create_by_order_id(order_id)
9
9
  if @invoice_print
10
10
  respond_to do |format|
11
11
  format.pdf { send_data @invoice_print.generate_pdf, :filename => "#{@invoice_print.invoice_number}.pdf", :type => 'application/pdf' }
12
- format.html { render :file => Spree::Config[:invoice_template_path].to_s, :layout => false }
12
+ format.html { render :file => SpreeInvoice.invoice_template_path.to_s, :layout => false }
13
13
  end
14
14
  else
15
15
  if current_user.has_role?(:admin)
@@ -1,17 +1,18 @@
1
- Spree::OrderMailer.class_eval do
2
-
3
- def confirm_email(order, resend = false)
4
- if Spree::Config[:on_confirm_email]
5
- inv_print = Spree::Invoice.find_or_create_by_oser_id_and_user_id(order.id, order.user_id)
6
- attachments["#{inv_print.invoice_number}.pdf"] = {
7
- :content => inv_print.generate_pdf,
8
- :mime_type => 'application/pdf'
9
- } if inv_print
1
+ module Spree
2
+ OrderMailer.class_eval do
3
+
4
+ def confirm_email(order, resend = false)
5
+ if SpreeInvoice.on_confirm_email && !SpreeInvoice.except_payment.include?(order.payment_method.type)
6
+ inv_print = Spree::Invoice.find_or_create_by_order_id({:order_id => order.id, :user_id => order.user_id})
7
+ attachments["#{inv_print.invoice_number}.pdf"] = {
8
+ :content => inv_print.generate_pdf,
9
+ :mime_type => 'application/pdf'
10
+ } if inv_print
11
+ end
12
+ @order = order
13
+ subject = (resend ? "[#{t(:resend).upcase}] " : "")
14
+ subject += "#{Config[:site_name]} #{t('order_mailer.confirm_email.subject')} ##{order.number}"
15
+ mail(:to => order.email, :subject => subject)
10
16
  end
11
- @order = order
12
- subject = (resend ? "[#{t(:resend).upcase}] " : '')
13
- subject += "#{Spree::Config[:site_name]} #{t('order_mailer.cancel_email.subject')} ##{order.number}"
14
- mail(:to => order.email,
15
- :subject => subject)
16
17
  end
17
18
  end
@@ -3,7 +3,7 @@ module Spree
3
3
  belongs_to :user
4
4
  belongs_to :order
5
5
 
6
- before_validation :generate_invoice_number, :on => :create
6
+ before_create :generate_invoice_number
7
7
 
8
8
  scope :from_current_year, where(["created_at > ? AND created_at < ?", Time.now.at_beginning_of_year, Time.now.at_end_of_year])
9
9
 
@@ -12,20 +12,19 @@ module Spree
12
12
  def generate_pdf
13
13
  self.update_attribute(:counter, self.counter + 1)
14
14
  WickedPdf.new.pdf_from_string(
15
- StaticRender.render_erb(Spree::Config[:invoice_template_path], {
15
+ StaticRender.render_erb(SpreeInvoice.invoice_template_path, {
16
16
  :@order => self.order,
17
17
  :@address => self.order.bill_address,
18
18
  :@invoice_print => self
19
19
  }), {
20
- :margin => ActiveSupport::JSON.decode(Spree::Config[:invoice_wkhtmltopdf_margin])
20
+ :margin => SpreeInvoice.wkhtmltopdf_margin
21
21
  }
22
22
  )
23
23
  end
24
24
 
25
+ private
25
26
  def generate_invoice_number
26
- last_record = self.class.from_current_year.size
27
- new_record = "%04d" % (last_record + 1).to_s
28
- self.invoice_number = "#{new_record}/A" if self.invoice_number.blank?
27
+ write_attribute(:invoice_number, SpreeInvoice.invoice_number_generation_method.call(Spree::Invoice.from_current_year.length + 1))
29
28
  end
30
29
  end
31
30
 
@@ -1,13 +1,11 @@
1
1
  Spree::Order.class_eval do
2
- has_one :invoice
2
+ has_one :invoice, :dependent => :destroy
3
3
  after_update :add_invoice
4
4
 
5
5
  private
6
6
  def add_invoice
7
7
  # Only create an invoice if the order is completed!
8
8
  # And only create it if there is no invoice yet.
9
- if Spree::Config[:invoice_on_order_complete]
10
- self.create_invoice(:user => user) if self.completed? && self.invoice.blank?
11
- end
9
+ self.create_invoice(:user => user) if self.completed? && self.invoice.blank?
12
10
  end
13
11
  end
@@ -1,3 +1,3 @@
1
1
  Spree::User.class_eval do
2
- has_many :invoices
2
+ has_many :invoice
3
3
  end
@@ -8,10 +8,10 @@ class CreateInvoices < ActiveRecord::Migration
8
8
 
9
9
  t.timestamps
10
10
  end
11
- add_index :spree_invoices, :invoice_number
11
+ add_index :spree_invoice, :invoice_number
12
12
  end
13
13
 
14
14
  def down
15
- drop_table :spree_invoices
15
+ drop_table :spree_invoice
16
16
  end
17
17
  end
@@ -3,3 +3,28 @@ require 'wicked_pdf'
3
3
  WickedPdf.config = {
4
4
  :exe_path => SpreeInvoice::WKHTMLToPDF.bin_path
5
5
  }
6
+
7
+ SpreeInvoice.setup do |config|
8
+ config.on_confirm_email = true
9
+ config.invoice_number_generation_method = lambda { |next_invoice_count|
10
+ number = "%04d" % next_invoice_count.to_s
11
+ "R-#{Time.now.year}-#{number}"
12
+ }
13
+
14
+ config.invoice_template_path = "app/views/spree/invoices/invoice_template.html.erb"
15
+ config.except_payment = ['Spree::PaymentMethod::Check']
16
+ config.wkhtmltopdf_margin = {
17
+ :top => 10,
18
+ :bottom => 10,
19
+ :left => 15,
20
+ :right => 15
21
+ }
22
+ config.invoice_seller_details = %Q|
23
+ Spree Demo
24
+ P.IVA: 12345678901
25
+ C.F.: 12345678901
26
+ Street Address, 12
27
+ 00000 City (STATE)
28
+ |
29
+ config.invoice_seller_logo = Spree::Config[:admin_interface_logo]
30
+ end
@@ -8,10 +8,10 @@
8
8
  <body>
9
9
  <div id="wrapper">
10
10
  <div id="header">
11
- <%= wicked_pdf_image_tag(Spree::Config[:invoice_seller_logo]) %>
11
+ <%= wicked_pdf_image_tag(SpreeInvoice.invoice_seller_logo) %>
12
12
  </div>
13
13
  <div id="content">
14
- <%= Spree::Config[:invoice_seller_details].gsub("|", "<br />").html_safe %><br />
14
+ <%= SpreeInvoice.invoice_seller_details %><br />
15
15
  <%= @order.id %>
16
16
  </div>
17
17
  </div>
@@ -1,3 +1,3 @@
1
1
  module SpreeInvoice
2
- VERSION = "1.1.3"
2
+ VERSION = "1.1.10"
3
3
  end
data/lib/spree_invoice.rb CHANGED
@@ -1,3 +1,33 @@
1
1
  require 'spree_core'
2
- require 'wicked_pdf'
3
2
  require 'spree_invoice/engine'
3
+
4
+ module SpreeInvoice
5
+ ## CONFIGURATION OPTIONS
6
+ mattr_accessor :on_confirm_email
7
+ @@on_confirm_email = true
8
+
9
+ mattr_accessor :invoice_seller_details
10
+ @@invoice_seller_details = nil
11
+
12
+ mattr_accessor :invoice_seller_logo
13
+ @@invoice_seller_logo = nil
14
+
15
+ mattr_accessor :invoice_template_path
16
+ @@invoice_template_path = "app/views/spree/invoices/invoice_template.html.erb"
17
+
18
+ mattr_accessor :except_payment
19
+ @@except_payment = ['Spree::PaymentMethod::Check']
20
+
21
+ mattr_accessor :wkhtmltopdf_margin
22
+ @@wkhtmltopdf_margin = {:top => 10, :bottom => 10, :left => 15, :right => 15}
23
+
24
+ mattr_accessor :invoice_number_generation_method
25
+ @@invoice_number_generation_method = lambda { |next_invoice_count|
26
+ number = "%04d" % next_invoice_count.to_s
27
+ "R-#{Time.now.year}-#{number}"
28
+ }
29
+
30
+ def self.setup
31
+ yield self
32
+ end
33
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_invoice
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.1.10
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2013-03-29 00:00:00.000000000 Z
14
+ date: 2012-11-06 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: spree_core
@@ -20,7 +20,7 @@ dependencies:
20
20
  requirements:
21
21
  - - ! '>='
22
22
  - !ruby/object:Gem::Version
23
- version: 1.1.5
23
+ version: '0'
24
24
  type: :runtime
25
25
  prerelease: false
26
26
  version_requirements: !ruby/object:Gem::Requirement
@@ -28,23 +28,39 @@ dependencies:
28
28
  requirements:
29
29
  - - ! '>='
30
30
  - !ruby/object:Gem::Version
31
- version: 1.1.5
31
+ version: '0'
32
32
  - !ruby/object:Gem::Dependency
33
33
  name: wicked_pdf
34
34
  requirement: !ruby/object:Gem::Requirement
35
35
  none: false
36
36
  requirements:
37
- - - ~>
37
+ - - ! '>='
38
38
  - !ruby/object:Gem::Version
39
- version: 0.9.4
39
+ version: '0'
40
40
  type: :runtime
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  none: false
44
44
  requirements:
45
- - - ~>
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ - !ruby/object:Gem::Dependency
49
+ name: rspec-rails
50
+ requirement: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
46
62
  - !ruby/object:Gem::Version
47
- version: 0.9.4
63
+ version: '0'
48
64
  description: This gem provides invoice pdf generation from a html template via wkhtmltopdf.
49
65
  email:
50
66
  - damiano.giacomello@diginess.it
@@ -66,7 +82,6 @@ files:
66
82
  - app/assets/images/admin/icons/receipt.png
67
83
  - app/controllers/spree/invoice_controller.rb
68
84
  - app/mailers/spree/order_mailer_decorator.rb
69
- - app/models/spree/app_configuration_decorator.rb
70
85
  - app/models/spree/invoice.rb
71
86
  - app/models/spree/order_decorator.rb
72
87
  - app/models/spree/user_decorator.rb
@@ -1,26 +0,0 @@
1
- # This is the primary location for defining spree preferences
2
- #
3
- # The expectation is that this is created once and stored in
4
- # the spree environment
5
- #
6
- # setters:
7
- # a.color = :blue
8
- # a[:color] = :blue
9
- # a.set :color = :blue
10
- # a.preferred_color = :blue
11
- #
12
- # getters:
13
- # a.color
14
- # a[:color]
15
- # a.get :color
16
- # a.preferred_color
17
- #
18
- Spree::AppConfiguration.class_eval do
19
- # Alphabetized to more easily lookup particular preferences
20
- preference :invoice_on_confirm_email, :boolean, :default => false
21
- preference :invoice_on_order_complete, :boolean, :default => false
22
- preference :invoice_seller_logo, :string, :default => Spree::Config[:admin_interface_logo]
23
- preference :invoice_template_path, :string, :default => "spree/invoices/invoice_template.html"
24
- preference :invoice_wkhtmltopdf_margin, :string, :default => "{\"top\":\"10\",\"bottom\":\"10\",\"left\":\"15\",\"right\":\"15\"}"
25
- preference :invoice_seller_details, :string, :default => "Spree Demo| P.IVA: 12345678901| C.F.: 12345678901| Street Address, 12| 00000 City (STATE)"
26
- end