opensteam 0.9.2 → 0.9.3
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.
- data/CHANGELOG +53 -0
- data/README.rdoc +19 -10
- data/generators/opensteam/opensteam_generator.rb +27 -3
- data/generators/opensteam/templates/app/controllers/admin/configurations_controller.rb +85 -0
- data/generators/opensteam/templates/app/controllers/admin/inventories_controller.rb +1 -1
- data/generators/opensteam/templates/app/controllers/admin/invoices_controller.rb +35 -4
- data/generators/opensteam/templates/app/controllers/admin/orders_controller.rb +5 -4
- data/generators/opensteam/templates/app/controllers/admin/shipments_controller.rb +6 -3
- data/generators/opensteam/templates/app/controllers/admin/shipping_rate_groups_controller.rb +76 -0
- data/generators/opensteam/templates/app/controllers/admin/tax_groups_controller.rb +124 -0
- data/generators/opensteam/templates/app/controllers/admin/tax_rules_controller.rb +19 -0
- data/generators/opensteam/templates/app/controllers/admin/tax_zones_controller.rb +118 -0
- data/generators/opensteam/templates/app/controllers/admin/users_controller.rb +1 -1
- data/generators/opensteam/templates/app/controllers/admin_controller.rb +20 -0
- data/generators/opensteam/templates/app/controllers/carts_controller.rb +118 -0
- data/generators/opensteam/templates/app/controllers/checkout_controller.rb +119 -79
- data/generators/opensteam/templates/app/controllers/profile_controller.rb +2 -4
- data/generators/opensteam/templates/app/controllers/searches_controller.rb +1 -1
- data/generators/opensteam/templates/app/controllers/user_sessions_controller.rb +2 -1
- data/generators/opensteam/templates/app/controllers/users_controller.rb +10 -3
- data/generators/opensteam/templates/app/helpers/admin_helper.rb +15 -1
- data/generators/opensteam/templates/app/helpers/checkout_helper.rb +38 -0
- data/generators/opensteam/templates/app/helpers/webshop_helper.rb +6 -1
- data/generators/opensteam/templates/app/models/zone.rb +18 -0
- data/generators/opensteam/templates/app/views/admin/_menu.html.erb +18 -0
- data/generators/opensteam/templates/app/views/admin/catalog.html.erb +2 -3
- data/generators/opensteam/templates/app/views/admin/configurations/edit.html.erb +20 -0
- data/generators/opensteam/templates/app/views/admin/configurations/index.html.erb +22 -0
- data/generators/opensteam/templates/app/views/admin/configurations/new.html.erb +19 -0
- data/generators/opensteam/templates/app/views/admin/configurations/show.html.erb +13 -0
- data/generators/opensteam/templates/app/views/admin/filters/_filter.html.erb +1 -1
- data/generators/opensteam/templates/app/views/admin/index.html.erb +0 -19
- data/generators/opensteam/templates/app/views/admin/inventories/edit.html.erb +10 -6
- data/generators/opensteam/templates/app/views/admin/inventories/new.html.erb +5 -0
- data/generators/opensteam/templates/app/views/admin/inventories/show.html.erb +10 -6
- data/generators/opensteam/templates/app/views/admin/invoices/_invoice.html.erb +1 -0
- data/generators/opensteam/templates/app/views/admin/invoices/_invoice_fields.html.erb +52 -0
- data/generators/opensteam/templates/app/views/admin/invoices/new.html.erb +9 -37
- data/generators/opensteam/templates/app/views/admin/invoices/show.html.erb +10 -36
- data/generators/opensteam/templates/app/views/admin/invoices/show.pdf.prawn +59 -0
- data/generators/opensteam/templates/app/views/admin/order_config.html.erb +5 -0
- data/generators/opensteam/templates/app/views/admin/order_items/_item_entry.html.erb +9 -0
- data/generators/opensteam/templates/app/views/admin/order_items/_items_table.html.erb +16 -0
- data/generators/opensteam/templates/app/views/admin/orders/_order.html.erb +9 -9
- data/generators/opensteam/templates/app/views/admin/orders/_orders.html.erb +1 -1
- data/generators/opensteam/templates/app/views/admin/orders/show.html.erb +25 -9
- data/generators/opensteam/templates/app/views/admin/payment_types.html.erb +27 -0
- data/generators/opensteam/templates/app/views/admin/payments/_credit_card_payment.html.erb +26 -0
- data/generators/opensteam/templates/app/views/admin/payments/_credit_card_payment_info.html.erb +15 -0
- data/generators/opensteam/templates/app/views/admin/payments/_direct_debit_payment.html.erb +5 -0
- data/generators/opensteam/templates/app/views/admin/shipments/new.html.erb +45 -30
- data/generators/opensteam/templates/app/views/admin/shipments/show.html.erb +3 -3
- data/generators/opensteam/templates/app/views/admin/shipping_rate_groups/_payment_addition.html.erb +12 -0
- data/generators/opensteam/templates/app/views/admin/shipping_rate_groups/_rate.html.erb +16 -0
- data/generators/opensteam/templates/app/views/admin/shipping_rate_groups/edit.html.erb +63 -0
- data/generators/opensteam/templates/app/views/admin/shipping_rate_groups/index.html.erb +28 -0
- data/generators/opensteam/templates/app/views/admin/shipping_rate_groups/new.html.erb +60 -0
- data/generators/opensteam/templates/app/views/admin/shipping_rate_groups/show.html.erb +13 -0
- data/generators/opensteam/templates/app/views/admin/system.html.erb +5 -0
- data/generators/opensteam/templates/app/views/admin/tax_groups/_attributes.html.erb +11 -0
- data/generators/opensteam/templates/app/views/admin/tax_groups/_tax_groups.html.erb +17 -0
- data/generators/opensteam/templates/app/views/admin/tax_groups/_tax_groups_row.html.erb +12 -0
- data/generators/opensteam/templates/app/views/admin/tax_groups/_tax_rule.html.erb +14 -0
- data/generators/opensteam/templates/app/views/admin/tax_groups/edit.html.erb +26 -0
- data/generators/opensteam/templates/app/views/admin/tax_groups/index.html.erb +8 -0
- data/generators/opensteam/templates/app/views/admin/tax_groups/new.html.erb +27 -0
- data/generators/opensteam/templates/app/views/admin/tax_groups/show.html.erb +28 -0
- data/generators/opensteam/templates/app/views/admin/tax_zones/_attributes.html.erb +18 -0
- data/generators/opensteam/templates/app/views/admin/tax_zones/_tax_zone_row.html.erb +13 -0
- data/generators/opensteam/templates/app/views/admin/tax_zones/_tax_zones.html.erb +11 -0
- data/generators/opensteam/templates/app/views/admin/tax_zones/edit.html.erb +16 -0
- data/generators/opensteam/templates/app/views/admin/tax_zones/index.html.erb +16 -0
- data/generators/opensteam/templates/app/views/admin/tax_zones/new.html.erb +14 -0
- data/generators/opensteam/templates/app/views/admin/tax_zones/show.html.erb +15 -0
- data/generators/opensteam/templates/app/views/admin/users.html.erb +0 -1
- data/generators/opensteam/templates/app/views/admin/users/show.html.erb +10 -0
- data/generators/opensteam/templates/app/views/administration_mailer/order_customer.erb +1 -1
- data/generators/opensteam/templates/app/views/carts/_cart.html.erb +7 -0
- data/generators/opensteam/templates/app/views/carts/_cart_content.html.erb +45 -0
- data/generators/opensteam/templates/app/views/carts/create.rjs +3 -0
- data/generators/opensteam/templates/app/views/{cart → carts}/index.html.erb +0 -0
- data/generators/opensteam/templates/app/views/carts/update.rjs +11 -0
- data/generators/opensteam/templates/app/views/checkout/_address.html.erb +42 -0
- data/generators/opensteam/templates/app/views/checkout/_customer.html.erb +31 -0
- data/generators/opensteam/templates/app/views/checkout/_edit_checkout.html.erb +42 -0
- data/generators/opensteam/templates/app/views/checkout/_new_checkout.html.erb +44 -0
- data/generators/opensteam/templates/app/views/checkout/_shipping_buttons.html.erb +8 -0
- data/generators/opensteam/templates/app/views/checkout/edit.html.erb +7 -0
- data/generators/opensteam/templates/app/views/checkout/new.html.erb +11 -0
- data/generators/opensteam/templates/app/views/checkout/outro.html.erb +1 -4
- data/generators/opensteam/templates/app/views/checkout/show.html.erb +63 -0
- data/generators/opensteam/templates/app/views/common/_header_admin.html.erb +5 -0
- data/generators/opensteam/templates/app/views/layouts/admin.html.erb +28 -12
- data/generators/opensteam/templates/app/views/layouts/profile.html.erb +2 -2
- data/generators/opensteam/templates/app/views/layouts/webshop.html.erb +5 -4
- data/generators/opensteam/templates/app/views/payment/_advance_payment_payment.html.erb +1 -0
- data/generators/opensteam/templates/app/views/payment/_credit_card_payment.html.erb +37 -0
- data/generators/opensteam/templates/app/views/payment/_credit_card_payment_confirmation.html.erb +20 -0
- data/generators/opensteam/templates/app/views/payment/_direct_debit_payment.html.erb +5 -0
- data/generators/opensteam/templates/app/views/payment/_direct_debit_payment_confirmation.html.erb +5 -0
- data/generators/opensteam/templates/app/views/profile/index.html.erb +1 -1
- data/generators/opensteam/templates/app/views/profile/infos/edit.html.erb +20 -12
- data/generators/opensteam/templates/app/views/profile/infos/edit_password.html.erb +16 -12
- data/generators/opensteam/templates/app/views/profile/orders/_order.html.erb +1 -1
- data/generators/opensteam/templates/app/views/profile/orders/show.html.erb +10 -7
- data/generators/opensteam/templates/app/views/webshop/_inventory_content.html.erb +1 -0
- data/generators/opensteam/templates/app/views/webshop/show.html.erb +3 -1
- data/generators/opensteam/templates/config/initializers/init_states.rb +13 -24
- data/generators/opensteam/templates/config/initializers/opensteam.rb +41 -0
- data/generators/opensteam/templates/config/initializers/opensteam_model_tables.rb +49 -10
- data/generators/opensteam/templates/config/initializers/opensteam_security.rb +8 -0
- data/generators/opensteam/templates/config/initializers/payment_process.rb +37 -0
- data/generators/opensteam/templates/db/migrate/20080609095723_create_addresses.rb +8 -2
- data/generators/opensteam/templates/db/migrate/20080609095726_create_inventories.rb +6 -3
- data/generators/opensteam/templates/db/migrate/20080609095728_create_order_items.rb +12 -1
- data/generators/opensteam/templates/db/migrate/20080609095729_create_orders.rb +8 -12
- data/generators/opensteam/templates/db/migrate/20080609095730_create_payment_types.rb +2 -0
- data/generators/opensteam/templates/db/migrate/20080714131513_create_invoices.rb +2 -1
- data/generators/opensteam/templates/db/migrate/20080714131650_create_shipments.rb +3 -1
- data/generators/opensteam/templates/db/migrate/20080808075247_create_containers.rb +30 -0
- data/generators/opensteam/templates/db/migrate/20080808083011_create_container_items.rb +25 -0
- data/generators/opensteam/templates/db/migrate/20080812102727_create_tax_zones.rb +16 -0
- data/generators/opensteam/templates/db/migrate/20080812102858_create_tax_rules.rb +15 -0
- data/generators/opensteam/templates/db/migrate/20080812102956_create_tax_groups.rb +14 -0
- data/generators/opensteam/templates/db/migrate/20080831181436_create_configurations.rb +15 -0
- data/generators/opensteam/templates/db/migrate/20080903131506_create_payments.rb +22 -0
- data/generators/opensteam/templates/db/migrate/20080904133625_create_payment_transactions.rb +24 -0
- data/generators/opensteam/templates/db/migrate/20080916102341_create_zones.rb +19 -0
- data/generators/opensteam/templates/db/migrate/20080916134340_create_region_shipping_rates.rb +18 -0
- data/generators/opensteam/templates/db/migrate/20080916134523_create_shipping_rate_groups.rb +18 -0
- data/generators/opensteam/templates/db/migrate/20080916135226_create_shipping_payment_additions.rb +20 -0
- data/generators/opensteam/templates/db/migrate/20080916135228_init_opensteam_config.rb +60 -0
- data/generators/opensteam/templates/public/images/opensteam_black.jpg +0 -0
- data/generators/opensteam/templates/public/images/pdf.png +0 -0
- data/generators/opensteam/templates/public/images/shader.png +0 -0
- data/generators/opensteam/templates/public/index.html +1 -0
- data/generators/opensteam/templates/public/javascripts/opensteam.js +21 -21
- data/generators/opensteam/templates/public/stylesheets/opensteam_admin.css +291 -0
- data/generators/opensteam/templates/public/stylesheets/opensteam_white.css +47 -11
- data/generators/opensteam/templates/tasks/opensteam.rake +2 -12
- data/generators/opensteam/templates/test/fixtures/addresses.yml +26 -0
- data/generators/opensteam/templates/test/fixtures/configurations.yml +29 -0
- data/generators/opensteam/templates/test/fixtures/inventories.yml +32 -15
- data/generators/opensteam/templates/test/fixtures/profiles.yml +21 -0
- data/generators/opensteam/templates/test/fixtures/region_shipping_rates.yml +33 -0
- data/generators/opensteam/templates/test/fixtures/shipping_payment_additions.yml +91 -0
- data/generators/opensteam/templates/test/fixtures/shipping_rate_groups.yml +25 -0
- data/generators/opensteam/templates/test/fixtures/tax_groups.yml +13 -0
- data/generators/opensteam/templates/test/fixtures/tax_rules.yml +29 -0
- data/generators/opensteam/templates/test/fixtures/tax_zones.yml +33 -0
- data/generators/opensteam/templates/test/fixtures/users.yml +26 -0
- data/generators/opensteam/templates/test/fixtures/zones.yml +2707 -0
- data/generators/opensteam/templates/test/functional/carts_controller_test.rb +103 -0
- data/generators/opensteam/templates/test/test_helper.rb +38 -0
- data/generators/opensteam/templates/test/unit/container_test.rb +71 -0
- data/generators/opensteam/templates/test/unit/order_test.rb +93 -0
- data/generators/opensteam/templates/test/unit/payment_test.rb +220 -0
- data/generators/opensteam/templates/test/unit/product_test.rb +158 -0
- data/generators/opensteam/templates/vendor/plugins/prawnto/.gitignore +3 -0
- data/generators/opensteam/templates/vendor/plugins/prawnto/MIT-LICENSE +20 -0
- data/generators/opensteam/templates/vendor/plugins/prawnto/README +12 -0
- data/generators/opensteam/templates/vendor/plugins/prawnto/Rakefile +22 -0
- data/generators/opensteam/templates/vendor/plugins/prawnto/init.rb +6 -0
- data/generators/opensteam/templates/vendor/plugins/prawnto/lib/prawnto.rb +13 -0
- data/generators/opensteam/templates/vendor/plugins/prawnto/lib/prawnto/action_controller.rb +47 -0
- data/generators/opensteam/templates/vendor/plugins/prawnto/lib/prawnto/template_handler/base.rb +75 -0
- data/generators/opensteam/templates/vendor/plugins/prawnto/lib/prawnto/template_handler/raw.rb +54 -0
- data/generators/opensteam/templates/vendor/plugins/prawnto/tasks/prawnto_tasks.rake +4 -0
- data/generators/opensteam/templates/vendor/plugins/prawnto/test/action_controller_test.rb +36 -0
- data/generators/opensteam/templates/vendor/plugins/prawnto/test/base_template_handler_test.rb +58 -0
- data/generators/opensteam/templates/vendor/plugins/prawnto/test/raw_template_handler_test.rb +163 -0
- data/generators/opensteam/templates/vendor/plugins/prawnto/test/template_handler_test_mocks.rb +83 -0
- data/generators/opensteam_product/templates/views/admin/_attributes.html.erb +8 -3
- data/generators/opensteam_product/templates/views/admin/_inventories.html.erb +2 -0
- data/lib/opensteam.rb +0 -1
- data/lib/opensteam/base.rb +2 -1
- data/lib/opensteam/checkout.rb +3 -12
- data/lib/opensteam/config.rb +50 -2
- data/lib/opensteam/container.rb +196 -0
- data/lib/opensteam/extension_base.rb +19 -1
- data/lib/opensteam/finder.rb +1 -1
- data/lib/opensteam/helpers/config_table_helper.rb +18 -6
- data/lib/opensteam/initializer.rb +24 -4
- data/lib/opensteam/inventory_base.rb +6 -1
- data/lib/opensteam/invoice_base.rb +12 -13
- data/lib/opensteam/money.rb +230 -0
- data/lib/opensteam/order_base.rb +122 -48
- data/lib/opensteam/payment.rb +225 -0
- data/lib/opensteam/payment/advance_payment.rb +34 -0
- data/lib/opensteam/payment/credit_card_payment.rb +217 -0
- data/lib/opensteam/payment/direct_debit_payment.rb +53 -0
- data/lib/opensteam/product_base.rb +48 -12
- data/lib/opensteam/security.rb +54 -0
- data/lib/opensteam/shipment_base.rb +214 -6
- data/lib/opensteam/shopping_cart.rb +20 -300
- data/lib/opensteam/state_logic.rb +5 -3
- data/lib/opensteam/state_machine.rb +8 -3
- data/lib/opensteam/user_base.rb +48 -6
- data/lib/opensteam/version.rb +1 -1
- metadata +122 -16
- data/generators/opensteam/templates/app/controllers/cart_controller.rb +0 -94
- data/generators/opensteam/templates/app/views/admin/orders/_event.html.erb +0 -5
- data/generators/opensteam/templates/app/views/admin/orders/_order_item.html.erb +0 -10
- data/generators/opensteam/templates/app/views/cart/_cart.html.erb +0 -8
- data/generators/opensteam/templates/app/views/cart/_cart_content.html.erb +0 -20
- data/generators/opensteam/templates/app/views/cart/update.rjs +0 -1
- data/generators/opensteam/templates/app/views/checkout/payment.html.erb +0 -8
- data/generators/opensteam/templates/app/views/checkout/shipping.html.erb +0 -45
- data/generators/opensteam/templates/app/views/checkout/show_cart.html.erb +0 -13
- data/generators/opensteam/templates/app/views/checkout/update_cart_content.rjs +0 -2
- data/generators/opensteam/templates/app/views/profile/orders/_order_item.html.erb +0 -10
- data/generators/opensteam/templates/db/migrate/20080609095725_create_dummy_users.rb +0 -21
- data/lib/opensteam/cart_base.rb +0 -227
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
# openSteam - http://www.opensteam.net
|
|
2
|
+
# Copyright (C) 2008 DiamondDogs Webconsulting
|
|
3
|
+
#
|
|
4
|
+
# This program is free software; you can redistribute it and/or modify
|
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
|
6
|
+
# the Free Software Foundation; version 2 of the License.
|
|
7
|
+
#
|
|
8
|
+
# This program is distributed in the hope that it will be useful,
|
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11
|
+
# GNU General Public License for more details.
|
|
12
|
+
#
|
|
13
|
+
# You should have received a copy of the GNU General Public License along
|
|
14
|
+
# with this program; if not, write to the Free Software Foundation, Inc.,
|
|
15
|
+
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
16
|
+
|
|
17
|
+
module Opensteam
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
module Container
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
# Container Base Class
|
|
24
|
+
# used for Cart, Orders, Wishlists, etc
|
|
25
|
+
# TODO: check self.abstract == useful
|
|
26
|
+
class Base < ActiveRecord::Base
|
|
27
|
+
def self.table_name ; "containers" ; end
|
|
28
|
+
|
|
29
|
+
has_many :items, :class_name => "Opensteam::Container::Item",
|
|
30
|
+
:foreign_key => 'container_id',
|
|
31
|
+
:dependent => :destroy
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
belongs_to :customer, :class_name => 'Opensteam::UserBase::User'
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
# move all items from container +c+ to current container +self+
|
|
39
|
+
def move_items_from c
|
|
40
|
+
c.items.each do |v|
|
|
41
|
+
v.update_attribute( :container, self )
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# copy all items from container +c+ to current container +self+
|
|
47
|
+
def copy_items_from c
|
|
48
|
+
c.items.each do |v|
|
|
49
|
+
items.build( v.attributes )
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
# Shopping Cart implementation
|
|
59
|
+
# SubClass of Opensteam::Container::Base
|
|
60
|
+
class Cart < Opensteam::Container::Base
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
# access items as array
|
|
66
|
+
def []( id ) ; items[id.to_i] ; end
|
|
67
|
+
|
|
68
|
+
# push/add item to container
|
|
69
|
+
# if item exists, increment quantity
|
|
70
|
+
def push( item )
|
|
71
|
+
unless( i = find_item( item ) )
|
|
72
|
+
items.create( :item => item )
|
|
73
|
+
else
|
|
74
|
+
i.incr
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def update!
|
|
79
|
+
update_tax( :country => "Austria" )
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
# access index of items
|
|
84
|
+
def index(i)
|
|
85
|
+
@items.index(i)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
# find +item+
|
|
90
|
+
def find_item( item )
|
|
91
|
+
Array(items).find { |i| i.item == item }
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def total_price
|
|
96
|
+
items.collect(&:total_price).sum
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
# set quantity for items in +h+ (hash)
|
|
100
|
+
# container.set_quantity = { "0" => 123, "1" => 345 }
|
|
101
|
+
# where key is the array index of +items+
|
|
102
|
+
def set_quantity=(h)
|
|
103
|
+
h.each_pair { |k,v| self.items[k.to_i].set_quantity(v) }
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
# alias for push
|
|
108
|
+
alias :<< :push
|
|
109
|
+
alias :add :push
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
# Items for Container Class
|
|
118
|
+
# used for CartItems, OrderItems, etc
|
|
119
|
+
#
|
|
120
|
+
# implements quantity mechanism (increment, decrement, set_quantity). if quantity == 0, item destroys itself.
|
|
121
|
+
# implements a method_missing to delegate all unknown method calls to (polymorphic) item.
|
|
122
|
+
class Item < ActiveRecord::Base
|
|
123
|
+
|
|
124
|
+
def self.table_name ; "container_items" ; end
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
before_create :init_price, :init_quantity
|
|
128
|
+
after_save :check_quantity
|
|
129
|
+
before_save :update_total_price
|
|
130
|
+
|
|
131
|
+
belongs_to :container, :class_name => 'Opensteam::Container::Base',
|
|
132
|
+
:counter_cache => "items_count"
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
belongs_to :item, :polymorphic => true
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
belongs_to :invoice, :class_name => 'Opensteam::InvoiceBase::Invoice'
|
|
140
|
+
belongs_to :shipment, :class_name => 'Opensteam::ShipmentBase::Shipment'
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
# increment quantity
|
|
144
|
+
def incr ; self.increment!( :quantity, 1 ) ; end
|
|
145
|
+
|
|
146
|
+
# decrement quantity
|
|
147
|
+
def decr ; self.decrement!( :quantity, 1 ) ; end
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
# set quantity and save item
|
|
151
|
+
def set_quantity( qnt )
|
|
152
|
+
self.quantity = qnt
|
|
153
|
+
save
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
# delegate all missing methods to item, if item responds
|
|
157
|
+
def method_missing(name, *args, &block )
|
|
158
|
+
self.item.respond_to?( name ) ? self.item.__send__( name, *args, &block ) : super
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
private
|
|
162
|
+
|
|
163
|
+
# init quantity
|
|
164
|
+
def init_quantity
|
|
165
|
+
self.quantity = 1 ;
|
|
166
|
+
update_total_price
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def init_price
|
|
172
|
+
self.price = self.item.price
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def update_total_price
|
|
177
|
+
self.total_price = self.quantity * self.price
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
# if quantity == 0, destroy yourself
|
|
182
|
+
def check_quantity
|
|
183
|
+
if self.quantity <= 0
|
|
184
|
+
self.destroy
|
|
185
|
+
end
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
end
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
Cart = Opensteam::Container::Cart
|
|
@@ -1,5 +1,23 @@
|
|
|
1
|
+
# openSteam - http://www.opensteam.net
|
|
2
|
+
# Copyright (C) 2008 DiamondDogs Webconsulting
|
|
3
|
+
#
|
|
4
|
+
# This program is free software; you can redistribute it and/or modify
|
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
|
6
|
+
# the Free Software Foundation; version 2 of the License.
|
|
7
|
+
#
|
|
8
|
+
# This program is distributed in the hope that it will be useful,
|
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11
|
+
# GNU General Public License for more details.
|
|
12
|
+
#
|
|
13
|
+
# You should have received a copy of the GNU General Public License along
|
|
14
|
+
# with this program; if not, write to the Free Software Foundation, Inc.,
|
|
15
|
+
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
16
|
+
|
|
1
17
|
module Opensteam
|
|
2
18
|
|
|
19
|
+
# module to handle Opensteam Extensions
|
|
20
|
+
# (not in use right now)
|
|
3
21
|
module ExtensionBase #:nodoc:
|
|
4
22
|
|
|
5
23
|
mattr_accessor :extension_path
|
|
@@ -69,7 +87,7 @@ module Opensteam
|
|
|
69
87
|
|
|
70
88
|
end
|
|
71
89
|
|
|
72
|
-
class Backend < Extension
|
|
90
|
+
class Backend < Extension #:nodoc:
|
|
73
91
|
end
|
|
74
92
|
|
|
75
93
|
end
|
data/lib/opensteam/finder.rb
CHANGED
|
@@ -1,4 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
# openSteam - http://www.opensteam.net
|
|
2
|
+
# Copyright (C) 2008 DiamondDogs Webconsulting
|
|
3
|
+
#
|
|
4
|
+
# This program is free software; you can redistribute it and/or modify
|
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
|
6
|
+
# the Free Software Foundation; version 2 of the License.
|
|
7
|
+
#
|
|
8
|
+
# This program is distributed in the hope that it will be useful,
|
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11
|
+
# GNU General Public License for more details.
|
|
12
|
+
#
|
|
13
|
+
# You should have received a copy of the GNU General Public License along
|
|
14
|
+
# with this program; if not, write to the Free Software Foundation, Inc.,
|
|
15
|
+
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
16
|
+
|
|
17
|
+
module Opensteam::Helpers #:nodoc:
|
|
2
18
|
|
|
3
19
|
|
|
4
20
|
module ConfigTableHelper
|
|
@@ -8,10 +24,6 @@ module Opensteam::Helpers
|
|
|
8
24
|
base.class_eval do
|
|
9
25
|
include InstanceMethods
|
|
10
26
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
27
|
end
|
|
16
28
|
|
|
17
29
|
end
|
|
@@ -117,7 +129,7 @@ module Opensteam::Helpers
|
|
|
117
129
|
html_options = opts[:html] || {}
|
|
118
130
|
|
|
119
131
|
concat(
|
|
120
|
-
content_tag( :div, { :class => '
|
|
132
|
+
content_tag( :div, { :class => 'osteam_configured_table_div' } ) do
|
|
121
133
|
content_tag( :table, html_options ) do
|
|
122
134
|
content
|
|
123
135
|
end
|
|
@@ -81,7 +81,7 @@ module Opensteam
|
|
|
81
81
|
end
|
|
82
82
|
|
|
83
83
|
|
|
84
|
-
def require_libs
|
|
84
|
+
def require_libs #:nodoc:
|
|
85
85
|
require 'opensteam/version'
|
|
86
86
|
require 'opensteam/config'
|
|
87
87
|
require 'opensteam/finder'
|
|
@@ -90,17 +90,37 @@ module Opensteam
|
|
|
90
90
|
require 'opensteam/base'
|
|
91
91
|
require 'opensteam/history'
|
|
92
92
|
require 'opensteam/state_machine'
|
|
93
|
-
require 'opensteam/invoice_base'
|
|
94
93
|
require 'opensteam/shipment_base'
|
|
94
|
+
require 'opensteam/invoice_base'
|
|
95
|
+
require 'opensteam/container'
|
|
96
|
+
|
|
97
|
+
require 'opensteam/security'
|
|
98
|
+
require 'opensteam/payment'
|
|
99
|
+
|
|
95
100
|
require 'opensteam/order_base'
|
|
101
|
+
|
|
96
102
|
require 'opensteam/state_logic'
|
|
97
103
|
require 'opensteam/extension_base'
|
|
104
|
+
|
|
105
|
+
# require all payment types
|
|
106
|
+
Dir.glob( File.join( File.dirname(__FILE__), "payment", "*.rb" ) ) { |f|
|
|
107
|
+
require f
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
|
|
98
111
|
require 'opensteam/shopping_cart'
|
|
99
|
-
require 'opensteam/cart_base'
|
|
112
|
+
# require 'opensteam/cart_base'
|
|
100
113
|
require 'opensteam/checkout'
|
|
101
114
|
require 'opensteam/inventory_base'
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
# require 'opensteam/order_container'
|
|
102
120
|
|
|
121
|
+
# require 'opensteam/tax'
|
|
103
122
|
|
|
123
|
+
require 'opensteam/money'
|
|
104
124
|
|
|
105
125
|
end
|
|
106
126
|
|
|
@@ -109,7 +129,7 @@ module Opensteam
|
|
|
109
129
|
|
|
110
130
|
|
|
111
131
|
|
|
112
|
-
class Configuration
|
|
132
|
+
class Configuration #:nodoc:
|
|
113
133
|
|
|
114
134
|
def say_something
|
|
115
135
|
|
|
@@ -43,6 +43,7 @@ module Opensteam
|
|
|
43
43
|
# Inventory Model
|
|
44
44
|
class Inventory < ActiveRecord::Base
|
|
45
45
|
|
|
46
|
+
|
|
46
47
|
has_many :order_items, :class_name => "Opensteam::OrderBase::OrderItem"
|
|
47
48
|
|
|
48
49
|
belongs_to :product, :polymorphic => true
|
|
@@ -52,12 +53,16 @@ module Opensteam
|
|
|
52
53
|
|
|
53
54
|
validates_presence_of :price, :storage
|
|
54
55
|
|
|
56
|
+
named_scope :by_properties, lambda { |properties| { :include => :properties,
|
|
57
|
+
:conditions => { "properties.id" => properties.collect(&:id) },
|
|
58
|
+
:group => "inventories.id HAVING COUNT( inventories.id ) = #{properties.size}" } }
|
|
59
|
+
|
|
55
60
|
|
|
56
61
|
def products
|
|
57
62
|
find(:all, :include => :product ).collect(&:product)
|
|
58
63
|
end
|
|
59
64
|
|
|
60
|
-
|
|
65
|
+
[:name, :description ].each { |m| delegate m, :to => :product }
|
|
61
66
|
|
|
62
67
|
|
|
63
68
|
|
|
@@ -20,29 +20,20 @@ module Opensteam
|
|
|
20
20
|
# Base Module for all Invoice-specific modules + classes
|
|
21
21
|
module InvoiceBase
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
# available States for an Invoice-Instance
|
|
26
|
-
module States
|
|
27
|
-
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
23
|
+
module States ; end
|
|
24
|
+
|
|
32
25
|
|
|
33
26
|
# Invoice Model
|
|
34
27
|
class Invoice < ActiveRecord::Base
|
|
35
|
-
include Opensteam::StateMachine
|
|
36
28
|
|
|
37
29
|
belongs_to :order, :class_name => 'Opensteam::OrderBase::Order'
|
|
38
30
|
belongs_to :customer, :class_name => 'Opensteam::UserBase::User'
|
|
39
31
|
belongs_to :address, :class_name => 'Opensteam::UserBase::Address'
|
|
40
32
|
|
|
41
|
-
has_many :order_items, :class_name => 'Opensteam::
|
|
42
|
-
|
|
33
|
+
has_many :order_items, :class_name => 'Opensteam::Container::Item'
|
|
43
34
|
|
|
44
35
|
named_scope :by_order, lambda { |order_id| { :include => :order, :conditions => { :order_id => order_id } } }
|
|
45
|
-
named_scope :order_by, lambda { |by| { :include => Invoice.osteam_configtable.default_include, :order => Array(by).join(",") , :conditions => "
|
|
36
|
+
named_scope :order_by, lambda { |by| { :include => Invoice.osteam_configtable.default_include, :order => Array(by).join(",") , :conditions => "addresses.id = addresses.id" } }
|
|
46
37
|
|
|
47
38
|
|
|
48
39
|
def initialize(*args)
|
|
@@ -54,6 +45,14 @@ module Opensteam
|
|
|
54
45
|
end
|
|
55
46
|
|
|
56
47
|
|
|
48
|
+
def amount_in_cents
|
|
49
|
+
( price * 100 ).to_i
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def items ; order_items ; end
|
|
54
|
+
|
|
55
|
+
|
|
57
56
|
end
|
|
58
57
|
|
|
59
58
|
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
# openSteam - http://www.opensteam.net
|
|
2
|
+
# Copyright (C) 2008 DiamondDogs Webconsulting
|
|
3
|
+
#
|
|
4
|
+
# This program is free software; you can redistribute it and/or modify
|
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
|
6
|
+
# the Free Software Foundation; version 2 of the License.
|
|
7
|
+
#
|
|
8
|
+
# This program is distributed in the hope that it will be useful,
|
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11
|
+
# GNU General Public License for more details.
|
|
12
|
+
#
|
|
13
|
+
# You should have received a copy of the GNU General Public License along
|
|
14
|
+
# with this program; if not, write to the Free Software Foundation, Inc.,
|
|
15
|
+
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
module Opensteam
|
|
19
|
+
|
|
20
|
+
# module for all Money specific modules and classes
|
|
21
|
+
#
|
|
22
|
+
# includes:
|
|
23
|
+
# - helper methods for View, Opensteam::Money::Helper
|
|
24
|
+
# - class for rounding, Opensteam::Money::Rounding
|
|
25
|
+
# - Tax specific modules and classes, Opensteam::Money::Tax
|
|
26
|
+
#
|
|
27
|
+
module Money
|
|
28
|
+
|
|
29
|
+
module Helper
|
|
30
|
+
|
|
31
|
+
def get_rate_for item, country = nil
|
|
32
|
+
item.get_rate( :country => country || Opensteam::Config[ :default_country ] )
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def calculate_tax_for item, country = nil
|
|
36
|
+
item.calculate_tax( :country => country || Opensteam::Config[ :default_country ] )
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
module Rounding
|
|
43
|
+
|
|
44
|
+
# TODO: define rounding methods for zones
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
# normal rounding
|
|
48
|
+
def round f
|
|
49
|
+
BigDecimal.new( f.to_s ).round(2)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
# rappen rounding (for CH)
|
|
54
|
+
def round_rappen f
|
|
55
|
+
( BigDecimal.new( f.to_s ) * 20 ).round / 20
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
# Contains all tax specific modules and classes
|
|
64
|
+
module Tax
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
module Calculation
|
|
68
|
+
include Opensteam::Money::Rounding
|
|
69
|
+
|
|
70
|
+
def calculate_tax( address )
|
|
71
|
+
round( self.price * ( get_rate( address ) / 100 ) )
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def get_rate( address )
|
|
75
|
+
return 0.0 unless self.tax_group
|
|
76
|
+
|
|
77
|
+
zones = self.tax_group.tax_zones.by_address( address )
|
|
78
|
+
|
|
79
|
+
if !zones || zones.empty?
|
|
80
|
+
return 0.0
|
|
81
|
+
else
|
|
82
|
+
zones.first.rate
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
# TaxZones
|
|
94
|
+
# defines rates
|
|
95
|
+
class TaxZone < ActiveRecord::Base
|
|
96
|
+
self.table_name = "tax_zones"
|
|
97
|
+
|
|
98
|
+
has_many :tax_rules, :class_name => "Opensteam::Money::Tax::TaxRule"
|
|
99
|
+
|
|
100
|
+
named_scope :order_by, lambda { |by| { :order => Array(by).join(",") } }
|
|
101
|
+
named_scope :by_product_tax_group, lambda { |a| { :include => { :tax_rules => :product_tax_group },
|
|
102
|
+
:conditions => { "tax_groups.name" => a } } }
|
|
103
|
+
|
|
104
|
+
named_scope :by_address, lambda { |a| { :conditions => a } }
|
|
105
|
+
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
# Base Class for TaxGroups
|
|
111
|
+
class TaxGroup < ActiveRecord::Base
|
|
112
|
+
self.table_name = "tax_groups"
|
|
113
|
+
named_scope :order_by, lambda { |by| { :order => Array(by).join(",") } }
|
|
114
|
+
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
# Tax Groups for a Custmoer, not yet implemented !!
|
|
119
|
+
class CustomerTaxGroup < TaxGroup
|
|
120
|
+
|
|
121
|
+
has_many :customers, :class_name => "Opensteam::UserBase::User", :foreign_key => "tax_group_id"
|
|
122
|
+
|
|
123
|
+
has_many :tax_rules, :foreign_key => "customer_tax_groupd_id", :class_name => "Opensteam::Money::Tax::TaxRule"
|
|
124
|
+
has_many :tax_zones, :through => :tax_rules, :class_name => "Opensteam::Money::Tax::TaxZone"
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
# Tax Groups for a Product (Inventory)
|
|
130
|
+
class ProductTaxGroup < TaxGroup
|
|
131
|
+
|
|
132
|
+
has_many :inventories, :class_name => 'Opensteam::InventoryBase::Inventory', :foreign_key => "tax_group_id"
|
|
133
|
+
|
|
134
|
+
has_many :tax_rules, :foreign_key => "product_tax_group_id", :class_name => "Opensteam::Money::Tax::TaxRule"
|
|
135
|
+
has_many :tax_zones, :through => :tax_rules, :class_name => "Opensteam::Money::Tax::TaxZone"
|
|
136
|
+
|
|
137
|
+
validates_presence_of :name
|
|
138
|
+
validates_uniqueness_of :name
|
|
139
|
+
|
|
140
|
+
after_update :save_tax_rules
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def new_tax_rule_attributes=( rule_attributes )
|
|
144
|
+
rules = []
|
|
145
|
+
rule_attributes.each do |attributes|
|
|
146
|
+
tax_rules.build( attributes ) unless rules.include?( attributes["tax_zone_id"] )
|
|
147
|
+
rules << attributes["tax_zone_id"]
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
def existing_tax_rule_attributes=( rule_attributes )
|
|
152
|
+
tax_rules.reject(&:new_record?).each do |tax_rule|
|
|
153
|
+
attributes = rule_attributes[tax_rule.id.to_s]
|
|
154
|
+
if attributes
|
|
155
|
+
tax_rule.attributes = attributes
|
|
156
|
+
else
|
|
157
|
+
tax_rules.delete( tax_rule )
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
def save_tax_rules
|
|
163
|
+
tax_rules.each { |rule| rule.save(false) }
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
def tax_rules=( rules )
|
|
168
|
+
return false unless save
|
|
169
|
+
self.tax_rules.delete_all
|
|
170
|
+
rules.each { |r| self.tax_rules.create( r ) }
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
# TaxRules
|
|
178
|
+
# maps TaxGroups to TaxZones
|
|
179
|
+
class TaxRule < ActiveRecord::Base
|
|
180
|
+
self.table_name = "tax_rules"
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
belongs_to :customer_tax_group, :class_name => "Opensteam::Money::Tax::TaxGroup"
|
|
184
|
+
belongs_to :product_tax_group, :class_name => "Opensteam::Money::Tax::TaxGroup"
|
|
185
|
+
|
|
186
|
+
belongs_to :tax_zone
|
|
187
|
+
|
|
188
|
+
named_scope :by_product_tax_group, lambda { |p| { :include => :product_tax_group, :conditions => { "tax_groups.name" => p } } }
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
TaxZone = Opensteam::Money::Tax::TaxZone
|
|
204
|
+
TaxRule = Opensteam::Money::Tax::TaxRule
|
|
205
|
+
TaxGroup = Opensteam::Money::Tax::TaxGroup
|
|
206
|
+
ProductTaxGroup = Opensteam::Money::Tax::ProductTaxGroup
|
|
207
|
+
CustomerTaxGroup = Opensteam::Money::Tax::CustomerTaxGroup
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
Opensteam::Container::Item.send( :include, Opensteam::Money::Tax::Calculation )
|
|
211
|
+
|
|
212
|
+
Opensteam::InventoryBase::Inventory.class_eval do
|
|
213
|
+
belongs_to :tax_group, :class_name => 'Opensteam::Money::Tax::ProductTaxGroup'
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
#Opensteam::InventoryBase::Inventory.send( :include, Opensteam::Money::Tax::InventoryHelper )
|
|
219
|
+
#Opensteam::OrderBase::OrderItem.send( :include, Opensteam::Money::Tax::OrderItemHelper )
|
|
220
|
+
#Opensteam::OrderBase::Order.send( :include, Opensteam::Tax::OrderHelper)
|
|
221
|
+
#
|
|
222
|
+
#
|
|
223
|
+
#Opensteam::Container::Cart.send( :include, Opensteam::Tax::ContainerHelper )
|
|
224
|
+
#Opensteam::Container::Item.send( :include, Opensteam::Tax::ContainerItemHelper)
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
|