-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from vshn/impersonation
Add support to create report for someone else
- Loading branch information
Showing
11 changed files
with
144 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package odoo | ||
|
||
import "fmt" | ||
|
||
type Employee struct { | ||
ID int `json:"id"` | ||
Name string `json:"name"` | ||
} | ||
|
||
// SearchEmployee searches for an Employee with the given searchString in the Employee.Name. | ||
// If multiple employees are found, the first is returned. | ||
// Returns nil if none found. | ||
func (c *Client) SearchEmployee(searchString string, sid string) (*Employee, error) { | ||
// Prepare request | ||
body, err := NewJsonRpcRequest(&ReadModelRequest{ | ||
Model: "hr.employee", | ||
Domain: []Filter{{"name", "ilike", searchString}}, | ||
Fields: []string{"name"}, | ||
Limit: 0, | ||
Offset: 0, | ||
}).Encode() | ||
if err != nil { | ||
return nil, fmt.Errorf("encoding request: %w", err) | ||
} | ||
|
||
res, err := c.makeRequest(sid, body) | ||
if err != nil { | ||
return nil, err | ||
} | ||
type readResults struct { | ||
Length int `json:"length,omitempty"` | ||
Records []Employee `json:"records,omitempty"` | ||
} | ||
|
||
result := &readResults{} | ||
if err := c.unmarshalResponse(res.Body, result); err != nil { | ||
return nil, err | ||
} | ||
if len(result.Records) >= 1 { | ||
return &result.Records[0], nil | ||
} | ||
return nil, nil | ||
} | ||
|
||
// FetchEmployee fetches an Employee for the given user ID. | ||
// Returns nil if not found. | ||
func (c *Client) FetchEmployee(userId int, sid string) (*Employee, error) { | ||
// Prepare request | ||
body, err := NewJsonRpcRequest(&ReadModelRequest{ | ||
Model: "hr.employee", | ||
Domain: []Filter{{"user_id", "=", userId}}, | ||
Fields: []string{"name"}, | ||
Limit: 0, | ||
Offset: 0, | ||
}).Encode() | ||
if err != nil { | ||
return nil, fmt.Errorf("encoding request: %w", err) | ||
} | ||
|
||
res, err := c.makeRequest(sid, body) | ||
if err != nil { | ||
return nil, err | ||
} | ||
type readResults struct { | ||
Length int `json:"length,omitempty"` | ||
Records []Employee `json:"records,omitempty"` | ||
} | ||
|
||
result := &readResults{} | ||
if err := c.unmarshalResponse(res.Body, result); err != nil { | ||
return nil, err | ||
} | ||
if len(result.Records) >= 1 { | ||
return &result.Records[0], nil | ||
} | ||
return nil, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters