Add custom fields to invoice, odergroup, supplier and user
This commit is contained in:
parent
72b5a5ca82
commit
75deec9f06
13 changed files with 48 additions and 7 deletions
16
app/models/concerns/custom_fields.rb
Normal file
16
app/models/concerns/custom_fields.rb
Normal file
|
@ -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,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'
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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') }
|
||||
|
@ -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 }
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
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
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
# encoding: utf-8
|
||||
class Workgroup < Group
|
||||
include CustomFields
|
||||
|
||||
has_many :tasks
|
||||
# returns all non-finished tasks
|
||||
|
@ -27,4 +28,3 @@ class Workgroup < Group
|
|||
end
|
||||
|
||||
end
|
||||
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
7
app/views/shared/_custom_form_fields.html.haml
Normal file
7
app/views/shared/_custom_form_fields.html.haml
Normal file
|
@ -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})
|
|
@ -19,6 +19,7 @@
|
|||
= 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']
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 -->
|
||||
|
|
Loading…
Reference in a new issue