erp_base_erp_svcs 3.1.5 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. checksums.yaml +7 -0
  2. data/app/controllers/erp_base_erp_svcs/shared/units_of_measurement_controller.rb +32 -0
  3. data/app/models/compass_ae_instance.rb +2 -0
  4. data/app/models/contact.rb +4 -0
  5. data/app/models/email_address.rb +4 -1
  6. data/app/models/facility.rb +12 -0
  7. data/app/models/facility_type.rb +8 -0
  8. data/app/models/fixed_asset.rb +8 -0
  9. data/app/models/fixed_asset_party_role.rb +8 -0
  10. data/app/models/fixed_asset_type.rb +9 -0
  11. data/app/models/individual.rb +10 -14
  12. data/app/models/party.rb +138 -51
  13. data/app/models/party_unit_of_measurement.rb +6 -0
  14. data/app/models/phone_number.rb +5 -1
  15. data/app/models/postal_address.rb +5 -1
  16. data/app/models/unit_of_measurement.rb +16 -0
  17. data/config/initializers/root_loader.rb +9 -0
  18. data/config/routes.rb +5 -0
  19. data/db/migrate/20080805000020_base_erp_services.rb +1 -29
  20. data/db/migrate/20130522125404_create_facilities.rb +114 -0
  21. data/db/migrate/20130621182047_create_unit_of_measurements.rb +18 -0
  22. data/db/migrate/20130909163912_add_iid_index_to_role_types.rb +9 -0
  23. data/db/migrate/20130926023541_add_domain_to_unit_of_measure.rb +13 -0
  24. data/db/migrate/20130929025342_add_type_semantics_to_uom.rb +54 -0
  25. data/db/migrate/20131112013047_add_primary_to_contacts.rb +13 -0
  26. data/db/migrate/20131112013048_add_erp_base_erp_svcs_missing_indexes.rb +33 -0
  27. data/db/migrate/20131211180831_add_postal_address_to_facility.rb +5 -0
  28. data/db/migrate/20140102154311_create_fixed_asset_party_roles.rb +12 -0
  29. data/db/migrate/20140401072612_add_custom_fields_to_party.rb +12 -0
  30. data/lib/erp_base_erp_svcs.rb +5 -5
  31. data/lib/erp_base_erp_svcs/engine.rb +5 -3
  32. data/lib/erp_base_erp_svcs/extensions.rb +3 -0
  33. data/lib/erp_base_erp_svcs/extensions/active_record/acts_as_facility.rb +54 -0
  34. data/lib/erp_base_erp_svcs/extensions/active_record/acts_as_fixed_asset.rb +54 -0
  35. data/lib/erp_base_erp_svcs/extensions/active_record/has_contact.rb +25 -12
  36. data/lib/erp_base_erp_svcs/extensions/active_record/has_notes.rb +25 -2
  37. data/lib/erp_base_erp_svcs/extensions/active_record/has_tracked_status.rb +58 -6
  38. data/lib/erp_base_erp_svcs/extensions/active_record/to_hash.rb +12 -12
  39. data/lib/erp_base_erp_svcs/extensions/core/acts_as_aspector_on.rb +73 -0
  40. data/lib/erp_base_erp_svcs/extensions/core/object.rb +7 -0
  41. data/lib/erp_base_erp_svcs/version.rb +7 -3
  42. data/lib/tasks/compass_backup.rake +11 -6
  43. data/lib/tasks/erp_base_erp_svcs_tasks.rake +22 -9
  44. data/spec/models/party_spec.rb +9 -1
  45. metadata +80 -113
  46. data/app/assets/javascripts/erp_base_erp_svcs/application.js +0 -9
  47. data/app/assets/stylesheets/erp_base_erp_svcs/application.css +0 -7
  48. data/app/controllers/erp_base_erp_svcs/application_controller.rb +0 -4
  49. data/app/views/layouts/erp_base_erp_svcs/application.html.erb +0 -14
  50. data/spec/dummy/db/data_migrations/20110525001935_add_usd_currency.erp_base_erp_svcs.rb +0 -12
  51. data/spec/dummy/db/data_migrations/20110609150135_add_iso_codes.erp_base_erp_svcs.rb +0 -19
  52. data/spec/dummy/db/data_migrations/20110913145838_setup_compass_ae_instance.erp_base_erp_svcs.rb +0 -12
  53. data/spec/dummy/db/data_migrations/20130422154233_upgrade_compass_ae_instances_data.erp_base_erp_svcs.rb +0 -19
  54. data/spec/dummy/db/data_migrations/20130422154234_add_guid_to_instances.erp_base_erp_svcs.rb +0 -10
  55. data/spec/dummy/db/migrate/20130105143821_base_erp_services.erp_base_erp_svcs.rb +0 -461
  56. data/spec/dummy/db/migrate/20130422154229_add_txn_status.erp_base_erp_svcs.rb +0 -37
  57. data/spec/dummy/db/migrate/20130422154230_upgrade_compass_ae_instances.erp_base_erp_svcs.rb +0 -34
  58. data/spec/dummy/db/migrate/20130422154231_add_uuid_compass_ae_instance.erp_base_erp_svcs.rb +0 -17
  59. data/spec/dummy/db/migrate/20130422154232_add_long_lat_to_address.erp_base_erp_svcs.rb +0 -16
  60. data/spec/dummy/db/schema.rb +0 -435
  61. data/spec/dummy/db/spec.sqlite3 +0 -0
@@ -9,17 +9,19 @@ module ErpBaseErpSvcs
9
9
 
10
10
  config.erp_base_erp_svcs = ErpBaseErpSvcs::Config
11
11
 
12
- ActiveSupport.on_load(:active_record) do
12
+ ActiveSupport.on_load(:active_record) do
13
13
  include ErpBaseErpSvcs::Extensions::ActiveRecord::IsDescribable
14
14
  include ErpBaseErpSvcs::Extensions::ActiveRecord::HasNotes
15
15
  include ErpBaseErpSvcs::Extensions::ActiveRecord::ActsAsNoteType
16
- include ErpBaseErpSvcs::Extensions::ActiveRecord::ActsAsErpType
16
+ include ErpBaseErpSvcs::Extensions::ActiveRecord::ActsAsErpType
17
17
  include ErpBaseErpSvcs::Extensions::ActiveRecord::ActsAsCategory
18
18
  include ErpBaseErpSvcs::Extensions::ActiveRecord::HasContact
19
+ include ErpBaseErpSvcs::Extensions::ActiveRecord::ActsAsFixedAsset
20
+ include ErpBaseErpSvcs::Extensions::ActiveRecord::ActsAsFacility
19
21
  extend ErpBaseErpSvcs::Extensions::ActiveRecord::StiInstantiation::ActMacro
20
22
  end
21
23
 
22
24
  ErpBaseErpSvcs.register_as_compass_ae_engine(config, self)
23
-
25
+
24
26
  end
25
27
  end
@@ -3,6 +3,7 @@ require 'erp_base_erp_svcs/extensions/core/array'
3
3
  require 'erp_base_erp_svcs/extensions/core/hash'
4
4
  require 'erp_base_erp_svcs/extensions/core/numbers'
5
5
  require 'erp_base_erp_svcs/extensions/core/object'
6
+ require 'erp_base_erp_svcs/extensions/core/acts_as_aspector_on'
6
7
 
7
8
  #active record extensions
8
9
  require 'erp_base_erp_svcs/extensions/active_record/acts_as_category'
@@ -15,4 +16,6 @@ require 'erp_base_erp_svcs/extensions/active_record/has_contact'
15
16
  require 'erp_base_erp_svcs/extensions/active_record/sti_instantiation'
16
17
  require 'erp_base_erp_svcs/extensions/active_record/to_hash'
17
18
  require 'erp_base_erp_svcs/extensions/active_record/migration'
19
+ require 'erp_base_erp_svcs/extensions/active_record/acts_as_fixed_asset'
20
+ require 'erp_base_erp_svcs/extensions/active_record/acts_as_facility'
18
21
 
@@ -0,0 +1,54 @@
1
+ module ErpBaseErpSvcs
2
+ module Extensions
3
+ module ActiveRecord
4
+ module ActsAsFacility
5
+
6
+ def self.included(base)
7
+ base.extend(ClassMethods)
8
+ end
9
+
10
+ module ClassMethods
11
+ def acts_as_facility
12
+ extend ActsAsFacility::SingletonMethods
13
+ include ActsAsFacility::InstanceMethods
14
+
15
+ after_initialize :initialize_facility
16
+ after_create :save_facility
17
+ after_update :save_facility
18
+ after_destroy :destroy_facility
19
+
20
+ has_one :facility, :as => :facility_record
21
+
22
+ end
23
+ end
24
+
25
+ module SingletonMethods
26
+ end
27
+
28
+ module InstanceMethods
29
+ def root_asset
30
+ self.facility
31
+ end
32
+
33
+ def save_facility
34
+ self.facility.description = self.description
35
+ self.facility.save
36
+ end
37
+
38
+ def initialize_facility
39
+ if self.new_record? and self.facility.nil?
40
+ f = Facility.new
41
+ self.facility = f
42
+ f.facility_record = self
43
+ end
44
+ end
45
+
46
+ def destroy_facility
47
+ self.facility.destroy if (self.facility && !self.facility.frozen?)
48
+ end
49
+ end
50
+
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,54 @@
1
+ module ErpBaseErpSvcs
2
+ module Extensions
3
+ module ActiveRecord
4
+ module ActsAsFixedAsset
5
+
6
+ def self.included(base)
7
+ base.extend(ClassMethods)
8
+ end
9
+
10
+ module ClassMethods
11
+ def acts_as_fixed_asset
12
+ extend ActsAsFixedAsset::SingletonMethods
13
+ include ActsAsFixedAsset::InstanceMethods
14
+
15
+ after_initialize :initialize_fixed_asset
16
+ after_create :save_fixed_asset
17
+ after_update :save_fixed_asset
18
+ after_destroy :destroy_fixed_asset
19
+
20
+ has_one :fixed_asset, :as => :fixed_asset_record
21
+
22
+ end
23
+ end
24
+
25
+ module SingletonMethods
26
+ end
27
+
28
+ module InstanceMethods
29
+ def root_asset
30
+ self.fixed_asset
31
+ end
32
+
33
+ def save_fixed_asset
34
+ self.fixed_asset.description = self.description
35
+ self.fixed_asset.save
36
+ end
37
+
38
+ def initialize_fixed_asset
39
+ if self.new_record? and self.fixed_asset.nil?
40
+ fa = FixedAsset.new
41
+ self.fixed_asset = fa
42
+ fa.fixed_asset_record = self
43
+ end
44
+ end
45
+
46
+ def destroy_fixed_asset
47
+ self.fixed_asset.destroy if (self.fixed_asset && !self.fixed_asset.frozen?)
48
+ end
49
+ end
50
+
51
+ end
52
+ end
53
+ end
54
+ end
@@ -17,6 +17,12 @@ module ErpBaseErpSvcs
17
17
  after_destroy :destroy_contact
18
18
 
19
19
  has_one :contact, :as => :contact_mechanism
20
+
21
+ [:purpose,
22
+ :purposes,
23
+ :is_primary,
24
+ :is_primary=,
25
+ :is_primary?].each { |m| delegate m, :to => :contact }
20
26
  end
21
27
  end
22
28
 
@@ -24,19 +30,25 @@ module ErpBaseErpSvcs
24
30
  end
25
31
 
26
32
  module InstanceMethods
27
- # return first contact purpose
28
- def contact_purpose
29
- contact.contact_purposes.count == 0 ? nil : contact.contact_purposes.first
33
+
34
+ def save_contact
35
+ self.contact.save
36
+ end
37
+
38
+ # return all contact purposes in one comma separated string
39
+ def contact_purposes_to_s
40
+ contact.contact_purposes.collect(&:description).join(', ')
41
+ end
42
+
43
+ # return all contact purpose iids in one comma separated string
44
+ def contact_purpose_iids
45
+ contact.contact_purposes.collect(&:internal_identifier).join(',')
30
46
  end
31
47
 
32
48
  # return all contact purposes
33
49
  def contact_purposes
34
50
  contact.contact_purposes
35
51
  end
36
-
37
- def save_contact
38
- self.contact.save
39
- end
40
52
 
41
53
  def destroy_contact
42
54
  self.contact.destroy unless self.contact.nil?
@@ -48,9 +60,10 @@ module ErpBaseErpSvcs
48
60
  self.contact.description = self.description
49
61
  end
50
62
  end
51
-
63
+
52
64
  end
53
- end
54
- end
55
- end
56
- end
65
+
66
+ end #HasContact
67
+ end #ActiveRecord
68
+ end #Extensions
69
+ end #ErpBaseErpSvcs
@@ -15,8 +15,8 @@ module ErpBaseErpSvcs
15
15
  end
16
16
  end
17
17
 
18
- extend ErpBaseErpSvcs::Extensions::ActiveRecord::HasNotes
19
- include ErpBaseErpSvcs::Extensions::ActiveRecord::HasNotes
18
+ extend SingletonMethods
19
+ include InstanceMethods
20
20
 
21
21
  end
22
22
  end
@@ -25,6 +25,29 @@ module ErpBaseErpSvcs
25
25
  end
26
26
 
27
27
  module InstanceMethods
28
+
29
+ def create_or_update_note_by_type(note_type_iid='basic_note', content='', user=nil)
30
+ note = note_by_type(note_type_iid)
31
+ if note.nil?
32
+ note = Note.new if note.nil?
33
+ note.note_type_id = NoteType.find_by_internal_identifier(note_type_iid).id
34
+ note.noted_record = self
35
+ note.created_by_id = user.id unless user.nil?
36
+ end
37
+ note.content = content
38
+ note.save
39
+ end
40
+
41
+ def note_by_type(note_type_iid)
42
+ note_type = NoteType.find_by_internal_identifier(note_type_iid)
43
+ notes.where(:note_type_id => note_type.id).first
44
+ end
45
+
46
+ def notes_by_type(note_type_iid)
47
+ note_type = NoteType.find_by_internal_identifier(note_type_iid)
48
+ notes.where(:note_type_id => note_type.id)
49
+ end
50
+
28
51
  end
29
52
  end
30
53
  end
@@ -12,6 +12,26 @@ module ErpBaseErpSvcs
12
12
  include HasTrackedStatus::InstanceMethods
13
13
 
14
14
  has_many :status_applications, :as => :status_application_record, :dependent => :destroy
15
+
16
+ scope :with_status, lambda { |status_type_iids|
17
+ joins(:status_applications => :tracked_status_type).
18
+ where("status_applications.thru_date IS NULL AND tracked_status_types.internal_identifier IN (?)",
19
+ status_type_iids)
20
+ }
21
+
22
+ scope :with_current_status, lambda {
23
+ model_table = self.arel_table
24
+ status_applications_tbl = StatusApplication.arel_table
25
+
26
+ #determine status_application_record_type
27
+ status_application_record_type = (self.superclass == ::ActiveRecord::Base) ? self.name.to_s : self.superclass.to_s
28
+
29
+ current_status_select = status_applications_tbl.project(status_applications_tbl[:id].maximum)
30
+ .where(model_table[:id].eq(status_applications_tbl[:status_application_record_id])
31
+ .and(status_applications_tbl[:status_application_record_type].eq(status_application_record_type)))
32
+
33
+ joins(:status_applications).where(status_applications_tbl[:id].in(current_status_select))
34
+ }
15
35
  end
16
36
  end
17
37
 
@@ -20,6 +40,23 @@ module ErpBaseErpSvcs
20
40
 
21
41
  module InstanceMethods
22
42
 
43
+ # does this status match the current_status?
44
+ def has_status?(tracked_status_iid)
45
+ current_status == tracked_status_iid
46
+ end
47
+
48
+ # did it have this status in the past but NOT currently?
49
+ def had_status?(tracked_status_iid)
50
+ return false if has_status?(tracked_status_iid)
51
+ has_had_status?(tracked_status_iid)
52
+ end
53
+
54
+ # does it now or has it ever had this status?
55
+ def has_had_status?(tracked_status_iid)
56
+ result = self.status_applications.joins(:tracked_status_types).where("tracked_status_types.internal_identifier = ?", tracked_status_iid)
57
+ result.nil? ? false : true
58
+ end
59
+
23
60
  #get status for given date
24
61
  #checks from_date attribute
25
62
  def get_status_for_date_time(datetime)
@@ -41,8 +78,19 @@ module ErpBaseErpSvcs
41
78
  arel_query.all
42
79
  end
43
80
 
81
+ # gets current StatusApplication record
82
+ def current_status_application
83
+ self.status_applications.where("status_applications.thru_date IS NULL").order('id DESC').first
84
+ end
85
+
86
+ # get's current status's tracked_status_type
87
+ def current_status_type
88
+ self.current_status_application.tracked_status_type unless self.current_status_application.nil?
89
+ end
90
+
91
+ # gets current status's internal_identifier
44
92
  def current_status
45
- self.status_applications.order('id DESC').first.tracked_status_type.internal_identifier unless self.status_applications.empty?
93
+ self.current_status_type.internal_identifier unless self.current_status_type.nil?
46
94
  end
47
95
 
48
96
  #set current status of entity.
@@ -51,7 +99,6 @@ module ErpBaseErpSvcs
51
99
  #optionally can passed from_date and thru_date to manually set these
52
100
  #it will set the thru_date on the current StatusApplication to now
53
101
  def current_status=(args)
54
- status_iid = nil
55
102
  options = {}
56
103
 
57
104
  if args.is_a?(Array)
@@ -64,10 +111,10 @@ module ErpBaseErpSvcs
64
111
  raise "TrackedStatusType does not exist #{status.to_s}" unless tracked_status_type
65
112
 
66
113
  #set current StatusApplication thru_date to now
67
- current_status_application = self.status_applications.last
68
- unless current_status_application.nil?
69
- current_status_application.thru_date = options[:thru_date].nil? ? Time.now : options[:thru_date]
70
- current_status_application.save
114
+ cta = self.current_status_application
115
+ unless cta.nil?
116
+ cta.thru_date = options[:thru_date].nil? ? Time.now : options[:thru_date]
117
+ cta.save
71
118
  end
72
119
 
73
120
  status_application = StatusApplication.new
@@ -79,6 +126,11 @@ module ErpBaseErpSvcs
79
126
  self.save
80
127
  end
81
128
 
129
+ # add_status aliases current_status= for legacy support
130
+ def add_status(tracked_status_iid)
131
+ self.current_status = tracked_status_iid
132
+ end
133
+
82
134
  end
83
135
 
84
136
  end #HasTrackedStatus
@@ -7,7 +7,7 @@ ActiveRecord::Base.class_eval do
7
7
  if options[:only]
8
8
  options[:only].each do |attribute|
9
9
  if attribute.is_a?(Hash)
10
- attribute.each do |k,v|
10
+ attribute.each do |k, v|
11
11
  k = k.to_sym
12
12
  v = v.to_sym
13
13
  hash[v] = self.send(k)
@@ -21,26 +21,26 @@ ActiveRecord::Base.class_eval do
21
21
  hash.merge!(self.attributes)
22
22
  end
23
23
 
24
- #check for methods option
25
24
  if options[:methods]
26
25
  options[:methods].each do |method|
27
26
  if method.is_a?(Hash)
28
- method.each do |k,v|
29
- k = k.to_sym
30
- v = v.to_sym
31
- hash[v] = self.send(k)
32
- end
27
+ name, method_name = method.first
28
+ hash[name] = self.send(method_name)
33
29
  else
34
- method = method.to_sym
35
30
  hash[method] = self.send(method)
36
31
  end
32
+ hash[method] = self.send(method)
37
33
  end
38
34
  end
39
35
 
40
- #check for additional values
41
- options[:additional_values].each{|k, v| hash[k] = v} if options[:additional_values]
42
-
43
- end#end hash tap
36
+ options.each do |key, value|
37
+ next if [:only].include?(key)
38
+ next if [:methods].include?(key)
39
+
40
+ hash[key] = value
41
+ end
42
+
43
+ end #end hash tap
44
44
  end
45
45
  end
46
46
 
@@ -0,0 +1,73 @@
1
+ # gives the ability to execute code before and after instance method,
2
+ # the methods on which to attach code can be passed declaritive using
3
+ # this marco
4
+ # class Foo
5
+ # acts_as_aspector_on :bar
6
+ #
7
+ # def bar
8
+ # puts "bar"
9
+ # end
10
+ #
11
+ #
12
+ # before :bar do |foo| #foo is the object invoking bar
13
+ # puts "before bar"
14
+ # end
15
+ #
16
+ # after :bar do |foo, result| # result is the return from foo.bar
17
+ # puts "after bar"
18
+ # end
19
+ # end
20
+
21
+ module ErpBaseErpSvcs
22
+ module Extensions
23
+ module Core
24
+ module ActsAsAspectorOn
25
+
26
+ def self.included(base)
27
+ base.extend(ClassMethods)
28
+ end
29
+
30
+ module ClassMethods
31
+ def acts_as_aspector_on(*meth_names)
32
+ self.instance_eval do
33
+
34
+ define_singleton_method :before do |method_name, &blk|
35
+ if meth_names.include?(method_name)
36
+ m = instance_method(method_name)
37
+ define_method(method_name) do |*args, &block|
38
+ blk.call(self) unless blk.nil?
39
+ m.bind(self).call(*args, &block)
40
+ end
41
+ end
42
+ end
43
+
44
+
45
+ define_singleton_method :after do |method_name, &blk|
46
+ if meth_names.include?(method_name)
47
+ m = instance_method(method_name)
48
+ define_method(method_name) do |*args, &block|
49
+ result = m.bind(self).call(*args, &block)
50
+ blk.call(self, result) unless blk.nil?
51
+ result
52
+ end
53
+ end
54
+ end
55
+
56
+ end # instance_eval
57
+
58
+
59
+ end # acts_as_aspector
60
+ end # ClassMethods
61
+
62
+ end # ActsAsAspector
63
+ end # Core
64
+ end # Extensions
65
+ end # ErpTechSvcs
66
+
67
+ Object.class_eval do
68
+ include ErpBaseErpSvcs::Extensions::Core::ActsAsAspectorOn
69
+ end
70
+
71
+
72
+
73
+