Class: Dolibarr::Thirdparties

Inherits:
Resource
  • Object
show all
Defined in:
lib/dolibarr/thirdparties.rb

Overview

Thirdparties (customers/suppliers): list and fetch. Reads go through the raw connection (type: nil) so the payload survives the transport's placeholder model.

Constant Summary collapse

MODE_CODES =

Business-readable #list mode values → Dolibarr's integer mode filter. Dolibarr expects an integer (api_thirdparties.class.php@23.0.3): 1=customers, 2=prospects, 4=suppliers. Codes 0 (all) and 3 (neither customer nor prospect) have no business use here and are intentionally not exposed. Sending the raw label instead of the code makes Dolibarr answer HTTP 400.

{ 'customer' => 1, 'prospect' => 2, 'supplier' => 4 }.freeze

Instance Method Summary collapse

Methods inherited from Resource

#initialize

Constructor Details

This class inherits a constructor from Dolibarr::Resource

Instance Method Details

#all(**filters) ⇒ Array<Thirdparty>

Returns:



42
43
44
# File 'lib/dolibarr/thirdparties.rb', line 42

def all(**filters)
  each(**filters).to_a
end

#each(limit: 100, **filters, &block) ⇒ Object

Every matching thirdparty, paginating transparently. Enumerator when no block.



36
37
38
39
# File 'lib/dolibarr/thirdparties.rb', line 36

def each(limit: 100, **filters, &block)
  enum = paginate(limit: limit) { |page, lim| list(page: page, limit: lim, **filters) }
  block ? enum.each(&block) : enum
end

#find(id:) ⇒ Thirdparty

Fetch a single thirdparty by id.

Parameters:

  • id (Integer, String)

Returns:

Raises:



51
52
53
# File 'lib/dolibarr/thirdparties.rb', line 51

def find(id:)
  Thirdparty.from(get_one("/thirdparties/#{encode(id)}", "thirdparty #{id}"))
end

#list(mode: nil, category: nil, sqlfilters: nil, limit: 100, page: 0, sortfield: 't.rowid', sortorder: 'ASC') ⇒ Array<Thirdparty>

One page of thirdparties as Dolibarr::Thirdparty value objects.

Parameters:

  • mode (String, Symbol, nil) (defaults to: nil)

    "customer"/"prospect"/"supplier" (translated to Dolibarr's integer mode filter)

  • category (Integer, String, nil) (defaults to: nil)

    restrict to a category id

  • sqlfilters (String, nil) (defaults to: nil)

    raw Restler sqlfilter

  • limit (Integer) (defaults to: 100)

    page size

  • page (Integer) (defaults to: 0)

    0-based page index

  • sortfield (String) (defaults to: 't.rowid')
  • sortorder (String) (defaults to: 'ASC')

Returns:



25
26
27
28
29
30
31
32
33
# File 'lib/dolibarr/thirdparties.rb', line 25

def list(mode: nil, category: nil, sqlfilters: nil,
         limit: 100, page: 0, sortfield: 't.rowid', sortorder: 'ASC')
  get_list(
    '/thirdparties',
    'sortfield' => sortfield, 'sortorder' => sortorder,
    'limit' => limit, 'page' => page,
    'mode' => mode_code(mode), 'category' => category, 'sqlfilters' => sqlfilters
  ).map { |raw| Thirdparty.from(raw) }
end