Class: MOCO::Expense

Inherits:
BaseEntity show all
Defined in:
lib/moco/entities/expense.rb

Overview

Represents a MOCO expense Provides methods for expense-specific operations and associations

Instance Attribute Summary

Attributes inherited from BaseEntity

#attributes, #client

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseEntity

#==, #association, #destroy, #eql?, #has_many, #hash, #id, #initialize, #inspect, #reload, #save, #to_h, #to_json, #update

Constructor Details

This class inherits a constructor from MOCO::BaseEntity

Class Method Details

.bulk_create(client, project_id, expenses) ⇒ Object



18
19
20
# File 'lib/moco/entities/expense.rb', line 18

def self.bulk_create(client, project_id, expenses)
  client.post("projects/#{project_id}/expenses/bulk", { expenses: })
end

.disregard(client, expense_ids:) ⇒ Object

Class methods for bulk operations



14
15
16
# File 'lib/moco/entities/expense.rb', line 14

def self.disregard(client, expense_ids:)
  client.post("projects/expenses/disregard", { expense_ids: })
end

.entity_pathObject

Override entity_path to use the global expenses endpoint Note: Expenses can also be accessed via projects/BaseEntity#id/expenses



9
10
11
# File 'lib/moco/entities/expense.rb', line 9

def self.entity_path
  "projects/expenses"
end

Instance Method Details

#projectObject

Associations



23
24
25
26
# File 'lib/moco/entities/expense.rb', line 23

def project
  # Use the association method which handles embedded objects
  association(:project, "Project")
end

#to_sObject



33
34
35
# File 'lib/moco/entities/expense.rb', line 33

def to_s
  "#{date} - #{title} (#{amount})"
end

#userObject



28
29
30
31
# File 'lib/moco/entities/expense.rb', line 28

def user
  # Use the association method which handles embedded objects
  association(:user, "User")
end