dorsale 3.1.7 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (157) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +15 -0
  3. data/app/assets/javascripts/dorsale/common/comments.coffee +18 -20
  4. data/app/assets/javascripts/dorsale/common/datepicker.coffee +1 -1
  5. data/app/assets/javascripts/dorsale/common/forms.coffee +1 -1
  6. data/app/assets/javascripts/dorsale/common/modals.coffee +1 -1
  7. data/app/assets/javascripts/dorsale/common/tabs_loader.coffee +1 -1
  8. data/app/assets/javascripts/dorsale/common/tags.coffee +1 -1
  9. data/app/assets/javascripts/dorsale/common/tooltips.coffee +1 -1
  10. data/app/assets/javascripts/dorsale/dependencies.coffee +2 -0
  11. data/app/assets/javascripts/dorsale/engines/billing_machine.coffee +1 -1
  12. data/app/assets/stylesheets/dorsale/all.sass +1 -1
  13. data/app/assets/stylesheets/dorsale/common/comments.sass +1 -1
  14. data/app/assets/stylesheets/dorsale/common/filters.sass +16 -1
  15. data/app/assets/stylesheets/dorsale/common/styles.sass +3 -0
  16. data/app/assets/stylesheets/dorsale/engines/customer_vault.sass +2 -2
  17. data/app/assets/stylesheets/dorsale/engines/expense_gun.sass +3 -0
  18. data/app/assets/stylesheets/dorsale/engines/flyboy.sass +4 -0
  19. data/app/assets/stylesheets/dorsale/print.sass +73 -0
  20. data/app/controllers/dorsale/alexandrie/attachments_controller.rb +0 -4
  21. data/app/controllers/dorsale/application_controller.rb +12 -0
  22. data/app/controllers/dorsale/billing_machine/application_controller.rb +0 -5
  23. data/app/controllers/dorsale/billing_machine/id_cards_controller.rb +0 -4
  24. data/app/controllers/dorsale/billing_machine/invoices_controller.rb +0 -4
  25. data/app/controllers/dorsale/billing_machine/payment_terms_controller.rb +0 -4
  26. data/app/controllers/dorsale/billing_machine/quotations_controller.rb +0 -4
  27. data/app/controllers/dorsale/comments_controller.rb +30 -55
  28. data/app/controllers/dorsale/customer_vault/links_controller.rb +5 -5
  29. data/app/controllers/dorsale/customer_vault/people_controller.rb +9 -11
  30. data/app/controllers/dorsale/expense_gun/categories_controller.rb +0 -4
  31. data/app/controllers/dorsale/expense_gun/expenses_controller.rb +1 -5
  32. data/app/controllers/dorsale/flyboy/folders_controller.rb +0 -4
  33. data/app/controllers/dorsale/flyboy/tasks_controller.rb +0 -4
  34. data/app/controllers/dorsale/users_controller.rb +7 -11
  35. data/app/filters/dorsale/billing_machine/small_data/filter_strategy_by_customer.rb +1 -1
  36. data/app/filters/dorsale/flyboy/small_data/filter_for_tasks.rb +1 -1
  37. data/app/helpers/dorsale/all_helpers.rb +1 -0
  38. data/app/helpers/dorsale/billing_machine/application_helper.rb +23 -0
  39. data/app/helpers/dorsale/comments_helper.rb +14 -2
  40. data/app/helpers/dorsale/flyboy/application_helper.rb +4 -0
  41. data/app/helpers/dorsale/text_helper.rb +12 -7
  42. data/app/libs/dorsale/sortable_uuid_generator.rb +11 -0
  43. data/app/mailers/dorsale/billing_machine/invoice_mailer.rb +2 -4
  44. data/app/models/concerns/dorsale/active_record_uuid_concern.rb +15 -0
  45. data/app/models/concerns/dorsale/default_values_concern.rb +13 -0
  46. data/app/models/dorsale/alexandrie/attachment.rb +3 -3
  47. data/app/models/dorsale/application_record.rb +11 -0
  48. data/app/models/dorsale/billing_machine/invoice.rb +13 -13
  49. data/app/models/dorsale/billing_machine/invoice_line.rb +3 -9
  50. data/app/models/dorsale/billing_machine/quotation.rb +6 -12
  51. data/app/models/dorsale/billing_machine/quotation_line.rb +3 -8
  52. data/app/models/dorsale/customer_vault/person.rb +5 -4
  53. data/app/models/dorsale/expense_gun/expense.rb +3 -4
  54. data/app/models/dorsale/expense_gun/expense_line.rb +4 -5
  55. data/app/models/dorsale/flyboy/folder.rb +2 -3
  56. data/app/models/dorsale/flyboy/task.rb +5 -6
  57. data/app/models/dorsale/flyboy/task_comment.rb +3 -8
  58. data/app/models/dorsale/users/active.rb +1 -1
  59. data/app/policies/dorsale/billing_machine/invoice_policy_helper.rb +5 -0
  60. data/app/policies/dorsale/comment_policy_helper.rb +21 -0
  61. data/app/serializers/dorsale/serializers/xlsx.rb +13 -2
  62. data/app/views/dorsale/billing_machine/invoices/_details.html.slim +1 -1
  63. data/app/views/dorsale/billing_machine/invoices/_filters.html.slim +1 -1
  64. data/app/views/dorsale/billing_machine/invoices/_form.html.slim +1 -1
  65. data/app/views/dorsale/billing_machine/invoices/_header_infos.html.slim +9 -4
  66. data/app/views/dorsale/billing_machine/invoices/_list.html.slim +3 -2
  67. data/app/views/dorsale/billing_machine/invoices/email.html.slim +6 -0
  68. data/app/views/dorsale/billing_machine/invoices/index.html.slim +1 -1
  69. data/app/views/dorsale/billing_machine/invoices/index.xlsx.ruby +41 -0
  70. data/app/views/dorsale/billing_machine/quotations/_filters.html.slim +1 -1
  71. data/app/views/dorsale/billing_machine/quotations/_list.html.slim +4 -3
  72. data/app/views/dorsale/comments/_comment.html.slim +2 -2
  73. data/app/views/dorsale/comments/_comments.html.slim +5 -0
  74. data/app/views/dorsale/comments/_form.html.slim +5 -6
  75. data/app/views/dorsale/comments/_list.html.slim +1 -1
  76. data/app/views/dorsale/comments/edit.html.slim +1 -1
  77. data/app/views/dorsale/customer_vault/links/edit.html.slim +13 -17
  78. data/app/views/dorsale/customer_vault/links/index.html.slim +10 -0
  79. data/app/views/dorsale/customer_vault/links/new.html.slim +10 -14
  80. data/app/views/dorsale/customer_vault/people/_actions.html.slim +2 -2
  81. data/app/views/dorsale/customer_vault/people/_data_context.html.slim +1 -1
  82. data/app/views/dorsale/customer_vault/people/_index_tabs.html.slim +2 -2
  83. data/app/views/dorsale/customer_vault/people/_show_layout.html.slim +10 -0
  84. data/app/views/dorsale/customer_vault/people/_tabs.html.slim +24 -0
  85. data/app/views/dorsale/customer_vault/people/activity.slim +2 -3
  86. data/app/views/dorsale/customer_vault/people/edit.html.slim +1 -0
  87. data/app/views/dorsale/customer_vault/people/index.html.slim +2 -2
  88. data/app/views/dorsale/customer_vault/people/index.xlsx.ruby +49 -0
  89. data/app/views/dorsale/customer_vault/people/invoices.html.slim +5 -0
  90. data/app/views/dorsale/customer_vault/people/show.html.slim +5 -26
  91. data/app/views/dorsale/customer_vault/people/tasks.html.slim +4 -0
  92. data/app/views/dorsale/expense_gun/categories/_list.html.slim +4 -1
  93. data/app/views/dorsale/expense_gun/expenses/_list.html.slim +1 -1
  94. data/app/views/dorsale/expense_gun/expenses/show.html.slim +3 -3
  95. data/app/views/dorsale/flyboy/_filters.html.slim +3 -0
  96. data/app/views/dorsale/flyboy/folders/_form.html.slim +3 -1
  97. data/app/views/dorsale/flyboy/folders/_list.html.slim +2 -2
  98. data/app/views/dorsale/flyboy/task_comments/_list.html.slim +2 -2
  99. data/app/views/dorsale/flyboy/tasks/_form.html.slim +4 -1
  100. data/app/views/dorsale/flyboy/tasks/_list.html.slim +1 -1
  101. data/app/views/dorsale/flyboy/tasks/_summary_list.html.slim +6 -5
  102. data/app/views/dorsale/flyboy/tasks/index.html.slim +2 -4
  103. data/app/views/dorsale/flyboy/tasks/index.xlsx.ruby +23 -0
  104. data/app/views/dorsale/flyboy/tasks/summary.html.slim +0 -2
  105. data/config/locales/common.en.yml +2 -0
  106. data/config/locales/common.fr.yml +2 -0
  107. data/config/locales/customer_vault.en.yml +0 -6
  108. data/config/locales/customer_vault.fr.yml +0 -6
  109. data/config/locales/flyboy.en.yml +2 -0
  110. data/config/locales/flyboy.fr.yml +2 -0
  111. data/config/routes.rb +7 -2
  112. data/db/migrate/20161118071317_dorsale_add_missing_indexes.rb +25 -0
  113. data/features/billing_machine_invoices.feature +4 -2
  114. data/features/customer_vault_invoices.feature +10 -0
  115. data/features/customer_vault_tasks.feature +1 -1
  116. data/features/flyboy_tasks.feature +3 -15
  117. data/features/step_definitions/billing_machine_invoices_steps.rb +2 -6
  118. data/features/step_definitions/billing_machine_quotations_steps.rb +5 -5
  119. data/features/step_definitions/common_steps.rb +7 -1
  120. data/features/step_definitions/customer_vault_corporations_steps.rb +7 -7
  121. data/features/step_definitions/customer_vault_filters_steps.rb +3 -3
  122. data/features/step_definitions/customer_vault_individuals_steps.rb +1 -1
  123. data/features/step_definitions/customer_vault_invoices_steps.rb +7 -0
  124. data/features/step_definitions/customer_vault_links_steps.rb +5 -3
  125. data/features/step_definitions/customer_vault_people_steps.rb +1 -1
  126. data/features/step_definitions/customer_vault_search_steps.rb +4 -4
  127. data/features/step_definitions/customer_vault_tasks_steps.rb +6 -16
  128. data/features/step_definitions/expense_gun_expenses_steps.rb +2 -2
  129. data/features/step_definitions/flyboy_folders_steps.rb +5 -5
  130. data/features/step_definitions/flyboy_tasks_steps.rb +5 -29
  131. data/lib/dorsale/engine.rb +6 -1
  132. data/lib/dorsale/polymorphic_id.rb +1 -1
  133. data/lib/dorsale/version.rb +1 -1
  134. data/spec/controllers/dorsale/billing_machine/invoices_controller_spec.rb +3 -4
  135. data/spec/controllers/dorsale/comments_controller_spec.rb +3 -3
  136. data/spec/controllers/dorsale/expense_gun/expenses_controller_spec.rb +10 -0
  137. data/spec/controllers/dorsale/flyboy/tasks_controller_spec.rb +1 -13
  138. data/spec/factories/dorsale_comments.rb +3 -3
  139. data/spec/helpers/dorsale/text_helper_spec.rb +15 -0
  140. data/spec/{lib → libs}/active_record_comma_type_cast_spec.rb +0 -0
  141. data/spec/{lib → libs/dorsale}/polymorphic_id_spec.rb +0 -0
  142. data/spec/libs/dorsale/sortable_uuid_generator_spec.rb +29 -0
  143. data/spec/rails_helper.rb +2 -0
  144. data/spec/routing/dorsale/customer_vault/people_routing_spec.rb +15 -0
  145. metadata +54 -18
  146. data/app/pdfs/dorsale/flyboy/roadmap.rb +0 -47
  147. data/app/views/dorsale/billing_machine/invoices/index.csv.ruby +0 -46
  148. data/app/views/dorsale/comments/_loader.html.slim +0 -5
  149. data/app/views/dorsale/comments/index.html.slim +0 -11
  150. data/app/views/dorsale/customer_vault/people/_activity_tab.html.slim +0 -4
  151. data/app/views/dorsale/customer_vault/people/_comment.html.slim +0 -1
  152. data/app/views/dorsale/customer_vault/people/_links_tab.html.slim +0 -7
  153. data/app/views/dorsale/customer_vault/people/_tasks_tab.html.slim +0 -1
  154. data/app/views/dorsale/customer_vault/people/index.xls.slim +0 -24
  155. data/app/views/dorsale/flyboy/tasks/index.csv.ruby +0 -24
  156. data/app/views/dorsale/flyboy/tasks/index.pdf.ruby +0 -6
  157. data/app/views/dorsale/flyboy/tasks/index.xls.erb +0 -29
@@ -1,6 +1,10 @@
1
1
  class Dorsale::CustomerVault::LinksController < ::Dorsale::CustomerVault::ApplicationController
2
2
  before_action :set_objects
3
3
 
4
+ def index
5
+ authorize @person, :read?
6
+ end
7
+
4
8
  def new
5
9
  authorize @person, :update?
6
10
 
@@ -54,11 +58,7 @@ class Dorsale::CustomerVault::LinksController < ::Dorsale::CustomerVault::Applic
54
58
  end
55
59
 
56
60
  def back_url
57
- customer_vault_person_path(@person) + "#links"
58
- end
59
-
60
- def scope
61
- policy_scope(model)
61
+ customer_vault_person_links_path(@person)
62
62
  end
63
63
 
64
64
  def person_scope
@@ -1,12 +1,7 @@
1
1
  class Dorsale::CustomerVault::PeopleController < ::Dorsale::CustomerVault::ApplicationController
2
2
  handles_sortable_columns
3
3
 
4
- before_action :set_objects, only: [
5
- :show,
6
- :edit,
7
- :update,
8
- :destroy,
9
- ]
4
+ before_action :set_objects
10
5
 
11
6
  def index
12
7
  authorize model, :list?
@@ -80,6 +75,13 @@ class Dorsale::CustomerVault::PeopleController < ::Dorsale::CustomerVault::Appli
80
75
  authorize @person, :read?
81
76
  end
82
77
 
78
+ def tasks
79
+ show
80
+ end
81
+
82
+ def invoices
83
+ show
84
+ end
83
85
 
84
86
  def edit
85
87
  authorize @person, :update?
@@ -137,12 +139,8 @@ class Dorsale::CustomerVault::PeopleController < ::Dorsale::CustomerVault::Appli
137
139
  model.to_s.demodulize.downcase.to_sym
138
140
  end
139
141
 
140
- def scope
141
- policy_scope(model)
142
- end
143
-
144
142
  def set_objects
145
- @person ||= scope.find(params[:id])
143
+ @person ||= scope.find(params[:id]) if params.key?(:id)
146
144
  end
147
145
 
148
146
  def common_permitted_params
@@ -51,10 +51,6 @@ class Dorsale::ExpenseGun::CategoriesController < ::Dorsale::ExpenseGun::Applica
51
51
  ::Dorsale::ExpenseGun::Category
52
52
  end
53
53
 
54
- def scope
55
- policy_scope(model)
56
- end
57
-
58
54
  def back_url
59
55
  expense_gun_categories_path
60
56
  end
@@ -109,10 +109,6 @@ class Dorsale::ExpenseGun::ExpensesController < Dorsale::ExpenseGun::Application
109
109
  ::Dorsale::ExpenseGun::Expense
110
110
  end
111
111
 
112
- def scope
113
- policy_scope(model)
114
- end
115
-
116
112
  def set_expense
117
113
  @expense = scope.find(params[:id])
118
114
  end
@@ -147,7 +143,7 @@ class Dorsale::ExpenseGun::ExpensesController < Dorsale::ExpenseGun::Application
147
143
  end
148
144
 
149
145
  def set_filters_variables
150
- @users ||= policy_scope(User).all
146
+ @users ||= scope.preload(:user).map(&:user).uniq.compact
151
147
  end
152
148
 
153
149
  end
@@ -114,10 +114,6 @@ class Dorsale::Flyboy::FoldersController < ::Dorsale::Flyboy::ApplicationControl
114
114
  ::Dorsale::Flyboy::Folder
115
115
  end
116
116
 
117
- def scope
118
- policy_scope(model)
119
- end
120
-
121
117
  def set_objects
122
118
  @folder = scope.find(params[:id])
123
119
  end
@@ -152,10 +152,6 @@ class Dorsale::Flyboy::TasksController < ::Dorsale::Flyboy::ApplicationControlle
152
152
  ::Dorsale::Flyboy::Task
153
153
  end
154
154
 
155
- def scope
156
- policy_scope(model)
157
- end
158
-
159
155
  def default_back_url
160
156
  if @task
161
157
  url_for(action: :show, id: @task.to_param)
@@ -5,9 +5,6 @@ class Dorsale::UsersController < ::Dorsale::ApplicationController
5
5
  :update,
6
6
  ]
7
7
 
8
- def show
9
- end
10
-
11
8
  def index
12
9
  authorize User, :list?
13
10
 
@@ -20,10 +17,6 @@ class Dorsale::UsersController < ::Dorsale::ApplicationController
20
17
  authorize @user, :create?
21
18
  end
22
19
 
23
- def edit
24
- authorize @user, :update?
25
- end
26
-
27
20
  def create
28
21
  @user ||= scope.new(user_params_for_create)
29
22
 
@@ -38,6 +31,13 @@ class Dorsale::UsersController < ::Dorsale::ApplicationController
38
31
  end
39
32
  end
40
33
 
34
+ def show
35
+ end
36
+
37
+ def edit
38
+ authorize @user, :update?
39
+ end
40
+
41
41
  def update
42
42
  authorize @user, :update?
43
43
 
@@ -56,10 +56,6 @@ class Dorsale::UsersController < ::Dorsale::ApplicationController
56
56
  User
57
57
  end
58
58
 
59
- def scope
60
- policy_scope(model)
61
- end
62
-
63
59
  def set_objects
64
60
  @user = scope.find(params[:id])
65
61
  end
@@ -1,6 +1,6 @@
1
1
  class Dorsale::BillingMachine::SmallData::FilterStrategyByCustomer < ::Dorsale::SmallData::FilterStrategy
2
2
  def apply(query, value)
3
- type, id = value.split("-")
3
+ type, id = value.split("-", 2)
4
4
  query.where(customer_type: type, customer_id: id)
5
5
  end
6
6
  end
@@ -1,6 +1,6 @@
1
1
  class Dorsale::Flyboy::SmallData::FilterForTasks < ::Dorsale::SmallData::Filter
2
2
  STRATEGIES = {
3
3
  "fb_status" => ::Dorsale::Flyboy::SmallData::FilterStrategyByDone.new,
4
- "owner" => ::Dorsale::SmallData::FilterStrategyByKeyValue.new("owner_id")
4
+ "fb_owner" => ::Dorsale::SmallData::FilterStrategyByKeyValue.new(:owner_id)
5
5
  }
6
6
  end
@@ -13,6 +13,7 @@ module Dorsale::AllHelpers
13
13
  include ::Dorsale::BootstrapHelper
14
14
 
15
15
  include ::Dorsale::Alexandrie::AttachmentsHelper
16
+ include ::Dorsale::BillingMachine::ApplicationHelper
16
17
  include ::Dorsale::Flyboy::ApplicationHelper
17
18
  include ::Dorsale::ExpenseGun::ApplicationHelper
18
19
  include ::Dorsale::UsersHelper
@@ -33,4 +33,27 @@ module Dorsale::BillingMachine::ApplicationHelper
33
33
  end
34
34
  end
35
35
 
36
+ def billing_machine_invoices_chart
37
+ invoices = policy_scope(::Dorsale::BillingMachine::Invoice)
38
+ .where("date > ?", 1.year.ago.beginning_of_month)
39
+
40
+ totals = {}
41
+
42
+ (0..12).to_a.reverse.map do |n|
43
+ date = n.month.ago
44
+ label = l(date, format: "%B %Y").titleize
45
+ totals[label] = 0
46
+ invoices.each do |i|
47
+ next if i.date.year != date.year
48
+ next if i.date.month != date.month
49
+ totals[label] += i.total_excluding_taxes
50
+ end
51
+ end
52
+
53
+ column_chart totals, height: "200px"
54
+ end
55
+
56
+ def bm_currency(n)
57
+ currency(n, ::Dorsale::BillingMachine.default_currency)
58
+ end
36
59
  end
@@ -1,5 +1,17 @@
1
1
  module Dorsale::CommentsHelper
2
- def comments_for(commentable)
3
- render partial: "dorsale/comments/loader", locals: {commentable: commentable}
2
+ def comments_for(commentable, options = {})
3
+ comments = policy_scope(::Dorsale::Comment)
4
+ .where(commentable: commentable)
5
+ .preload(:commentable, :author)
6
+
7
+ new_comment = comments.new(author: current_user)
8
+
9
+ render(
10
+ :partial => "dorsale/comments/comments",
11
+ :locals => {
12
+ :comments => comments,
13
+ :new_comment => new_comment,
14
+ },
15
+ )
4
16
  end
5
17
  end
@@ -49,4 +49,8 @@ module Dorsale::Flyboy::ApplicationHelper
49
49
  }
50
50
  end
51
51
 
52
+ def flyboy_tasks_owners_for_filters_select
53
+ policy_scope(User)
54
+ end
55
+
52
56
  end
@@ -65,12 +65,19 @@ module Dorsale::TextHelper
65
65
  str.gsub("\r", "").gsub("\n", "<br />").html_safe
66
66
  end
67
67
 
68
- def info(object, attribute, text_or_options = nil, options = {})
69
- if text_or_options.is_a?(Hash)
70
- text = nil
71
- options = text_or_options
68
+ def info(object, attribute, value_or_options = nil, options = {})
69
+ if value_or_options.nil?
70
+ value = object.public_send(attribute)
71
+ elsif value_or_options.is_a?(Hash)
72
+ value = object.public_send(attribute)
73
+ options = value_or_options
72
74
  else
73
- text = text_or_options
75
+ value = value_or_options
76
+ end
77
+
78
+ if value.blank?
79
+ value = options[:default]
80
+ return if value == :hide
74
81
  end
75
82
 
76
83
  label = options[:label] || object.t(attribute)
@@ -82,8 +89,6 @@ module Dorsale::TextHelper
82
89
  klass = object.is_a?(Module) ? object : object.class
83
90
  object_type = klass.to_s.split("::").last.underscore
84
91
 
85
- value = text
86
- value = object.public_send(attribute) if value.nil?
87
92
  value = t("yes") if value === true
88
93
  value = t("no") if value === false
89
94
  value = object.t("#{attribute}.#{value}") if nested
@@ -0,0 +1,11 @@
1
+ # Microtime based uuids to be sortable
2
+ class Dorsale::SortableUUIDGenerator
3
+ REGEX_WITH_DASHES = /^([0-9a-f]{8})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{12})$/
4
+ REGEX_WITHOUT_DASHES = /^([0-9a-f]{8})([0-9a-f]{4})([0-9a-f]{4})([0-9a-f]{4})([0-9a-f]{12})$/
5
+
6
+ def self.generate
7
+ prefix = Time.zone.now.strftime("%s%9N").to_i.to_s(16)
8
+ suffix = SecureRandom.hex(8)
9
+ (prefix + suffix).gsub(REGEX_WITHOUT_DASHES, '\1-\2-\3-\4-\5')
10
+ end
11
+ end
@@ -1,13 +1,11 @@
1
1
  class Dorsale::BillingMachine::InvoiceMailer < ::Dorsale::ApplicationMailer
2
2
  def send_invoice_to_customer(invoice, subject, body, sender = nil)
3
- return false if invoice.try(:customer).try(:email).blank?
4
-
5
3
  attachments["#{invoice.t}_#{invoice.tracking_id}.pdf"] = invoice.to_pdf
6
4
 
7
5
  mail(
8
6
  :to => invoice.customer.email,
9
- :cc => sender.try(:email),
10
- :reply_to => sender.try(:email),
7
+ :cc => sender.email,
8
+ :reply_to => sender.email,
11
9
  :subject => subject,
12
10
  :body => body,
13
11
  )
@@ -0,0 +1,15 @@
1
+ module Dorsale::ActiveRecordUUIDConcern
2
+ extend ActiveSupport::Concern
3
+
4
+ private
5
+
6
+ def assign_default_uuid
7
+ if id.nil? && self.class.columns_hash["id"].type == :uuid
8
+ self.id = ::Dorsale::SortableUUIDGenerator.generate
9
+ end
10
+ end
11
+
12
+ included do
13
+ before_save :assign_default_uuid
14
+ end
15
+ end
@@ -0,0 +1,13 @@
1
+ module Dorsale::DefaultValuesConcern
2
+ extend ActiveSupport::Concern
3
+
4
+ def assign_default_values; end
5
+
6
+ def assign_default(attribute, value)
7
+ self.send("#{attribute}=", value) if self.send(attribute).nil?
8
+ end
9
+
10
+ included do
11
+ after_initialize :assign_default_values
12
+ end
13
+ end
@@ -11,15 +11,15 @@ class Dorsale::Alexandrie::Attachment < ::Dorsale::ApplicationRecord
11
11
 
12
12
  mount_uploader :file, ::Dorsale::Alexandrie::FileUploader
13
13
 
14
- before_save :set_default_name
14
+ before_save :assign_default_name
15
15
 
16
16
  default_scope -> {
17
17
  all
18
- .order(id: :desc)
18
+ .order(created_at: :desc, id: :desc)
19
19
  .preload(:attachment_type)
20
20
  }
21
21
 
22
- def set_default_name
22
+ def assign_default_name
23
23
  self.name = file_identifier if name.blank?
24
24
  end
25
25
 
@@ -1,3 +1,14 @@
1
1
  class Dorsale::ApplicationRecord < ActiveRecord::Base
2
2
  self.abstract_class = true
3
+
4
+ include Dorsale::ActiveRecordUUIDConcern
5
+ include Dorsale::DefaultValuesConcern
6
+ nilify_blanks
7
+
8
+ def self.last_created
9
+ reorder(:created_at, :id).last
10
+ end
3
11
  end
12
+
13
+ ActsAsTaggableOn::Tagging.send(:include, Dorsale::ActiveRecordUUIDConcern)
14
+ ActsAsTaggableOn::Tag.send(:include, Dorsale::ActiveRecordUUIDConcern)
@@ -18,16 +18,8 @@ class Dorsale::BillingMachine::Invoice < ::Dorsale::ApplicationRecord
18
18
  order(unique_index: :desc)
19
19
  }
20
20
 
21
- def initialize(*args)
22
- super
23
- assign_default_values
24
- self.due_date = 30.days.from_now if due_date.nil?
25
- self.date = Time.zone.now.to_date if date.nil?
26
- end
27
-
28
21
  before_create :assign_unique_index
29
22
  before_create :assign_tracking_id
30
- before_validation :assign_default_values
31
23
 
32
24
  def assign_unique_index
33
25
  if unique_index.nil?
@@ -40,11 +32,19 @@ class Dorsale::BillingMachine::Invoice < ::Dorsale::ApplicationRecord
40
32
  end
41
33
 
42
34
  def assign_default_values
43
- self.advance = 0.0 if advance.nil?
44
- self.vat_amount = 0.0 if vat_amount.nil?
45
- self.commercial_discount = 0.0 if commercial_discount.nil?
46
- self.total_excluding_taxes = 0.0 if total_excluding_taxes.nil?
47
- self.paid = false if paid.nil?
35
+ assign_default :advance, 0.0
36
+ assign_default :vat_amount, 0.0
37
+ assign_default :commercial_discount, 0.0
38
+ assign_default :total_excluding_taxes, 0.0
39
+ assign_default :paid, false
40
+
41
+ end
42
+
43
+ after_initialize :assign_default_dates
44
+
45
+ def assign_default_dates
46
+ assign_default :date, Time.zone.now.to_date
47
+ assign_default :due_date, Time.zone.now.to_date + 30.days
48
48
  end
49
49
 
50
50
  before_save :update_totals
@@ -9,18 +9,12 @@ class Dorsale::BillingMachine::InvoiceLine < ::Dorsale::ApplicationRecord
9
9
  order(created_at: :asc)
10
10
  }
11
11
 
12
- def initialize(*)
13
- super
14
- assign_default_values
15
- end
16
-
17
- before_validation :assign_default_values
18
12
  before_validation :update_total
19
13
 
20
14
  def assign_default_values
21
- self.quantity ||= 0
22
- self.unit_price ||= 0
23
- self.vat_rate ||= ::Dorsale::BillingMachine::DEFAULT_VAT_RATE
15
+ assign_default :quantity, 0
16
+ assign_default :unit_price, 0
17
+ assign_default :vat_rate, ::Dorsale::BillingMachine::DEFAULT_VAT_RATE
24
18
  end
25
19
 
26
20
  def update_total