Class: MOCO::Offer
- Inherits:
-
BaseEntity
- Object
- BaseEntity
- MOCO::Offer
- Defined in:
- lib/moco/entities/offer.rb
Overview
Represents a MOCO offer/quote
Required attributes for create:
recipient_address - String, full address (use \r\n for line breaks)
date - String, "YYYY-MM-DD" offer date
due_date - String, "YYYY-MM-DD" valid until date
title - String, offer title (e.g., "Offer - Website Relaunch")
tax - Float, tax rate percentage (e.g., 19.0)
items - Array of Hashes, offer line items (see below)
Item types (for items array):
{ type: "title", title: "Section Title" }
{ type: "description", description: "Description text" }
{ type: "item", title: "Service", quantity: 10, unit: "h", unit_price: 150.0 }
{ type: "item", title: "Fixed Fee", net_total: 500.0 } # lump sum
{ type: "subtotal" }
{ type: "separator" }
{ type: "page-break" }
Optional attributes:
company_id - Integer, customer company ID (set from project if project_id provided)
deal_id - Integer, associated deal ID
project_id - Integer, associated project ID
currency - String, 3-letter code (required if no company/deal/project)
salutation - String, greeting text
footer - String, footer text
discount - Float, discount percentage
contact_id - Integer, customer contact ID
change_address - String, "offer" or "customer"
tags - Array of Strings
Read-only attributes:
id, identifier, status, net_total, gross_total, created_at, updated_at
Example:
moco.offers.create(
deal_id: 123456,
recipient_address: "Acme Corp\r\n123 Main St",
date: "2024-01-15",
due_date: "2024-02-15",
title: "Offer - Website Relaunch",
tax: 19.0,
items: [
{ type: "title", title: "Development Services" },
{ type: "item", title: "Frontend Development", quantity: 40, unit: "h", unit_price: 150.0 },
{ type: "item", title: "Backend Development", quantity: 60, unit: "h", unit_price: 150.0 }
]
)
Instance Attribute Summary
Attributes inherited from BaseEntity
Instance Method Summary collapse
-
#assign(company_id: nil, project_id: nil, deal_id: nil) ⇒ Object
Assign offer to company, project, and/or deal.
-
#attachments ⇒ Object
Fetches attachments for this offer as a NestedCollectionProxy.
-
#company ⇒ Object
Associations.
- #deal ⇒ Object
-
#pdf ⇒ Object
Get the offer as PDF.
- #project ⇒ Object
-
#send_email(recipient:, subject:, text:, **options) ⇒ Object
Send the offer via email.
- #to_s ⇒ Object
-
#update_status(status) ⇒ Object
Update the offer status.
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
Instance Method Details
#assign(company_id: nil, project_id: nil, deal_id: nil) ⇒ Object
Assign offer to company, project, and/or deal
78 79 80 81 82 83 84 85 86 |
# File 'lib/moco/entities/offer.rb', line 78 def assign(company_id: nil, project_id: nil, deal_id: nil) payload = {} payload[:company_id] = company_id if company_id payload[:project_id] = project_id if project_id payload[:deal_id] = deal_id if deal_id client.put("offers/#{id}/assign", payload) reload end |
#attachments ⇒ Object
Fetches attachments for this offer as a NestedCollectionProxy. Supports .all, .find(id), .create(attachment: { filename:, base64: }), and .destroy.
90 91 92 |
# File 'lib/moco/entities/offer.rb', line 90 def MOCO::NestedCollectionProxy.new(client, self, :attachments, "OfferAttachment") end |
#company ⇒ Object
Associations
95 96 97 |
# File 'lib/moco/entities/offer.rb', line 95 def company association(:customer, "Company") end |
#deal ⇒ Object
103 104 105 |
# File 'lib/moco/entities/offer.rb', line 103 def deal association(:deal) end |
#pdf ⇒ Object
Get the offer as PDF
61 62 63 |
# File 'lib/moco/entities/offer.rb', line 61 def pdf client.get("offers/#{id}.pdf") end |
#project ⇒ Object
99 100 101 |
# File 'lib/moco/entities/offer.rb', line 99 def project association(:project) end |
#send_email(recipient:, subject:, text:, **options) ⇒ Object
Send the offer via email
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/moco/entities/offer.rb', line 66 def send_email(recipient:, subject:, text:, **) payload = { recipient:, subject:, text: }.merge() client.post("offers/#{id}/send_email", payload) self end |
#to_s ⇒ Object
107 108 109 |
# File 'lib/moco/entities/offer.rb', line 107 def to_s "#{identifier} - #{title}" end |
#update_status(status) ⇒ Object
Update the offer status
55 56 57 58 |
# File 'lib/moco/entities/offer.rb', line 55 def update_status(status) client.put("offers/#{id}/update_status", { status: }) self end |