Skip to content

Commit

Permalink
Add custom fields to invoice, odergroup, supplier and user
Browse files Browse the repository at this point in the history
  • Loading branch information
paroga committed Oct 28, 2017
1 parent 72b5a5c commit 75deec9
Show file tree
Hide file tree
Showing 13 changed files with 48 additions and 7 deletions.
16 changes: 16 additions & 0 deletions app/models/concerns/custom_fields.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module CustomFields
extend ActiveSupport::Concern
include RailsSettings::Extend

attr_accessor :custom_fields

included do
after_initialize do
settings.defaults['custom_fields'] = { } unless settings.custom_fields
end

after_save do
self.settings.custom_fields = custom_fields if custom_fields
end
end
end
1 change: 1 addition & 0 deletions app/models/invoice.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class Invoice < ActiveRecord::Base
include CustomFields

belongs_to :supplier
belongs_to :created_by, :class_name => 'User', :foreign_key => 'created_by_user_id'
Expand Down
1 change: 1 addition & 0 deletions app/models/ordergroup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# Ordergroup have the following attributes, in addition to Group
# * account_balance (decimal)
class Ordergroup < Group
include CustomFields

APPLE_MONTH_AGO = 6 # How many month back we will count tasks and orders sum

Expand Down
3 changes: 2 additions & 1 deletion app/models/supplier.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# encoding: utf-8
class Supplier < ActiveRecord::Base
include MarkAsDeletedWithName
include CustomFields

has_many :articles, -> { where(:type => nil).includes(:article_category).order('article_categories.name', 'articles.name') }
has_many :stock_articles, -> { includes(:article_category).order('article_categories.name', 'articles.name') }
Expand All @@ -10,7 +11,7 @@ class Supplier < ActiveRecord::Base
belongs_to :shared_supplier # for the sharedLists-App

include ActiveModel::MassAssignmentSecurity
attr_accessible :name, :address, :phone, :phone2, :fax, :email, :url, :contact_person, :customer_number, :iban,
attr_accessible :name, :address, :phone, :phone2, :fax, :email, :url, :contact_person, :customer_number, :iban, :custom_fields,
:delivery_days, :order_howto, :note, :shared_supplier_id, :min_order_quantity, :shared_sync_method

validates :name, :presence => true, :length => { :in => 4..30 }
Expand Down
4 changes: 2 additions & 2 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
require 'digest/sha1'
# specific user rights through memberships (see Group)
class User < ActiveRecord::Base
include RailsSettings::Extend
include CustomFields
#TODO: acts_as_paraniod ??

has_many :memberships, :dependent => :destroy
has_many :groups, :through => :memberships
#has_one :ordergroup, :through => :memberships, :source => :group, :class_name => "Ordergroup"
Expand Down
6 changes: 3 additions & 3 deletions app/models/workgroup.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# encoding: utf-8
class Workgroup < Group

include CustomFields

has_many :tasks
# returns all non-finished tasks
has_many :open_tasks, -> { where(:done => false).order('due_date', 'name') }, :class_name => 'Task'
Expand All @@ -25,6 +26,5 @@ def last_admin_on_earth
errors.add(:role_admin, I18n.t('workgroups.error_last_admin_role'))
end
end

end

end
1 change: 1 addition & 0 deletions app/views/admin/ordergroups/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
= f.input :contact_person
= f.input :contact_phone
= f.input :contact_address
= render 'shared/custom_form_fields', f: f, type: :ordergroup
.fold-line
= f.input :break_start, as: :date_picker, label: Ordergroup.human_attribute_name('break')
= f.input :break_end, as: :date_picker, label: Ordergroup.human_attribute_name('break_until')
Expand Down
1 change: 1 addition & 0 deletions app/views/admin/workgroups/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
%p= t('.first_paragraph', url: link_to(t('.here'), new_invite_path(id: @workgroup.id), remote: true)).html_safe
= simple_form_for [:admin, @workgroup] do |f|
- captured = capture do
= render 'shared/custom_form_fields', f: f, type: :workgroup
%h4= t 'admin.access_to'
= f.input :role_suppliers
= f.input :role_article_meta
Expand Down
1 change: 1 addition & 0 deletions app/views/finance/invoices/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
= f.input :amount, as: :string
= f.input :deposit, as: :string
= f.input :deposit_credit, as: :string
= render 'shared/custom_form_fields', f: f, type: :invoice
= f.input :attachment, as: :file, hint: t('.attachment_hint')
- if f.object.attachment_data.present?
= f.input :delete_attachment, as: :boolean
Expand Down
7 changes: 7 additions & 0 deletions app/views/shared/_custom_form_fields.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- if FoodsoftConfig[:custom_fields] && FoodsoftConfig[:custom_fields][type]
= f.simple_fields_for :custom_fields, defaults: { required: false } do |s|
- FoodsoftConfig[:custom_fields][type].each do |options|
- options = options.deep_symbolize_keys
- name = options.delete(:name)
- value = f.object.settings.custom_fields[name]
= s.input name, options.deep_merge(input_html: {value:value})
3 changes: 2 additions & 1 deletion app/views/shared/_user_form_fields.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@
= ogf.input :contact_address, label: t('activerecord.attributes.ordergroup.contact_address'), required: false,
input_html: { title: address_hint, data: {toggle: 'tooltip', placement: 'right'} }

= render 'shared/custom_form_fields', f: f, type: :user
= f.simple_fields_for :settings_attributes do |s|
= s.simple_fields_for :profile, defaults: { inline_label: true } do |profile|
= profile.input 'language', as: :select, collection: available_locales, required: false, selected: f.object.settings.profile['language']

.settings
.settings-group
= s.simple_fields_for :profile, defaults: { inline_label: true } do |profile|
Expand Down
1 change: 1 addition & 0 deletions app/views/suppliers/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
= f.input :order_howto, as: :text, input_html: {rows: 5}
= f.input :note, as: :text, input_html: {rows: 5}
= f.input :min_order_quantity
= render 'shared/custom_form_fields', f: f, type: :supplier
- if @supplier.shared_supplier
= f.input :shared_sync_method, collection: shared_sync_method_collection(@supplier.shared_supplier), input_html: {class: 'input-xlarge'}, include_blank: false, disabled: @supplier.shared_supplier.shared_sync_methods.count < 2
.form-actions
Expand Down
10 changes: 10 additions & 0 deletions config/app_config.yml.SAMPLE
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,16 @@ default: &defaults
# Custom CSS for the foodcoop
#custom_css: 'body { background-color: #fcffba; }'

# Custom fields for invoice, odergroup, supplier and user.
# Check out https://github.com/plataformatec/simple_form for details about the supported options.
#custom_fields:
# user:
# - name: address
# label: Address
# - name: birthday
# label: Birthday
# as: date_picker

# Uncomment to add tracking code for web statistics, e.g. for Piwik. (Added to bottom of page)
#webstats_tracking_code: |
# <!-- Piwik -->
Expand Down

0 comments on commit 75deec9

Please sign in to comment.