Class: MOCO::Expense
- Inherits:
-
BaseEntity
- Object
- BaseEntity
- MOCO::Expense
- Defined in:
- lib/moco/entities/expense.rb
Overview
Represents a MOCO project expense (additional service) Expenses are typically accessed via project: project.expenses.create(...)
Required attributes for create:
date - String, "YYYY-MM-DD" expense date
title - String, expense title (e.g., "Hosting XS")
quantity - Float/Integer, quantity (e.g., 3)
unit - String, unit label (e.g., "months", "pieces", "hours")
unit_price - Float, price per unit charged to customer
unit_cost - Float, cost per unit (your cost)
Optional attributes:
description - String, detailed description
billable - Boolean, whether expense is billable (default: true)
budget_relevant - Boolean, whether counts toward budget (default: false)
service_period_from - String, "YYYY-MM-DD" service period start
service_period_to - String, "YYYY-MM-DD" service period end
user_id - Integer, responsible user ID (default: current user)
custom_properties - Hash, e.g., {"Type": "Infrastructure"}
file - Hash, { filename: "receipt.pdf", base64: "..." }
Read-only attributes:
id, price, cost, currency, billed, invoice_id, project (Hash),
company (Hash), created_at, updated_at
Example:
project = moco.projects.find(123)
project.expenses.create(
date: "2024-01-15",
title: "Cloud Hosting",
quantity: 1,
unit: "month",
unit_price: 99.0,
unit_cost: 49.0,
billable: true
)
Instance Attribute Summary
Attributes inherited from BaseEntity
Class Method Summary collapse
- .bulk_create(client, project_id, expenses) ⇒ Object
-
.disregard(client, expense_ids:) ⇒ Object
Class methods for bulk operations.
-
.entity_path ⇒ Object
Override entity_path to use the global expenses endpoint Note: Expenses can also be accessed via projects/BaseEntity#id/expenses.
Instance Method Summary collapse
-
#project ⇒ Object
Associations.
- #to_s ⇒ Object
- #user ⇒ Object
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
53 54 55 |
# File 'lib/moco/entities/expense.rb', line 53 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
49 50 51 |
# File 'lib/moco/entities/expense.rb', line 49 def self.disregard(client, expense_ids:) client.post("projects/expenses/disregard", { expense_ids: }) end |
.entity_path ⇒ Object
Override entity_path to use the global expenses endpoint Note: Expenses can also be accessed via projects/BaseEntity#id/expenses
44 45 46 |
# File 'lib/moco/entities/expense.rb', line 44 def self.entity_path "projects/expenses" end |
Instance Method Details
#project ⇒ Object
Associations
58 59 60 61 |
# File 'lib/moco/entities/expense.rb', line 58 def project # Use the association method which handles embedded objects association(:project, "Project") end |
#to_s ⇒ Object
68 69 70 |
# File 'lib/moco/entities/expense.rb', line 68 def to_s "#{date} - #{title} (#{amount})" end |
#user ⇒ Object
63 64 65 66 |
# File 'lib/moco/entities/expense.rb', line 63 def user # Use the association method which handles embedded objects association(:user, "User") end |