erp_base_erp_svcs 4.0.0 → 4.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/api/v1/base_controller.rb +17 -0
- data/app/controllers/api/v1/categories_controller.rb +165 -0
- data/app/controllers/api/v1/contact_purposes_controller.rb +24 -0
- data/app/controllers/api/v1/geo_zones_controller.rb +25 -0
- data/app/controllers/api/v1/note_types_controller.rb +27 -0
- data/app/controllers/api/v1/parties_controller.rb +182 -0
- data/app/controllers/api/v1/role_types_controller.rb +146 -0
- data/app/controllers/api/v1/status_applications_controller.rb +40 -0
- data/app/controllers/api/v1/tracked_status_types_controller.rb +146 -0
- data/app/controllers/api/v1/unit_of_measurements_controller.rb +16 -0
- data/app/models/category.rb +116 -4
- data/app/models/contact.rb +16 -2
- data/app/models/contact_purpose.rb +13 -0
- data/app/models/descriptive_asset.rb +17 -0
- data/app/models/email_address.rb +21 -3
- data/app/models/entity_party_role.rb +8 -0
- data/app/models/fixed_asset.rb +2 -0
- data/app/models/fixed_asset_type.rb +1 -0
- data/app/models/generated_item.rb +17 -0
- data/app/models/geo_country.rb +12 -1
- data/app/models/individual.rb +11 -20
- data/app/models/note.rb +9 -0
- data/app/models/note_type.rb +2 -0
- data/app/models/organization.rb +19 -16
- data/app/models/party.rb +134 -229
- data/app/models/party_unit_of_measurement.rb +17 -1
- data/app/models/phone_number.rb +32 -12
- data/app/models/postal_address.rb +42 -11
- data/app/models/relationship_type.rb +28 -1
- data/app/models/role_type.rb +25 -2
- data/app/models/status_application.rb +40 -0
- data/app/models/tracked_status_type.rb +12 -0
- data/app/models/unit_of_measurement.rb +46 -7
- data/app/models/view_type.rb +14 -0
- data/config/routes.rb +24 -0
- data/db/data_migrations/20110913145838_setup_compass_ae_instance.rb +22 -9
- data/db/migrate/20080805000020_base_erp_services.rb +235 -6
- data/db/migrate/20130713171653_create_party_unit_of_measurements.rb +28 -0
- data/db/migrate/20150716201200_add_record_to_contact.rb +42 -0
- data/db/migrate/20150814202823_add_party_id_to_status_application.rb +10 -0
- data/db/migrate/20160310163040_add_created_by_updated_by_to_erp_base_erp_svcs.rb +44 -0
- data/lib/erp_base_erp_svcs.rb +1 -0
- data/lib/erp_base_erp_svcs/config.rb +3 -2
- data/lib/erp_base_erp_svcs/engine.rb +8 -1
- data/lib/erp_base_erp_svcs/extensions.rb +7 -1
- data/lib/erp_base_erp_svcs/extensions/active_record/acts_as_category.rb +5 -4
- data/lib/erp_base_erp_svcs/extensions/active_record/acts_as_erp_type.rb +48 -9
- data/lib/erp_base_erp_svcs/extensions/active_record/can_be_generated.rb +54 -0
- data/lib/erp_base_erp_svcs/extensions/active_record/has_contacts.rb +383 -0
- data/lib/erp_base_erp_svcs/extensions/active_record/has_notes.rb +15 -4
- data/lib/erp_base_erp_svcs/extensions/active_record/has_party_roles.rb +94 -0
- data/lib/erp_base_erp_svcs/extensions/active_record/has_tracked_status.rb +118 -35
- data/lib/erp_base_erp_svcs/extensions/active_record/is_contact_mechanism.rb +94 -0
- data/lib/erp_base_erp_svcs/extensions/active_record/is_describable.rb +46 -42
- data/lib/erp_base_erp_svcs/extensions/active_record/is_tenantable.rb +40 -0
- data/lib/erp_base_erp_svcs/extensions/active_record/tracks_created_by_updated_by.rb +39 -0
- data/lib/erp_base_erp_svcs/extensions/core/numbers.rb +29 -18
- data/lib/erp_base_erp_svcs/extensions/core/object.rb +5 -0
- data/lib/erp_base_erp_svcs/extensions/core/string.rb +53 -0
- data/lib/erp_base_erp_svcs/non_escape_json_string.rb +1 -1
- data/lib/erp_base_erp_svcs/time_zone_helper.rb +57 -0
- data/lib/erp_base_erp_svcs/version.rb +1 -1
- data/lib/tasks/erp_base_erp_svcs_tasks.rake +20 -23
- data/spec/dummy/log/development.log +3 -0
- metadata +29 -22
- data/db/data_migrations/20110525001935_add_usd_currency.rb +0 -11
- data/db/data_migrations/20110609150135_add_iso_codes.rb +0 -18
- data/db/data_migrations/20130211555555_upgrade_compass_ae_instances_data.rb +0 -18
- data/db/data_migrations/20130404201756_add_guid_to_instances.rb +0 -9
- data/db/migrate/20120606183856_add_txn_status.rb +0 -36
- data/db/migrate/20130211444444_upgrade_compass_ae_instances.rb +0 -33
- data/db/migrate/20130404171435_add_uuid_compass_ae_instance.rb +0 -16
- data/db/migrate/20130411125210_add_long_lat_to_address.rb +0 -15
- data/db/migrate/20130522125404_create_facilities.rb +0 -114
- data/db/migrate/20130621182047_create_unit_of_measurements.rb +0 -18
- data/db/migrate/20130909163912_add_iid_index_to_role_types.rb +0 -9
- data/db/migrate/20130926023541_add_domain_to_unit_of_measure.rb +0 -13
- data/db/migrate/20130929025342_add_type_semantics_to_uom.rb +0 -54
- data/db/migrate/20131112013047_add_primary_to_contacts.rb +0 -13
- data/db/migrate/20131112013048_add_erp_base_erp_svcs_missing_indexes.rb +0 -33
- data/db/migrate/20131211180831_add_postal_address_to_facility.rb +0 -5
- data/db/migrate/20140102154311_create_fixed_asset_party_roles.rb +0 -12
- data/db/migrate/20140401072612_add_custom_fields_to_party.rb +0 -12
- data/lib/erp_base_erp_svcs/extensions/active_record/has_contact.rb +0 -69
@@ -10,9 +10,10 @@ module ErpBaseErpSvcs
|
|
10
10
|
def has_notes
|
11
11
|
|
12
12
|
has_many :notes, :as => :noted_record, :dependent => :delete_all do
|
13
|
-
def by_type(
|
14
|
-
|
13
|
+
def by_type(note_type_iid)
|
14
|
+
where('note_type_id = ?', NoteType.iid(note_type_iid))
|
15
15
|
end
|
16
|
+
|
16
17
|
end
|
17
18
|
|
18
19
|
extend SingletonMethods
|
@@ -26,13 +27,23 @@ module ErpBaseErpSvcs
|
|
26
27
|
|
27
28
|
module InstanceMethods
|
28
29
|
|
29
|
-
|
30
|
+
# adds note to model
|
31
|
+
def add_note(note_type_iid, content, party=nil)
|
32
|
+
note = Note.new
|
33
|
+
note.note_type = NoteType.iid(note_type_iid)
|
34
|
+
note.noted_record = self
|
35
|
+
note.created_by = party unless party.nil?
|
36
|
+
note.content = content
|
37
|
+
note if note.save
|
38
|
+
end
|
39
|
+
|
40
|
+
def create_or_update_note_by_type(note_type_iid='basic_note', content='', party=nil)
|
30
41
|
note = note_by_type(note_type_iid)
|
31
42
|
if note.nil?
|
32
43
|
note = Note.new if note.nil?
|
33
44
|
note.note_type_id = NoteType.find_by_internal_identifier(note_type_iid).id
|
34
45
|
note.noted_record = self
|
35
|
-
note.created_by_id =
|
46
|
+
note.created_by_id = party unless party.nil?
|
36
47
|
end
|
37
48
|
note.content = content
|
38
49
|
note.save
|
@@ -0,0 +1,94 @@
|
|
1
|
+
module ErpBaseErpSvcs
|
2
|
+
module Extensions
|
3
|
+
module ActiveRecord
|
4
|
+
module HasPartyRoles
|
5
|
+
def self.included(base)
|
6
|
+
base.extend(ClassMethods)
|
7
|
+
end
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
def has_party_roles
|
11
|
+
extend HasPartyRoles::SingletonMethods
|
12
|
+
include HasPartyRoles::InstanceMethods
|
13
|
+
|
14
|
+
has_many :entity_party_roles, :as => :entity_record, dependent: :destroy
|
15
|
+
has_many :role_types, :through => :entity_party_roles
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
module SingletonMethods
|
20
|
+
# Scope by a set of RoleTypes
|
21
|
+
#
|
22
|
+
# @param role_types [Integer | RoleType | Array] either a id of RoleType record, a RoleType record,
|
23
|
+
# an array of RoleType records or an array of RoleType ids
|
24
|
+
def with_party_role_types(role_types)
|
25
|
+
joins(:entity_party_roles)
|
26
|
+
.where(entity_party_roles: {role_type_id: role_types})
|
27
|
+
end
|
28
|
+
|
29
|
+
# Scope by a set of parties with the passed role_types
|
30
|
+
#
|
31
|
+
# @param party [Integer | Party | Array] either a id of Party record, a Party record,
|
32
|
+
# an array of Party records or an array of Party ids
|
33
|
+
# @param role_types [Integer | RoleType | Array] either a id of RoleType record, a RoleType record,
|
34
|
+
# an array of RoleType records or an array of RoleType ids
|
35
|
+
def with_party_role(parties, role_types)
|
36
|
+
joins(:entity_party_roles).where(entity_party_roles: {role_type_id: role_types})
|
37
|
+
.where(entity_party_roles: {party_id: parties})
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
module InstanceMethods
|
42
|
+
def add_party_with_role(party, role_type)
|
43
|
+
entity_party_role = EntityPartyRole.where(party_id: party,
|
44
|
+
role_type_id: role_type,
|
45
|
+
entity_record_id: self.id,
|
46
|
+
entity_record_type: self.class.name).first
|
47
|
+
|
48
|
+
unless entity_party_role
|
49
|
+
entity_party_role = EntityPartyRole.create(party: party,
|
50
|
+
role_type: role_type,
|
51
|
+
entity_record: self)
|
52
|
+
end
|
53
|
+
|
54
|
+
entity_party_role
|
55
|
+
end
|
56
|
+
|
57
|
+
def remove_party_with_role(party, role_type)
|
58
|
+
entity_party_role = EntityPartyRole.where(party_id: party,
|
59
|
+
role_type_id: role_type,
|
60
|
+
entity_record_id: self.id,
|
61
|
+
entity_record_type: self.class.name).first
|
62
|
+
|
63
|
+
if entity_party_role
|
64
|
+
entity_party_role.destroy
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def find_parties_by_role(role_type)
|
69
|
+
if role_type.is_a?(String)
|
70
|
+
role_type = RoleType.iid(role_type)
|
71
|
+
end
|
72
|
+
|
73
|
+
entity_party_roles.where(role_type_id: role_type.id).collect(&:party)
|
74
|
+
end
|
75
|
+
|
76
|
+
def find_party_with_role(role_type)
|
77
|
+
if role_type.is_a?(String)
|
78
|
+
role_type = RoleType.iid(role_type)
|
79
|
+
end
|
80
|
+
|
81
|
+
entity_party_role = entity_party_roles.where(role_type_id: role_type.id).first
|
82
|
+
|
83
|
+
if entity_party_role
|
84
|
+
entity_party_role.party
|
85
|
+
else
|
86
|
+
nil
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
end # HasPartyRoles
|
92
|
+
end # ActiveRecord
|
93
|
+
end # Extensions
|
94
|
+
end # ErpBaseErpSvcs
|
@@ -11,27 +11,89 @@ module ErpBaseErpSvcs
|
|
11
11
|
extend HasTrackedStatus::SingletonMethods
|
12
12
|
include HasTrackedStatus::InstanceMethods
|
13
13
|
|
14
|
-
has_many :status_applications, :as => :status_application_record
|
14
|
+
has_many :status_applications, :as => :status_application_record
|
15
15
|
|
16
|
-
|
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
|
16
|
+
before_destroy :destroy_status_applications
|
28
17
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
18
|
+
scope :with_status, lambda { |status_type_iids|
|
19
|
+
joins(:status_applications => :tracked_status_type).
|
20
|
+
where("status_applications.thru_date IS NULL AND tracked_status_types.internal_identifier IN (?)",
|
21
|
+
status_type_iids)
|
22
|
+
}
|
23
|
+
|
24
|
+
# scope record by its current status application
|
25
|
+
# status_type_iids can either be an Array of status to scope by or a Hash with the parent status
|
26
|
+
# as the key and the children statues to scope by as the value
|
27
|
+
scope :with_current_status, lambda { |status_type_iids=[]|
|
28
|
+
model_table = self.arel_table
|
29
|
+
status_applications_tbl = StatusApplication.arel_table
|
30
|
+
|
31
|
+
#determine status_application_record_type
|
32
|
+
status_application_record_type = (self.superclass == ::ActiveRecord::Base) ? self.name.to_s : self.superclass.to_s
|
33
|
+
|
34
|
+
current_status_select = status_applications_tbl.project(status_applications_tbl[:id].maximum)
|
35
|
+
.where(model_table[:id].eq(status_applications_tbl[:status_application_record_id])
|
36
|
+
.and(status_applications_tbl[:status_application_record_type].eq(status_application_record_type)))
|
37
|
+
|
38
|
+
statement = joins(:status_applications => :tracked_status_type).where(status_applications_tbl[:id].in(current_status_select))
|
39
|
+
|
40
|
+
if status_type_iids
|
41
|
+
status_ids = []
|
42
|
+
|
43
|
+
if status_type_iids.is_a?(Hash)
|
44
|
+
parent_status = TrackedStatusType.iid(status_type_iids.keys.first)
|
45
|
+
status_ids = parent_status.children.where(:internal_identifier => status_type_iids.values.first).pluck(:id)
|
46
|
+
|
47
|
+
elsif status_type_iids.is_a?(Array)
|
48
|
+
unless status_type_iids.empty?
|
49
|
+
status_ids = TrackedStatusType.where(:internal_identifier => status_type_iids).pluck(:id)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
unless status_ids.empty?
|
54
|
+
statement = statement.where(TrackedStatusType.arel_table[:id].in status_ids)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
statement
|
59
|
+
}
|
60
|
+
|
61
|
+
# scope record by its current status application and exclude records with the passed statuses
|
62
|
+
# status_type_iids can either be an Array of status to scope by or a Hash with the parent status
|
63
|
+
# as the key and the children statues to scope by as the value
|
64
|
+
scope :without_current_status, lambda { |status_type_iids=[]|
|
65
|
+
model_table = self.arel_table
|
66
|
+
status_applications_tbl = StatusApplication.arel_table
|
67
|
+
|
68
|
+
#determine status_application_record_type
|
69
|
+
status_application_record_type = (self.superclass == ::ActiveRecord::Base) ? self.name.to_s : self.superclass.to_s
|
70
|
+
|
71
|
+
current_status_select = status_applications_tbl.project(status_applications_tbl[:id].maximum)
|
72
|
+
.where(model_table[:id].eq(status_applications_tbl[:status_application_record_id])
|
73
|
+
.and(status_applications_tbl[:status_application_record_type].eq(status_application_record_type)))
|
74
|
+
|
75
|
+
statement = joins(:status_applications => :tracked_status_type).where(status_applications_tbl[:id].in(current_status_select))
|
76
|
+
|
77
|
+
if status_type_iids
|
78
|
+
status_ids = []
|
79
|
+
|
80
|
+
if status_type_iids.is_a?(Hash)
|
81
|
+
parent_status = TrackedStatusType.iid(status_type_iids.keys.first)
|
82
|
+
status_ids = parent_status.children.where(:internal_identifier => status_type_iids.values.first).pluck(:id)
|
83
|
+
|
84
|
+
elsif status_type_iids.is_a?(Array)
|
85
|
+
unless status_type_iids.empty?
|
86
|
+
status_ids = TrackedStatusType.where(:internal_identifier => status_type_iids).pluck(:id)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
unless status_ids.empty?
|
91
|
+
statement = statement.where(TrackedStatusType.arel_table[:id].not_in status_ids)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
statement
|
96
|
+
}
|
35
97
|
end
|
36
98
|
end
|
37
99
|
|
@@ -40,6 +102,12 @@ module ErpBaseErpSvcs
|
|
40
102
|
|
41
103
|
module InstanceMethods
|
42
104
|
|
105
|
+
def destroy_status_applications
|
106
|
+
self.status_applications.each do |status_application|
|
107
|
+
status_application.destroy
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
43
111
|
# does this status match the current_status?
|
44
112
|
def has_status?(tracked_status_iid)
|
45
113
|
current_status == tracked_status_iid
|
@@ -93,37 +161,52 @@ module ErpBaseErpSvcs
|
|
93
161
|
self.current_status_type.internal_identifier unless self.current_status_type.nil?
|
94
162
|
end
|
95
163
|
|
96
|
-
#set current status of entity.
|
97
|
-
#
|
98
|
-
#
|
99
|
-
#
|
100
|
-
#it will set the thru_date on the current StatusApplication to now
|
164
|
+
# set current status of entity.
|
165
|
+
#
|
166
|
+
# @param args [String, TrackedStatusType, Array] This can be a string of the internal identifier of the
|
167
|
+
# TrackedStatusType to set, a TrackedStatusType instance, or three params the status, options and party_id
|
101
168
|
def current_status=(args)
|
102
169
|
options = {}
|
103
170
|
|
104
171
|
if args.is_a?(Array)
|
105
172
|
status = args[0]
|
106
173
|
options = args[1]
|
174
|
+
party_id = args[2]
|
107
175
|
else
|
108
176
|
status = args
|
109
177
|
end
|
178
|
+
|
110
179
|
tracked_status_type = status.is_a?(TrackedStatusType) ? status : TrackedStatusType.find_by_internal_identifier(status.to_s)
|
111
180
|
raise "TrackedStatusType does not exist #{status.to_s}" unless tracked_status_type
|
112
181
|
|
113
|
-
#
|
114
|
-
|
115
|
-
|
116
|
-
cta
|
117
|
-
cta.
|
182
|
+
# if passed status is current status then do nothing
|
183
|
+
unless self.current_status_type && (self.current_status_type.id == tracked_status_type.id)
|
184
|
+
#set current StatusApplication thru_date to now
|
185
|
+
cta = self.current_status_application
|
186
|
+
unless cta.nil?
|
187
|
+
cta.thru_date = options[:thru_date].nil? ? Time.now : options[:thru_date]
|
188
|
+
cta.save
|
189
|
+
end
|
190
|
+
|
191
|
+
status_application = StatusApplication.new
|
192
|
+
status_application.tracked_status_type = tracked_status_type
|
193
|
+
status_application.from_date = options[:from_date].nil? ? Time.now : options[:from_date]
|
194
|
+
status_application.party_id = party_id
|
195
|
+
status_application.save
|
196
|
+
|
197
|
+
self.status_applications << status_application
|
198
|
+
self.save
|
118
199
|
end
|
119
200
|
|
120
|
-
|
121
|
-
status_application.tracked_status_type = tracked_status_type
|
122
|
-
status_application.from_date = options[:from_date].nil? ? Time.now : options[:from_date]
|
123
|
-
status_application.save
|
201
|
+
end
|
124
202
|
|
125
|
-
|
126
|
-
self.
|
203
|
+
def previous_status
|
204
|
+
result = self.status_applications.joins(:tracked_status_type).order("status_applications.id desc").limit(2).all
|
205
|
+
if result.count == 2
|
206
|
+
result[1].tracked_status_type.internal_identifier
|
207
|
+
else
|
208
|
+
nil
|
209
|
+
end
|
127
210
|
end
|
128
211
|
|
129
212
|
# add_status aliases current_status= for legacy support
|
@@ -0,0 +1,94 @@
|
|
1
|
+
module ErpBaseErpSvcs
|
2
|
+
module Extensions
|
3
|
+
module ActiveRecord
|
4
|
+
module IsContactMechanism
|
5
|
+
def self.included(base)
|
6
|
+
base.extend(ClassMethods)
|
7
|
+
end
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
def is_contact_mechanism
|
11
|
+
extend IsContactMechanism::SingletonMethods
|
12
|
+
include IsContactMechanism::InstanceMethods
|
13
|
+
|
14
|
+
after_initialize :initialize_contact
|
15
|
+
after_create :save_contact
|
16
|
+
after_update :save_contact
|
17
|
+
after_destroy :destroy_contact
|
18
|
+
|
19
|
+
has_one :contact, :as => :contact_mechanism, :dependent => :destroy
|
20
|
+
|
21
|
+
[:purpose,
|
22
|
+
:purposes,
|
23
|
+
:is_primary,
|
24
|
+
:is_primary=,
|
25
|
+
:is_primary?].each { |m| delegate m, :to => :contact }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
module SingletonMethods
|
30
|
+
# return all contact mechanism instances for parties
|
31
|
+
#
|
32
|
+
# @param parties [Array] Array of parties to get contacts for
|
33
|
+
# @param contact_purposes [Array] Array of ContactPurposes to look up
|
34
|
+
def for_parties(parties, contact_purposes=[])
|
35
|
+
query = self.joins(contact: [:contact_purposes])
|
36
|
+
|
37
|
+
unless contact_purposes.empty?
|
38
|
+
query = query.where(contact_purposes: {id: contact_purposes})
|
39
|
+
end
|
40
|
+
|
41
|
+
query.where(contacts: {contact_record_type: 'Party', contact_record_id: parties})
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
module InstanceMethods
|
46
|
+
|
47
|
+
def save_contact
|
48
|
+
self.contact.save
|
49
|
+
end
|
50
|
+
|
51
|
+
# return all contact purposes in one comma separated string
|
52
|
+
def contact_purposes_to_s
|
53
|
+
contact.contact_purposes.collect(&:description).join(', ')
|
54
|
+
end
|
55
|
+
|
56
|
+
def add_contact_purpose(contact_purpose)
|
57
|
+
unless contact_purpose.is_a?(ContactPurpose)
|
58
|
+
contact_purpose = ContactPurpose.iid(contact_purpose)
|
59
|
+
end
|
60
|
+
|
61
|
+
# don't add the contact purpose if its already there
|
62
|
+
unless contact_purpose_iids.include?(contact_purpose.internal_identifier)
|
63
|
+
contact.contact_purposes << contact_purpose
|
64
|
+
contact.save
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
# return all contact purpose iids in one comma separated string
|
69
|
+
def contact_purpose_iids
|
70
|
+
contact.contact_purposes.collect(&:internal_identifier).join(',')
|
71
|
+
end
|
72
|
+
|
73
|
+
# return all contact purposes
|
74
|
+
def contact_purposes
|
75
|
+
contact.contact_purposes
|
76
|
+
end
|
77
|
+
|
78
|
+
def destroy_contact
|
79
|
+
self.contact.destroy unless self.contact.nil?
|
80
|
+
end
|
81
|
+
|
82
|
+
def initialize_contact
|
83
|
+
if self.new_record? and self.contact.nil?
|
84
|
+
self.contact = Contact.new
|
85
|
+
self.contact.description = self.description
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
end #HasContact
|
92
|
+
end #ActiveRecord
|
93
|
+
end #Extensions
|
94
|
+
end #ErpBaseErpSvcs
|
@@ -1,44 +1,48 @@
|
|
1
1
|
module ErpBaseErpSvcs
|
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
|
-
|
2
|
+
module Extensions
|
3
|
+
module ActiveRecord
|
4
|
+
module IsDescribable
|
5
|
+
|
6
|
+
def self.included(base)
|
7
|
+
base.extend(ClassMethods)
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
|
12
|
+
def is_describable
|
13
|
+
has_many :descriptions, :class_name => 'DescriptiveAsset', :as => :described_record, :dependent => :destroy
|
14
|
+
|
15
|
+
extend IsDescribable::SingletonMethods
|
16
|
+
include IsDescribable::InstanceMethods
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
module SingletonMethods
|
22
|
+
end
|
23
|
+
|
24
|
+
module InstanceMethods
|
25
|
+
def find_descriptions_by_view_type(view_iid)
|
26
|
+
self.descriptions.where('view_type_id = ?', ViewType.find_by_internal_identifier(view_iid).id).collect(&:description).join(' ')
|
27
|
+
end
|
28
|
+
|
29
|
+
def find_description_by_iid(iid)
|
30
|
+
self.descriptions.where('internal_identifier = ?', iid).first
|
31
|
+
end
|
32
|
+
|
33
|
+
def find_description_by_view_type(view_iid)
|
34
|
+
self.descriptions.where('view_type_id = ?', ViewType.find_by_internal_identifier(view_iid).id).first
|
35
|
+
end
|
36
|
+
|
37
|
+
def add_description(view_type, description)
|
38
|
+
descriptive_asset = DescriptiveAsset.create(
|
39
|
+
:view_type => view_type,
|
40
|
+
:description => description)
|
41
|
+
descriptive_asset.described_record = self
|
42
|
+
self.descriptions << descriptive_asset
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
44
48
|
end
|