Class: ErpIntegration::Fulfil::Resources::SalesOrderLine

Inherits:
ApiResource
  • Object
show all
Defined in:
lib/erp_integration/fulfil/resources/sales_order_line.rb

Constant Summary

Constants included from PaginationMethods

PaginationMethods::DEFAULT_LIMIT, PaginationMethods::DEFAULT_OFFSET, PaginationMethods::MAX_LIMIT

Instance Attribute Summary

Attributes inherited from ApiResource

#resource_klass

Attributes included from QueryMethods

#or_clauses, #selected_fields, #where_clauses

Attributes included from PaginationMethods

#limit_value, #offset_value, #page_number

Instance Method Summary collapse

Methods inherited from ApiResource

#all, client, config, #count, #each, #find_each, #initialize, model_name, model_name=

Methods included from QueryMethods

#or, #or!, #select, #select!, #where, #where!, #where_domain, #where_ilike, #where_in, #where_less_or_equal_to, #where_less_than, #where_like, #where_more_or_equal_to, #where_more_than, #where_not, #where_not_in

Methods included from Persistence

#create, #destroy, #update

Methods included from PaginationMethods

#limit, #limit!, #offset, #offset!, #page, #page!

Methods included from FinderMethods

#find, #find_by, #find_by!

Methods included from Context

#context?, #with_context

Constructor Details

This class inherits a constructor from ErpIntegration::Fulfil::ApiResource

Instance Method Details

#adjust_quantity(sales_channel, channel_identifier, sku, quantity, quantity_canceled) ⇒ boolean

Updates the sales order line quantity of canceled and non canceled items

Parameters:

  • sales_channel (Integer)

    Sales channel id

  • channel_identifier (String)
  • sku (String)
  • quantity (Integer)

    The total quantity (canceled + not canceled) Should be more or equal than quantity_canceled but the above criteria is suggested

  • quantity_canceled (Integer)

    the total quantity of canceled items (including new ones)

Returns:

  • (boolean)

    Whether the sales order line was changed successfully or not.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/erp_integration/fulfil/resources/sales_order_line.rb', line 33

def adjust_quantity(sales_channel, channel_identifier,
                    sku, quantity, quantity_canceled)
  options = [{
    "channel_identifier": channel_identifier,
    "sale_lines":
      [{
        "sku": sku,
        "quantity": quantity,
        "quantity_canceled": quantity_canceled
      }]
  }]
  client.put("model/sale.channel/#{sales_channel}/create_order", options)
  true
rescue ErpIntegration::HttpError::BadRequest
  false
end

#cancel(id) ⇒ boolean

Allows cancelling the entire sales order line in Fulfil.

Parameters:

  • id (Integer|String)

    The ID of the to be cancelled order line.

Returns:

  • (boolean)

    Whether the sales order line was cancelled successfully or not.



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/erp_integration/fulfil/resources/sales_order_line.rb', line 13

def cancel(id)
  client.put("model/sale.line/#{id}/cancel")
  true
rescue ErpIntegration::HttpError::BadRequest
  false
# Workaround: Fulfil api does not return a json when status code is 200 (a.k.a. "Ok")
# and faraday is having an error when trying to parse it. Let's skip the parse error
# and move on.
rescue Faraday::ParsingError
  true
end