fix logout
This commit is contained in:
@@ -44,24 +44,6 @@ class OdooClient {
|
||||
return _call('object', 'execute_kw', params);
|
||||
}
|
||||
|
||||
Future<dynamic> executeKwdWithArgs(String model, String method,
|
||||
{List<dynamic> fields = const [], Map<String, dynamic>? kwargs}) async {
|
||||
_uid ??= await authenticate();
|
||||
final args = [
|
||||
|
||||
db,
|
||||
_uid,
|
||||
password,
|
||||
model,
|
||||
method,
|
||||
[],
|
||||
fields,
|
||||
|
||||
if (kwargs != null) kwargs,
|
||||
];
|
||||
return _call('object', 'execute_kw', args);
|
||||
}
|
||||
|
||||
Future<dynamic> executeSearchReadPayload(String model, List<String> fields) async {
|
||||
int uid = await authenticate();
|
||||
final payload = OdooRpcHelper.searchRead(
|
||||
@@ -145,4 +127,41 @@ class OdooClient {
|
||||
}
|
||||
|
||||
void close() => _http.close();
|
||||
|
||||
Future<bool> logout(int uid, String db, String password) async {
|
||||
|
||||
int uid = await authenticate();
|
||||
|
||||
final payload = OdooRpcHelper.buildLogout(
|
||||
service: "common",
|
||||
db: db,
|
||||
uid: uid,
|
||||
password: password,
|
||||
model: "", // or just use session logout
|
||||
method: "", // some versions expose this
|
||||
domain: [[]],
|
||||
kwargs: {},
|
||||
);
|
||||
|
||||
try {
|
||||
final resp = await _http
|
||||
.post(_endpoint,
|
||||
headers: {'Content-Type': 'application/json'}, body: jsonEncode(payload))
|
||||
.timeout(const Duration(seconds: 25));
|
||||
final json = jsonDecode(resp.body) as Map<String, dynamic>;
|
||||
if (json.containsKey('error')) {
|
||||
final err = json['error'] as Map?;
|
||||
String? message = (err?['data'] as Map?)?['message'] as String? ??
|
||||
(err?['message'] as String?) ??
|
||||
'Unknown Odoo error';
|
||||
throw Exception('Odoo error: $message');
|
||||
}
|
||||
return json['result'];
|
||||
} on TimeoutException {
|
||||
throw Exception('Timeout — pastikan server Odoo:18069 tercapai');
|
||||
} on http.ClientException catch (e) {
|
||||
throw Exception('Koneksi gagal: ${e.message}');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user