Class: Cin7API::CreditNoteResource
- Defined in:
- lib/cin7_api/resources/credit_note_resource.rb
Instance Attribute Summary
Attributes inherited from Resource
Instance Method Summary collapse
-
#create(attributes_array) ⇒ Object
attributes_array = [ { branchId: 3, salesReference: “HBP1030”, lineItems: [ { code: “5-PAIRS-SOCKS”, styleCode: “5-PAIRS-SOCKS”, sizeCodes: nil, name: “5PAIRS SOCKS - ONE SIZE”, option1: “ONE SIZE”, option2: “”, option3: nil, qty: 1, unitPrice: 0 }, ], } ] @client.credit_note.create(attributes_array).
-
#find(id) ⇒ Object
@client.credit_note.find(2223).
-
#find_by(**params) ⇒ Object
@client.credit_note.find_by(sales_reference: “#1050”, email: “[email protected]”).
-
#update(attributes_array) ⇒ Object
attributes_array = [ { id: 2223, lineItems: [{ id: 8142, unitPrice: 10 }, 8143, unitPrice: 10], completedDate: “2022-09-10T09:00:00Z”, creditNoteDate: “2022-09-10T09:00:00Z”, } ] @client.credit_note.update(attributes_array).
-
#where(**params) ⇒ Object
@client.credit_note.where(sales_reference: “#1050”, email: “[email protected]”).
Methods inherited from Resource
#get_request, #handle_response, #initialize, #post_request, #put_request
Constructor Details
This class inherits a constructor from Cin7API::Resource
Instance Method Details
#create(attributes_array) ⇒ Object
attributes_array = [
{
branchId: 3,
salesReference: "HBP1030",
lineItems: [
{
code: "5-PAIRS-SOCKS",
styleCode: "5-PAIRS-SOCKS",
sizeCodes: nil,
name: "5PAIRS SOCKS - ONE SIZE",
option1: "ONE SIZE",
option2: "",
option3: nil,
qty: 1,
unitPrice: 0
},
],
}
] @client.credit_note.create(attributes_array)
59 60 61 62 |
# File 'lib/cin7_api/resources/credit_note_resource.rb', line 59 def create(attributes_array) responses = post_request("CreditNotes", body: attributes_array).body responses.map { |attributes| Response.new(attributes) } end |
#find(id) ⇒ Object
@client.credit_note.find(2223)
21 22 23 |
# File 'lib/cin7_api/resources/credit_note_resource.rb', line 21 def find(id) CreditNote.new(get_request("CreditNotes/#{id}").body) end |
#find_by(**params) ⇒ Object
@client.credit_note.find_by(sales_reference: “#1050”, email: “[email protected]”)
16 17 18 |
# File 'lib/cin7_api/resources/credit_note_resource.rb', line 16 def find_by(**params) where(**params).first end |
#update(attributes_array) ⇒ Object
attributes_array = [
{
id: 2223,
lineItems: [{ id: 8142, unitPrice: 10 }, {id: 8143, unitPrice: 10}],
completedDate: "2022-09-10T09:00:00Z",
creditNoteDate: "2022-09-10T09:00:00Z",
}
] @client.credit_note.update(attributes_array)
34 35 36 37 |
# File 'lib/cin7_api/resources/credit_note_resource.rb', line 34 def update(attributes_array) responses = put_request("CreditNotes", body: attributes_array).body responses.map { |attributes| Response.new(attributes) } end |
#where(**params) ⇒ Object
@client.credit_note.where(sales_reference: “#1050”, email: “[email protected]”)
6 7 8 9 10 11 12 13 |
# File 'lib/cin7_api/resources/credit_note_resource.rb', line 6 def where(**params) response_body = get_request("CreditNotes", params: params).body credit_notes = response_body.map { |attributes| CreditNote.new(attributes) } # Doing a filter here because Cin7 is doing a binary OR check for the filter params credit_notes.filter do |credit_note| params.reduce(true) { |acc, (key, value)| acc && credit_note[key] == value } end end |