Skip to content

Commit

Permalink
first steps for gettin rid of fees for private users
Browse files Browse the repository at this point in the history
  • Loading branch information
chiramiso committed Jan 28, 2015
1 parent d66b396 commit 3e6ecb0
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 75 deletions.
2 changes: 1 addition & 1 deletion app/controllers/articles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def show
@user_libraries = current_user.libraries if current_user
@containing_libraries = @article.libraries.includes(user: [:image]).published.limit(10)

if !@article.active? && policy(@article).activate?
if !@article.active? && policy(@article).activate? && @article.seller.is_a?(LegalEntity)
@article.calculate_fees_and_donations
end

Expand Down
2 changes: 1 addition & 1 deletion app/helpers/articles_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def show_fair_percent_for? article
# we can't be sure if the book is german
# so we dont show fair percent on all new books
# book category is written in exceptions.yml
!article.could_be_book_price_agreement? && article.friendly_percent != 100
article.belongs_to_legal_entity? && !article.could_be_book_price_agreement? && article.friendly_percent != 100
end

#def export_time_ranges
Expand Down
16 changes: 8 additions & 8 deletions app/models/article/fees_and_donations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@ module Article::FeesAndDonations
extend ActiveSupport::Concern

TRANSACTION_FEES = {
:min => 0.1,
:max_fair => 15.0,
:max_default => 30.0,
:fair => 0.03,
:default => 0.06
min: 0.1,
max_fair: 15.0,
max_default: 30.0,
fair: 0.03,
default: 0.06
}

included do

before_create :set_friendly_percent_for_ngo, if: :seller_ngo

# Fees and donations
monetize :calculated_fair_cents, :allow_nil => true
monetize :calculated_friendly_cents, :allow_nil => true
monetize :calculated_fee_cents, :allow_nil => true
monetize :calculated_fair_cents, allow_nil: true
monetize :calculated_friendly_cents, allow_nil: true
monetize :calculated_fee_cents, allow_nil: true

## friendly percent
validates_presence_of :friendly_percent_organisation_id, :if => :friendly_percent_gt_0?
Expand Down
2 changes: 1 addition & 1 deletion app/models/article/validations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ module Article::Validations
validates :payment_details, length: { :maximum => 2500 }
validates :quantity, presence: true, numericality: { greater_than_or_equal_to: 1, less_than_or_equal_to: 10000 }
validates :quantity_available, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 10000 }
validates :tos_accepted, acceptance: true, presence: true, on: :update, if: :changing_state
validates :tos_accepted, acceptance: true, presence: true, on: :update, if: lambda { |art| art.changing_state && art.seller.is_a?(LegalEntity) }

#images

Expand Down
4 changes: 0 additions & 4 deletions app/models/user/extended_attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ module User::ExtendedAttributes
auto_sanitize :iban, :bic, remove_all_spaces: true
auto_sanitize :about_me, :terms, :cancellation, :about, method: 'tiny_mce'


attr_accessor :wants_to_sell
attr_accessor :bank_account_validation , :paypal_validation
attr_accessor :fastbill_profile_update
Expand All @@ -40,7 +39,4 @@ module User::ExtendedAttributes

end




end
2 changes: 0 additions & 2 deletions app/models/user/validations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
module User::Validations
extend ActiveSupport::Concern


included do

validates_presence_of :slug
Expand Down Expand Up @@ -34,5 +33,4 @@ module User::Validations
validates_inclusion_of :type, in: ["LegalEntity"], if: :is_ngo?
end


end
2 changes: 1 addition & 1 deletion app/models/users/private_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class PrivateUser < User
end

def private_seller_constants
private_seller_constants = {
{
:standard_salesvolume => $private_seller_constants['standard_salesvolume'],
:verified_bonus => $private_seller_constants['verified_bonus'],
:trusted_bonus => $private_seller_constants['trusted_bonus'],
Expand Down
10 changes: 7 additions & 3 deletions app/refineries/article_refinery.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
class ArticleRefinery < ApplicationRefinery

def self.root
false
end

def create
[
# Common attrs
Expand Down Expand Up @@ -72,8 +76,8 @@ def create
end

def update
create + [
:tos_accepted
]
create# + [
# :tos_accepted
#]
end
end
83 changes: 42 additions & 41 deletions app/views/articles/show/_activation_links.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -22,55 +22,56 @@
= semantic_form_for resource, url: article_path(activate: true), html: {class: 'js-visual-submit'} do |f|
.activation_links
h3
= t('article.preview.fees_and_donations.title')
= if show_fair_percent_for? resource
h3
= t('article.preview.fees_and_donations.title')

dl
dt.reduced_padding
= f.inputs do
- legal_link = checkbox_link_helper t('users.legal_link'), '/agb'
- privacy_link = checkbox_link_helper t('users.privacy_link'), '/privacy'
= f.input :tos_accepted, as: :boolean, required: false, wrapper_html: { class: 'no-margin' }, label: t("formtastic.labels.user.tos_accepted", legal: legal_link, privacy: privacy_link).html_safe
dt
= simple_format t('article.preview.fees_and_donations.fee', fee: (resource.fair ? "3%" : "6%"), max: (resource.fair ? "€15" : "€30") )
span.sprite_helper title= "Bei erfolgreichem Verkauf gehen 6% des Artikelendpreises an Fairmondo. Bei Artikeln unter dem Filter fair fallen lediglich 3% an."
dd
= humanized_money_with_symbol resource.calculated_fee
dt
= t('article.preview.fees_and_donations.fair_percent')
span.sprite_helper title= t("article.preview.tooltips.fees_and_donations")
dd
= humanized_money_with_symbol resource.calculated_fair

dt
= t('article.preview.fees_and_donations.friendly_percent')
- if show_friendly_percent_for? resource
span.sprite_helper title=t("article.preview.tooltips.fp_fee_info", percent: resource.friendly_percent, ngo: resource.friendly_percent_organisation_nickname)
dd= humanized_money_with_symbol resource.calculated_friendly
dl
dt.reduced_padding
= f.inputs do
- legal_link = checkbox_link_helper t('users.legal_link'), '/agb'
- privacy_link = checkbox_link_helper t('users.privacy_link'), '/privacy'
= f.input :tos_accepted, as: :boolean, required: false, wrapper_html: { class: 'no-margin' }, label: t("formtastic.labels.user.tos_accepted", legal: legal_link, privacy: privacy_link).html_safe
dt
= simple_format t('article.preview.fees_and_donations.fee', fee: (resource.fair ? "3%" : "6%"), max: (resource.fair ? "€15" : "€30") )
span.sprite_helper title= "Bei erfolgreichem Verkauf gehen 6% des Artikelendpreises an Fairmondo. Bei Artikeln unter dem Filter fair fallen lediglich 3% an."
dd
= humanized_money_with_symbol resource.calculated_fee
dt
= t('article.preview.fees_and_donations.fair_percent')
span.sprite_helper title= t("article.preview.tooltips.fees_and_donations")
dd
= humanized_money_with_symbol resource.calculated_fair

dt.total
= t('article.preview.fees_and_donations.total')
span.sprite_helper title="Die Gesamtgebühr setzt sich aus den obigen Komponenten zusammen."
dd.total
= humanized_money_with_symbol resource.calculated_fees_and_donations
= "*"
dt
= "* " << t('article.preview.fees_and_donations.netto')
= humanized_money_with_symbol resource.calculated_fees_and_donations_netto
dt
= t('article.preview.fees_and_donations.friendly_percent')
- if show_friendly_percent_for? resource
span.sprite_helper title=t("article.preview.tooltips.fp_fee_info", percent: resource.friendly_percent, ngo: resource.friendly_percent_organisation_nickname)
dd= humanized_money_with_symbol resource.calculated_friendly

- if !resource.seller.ngo
dt.total
= t('article.preview.fees_and_donations.total')
span.sprite_helper title="Die Gesamtgebühr setzt sich aus den obigen Komponenten zusammen."
dd.total
= humanized_money_with_symbol resource.calculated_fees_and_donations
= "*"
dt
/! = t('article.preview.fees_and_donations.quarter_fee')
| Zzgl. der
a href="/faq#geb1" target="_blank"
= " Quartalsgebühr "
| von 1,- Euro (inkl. 19% MwSt).
span.sprite_helper title=t("article.preview.tooltips.fees_quarter_fee")
= "* " << t('article.preview.fees_and_donations.netto')
= humanized_money_with_symbol resource.calculated_fees_and_donations_netto

- if !resource.seller.ngo
dt
/! = t('article.preview.fees_and_donations.quarter_fee')
| Zzgl. der
a href="/faq#geb1" target="_blank"
= " Quartalsgebühr "
| von 1,- Euro (inkl. 19% MwSt).
span.sprite_helper title=t("article.preview.tooltips.fees_quarter_fee")
.activation
- if resource.sold?
= link_to "Artikel zum Wiedereinstellen bearbeiten", new_article_path(edit_as_new: resource.id), :class=>"Button Button--large"
- else
- if resource.seller.ngo
- if resource.seller.ngo || resource.seller.is_a?(PrivateUser)
- btn_text = t("article.labels.submit_free")
- else
- btn_text = show_friendly_percent_for?(resource) ? t("article.labels.submit_with_fp") : t("article.labels.submit")
Expand Down
25 changes: 12 additions & 13 deletions test/features/articles_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def fill_form_with_valid_article
article = FactoryGirl.create :preview_article, :user_id => user.id
login_as user
visit article_path(article)
click_button I18n.t("article.labels.submit")
click_button I18n.t("article.labels.submit_free")
page.must_have_content I18n.t('article.notices.max_limit')
article.active?.must_equal false
end
Expand All @@ -152,23 +152,22 @@ def fill_form_with_valid_article
article = FactoryGirl.create :preview_article, seller: user
login_as user
visit article_path(article)
check 'article_tos_accepted'
click_button I18n.t("article.labels.submit")
click_button I18n.t("article.labels.submit_free")
page.wont_have_content I18n.t('article.notices.max_limit')
current_path.must_equal article_path article
article.reload.active?.must_equal true
end

scenario "user doesn't accept TOS" do
user = FactoryGirl.create :user
article = FactoryGirl.create :preview_article, seller: user
login_as user
visit article_path(article)
click_button I18n.t("article.labels.submit")
page.must_have_content I18n.t('article.notices.activation_failed')
current_path.must_equal article_path article
article.reload.active?.must_equal false
end
#scenario "user doesn't accept TOS" do
# user = FactoryGirl.create :user
# article = FactoryGirl.create :preview_article, seller: user
# login_as user
# visit article_path(article)
# click_button I18n.t("article.labels.submit")
# page.must_have_content I18n.t('article.notices.activation_failed')
# current_path.must_equal article_path article
# article.reload.active?.must_equal false
#end
end

feature "Article activation for legal entities" do
Expand Down

0 comments on commit 3e6ecb0

Please sign in to comment.