erp_base_erp_svcs 3.1.0 → 3.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,10 @@
1
1
  class CompassAeInstance < ActiveRecord::Base
2
2
  attr_protected :created_at, :updated_at
3
-
3
+ has_tracked_status
4
+ has_many :parties, :through => :compass_ae_instance_party_roles
5
+ has_many :compass_ae_instance_party_roles, :dependent => :destroy
6
+ validates :internal_identifier, :presence => {:message => 'internal_identifier cannot be blank'}, :uniqueness => {:case_sensitive => false}
7
+
4
8
  def installed_engines
5
9
  Rails.application.config.erp_base_erp_svcs.compass_ae_engines.map do |compass_ae_engine|
6
10
  klass_name = compass_ae_engine.railtie_name.camelize
@@ -0,0 +1,8 @@
1
+ class CompassAeInstancePartyRole < ActiveRecord::Base
2
+ attr_protected :created_at, :updated_at
3
+
4
+ belongs_to :compass_ae_instance
5
+ belongs_to :party
6
+ belongs_to :role_type
7
+
8
+ end
data/app/models/party.rb CHANGED
@@ -109,20 +109,18 @@ class Party < ActiveRecord::Base
109
109
  end
110
110
 
111
111
  def find_contact(contact_mechanism_class, contact_mechanism_args={}, contact_purposes=[])
112
- conditions = ''
113
-
114
112
  table_name = contact_mechanism_class.name.tableize
115
-
113
+
114
+ query = self.contacts.joins("inner join #{table_name} on #{table_name}.id = contact_mechanism_id and contact_mechanism_type = '#{contact_mechanism_class.name}'
115
+ inner join contact_purposes_contacts on contact_purposes_contacts.contact_id = contacts.id
116
+ and contact_purposes_contacts.contact_purpose_id in (#{contact_purposes.collect{|item| item.attributes["id"]}.join(',')})")
117
+
116
118
  contact_mechanism_args.each do |key, value|
117
119
  next if key == 'updated_at' or key == 'created_at' or key == 'id'
118
- conditions += " #{table_name}.#{key} = '#{value}' and" unless value.nil?
120
+ query = query.where("#{table_name}.#{key} = ?", value) unless value.nil?
119
121
  end unless contact_mechanism_args.nil?
120
122
 
121
- conditions = conditions[0..conditions.length - 5] unless conditions == ''
122
-
123
- self.contacts.joins("inner join #{table_name} on #{table_name}.id = contact_mechanism_id and contact_mechanism_type = '#{contact_mechanism_class.name}'
124
- inner join contact_purposes_contacts on contact_purposes_contacts.contact_id = contacts.id
125
- and contact_purposes_contacts.contact_purpose_id in (#{contact_purposes.collect{|item| item.attributes["id"]}.join(',')})").where(conditions).first
123
+ query.first
126
124
  end
127
125
 
128
126
  # looks for contacts matching on value and purpose
@@ -179,13 +177,20 @@ class Party < ActiveRecord::Base
179
177
  purpose = method_name[0]
180
178
  klass = method_name[1] + '_' + method_name[2]
181
179
  end
182
-
183
- contact_purpose = ContactPurpose.find_by_internal_identifier(purpose)
184
- if contact_purpose.nil? or !Object.const_defined?(klass.camelize)
180
+
181
+ #constantize klass to make sure it exists and is loaded
182
+ begin
183
+ klass_const = klass.camelize.constantize
184
+ contact_purpose = ContactPurpose.find_by_internal_identifier(purpose)
185
+ if contact_purpose.nil?
186
+ return nil
187
+ else
188
+ find_contact_mechanism_with_purpose(klass_const, contact_purpose)
189
+ end
190
+ rescue NameError
185
191
  return nil
186
- else
187
- find_contact_mechanism_with_purpose(klass.camelize.constantize, contact_purpose)
188
192
  end
193
+
189
194
  end
190
195
 
191
196
  def respond_to?(m, include_private_methods = false)
@@ -0,0 +1,5 @@
1
+ class StatusApplication < ActiveRecord::Base
2
+ belongs_to :tracked_status_type
3
+ belongs_to :status_application_record, :polymorphic => true
4
+
5
+ end
@@ -0,0 +1,6 @@
1
+ class TrackedStatusType < ActiveRecord::Base
2
+ attr_accessible :description, :internal_identifier
3
+
4
+ has_many :status_applications
5
+
6
+ end
@@ -1,7 +1,16 @@
1
1
  class SetupCompassAeInstance
2
2
 
3
3
  def self.up
4
- CompassAeInstance.create(version: 3.1)
4
+ c = CompassAeInstance.new
5
+ c.description = 'Base CompassAE Instance'
6
+ c.internal_identifier = 'base'
7
+ c.version = '3.1'
8
+ c.save
9
+
10
+ rt = RoleType.new
11
+ rt.description = 'CompassAE Instance Owner'
12
+ rt.internal_identifier = 'compass_ae_instance_owner'
13
+ rt.save
5
14
  end
6
15
 
7
16
  def self.down
@@ -0,0 +1,18 @@
1
+ class UpgradeCompassAeInstancesData < ActiveRecord::Migration
2
+ def self.up
3
+ if CompassAeInstance.find_by_internal_identifier('base').nil?
4
+ c = CompassAeInstance.order('id ASC').first
5
+ c.description = 'Base CompassAE Instance'
6
+ c.internal_identifier = 'base'
7
+ c.schema = 'public'
8
+ c.save
9
+ end
10
+
11
+ if RoleType.find_by_internal_identifier('compass_ae_instance_owner').nil?
12
+ rt = RoleType.new
13
+ rt.description = 'CompassAE Instance Owner'
14
+ rt.internal_identifier = 'compass_ae_instance_owner'
15
+ rt.save
16
+ end
17
+ end
18
+ end
@@ -3,10 +3,35 @@ class BaseErpServices < ActiveRecord::Migration
3
3
 
4
4
  unless table_exists?(:compass_ae_instances)
5
5
  create_table :compass_ae_instances do |t|
6
+ t.string :description
7
+ t.string :internal_identifier
6
8
  t.decimal :version, :precision => 8, :scale => 3
9
+ t.string :type
10
+ t.string :schema, :default => 'public'
11
+ t.integer :parent_id
7
12
 
8
13
  t.timestamps
9
14
  end
15
+
16
+ add_index :compass_ae_instances, :internal_identifier, :name => "iid_idx"
17
+ add_index :compass_ae_instances, :schema, :name => "schema_idx"
18
+ add_index :compass_ae_instances, :type, :name => "type_idx"
19
+ add_index :compass_ae_instances, :parent_id, :name => "parent_id_idx"
20
+ end
21
+
22
+ unless table_exists?(:compass_ae_instance_party_roles)
23
+ create_table :compass_ae_instance_party_roles do |t|
24
+ t.string :description
25
+ t.integer :compass_ae_instance_id
26
+ t.integer :party_id
27
+ t.integer :role_type_id
28
+
29
+ t.timestamps
30
+ end
31
+
32
+ add_index :compass_ae_instance_party_roles, :compass_ae_instance_id, :name => "compass_ae_instance_id_idx"
33
+ add_index :compass_ae_instance_party_roles, :party_id, :name => "party_id_idx"
34
+ add_index :compass_ae_instance_party_roles, :role_type_id, :name => "role_type_id_idx"
10
35
  end
11
36
 
12
37
  # Create parties table
@@ -17,7 +42,7 @@ class BaseErpServices < ActiveRecord::Migration
17
42
  t.column :business_party_type, :string
18
43
  t.column :list_view_image_id, :integer
19
44
 
20
- #This field is here to provide a direct way to map CompassERP
45
+ #This field is here to provide a direct way to map CompassAE
21
46
  #business parties to unified idenfiers in organizations if they
22
47
  #have been implemented in an enterprise.
23
48
  t.column :enterprise_identifier, :string
@@ -443,7 +468,7 @@ class BaseErpServices < ActiveRecord::Migration
443
468
 
444
469
  def self.down
445
470
  [
446
- :currencies, :money,
471
+ :currencies, :money, :compass_ae_instance_party_roles,
447
472
  :party_search_facts, :phone_numbers, :email_addresses,
448
473
  :postal_addresses, :contact_purposes, :contact_types,
449
474
  :contacts, :individuals, :organizations,
@@ -0,0 +1,36 @@
1
+ class AddTxnStatus < ActiveRecord::Migration
2
+ def up
3
+ unless table_exists?(:status_applications)
4
+ create_table :status_applications do |t|
5
+ t.references :tracked_status_type
6
+ t.references :status_application_record, :polymorphic => true
7
+ t.datetime :from_date
8
+ t.datetime :thru_date
9
+
10
+ t.timestamps
11
+ end
12
+
13
+ add_index :status_applications, [:status_application_record_id, :status_application_record_type], :name => 'status_applications_record_idx'
14
+ add_index :status_applications, :tracked_status_type_id, :name => 'tracked_status_type_id_idx'
15
+ add_index :status_applications, :from_date, :name => 'from_date_idx'
16
+ add_index :status_applications, :thru_date, :name => 'thru_date_idx'
17
+ end
18
+
19
+ unless table_exists?(:tracked_status_types)
20
+ create_table :tracked_status_types do |t|
21
+ t.string :description
22
+ t.string :internal_identifier
23
+ t.string :external_identifier
24
+
25
+ t.timestamps
26
+ end
27
+
28
+ add_index :tracked_status_types, :internal_identifier, :name => 'tracked_status_types_iid_idx'
29
+ end
30
+ end
31
+
32
+ def down
33
+ drop_table :status_applications if table_exists?(:status_applications)
34
+ drop_table :tracked_status_types if table_exists?(:tracked_status_types)
35
+ end
36
+ end
@@ -0,0 +1,33 @@
1
+ # This migration comes from erp_base_erp_svcs (originally 20130211444444)
2
+ class UpgradeCompassAeInstances < ActiveRecord::Migration
3
+ def self.up
4
+ unless columns(:compass_ae_instances).collect {|c| c.name}.include?('type')
5
+ add_column :compass_ae_instances, :description, :string
6
+ add_column :compass_ae_instances, :internal_identifier, :string
7
+ add_column :compass_ae_instances, :type, :string
8
+ add_column :compass_ae_instances, :schema, :string, :default => 'public'
9
+ add_column :compass_ae_instances, :parent_id, :integer
10
+
11
+ add_index :compass_ae_instances, :internal_identifier, :name => "iid_idx"
12
+ add_index :compass_ae_instances, :schema, :name => "schema_idx"
13
+ add_index :compass_ae_instances, :type, :name => "type_idx"
14
+ add_index :compass_ae_instances, :parent_id, :name => "parent_id_idx"
15
+ end
16
+ end
17
+
18
+ unless table_exists?(:compass_ae_instance_party_roles)
19
+ create_table :compass_ae_instance_party_roles do |t|
20
+ t.string :description
21
+ t.integer :compass_ae_instance_id
22
+ t.integer :party_id
23
+ t.integer :role_type_id
24
+
25
+ t.timestamps
26
+ end
27
+
28
+ add_index :compass_ae_instance_party_roles, :compass_ae_instance_id, :name => "compass_ae_instance_id_idx"
29
+ add_index :compass_ae_instance_party_roles, :party_id, :name => "party_id_idx"
30
+ add_index :compass_ae_instance_party_roles, :role_type_id, :name => "role_type_id_idx"
31
+ end
32
+
33
+ end
@@ -6,8 +6,13 @@ require "erp_base_erp_svcs/non_escape_json_string"
6
6
 
7
7
  module ErpBaseErpSvcs
8
8
  class << self
9
- def determine_callback
10
- (Rails.env == 'development') ? 'to_prepare' : 'after_initialize'
9
+ def setup_compass_ae_callback(config, engine, &block)
10
+ config.before_initialize do
11
+ callback = (Rails.application.config.cache_classes ? 'after_initialize' : 'to_prepare')
12
+ config.send(callback) do
13
+ block.call(engine)
14
+ end
15
+ end
11
16
  end
12
17
 
13
18
  def mount_compass_ae_engines(routes)
@@ -17,15 +22,15 @@ module ErpBaseErpSvcs
17
22
  end
18
23
 
19
24
  def register_as_compass_ae_engine(config, engine)
20
- config.send(ErpBaseErpSvcs.determine_callback) do
21
- ErpBaseErpSvcs.load_compass_ae_engine(engine, config)
25
+ setup_compass_ae_callback(config, engine) do |engine|
26
+ ErpBaseErpSvcs.load_compass_ae_engine(engine)
22
27
  end
23
28
  end
24
29
 
25
- def load_compass_ae_engine(engine, config)
30
+ def load_compass_ae_engine(engine)
26
31
  Rails.application.config.erp_base_erp_svcs.compass_ae_engines << engine unless Rails.application.config.erp_base_erp_svcs.compass_ae_engines.include?(engine)
27
32
  load_compass_ae_extensions(engine)
28
- load_root_compass_ae_framework_extensions(config)
33
+ load_root_compass_ae_framework_extensions
29
34
  end
30
35
 
31
36
  #forces rails to reload model extensions and framework extensions
@@ -96,19 +101,14 @@ module ErpBaseErpSvcs
96
101
  end
97
102
  end
98
103
 
99
- def load_root_compass_ae_framework_extensions(config)
100
- config.send(ErpBaseErpSvcs.determine_callback) do
101
- Dir.glob(File.join(Rails.root,"lib/extensions/compass_ae/**/*.rb")).each do |file|
102
- load file
103
- end
104
+ def load_root_compass_ae_framework_extensions
105
+ Dir.glob(File.join(Rails.root,"lib/extensions/compass_ae/**/*.rb")).each do |file|
106
+ load file
104
107
  end
105
-
106
108
  end
107
109
 
108
110
  end
109
111
  end
110
112
 
111
113
  #load the engine after this module is defined
112
- require "erp_base_erp_svcs/engine"
113
-
114
-
114
+ require "erp_base_erp_svcs/engine"
@@ -20,7 +20,6 @@ module ErpBaseErpSvcs
20
20
  end
21
21
 
22
22
  ErpBaseErpSvcs.register_as_compass_ae_engine(config, self)
23
- ErpBaseErpSvcs.load_root_compass_ae_framework_extensions(config)
24
23
 
25
24
  end
26
25
  end
@@ -7,6 +7,7 @@ require 'erp_base_erp_svcs/extensions/core/object'
7
7
  #active record extensions
8
8
  require 'erp_base_erp_svcs/extensions/active_record/acts_as_category'
9
9
  require 'erp_base_erp_svcs/extensions/active_record/acts_as_erp_type'
10
+ require 'erp_base_erp_svcs/extensions/active_record/has_tracked_status'
10
11
  require 'erp_base_erp_svcs/extensions/active_record/has_notes'
11
12
  require 'erp_base_erp_svcs/extensions/active_record/acts_as_note_type'
12
13
  require 'erp_base_erp_svcs/extensions/active_record/is_describable'
@@ -0,0 +1,88 @@
1
+ module ErpBaseErpSvcs
2
+ module Extensions
3
+ module ActiveRecord
4
+ module HasTrackedStatus
5
+ def self.included(base)
6
+ base.extend(ClassMethods)
7
+ end
8
+
9
+ module ClassMethods
10
+ def has_tracked_status
11
+ extend HasTrackedStatus::SingletonMethods
12
+ include HasTrackedStatus::InstanceMethods
13
+
14
+ has_many :status_applications, :as => :status_application_record, :dependent => :destroy
15
+ end
16
+ end
17
+
18
+ module SingletonMethods
19
+ end
20
+
21
+ module InstanceMethods
22
+ #get status for given date
23
+ #checks from_date attribute
24
+ def get_status_for_date_time(datetime)
25
+ status_applications = StatusApplication.arel_table
26
+
27
+ arel_query = StatusApplication.where(status_applications[:from_date].gteq(datetime - 1.day).or(status_applications[:from_date].lteq(datetime + 1.day)))
28
+
29
+ arel_query.all
30
+ end
31
+
32
+ #get status for passed date range from_date and thru_date
33
+ #checks from_date attribute
34
+ def get_statuses_for_date_time_range(from_date, thru_date)
35
+ status_applications = StatusApplication.arel_table
36
+
37
+ arel_query = StatusApplication.where(status_applications[:from_date].gteq(from_date - 1.day).or(status_applications[:from_date].lteq(from_date + 1.day)))
38
+ arel_query = arel_query.where(status_applications[:thru_date].gteq(thru_date - 1.day).or(status_applications[:thru_date].lteq(thru_date + 1.day)))
39
+
40
+ arel_query.all
41
+ end
42
+
43
+ def current_status
44
+ self.status_applications.order('id DESC').first.tracked_status_type.internal_identifier unless self.status_applications.empty?
45
+ end
46
+
47
+ #set current status of entity.
48
+ #takes a TrackedStatusType internal_identifier and creates a StatusApplication
49
+ #with from_date set to today and tracked_status_type set to passed TrackedStatusType internal_identifier
50
+ #optionally can passed from_date and thru_date to manually set these
51
+ #it will set the thru_date on the current StatusApplication to now
52
+ def current_status=(args)
53
+ status_iid = nil
54
+ options = {}
55
+
56
+ if args.is_a?(Array)
57
+ status = args[0]
58
+ options = args[1]
59
+ else
60
+ status = args
61
+ end
62
+ tracked_status_type = status.is_a?(TrackedStatusType) ? status : TrackedStatusType.find_by_internal_identifier(status.to_s)
63
+ raise "TrackedStatusType does not exists #{status.to_s}" unless tracked_status_type
64
+
65
+ #set current StatusApplication thru_date to now
66
+ current_status_application = self.status_applications.last
67
+ unless current_status_application.nil?
68
+ current_status_application.thru_date = options[:thru_date].nil? ? Time.now : options[:thru_date]
69
+ current_status_application.save
70
+ end
71
+
72
+ status_application = StatusApplication.new
73
+ status_application.tracked_status_type = tracked_status_type
74
+ status_application.from_date = options[:from_date].nil? ? Time.now : options[:from_date]
75
+ status_application.save
76
+
77
+ self.status_applications << status_application
78
+ self.save
79
+ end
80
+
81
+ end
82
+
83
+ end #HasTrackedStatus
84
+ end #Rezzcard
85
+ end #ActiveRecord
86
+ end #Extensions
87
+
88
+ ActiveRecord::Base.send :include, ErpBaseErpSvcs::Extensions::ActiveRecord::HasTrackedStatus
@@ -2,7 +2,7 @@ module ErpBaseErpSvcs
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 3
4
4
  MINOR = 1
5
- TINY = 0
5
+ TINY = 1
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].compact.join('.')
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: erp_base_erp_svcs
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 3.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-11 00:00:00.000000000 Z
12
+ date: 2013-02-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: attr_encrypted
@@ -236,6 +236,7 @@ files:
236
236
  - app/models/category.rb
237
237
  - app/models/category_classification.rb
238
238
  - app/models/compass_ae_instance.rb
239
+ - app/models/compass_ae_instance_party_role.rb
239
240
  - app/models/contact.rb
240
241
  - app/models/contact_purpose.rb
241
242
  - app/models/contact_type.rb
@@ -257,6 +258,8 @@ files:
257
258
  - app/models/postal_address.rb
258
259
  - app/models/relationship_type.rb
259
260
  - app/models/role_type.rb
261
+ - app/models/status_application.rb
262
+ - app/models/tracked_status_type.rb
260
263
  - app/models/valid_note_type.rb
261
264
  - app/models/view_type.rb
262
265
  - app/views/layouts/erp_base_erp_svcs/application.html.erb
@@ -264,9 +267,12 @@ files:
264
267
  - db/data_migrations/20110525001935_add_usd_currency.rb
265
268
  - db/data_migrations/20110609150135_add_iso_codes.rb
266
269
  - db/data_migrations/20110913145838_setup_compass_ae_instance.rb
270
+ - db/data_migrations/20130211555555_upgrade_compass_ae_instances_data.rb
267
271
  - db/data_sets/geo_countries.yml
268
272
  - db/data_sets/geo_zones.yml
269
273
  - db/migrate/20080805000020_base_erp_services.rb
274
+ - db/migrate/20120606183856_add_txn_status.rb
275
+ - db/migrate/20130211444444_upgrade_compass_ae_instances.rb
270
276
  - lib/erp_base_erp_svcs/ar_fixtures.rb
271
277
  - lib/erp_base_erp_svcs/config.rb
272
278
  - lib/erp_base_erp_svcs/engine.rb
@@ -275,6 +281,7 @@ files:
275
281
  - lib/erp_base_erp_svcs/extensions/active_record/acts_as_note_type.rb
276
282
  - lib/erp_base_erp_svcs/extensions/active_record/has_contact.rb
277
283
  - lib/erp_base_erp_svcs/extensions/active_record/has_notes.rb
284
+ - lib/erp_base_erp_svcs/extensions/active_record/has_tracked_status.rb
278
285
  - lib/erp_base_erp_svcs/extensions/active_record/is_describable.rb
279
286
  - lib/erp_base_erp_svcs/extensions/active_record/migration.rb
280
287
  - lib/erp_base_erp_svcs/extensions/active_record/sti_instantiation.rb
@@ -370,18 +377,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
370
377
  - - ! '>='
371
378
  - !ruby/object:Gem::Version
372
379
  version: '0'
373
- segments:
374
- - 0
375
- hash: -2074992093686783973
376
380
  required_rubygems_version: !ruby/object:Gem::Requirement
377
381
  none: false
378
382
  requirements:
379
383
  - - ! '>='
380
384
  - !ruby/object:Gem::Version
381
385
  version: '0'
382
- segments:
383
- - 0
384
- hash: -2074992093686783973
385
386
  requirements: []
386
387
  rubyforge_project:
387
388
  rubygems_version: 1.8.24