Module: ErpBaseErpSvcs::Extensions::ActiveRecord::HasNotes::InstanceMethods

Defined in:
lib/erp_base_erp_svcs/extensions/active_record/has_notes.rb

Instance Method Summary collapse

Instance Method Details

#add_note(note_type_iid, content, party = nil) ⇒ Object

adds note to model



31
32
33
34
35
36
37
38
# File 'lib/erp_base_erp_svcs/extensions/active_record/has_notes.rb', line 31

def add_note(note_type_iid, content, party=nil)
  note = Note.new
  note.note_type = NoteType.iid(note_type_iid)
  note.noted_record = self
  note.created_by = party unless party.nil?
  note.content = content
  note if note.save
end

#create_or_update_note_by_type(note_type_iid = 'basic_note', content = '', party = nil) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/erp_base_erp_svcs/extensions/active_record/has_notes.rb', line 40

def create_or_update_note_by_type(note_type_iid='basic_note', content='', party=nil)
  note = note_by_type(note_type_iid)
  if note.nil?
    note = Note.new if note.nil?
    note.note_type_id = NoteType.find_by_internal_identifier(note_type_iid).id
    note.noted_record = self
    note.created_by_id = party unless party.nil?
  end
  note.content = content
  note.save
end

#note_by_type(note_type_iid) ⇒ Object



52
53
54
55
# File 'lib/erp_base_erp_svcs/extensions/active_record/has_notes.rb', line 52

def note_by_type(note_type_iid)
  note_type = NoteType.find_by_internal_identifier(note_type_iid)
  notes.where(:note_type_id => note_type.id).first
end

#notes_by_type(note_type_iid) ⇒ Object



57
58
59
60
# File 'lib/erp_base_erp_svcs/extensions/active_record/has_notes.rb', line 57

def notes_by_type(note_type_iid)
  note_type = NoteType.find_by_internal_identifier(note_type_iid)
  notes.where(:note_type_id => note_type.id)
end