-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathinit.rb
215 lines (175 loc) · 9.14 KB
/
init.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
require 'redmine'
Rails.logger.info 'Starting haltr plugin'
require 'haltr'
# Haltr has plugins of his own
# similar to config/initializers/00-core_plugins.rb in Redmine
# Loads the core plugins located in lib/plugins
Dir.glob(File.join(File.dirname(__FILE__), "lib/plugins/*")).sort.each do |directory|
if File.directory?(directory)
lib = File.join(directory, "lib")
if File.directory?(lib)
$:.unshift lib
ActiveSupport::Dependencies.autoload_paths += [lib]
end
initializer = File.join(directory, "init.rb")
if File.file?(initializer)
config = config = RedmineApp::Application.config
eval(File.read(initializer), binding, initializer)
end
end
end
# groupdate won't work with config.active_record.default_timezone = :local
# https://github.com/ankane/groupdate/issues/66
unless ActiveRecord::Base.default_timezone == :utc
ActiveRecord::Base.default_timezone = :utc
end
Date::DATE_FORMATS[:ddmmyy] = "%d%m%y"
require 'utils'
require File.expand_path(File.join(File.dirname(__FILE__), 'app/models/export_channels'))
require 'haltr/hooks'
if (Redmine::VERSION::MAJOR == 1 and Redmine::VERSION::MINOR >= 4) or Redmine::VERSION::MAJOR == 2 or Redmine::VERSION::MAJOR == 3
require 'country_iso_translater'
else
config.gem 'sundawg_country_codes', :lib => 'country_iso_translater'
config.gem 'money', :version => '>=5.0.0'
end
Rails.configuration.to_prepare do
Project.send(:include, ProjectHaltrPatch)
User.send(:include, UserHaltrPatch)
MyHelper.send(:include, ChartsHelper)
MyHelper.send(:include, HaltrHelper)
end
Redmine::Plugin.register :haltr do
name 'haltr'
author 'Ingent'
description 'Hackers dont do books'
version '1.2'
settings :default => {
'trace_url' => 'http://localhost:3000',
'export_channels_path' => '/tmp',
'issues_controller_name' => 'issues',
'default_country' => 'es',
'default_currency' => 'EUR',
'hide_unauthorized' => '1',
'return_path' => '',
'default_invoice_format' => ''
},
:partial => '/common/settings'
project_module :haltr do
permission :general_use,
{ :clients => [:index, :show, :new, :edit, :create, :update, :destroy, :check_cif, :link_to_profile, :unlink,
:allow_link, :deny_link, :ccc2iban],
:people => [:index, :new, :show, :edit, :create, :update, :destroy],
:invoices => [:index, :new, :edit, :create, :update, :destroy, :show, :mark_sent, :mark_closed, :mark_not_sent,
:destroy_payment, :send_invoice, :legal, :update_payment_stuff, :amend_for_invoice, :download_new_invoices,
:send_new_invoices, :duplicate_invoice, :reports, :report_channel_state, :report_invoice_list, :report_received_table, :context_menu, :bulk_mark_as, :original,
:mark_as, :number_to_id],
:received => [:index, :new, :edit, :create, :update, :destroy, :show,
:mark_accepted, :mark_refused, :legal, :context_menu,
:original, :validate, :bulk_mark_as],
:companies => [:my_company,:bank_info,:update,:check_iban],
:charts => [:invoice_total, :invoice_status, :top_clients, :cash_flow],
:events => [:file, :index] },
:require => :member
permission :manage_payments, { :payments => [:index, :new, :edit, :create, :update, :destroy, :payment_initiation, :payment_done, :import_aeb43_index, :import_aeb43, :invoices, :reports, :report_payment_list] }, :require => :member
permission :use_templates, { :invoice_templates => [:index, :new, :edit, :create, :update, :destroy, :show, :new_from_invoice,
:new_invoices_from_template, :create_invoices, :update_taxes, :context_menu] }, :require => :member
permission :use_all_readonly,
{ :clients => [:index, :show, :edit, :check_cif, :ccc2iban],
:people => [:index, :edit],
:client_offices => [:index, :edit],
:invoices => [:index, :show, :legal, :download_new_invoices, :reports, :report_channel_state, :report_invoice_list, :report_received_table,
:context_menu, :number_to_id, :edit],
:received => [:index, :show, :legal, :context_menu],
:companies => [:my_company,:bank_info, :check_iban],
:payments => [:index, :payment_initiation, :invoices, :reports, :report_payment_list],
:invoice_templates => [:index, :show, :context_menu, :new_invoices_from_template],
:charts => [:invoice_total, :invoice_status, :top_clients],
:events => [:file, :index],
:import_errors => [:index, :show],
:orders => [:index, :show] },
:require => :member
permission :bulk_operations,
{ :invoices => [:bulk_download,:bulk_send],
:received => [:bulk_download,:bulk_validate] }, :require => :member
permission :add_multiple_bank_infos,
{ :companies => [:add_bank_info] }, :require => :member
permission :use_sepa,
{ :payments => [:sepa],
:mandates => [:index,:new,:show,:create,:edit,:update,:destroy,:signed_doc] }, :require => :member
permission :import_invoices,
{ :invoices => [:upload,:import,:import_facturae,:process_pdf, :bulk_process_pdf],
:received => [:upload,:import],
:invoice_imgs => [:context_menu,:tag],
:import_errors => [:index, :create, :show, :destroy, :context_menu] },
:require => :member
permission :email_customization, {}, require: :member
permission :configure_connections, {}, require: :member
permission :use_company_offices, {}, require: :member
permission :invoice_quotes,
{ :quotes => [:index, :new, :create, :show, :edit, :update, :send_quote,
:destroy, :accept, :refuse] }, :require => :member
permission :view_invoice_extra_fields, {}
permission :view_sequence_number, {}
permission :export_invoices, {:invoices => [:index]}
permission :export_clients, {:clients => [:index]}
permission :use_invoice_attachments, { :attachments => :upload}
permission :add_invoice_notes, { :invoices => :add_comment }
permission :manage_external_companies, {
:external_companies => [:index, :new, :create, :edit, :update, :destroy, :csv_import],
:dir3_entities => [:index, :new, :create, :edit, :update, :destroy, :csv_import]
}
permission :use_client_offices, {
:client_offices => [:index, :new, :show, :edit, :create, :update, :destroy],
}
permission :set_client_xpaths, {}
permission :view_channels, {
:export_channels => [:index],
}
permission :use_orders, {
orders: [:index, :show, :destroy, :import, :add_comment, :create_invoice, :accept, :mark_as]
}, require: :member
permission :use_local_signature, {
invoices: [:base64doc]
}, require: :member
# Loads permisons from config/channels.yml
ExportChannels.permissions.each do |permission,actions|
permission permission, actions, :require => :member
end
end
menu :project_menu, :my_company, {:controller=>'companies', :action=>'my_company'}, :param=>:project_id, :caption=>:label_my_company
menu :project_menu, :companies, {:controller=>'clients', :action=>'index' }, :param=>:project_id, :caption=>:label_companies
menu :project_menu, :invoices, {:controller=>'invoices', :action=>'index' }, :param=>:project_id, :caption=>:label_invoice_plural
menu :project_menu, :payments, {:controller=>'payments', :action=>'index' }, :param=>:project_id, :caption=>:label_payment_plural
menu :project_menu, :orders, { controller: 'orders', action: 'index' }, param: :project_id, caption: :label_order_plural
menu :project_menu, :quotes, { controller: 'quotes', action: 'index' }, param: :project_id, caption: :label_quote_plural
menu :admin_menu, :external_companies, {:controller=>'external_companies', :action=>'index'}, :caption=>:external_companies
menu :admin_menu, :dir3_entities, {:controller=>'dir3_entities', :action=>'index'}, :caption=>:dir3_entities
menu :admin_menu, :export_channels, {:controller=>'export_channels', :action=>'index'}, :caption=>:export_channels
# submenus defined at lib/haltr.rb
end
# avoid taxis error
ActiveSupport::Inflector.inflections do |inflect|
inflect.singular 'taxes', 'tax'
inflect.irregular 'unitat_tramitadora', 'unitats_tramitadores'
inflect.irregular 'organ_gestor', 'organs_gestors'
inflect.irregular 'oficina_comptable', 'oficines_comptables'
inflect.irregular 'organ_proponent', 'organs_proponents'
end
Mime::Type.register "text/xml", :facturae30
Mime::Type.register "text/xml", :facturae31
Mime::Type.register "text/xml", :facturae32
Mime::Type.register "text/xml", :peppolubl20
Mime::Type.register "text/xml", :peppolubl21
Mime::Type.register "text/xml", :svefaktura
Mime::Type.register "text/xml", :original
Mime::Type.register "text/xml", :edifact
Redmine::Activity.map do |activity|
activity.register :info_events, :class_name => 'Event'
activity.register :error_events, :class_name => 'Event'
end
Delayed::Worker.max_attempts = 3
Audited.current_user_method = :find_current_user
CountrySelect::FORMATS[:default] = lambda do |country|
[country.translations[I18n.locale.to_s] || country.name, country.alpha2.downcase]
end