crisalid_odoo_client 1.2.4 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b1e621d494600cfce376de0c40f6ef4c61ec75c79c119d43d8c69d71553b9594
4
- data.tar.gz: a068e59d3d471bc9219ea0796ff97b05967bd7dd82a5552ef985cfc0cb33b812
3
+ metadata.gz: a11e7e20f6125bcfb423db4351cfce82516b0997bba126b7818909007876561e
4
+ data.tar.gz: 43fe6da037eabb663d9fea8d857e23ddd796181d49cb028906dafc0e717757b2
5
5
  SHA512:
6
- metadata.gz: d0633234c6fe8c7082128551cf8b15da6439e12d93047404047ca52007b38f71b2edd807432f61be49b0ac62cf8cde793ad245687990fdb3a655a11d44cf0808
7
- data.tar.gz: 82126cdaadd810d3b8902c820f175d3ce717b3f7a366b7cdc8eeb6e79a68ee0136812781e11ce8905f23227c9003bae54c5b654e3362623df7351991519ede12
6
+ metadata.gz: ff052c4590d037d1a946dbfb37b996996cfe3451194037918417869522c31595bd9a1938b2f751dce793373f4ec13686672810f40772136571ac2bd8242344bd
7
+ data.tar.gz: ae5b27363c9a04c81f85dff54e5447346568c7996687fc37462356e9cd7e3c4b43823e027feef3ce988664da985a9aa4b6fd24e2504bc4bc4278ab880cfd743f
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- crisalid_odoo_client (1.2.4)
4
+ crisalid_odoo_client (2.0.0)
5
5
  xmlrpc (~> 0.3.0)
6
6
 
7
7
  GEM
@@ -1,19 +1,18 @@
1
1
  module CrisalidOdooClient
2
2
  class Client
3
- DEFAULT_TIMEOUT = 60
4
-
5
3
  require 'xmlrpc/client'
6
4
 
5
+ DEFAULT_TIMEOUT = 60
6
+
7
7
  attr_reader :odoo_url
8
8
  attr_reader :odoo_db
9
9
  attr_reader :odoo_user
10
10
  attr_reader :odoo_pass
11
11
 
12
- attr_reader :models
13
- attr_reader :uid
12
+ attr_reader :timeout
14
13
 
15
- def initialize(odoo_url:, odoo_db:, odoo_user:, odoo_pass:, odoo_uid: nil)
16
- @odoo_url, @odoo_db = odoo_url, odoo_db
14
+ def initialize(odoo_url:, odoo_db:, odoo_user:, odoo_pass:, odoo_uid: nil, timeout: DEFAULT_TIMEOUT)
15
+ @odoo_url, @odoo_db, @timeout = odoo_url, odoo_db, timeout
17
16
 
18
17
  if @uid.nil?
19
18
  @odoo_user, @odoo_pass = odoo_user, odoo_pass
@@ -21,86 +20,43 @@ module CrisalidOdooClient
21
20
  end
22
21
 
23
22
  if @uid != false
24
- @models = XMLRPC::Client.new2("#{@odoo_url}/xmlrpc/2/object", nil, DEFAULT_TIMEOUT).proxy
23
+ @models = XMLRPC::Client.new2("#{@odoo_url}/xmlrpc/2/object", nil, @timeout).proxy
24
+ @query ||= CrisalidOdooClient::Query.new(self)
25
25
  # Client connected
26
26
  else
27
27
  # Client not connected
28
28
  end
29
29
  end
30
30
 
31
- def table_schema(table, attributes: [])
32
- @models.execute_kw(@odoo_db, @uid, @odoo_pass, table, 'fields_get', [], {attributes: attributes})
33
- end
34
-
35
- def search(table, rules: [[]], params: {})
36
- @models.execute_kw(@odoo_db, @uid, @odoo_pass, table, 'search', rules, params)
31
+ def uid
32
+ @uid
37
33
  end
38
34
 
39
- def search_read(table, rules: [[]], params: {}, fields: [])
40
- params[:fields] = fields if fields.size > 0
41
-
42
- @models.execute_kw(@odoo_db, @uid, @odoo_pass, table, 'search_read', rules, params)
35
+ def models
36
+ @models
43
37
  end
44
38
 
45
- def find(table, ids = [], params: {}, fields: [], first: false)
46
- params[:limit] = 1 if first
47
- params[:fields] = fields if fields.size > 0
48
-
49
- @models.execute_kw(@odoo_db, @uid, @odoo_pass, table, 'read', [ids], params)
39
+ def query
40
+ @query
50
41
  end
51
42
 
52
- def where(table, rules: [[]], params: {}, fields: [], first: false)
53
- params[:limit] = 1 if first
54
- params[:fields] = fields if fields.size > 0
55
-
56
- search_read(table, rules: rules, params: params)
43
+ def product
44
+ @product ||= CrisalidOdooClient::Resource::Product.new(self)
57
45
  end
58
46
 
59
- def create(table, params)
60
- if params.is_a?(Hash) && params.size > 0
61
- @models.execute_kw(@odoo_db, @uid, @odoo_pass, table, 'create', [params])
62
- else
63
- raise CrisalidOdooClient::Error::OdooResourceManagerError.new('params must be a non empty Hash')
64
- end
65
- end
66
-
67
- def create_in_batch(table, headers, params)
68
- if headers.is_a?(Array) && headers.size > 0
69
- if params.is_a?(Array) && params.size > 0 && params.first.is_a?(Array) && params.first.size == headers.size
70
- @models.execute_kw(@odoo_db, @uid, @odoo_pass, table, 'load', [headers, params])["ids"]
71
- else
72
- raise CrisalidOdooClient::Error::OdooResourceManagerError.new('params must be a non empty Array of Array who has the same size as headers')
73
- end
74
- else
75
- raise CrisalidOdooClient::Error::OdooResourceManagerError.new('headers must be a non empty Array')
76
- end
77
- end
78
-
79
- def update(table, ids, params)
80
- if params.is_a?(Hash) && params.size > 0 && ids.is_a?(Array) && ids.size > 0
81
- @models.execute_kw(@odoo_db, @uid, @odoo_pass, table, 'write', [ids, params])
82
- else
83
- raise CrisalidOdooClient::Error::OdooResourceManagerError.new('params must be a non empty Hash and ids must be a non empty Array')
84
- end
85
- end
86
-
87
- def destroy(table, ids)
88
- if ids.is_a?(Array) && ids.size > 0
89
- @models.execute_kw(@odoo_db, @uid, @odoo_pass, table, 'unlink', [ids])
90
- else
91
- raise CrisalidOdooClient::Error::OdooResourceManagerError.new('ids must be a non empty Array')
92
- end
47
+ def employee
48
+ @employee ||= CrisalidOdooClient::Resource::Employee.new(self)
93
49
  end
94
50
 
95
51
  def connected?
96
- return (@uid || false) != false
52
+ return (uid || false) != false
97
53
  end
98
54
 
99
55
  private
100
56
 
101
57
  def connect
102
58
  begin
103
- common = XMLRPC::Client.new2("#{@odoo_url}/xmlrpc/2/common", nil, DEFAULT_TIMEOUT)
59
+ common = XMLRPC::Client.new2("#{@odoo_url}/xmlrpc/2/common", nil, @timeout)
104
60
  common.call('version')
105
61
  common.call('authenticate', @odoo_db, @odoo_user, @odoo_pass, {})
106
62
  rescue
@@ -0,0 +1,76 @@
1
+ module CrisalidOdooClient
2
+ class Query
3
+
4
+ def initialize(client)
5
+ @models = client.models
6
+ @odoo_db = client.odoo_db
7
+ @uid = client.uid
8
+ @odoo_pass = client.odoo_pass
9
+ end
10
+
11
+ def table_schema(table, attributes: [])
12
+ @models.execute_kw(@odoo_db, @uid, @odoo_pass, table, 'fields_get', [], {attributes: attributes})
13
+ end
14
+
15
+ def search(table, rules: [[]], params: {})
16
+ @models.execute_kw(@odoo_db, @uid, @odoo_pass, table, 'search', rules, params)
17
+ end
18
+
19
+ def search_read(table, rules: [[]], params: {}, fields: [])
20
+ params[:fields] = fields if fields.size > 0
21
+
22
+ @models.execute_kw(@odoo_db, @uid, @odoo_pass, table, 'search_read', rules, params)
23
+ end
24
+
25
+ def find(table, ids = [], params: {}, fields: [], first: false)
26
+ params[:limit] = 1 if first
27
+ params[:fields] = fields if fields.size > 0
28
+
29
+ @models.execute_kw(@odoo_db, @uid, @odoo_pass, table, 'read', [ids], params)
30
+ end
31
+
32
+ def where(table, rules: [[]], params: {}, fields: [], first: false)
33
+ params[:limit] = 1 if first
34
+ params[:fields] = fields if fields.size > 0
35
+
36
+ search_read(table, rules: rules, params: params)
37
+ end
38
+
39
+ def create(table, params)
40
+ if params.is_a?(Hash) && params.size > 0
41
+ @models.execute_kw(@odoo_db, @uid, @odoo_pass, table, 'create', [params])
42
+ else
43
+ raise CrisalidOdooClient::Error::OdooResourceManagerError.new('params must be a non empty Hash')
44
+ end
45
+ end
46
+
47
+ def create_in_batch(table, headers, params)
48
+ if headers.is_a?(Array) && headers.size > 0
49
+ if params.is_a?(Array) && params.size > 0 && params.first.is_a?(Array) && params.first.size == headers.size
50
+ @models.execute_kw(@odoo_db, @uid, @odoo_pass, table, 'load', [headers, params])["ids"]
51
+ else
52
+ raise CrisalidOdooClient::Error::OdooResourceManagerError.new('params must be a non empty Array of Array who has the same size as headers')
53
+ end
54
+ else
55
+ raise CrisalidOdooClient::Error::OdooResourceManagerError.new('headers must be a non empty Array')
56
+ end
57
+ end
58
+
59
+ def update(table, ids, params)
60
+ if params.is_a?(Hash) && params.size > 0 && ids.is_a?(Array) && ids.size > 0
61
+ @models.execute_kw(@odoo_db, @uid, @odoo_pass, table, 'write', [ids, params])
62
+ else
63
+ raise CrisalidOdooClient::Error::OdooResourceManagerError.new('params must be a non empty Hash and ids must be a non empty Array')
64
+ end
65
+ end
66
+
67
+ def destroy(table, ids)
68
+ if ids.is_a?(Array) && ids.size > 0
69
+ @models.execute_kw(@odoo_db, @uid, @odoo_pass, table, 'unlink', [ids])
70
+ else
71
+ raise CrisalidOdooClient::Error::OdooResourceManagerError.new('ids must be a non empty Array')
72
+ end
73
+ end
74
+
75
+ end
76
+ end
@@ -0,0 +1,7 @@
1
+ module CrisalidOdooClient::Resource
2
+ class Base
3
+ def initialize(client)
4
+ @client = client
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,41 @@
1
+ module CrisalidOdooClient::Resource
2
+ class Employee < Base
3
+ TABLE_NAME = CrisalidOdooClient::Table::EMPLOYEE
4
+
5
+ def schema(attributes: [])
6
+ @client.query.table_schema(TABLE_NAME, attributes: attributes)
7
+ end
8
+
9
+ def search(rules: [[]], params: {})
10
+ @client.query.search(TABLE_NAME, rules: rules, params: params)
11
+ end
12
+
13
+ def search_read(rules: [[]], params: {}, fields: [])
14
+ @client.query.search_read(TABLE_NAME, rules: rules, params: params, fields: fields)
15
+ end
16
+
17
+ def find(ids = [], params: {}, fields: [], first: false)
18
+ @client.query.find(TABLE_NAME, ids, params: params, fields: fields, first: first)
19
+ end
20
+
21
+ def where(rules: [[]], params: {}, fields: [], first: false)
22
+ @client.query.where(TABLE_NAME, rules: rules, params: params, fields: fields, first: first)
23
+ end
24
+
25
+ def create(params)
26
+ @client.query.create(TABLE_NAME, params)
27
+ end
28
+
29
+ def create_in_batch(headers, params)
30
+ @client.query.create_in_batch(TABLE_NAME, headers, params)
31
+ end
32
+
33
+ def update(ids, params)
34
+ @client.query.update(TABLE_NAME, ids, params)
35
+ end
36
+
37
+ def destroy(ids)
38
+ @client.query.destroy(TABLE_NAME, ids)
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,41 @@
1
+ module CrisalidOdooClient::Resource
2
+ class Product < Base
3
+ TABLE_NAME = CrisalidOdooClient::Table::PRODUCT
4
+
5
+ def schema(attributes: [])
6
+ @client.query.table_schema(TABLE_NAME, attributes: attributes)
7
+ end
8
+
9
+ def search(rules: [[]], params: {})
10
+ @client.query.search(TABLE_NAME, rules: rules, params: params)
11
+ end
12
+
13
+ def search_read(rules: [[]], params: {}, fields: [])
14
+ @client.query.search_read(TABLE_NAME, rules: rules, params: params, fields: fields)
15
+ end
16
+
17
+ def find(ids = [], params: {}, fields: [], first: false)
18
+ @client.query.find(TABLE_NAME, ids, params: params, fields: fields, first: first)
19
+ end
20
+
21
+ def where(rules: [[]], params: {}, fields: [], first: false)
22
+ @client.query.where(TABLE_NAME, rules: rules, params: params, fields: fields, first: first)
23
+ end
24
+
25
+ def create(params)
26
+ @client.query.create(TABLE_NAME, params)
27
+ end
28
+
29
+ def create_in_batch(headers, params)
30
+ @client.query.create_in_batch(TABLE_NAME, headers, params)
31
+ end
32
+
33
+ def update(ids, params)
34
+ @client.query.update(TABLE_NAME, ids, params)
35
+ end
36
+
37
+ def destroy(ids)
38
+ @client.query.destroy(TABLE_NAME, ids)
39
+ end
40
+ end
41
+ end
@@ -1,3 +1,3 @@
1
1
  module CrisalidOdooClient
2
- VERSION = "1.2.4"
2
+ VERSION = "2.0.0"
3
3
  end
@@ -1,6 +1,10 @@
1
1
  require "crisalid_odoo_client/version"
2
2
  require "crisalid_odoo_client/client"
3
+ require "crisalid_odoo_client/query"
3
4
  require "crisalid_odoo_client/table/table"
5
+ require "crisalid_odoo_client/resource/base"
6
+ require "crisalid_odoo_client/resource/product"
7
+ require "crisalid_odoo_client/resource/employee"
4
8
  require "crisalid_odoo_client/error/error"
5
9
 
6
10
  module CrisalidOdooClient
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crisalid_odoo_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.4
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maxime Palanchini
@@ -87,6 +87,10 @@ files:
87
87
  - lib/crisalid_odoo_client.rb
88
88
  - lib/crisalid_odoo_client/client.rb
89
89
  - lib/crisalid_odoo_client/error/error.rb
90
+ - lib/crisalid_odoo_client/query.rb
91
+ - lib/crisalid_odoo_client/resource/base.rb
92
+ - lib/crisalid_odoo_client/resource/employee.rb
93
+ - lib/crisalid_odoo_client/resource/product.rb
90
94
  - lib/crisalid_odoo_client/table/table.rb
91
95
  - lib/crisalid_odoo_client/version.rb
92
96
  homepage: https://github.com/Dakurei/crisalid_odoo_client