Class: Multiwoven::Integrations::Destination::Odoo::Client

Inherits:
DestinationConnector
  • Object
show all
Defined in:
lib/multiwoven/integrations/destination/odoo/client.rb

Instance Method Summary collapse

Instance Method Details

#check_connection(connection_config) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/multiwoven/integrations/destination/odoo/client.rb', line 7

def check_connection(connection_config)
  connection_config = connection_config.with_indifferent_access
  create_connection(connection_config)
  success_status
rescue StandardError => e
  failure_status(e)
end

#discover(connection_config) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/multiwoven/integrations/destination/odoo/client.rb', line 15

def discover(connection_config)
  connection_config = connection_config.with_indifferent_access
  create_connection(connection_config)
  models = @client.execute_kw(connection_config[:database], @uid, connection_config[:password],
                              "ir.model", "search_read", [[["transient", "=", false]]], { 'fields': %w[name model] })
  catalog = Catalog.new(streams: create_streams(connection_config, models))
  catalog.to_multiwoven_message
rescue StandardError => e
  handle_exception(e, {
                     context: "ODOO:DISCOVER:EXCEPTION",
                     type: "error"
                   })
end

#write(sync_config, records, _action = "destination_insert") ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/multiwoven/integrations/destination/odoo/client.rb', line 29

def write(sync_config, records, _action = "destination_insert")
  connection_config = sync_config.destination.connection_specification.with_indifferent_access
  create_connection(connection_config)
  model = sync_config.stream.name

  write_success = 0
  write_failure = 0
  log_message_array = []

  records.each do |record|
    logger.debug("ODOO:WRITE:#{model} sync_id = #{sync_config.sync_id} sync_run_id = #{sync_config.sync_run_id}")
    begin
      record = format_record(record, sync_config.stream.json_schema)
      response = @client.execute_kw(connection_config[:database], @uid, connection_config[:password],
                                    model, "create", [record])
      write_success += 1
      log_message_array << log_request_response("info", model, response)
    rescue StandardError => e
      handle_exception(e, {
                         context: "ODOO:WRITE:#{model}",
                         type: "error",
                         sync_id: sync_config.sync_id,
                         sync_run_id: sync_config.sync_run_id
                       })
      write_failure += 1
      log_message_array << log_request_response("error", model, e.message)
    end
  end
  tracking_message(write_success, write_failure, log_message_array)
rescue StandardError => e
  handle_exception(e, {
                     context: "ODOO:WRITE:EXCEPTION",
                     type: "error",
                     sync_id: sync_config.sync_id,
                     sync_run_id: sync_config.sync_run_id
                   })
end