diff --git a/app/controllers/admin/pricelists_controller.rb b/app/controllers/admin/pricelists_controller.rb index a0fa2c010..f17b877fd 100644 --- a/app/controllers/admin/pricelists_controller.rb +++ b/app/controllers/admin/pricelists_controller.rb @@ -39,6 +39,7 @@ class Admin::PricelistsController < AdminController end def pricelist_params - params.require(:pricelist).permit(:category, :name, :duration, :price, :valid_from, :valid_to) + params.require(:pricelist).permit(:operation_category, :category, :price_category, + :duration, :price, :valid_from, :valid_to) end end diff --git a/app/models/pricelist.rb b/app/models/pricelist.rb index 12a567a95..e43fa4475 100644 --- a/app/models/pricelist.rb +++ b/app/models/pricelist.rb @@ -3,9 +3,11 @@ class Pricelist < ActiveRecord::Base monetize :price_cents - validates :price_cents, :price_currency, :valid_from, :category, presence: true + validates :price_cents, :price_currency, :price, + :valid_from, :category, :operation_category, :duration, presence: true - CATEGORIES = %w(ee com.ee fie.ee pri.ee med.ee) + CATEGORIES = %w(ee pri.ee fie.ee med.ee com.ee) + OPERATION_CATEGORIES = %w(new renew) DURATIONS = %w(1year 2years 3years) after_initialize :init_values @@ -13,4 +15,8 @@ class Pricelist < ActiveRecord::Base return unless new_record? self.valid_from = Time.zone.now.beginning_of_year end + + def name + "#{operation_category} #{category}" + end end diff --git a/app/views/admin/pricelists/_form.haml b/app/views/admin/pricelists/_form.haml index 0472b0267..9ac3c4fa2 100644 --- a/app/views/admin/pricelists/_form.haml +++ b/app/views/admin/pricelists/_form.haml @@ -3,12 +3,12 @@ .row .col-md-6 + .form-group + = f.label :operation_category + = f.select(:operation_category, Pricelist::OPERATION_CATEGORIES, {}, { class: 'form-control' }) .form-group = f.label :category, t(:category) = f.select(:category, Pricelist::CATEGORIES, {}, { class: 'form-control' }) - .form-group - = f.label :name - = f.text_field(:name, class: 'form-control') .form-group = f.label :duration = f.select(:duration, Pricelist::DURATIONS, {}, { class: 'form-control' }) diff --git a/app/views/admin/pricelists/index.haml b/app/views/admin/pricelists/index.haml index 2116222c8..15a6b9c6b 100644 --- a/app/views/admin/pricelists/index.haml +++ b/app/views/admin/pricelists/index.haml @@ -5,20 +5,6 @@ %h2.text-right.text-center-xs = link_to(t(:new), new_admin_pricelist_path, class: 'btn btn-primary') -%hr --# .row - -# .col-md-12 - -# = form_tag admin_pricelists_path, html: { class: 'form-horizontal' } do - -# .col-md-11 - -# .form-group - -# = search_field_tag :name_cont, class: 'form-control' - -# .col-md-1.text-right.text-center-xs - -# .form-group - -# %button.btn.btn-primary - -#   - -# %span.glyphicon.glyphicon-search - -#   - %hr .row .col-md-12 @@ -29,9 +15,9 @@ %th{class: 'col-xs-2'} = sort_link(@q, 'category', t(:category)) %th{class: 'col-xs-2'} - = sort_link(@q, 'duration', t(:duration)) + = sort_link(@q, 'operation_category', t(:operation)) %th{class: 'col-xs-2'} - = sort_link(@q, 'name', t(:name)) + = sort_link(@q, 'duration', t(:duration)) %th{class: 'col-xs-2'} = sort_link(@q, 'price', t(:price)) %th{class: 'col-xs-2'} @@ -45,8 +31,8 @@ - @pricelists.each do |pricelist| %tr %td= pricelist.category + %td= pricelist.operation_category %td= pricelist.duration - %td= pricelist.name %td= pricelist.price %td= l(pricelist.valid_from, format: :ydate) %td= l(pricelist.valid_to, format: :ydate) diff --git a/db/migrate/20150609103333_update_pricelist_chema.rb b/db/migrate/20150609103333_update_pricelist_chema.rb new file mode 100644 index 000000000..b309a76b5 --- /dev/null +++ b/db/migrate/20150609103333_update_pricelist_chema.rb @@ -0,0 +1,6 @@ +class UpdatePricelistChema < ActiveRecord::Migration + def change + add_column :pricelists, :operation_category, :string + rename_column :pricelists, :name, :desc + end +end diff --git a/db/schema.rb b/db/schema.rb index ac1e7e118..4dd3a3743 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20150603212659) do +ActiveRecord::Schema.define(version: 20150609103333) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -19,7 +19,7 @@ ActiveRecord::Schema.define(version: 20150603212659) do create_table "account_activities", force: :cascade do |t| t.integer "account_id" t.integer "invoice_id" - t.decimal "sum", precision: 8, scale: 2 + t.decimal "sum", precision: 10, scale: 2 t.string "currency" t.integer "bank_transaction_id" t.datetime "created_at" @@ -36,7 +36,7 @@ ActiveRecord::Schema.define(version: 20150603212659) do create_table "accounts", force: :cascade do |t| t.integer "registrar_id" t.string "account_type" - t.decimal "balance", precision: 8, scale: 2, default: 0.0, null: false + t.decimal "balance", precision: 10, scale: 2, default: 0.0, null: false t.datetime "created_at" t.datetime "updated_at" t.string "currency" @@ -98,7 +98,7 @@ ActiveRecord::Schema.define(version: 20150603212659) do t.string "buyer_name" t.string "document_no" t.string "description" - t.decimal "sum", precision: 8, scale: 2 + t.decimal "sum", precision: 10, scale: 2 t.string "reference_no" t.datetime "paid_at" t.datetime "created_at" @@ -114,7 +114,7 @@ ActiveRecord::Schema.define(version: 20150603212659) do t.string "vk_rec_id" t.string "vk_stamp" t.string "vk_t_no" - t.decimal "vk_amount", precision: 8, scale: 2 + t.decimal "vk_amount", precision: 10, scale: 2 t.string "vk_curr" t.string "vk_rec_acc" t.string "vk_rec_name" @@ -328,10 +328,10 @@ ActiveRecord::Schema.define(version: 20150603212659) do create_table "invoice_items", force: :cascade do |t| t.integer "invoice_id" - t.string "description", null: false + t.string "description", null: false t.string "unit" t.integer "amount" - t.decimal "price", precision: 8, scale: 2 + t.decimal "price", precision: 10, scale: 2 t.datetime "created_at" t.datetime "updated_at" t.string "creator_str" @@ -341,20 +341,20 @@ ActiveRecord::Schema.define(version: 20150603212659) do add_index "invoice_items", ["invoice_id"], name: "index_invoice_items_on_invoice_id", using: :btree create_table "invoices", force: :cascade do |t| - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.string "invoice_type", null: false - t.datetime "due_date", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "invoice_type", null: false + t.datetime "due_date", null: false t.string "payment_term" - t.string "currency", null: false + t.string "currency", null: false t.string "description" t.string "reference_no" - t.decimal "vat_prc", precision: 8, scale: 2, null: false + t.decimal "vat_prc", precision: 10, scale: 2, null: false t.datetime "paid_at" t.integer "seller_id" - t.string "seller_name", null: false + t.string "seller_name", null: false t.string "seller_reg_no" - t.string "seller_iban", null: false + t.string "seller_iban", null: false t.string "seller_bank" t.string "seller_swift" t.string "seller_vat_no" @@ -368,7 +368,7 @@ ActiveRecord::Schema.define(version: 20150603212659) do t.string "seller_email" t.string "seller_contact_name" t.integer "buyer_id" - t.string "buyer_name", null: false + t.string "buyer_name", null: false t.string "buyer_reg_no" t.string "buyer_country_code" t.string "buyer_state" @@ -382,7 +382,7 @@ ActiveRecord::Schema.define(version: 20150603212659) do t.string "updator_str" t.integer "number" t.datetime "cancelled_at" - t.decimal "sum_cache", precision: 8, scale: 2 + t.decimal "sum_cache", precision: 10, scale: 2 end add_index "invoices", ["buyer_id"], name: "index_invoices_on_buyer_id", using: :btree @@ -886,17 +886,18 @@ ActiveRecord::Schema.define(version: 20150603212659) do add_index "people", ["reset_password_token"], name: "index_people_on_reset_password_token", unique: true, using: :btree create_table "pricelists", force: :cascade do |t| - t.string "name" + t.string "desc" t.string "category" - t.decimal "price_cents", precision: 8, scale: 2, default: 0.0, null: false - t.string "price_currency", default: "EUR", null: false + t.decimal "price_cents", precision: 8, scale: 2, default: 0.0, null: false + t.string "price_currency", default: "EUR", null: false t.datetime "valid_from" t.datetime "valid_to" t.string "creator_str" t.string "updator_str" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.string "duration" + t.string "operation_category" end create_table "registrant_verifications", force: :cascade do |t| @@ -982,7 +983,7 @@ ActiveRecord::Schema.define(version: 20150603212659) do t.text "crt" t.string "type" t.string "registrant_ident" - t.string "encrypted_password", default: "", null: false + t.string "encrypted_password", default: "" t.datetime "remember_created_at" t.integer "failed_attempts", default: 0, null: false t.datetime "locked_at" diff --git a/spec/fabricators/pricelist_fabricator.rb b/spec/fabricators/pricelist_fabricator.rb index c98308c1d..296c3b5fb 100644 --- a/spec/fabricators/pricelist_fabricator.rb +++ b/spec/fabricators/pricelist_fabricator.rb @@ -1,5 +1,8 @@ Fabricator(:pricelist) do - active_from 1.year.ago - active_until 1.year.since + valid_from 1.year.ago + valid_to 1.year.since category '.ee' + duration '1year' + operation_category 'new' + price 10 end diff --git a/spec/models/pricelist_spec.rb b/spec/models/pricelist_spec.rb index b7d8a2942..f52b1aeeb 100644 --- a/spec/models/pricelist_spec.rb +++ b/spec/models/pricelist_spec.rb @@ -15,9 +15,9 @@ describe Pricelist do it 'should not be valid' do @pricelist.valid? @pricelist.errors.full_messages.should match_array([ - "Valid from is missing", - "Active until is missing", - "Category is missing" + "Category is missing", + "Duration is missing", + "Operation category is missing" ]) end @@ -32,6 +32,11 @@ describe Pricelist do it 'should not have any versions' do @pricelist.versions.should == [] end + + it 'should not have name' do + @pricelist.name.should == ' ' + end + end context 'with valid attributes' do @@ -50,10 +55,14 @@ describe Pricelist do @pricelist.errors.full_messages.should match_array([]) end + it 'should have name' do + @pricelist.name.should == 'new .ee' + end + it 'should have one version' do with_versioning do @pricelist.versions.reload.should == [] - @pricelist.name = 'New name' + @pricelist.price = 11 @pricelist.save @pricelist.errors.full_messages.should match_array([]) @pricelist.versions.size.should == 1