fix logout
This commit is contained in:
@@ -4,12 +4,17 @@ const _kBase = 'odoo_base';
|
||||
const _kDb = 'odoo_db';
|
||||
const _kUser = 'odoo_user';
|
||||
const _kPass = 'odoo_pass';
|
||||
const _kUid = 'odoo_uid';
|
||||
|
||||
/// Menyimpan konfigurasi login (url, db, user, password) secara aman
|
||||
/// + menyediakan OdooClient terautentikasi.
|
||||
class Session {
|
||||
static const _storage = FlutterSecureStorage();
|
||||
|
||||
static Future<void> saveUid(int uid) async {
|
||||
await _storage.write(key: _kUid, value: uid.toString());
|
||||
}
|
||||
|
||||
static Future<void> save(String baseUrl, String db, String user, String pass) async {
|
||||
await _storage.write(key: _kBase, value: baseUrl);
|
||||
await _storage.write(key: _kDb, value: db);
|
||||
@@ -35,4 +40,28 @@ class Session {
|
||||
static Future<String?> readLastUrl() async {
|
||||
return _storage.read(key: _kBase);
|
||||
}
|
||||
|
||||
static Future<String> readBase() async {
|
||||
final base = await _storage.read(key: _kBase);
|
||||
if (base == null) throw Exception('URL tidak ditemukan');
|
||||
return base;
|
||||
}
|
||||
|
||||
static Future<String?> readDb() async {
|
||||
return _storage.read(key: _kDb);
|
||||
}
|
||||
|
||||
static Future<String?> readUser() async {
|
||||
return _storage.read(key: _kUser);
|
||||
}
|
||||
|
||||
static Future<String?> readPass() async {
|
||||
return _storage.read(key: _kPass);
|
||||
}
|
||||
|
||||
static Future<int?> readUid() async {
|
||||
final uid = await _storage.read(key: _kUid);
|
||||
if (uid == null) return null;
|
||||
return int.tryParse(uid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,31 +9,6 @@ class StockService {
|
||||
final OdooClient client;
|
||||
|
||||
// ---- Saham ----
|
||||
// Future<List<Saham>> listSahamOld() async {
|
||||
// final res = await client.executeKwd(
|
||||
// 'saat.saham',
|
||||
// 'search_read',
|
||||
// args: [
|
||||
// "saat.saham",
|
||||
// "search_read",
|
||||
// [[]],
|
||||
// {'fields': ['name', 'perusahaan', 'sector'], "limit": 100, "offset": 0, "order": "name asc"},
|
||||
// ],
|
||||
// );
|
||||
// return (res as List).map((e) => Saham.fromOdoo(e as Map<String, dynamic>)).toList();
|
||||
// }
|
||||
//
|
||||
// Future<List<Saham>> listSaham() async {
|
||||
// final res = await client.executeKwdWithArgs(
|
||||
// 'saat.saham',
|
||||
// 'search_read',
|
||||
// fields: [
|
||||
// {'fields': ['name', 'perusahaan', 'sector'],}
|
||||
// ]
|
||||
// );
|
||||
// return (res as List).map((e) => Saham.fromOdoo(e as Map<String, dynamic>)).toList();
|
||||
// }
|
||||
|
||||
Future<List<Saham>> listSaham() async {
|
||||
final fields = ['name', 'perusahaan', 'sector'];
|
||||
final res = await client.executeSearchReadPayload("saat.saham", fields);
|
||||
@@ -41,39 +16,6 @@ class StockService {
|
||||
}
|
||||
|
||||
// ---- Portofolio ----
|
||||
// Future<List<Portfolio>> listPortofolio() async {
|
||||
// final res = await client.executeKwd(
|
||||
// 'saat.portofolio',
|
||||
// 'search_read',
|
||||
// args: [
|
||||
// [],
|
||||
// {
|
||||
// 'fields': [
|
||||
// 'saham_id', 'sisa_lembar', 'avg_cost', 'harga_sekarang',
|
||||
// 'nilai_sekarang', 'realized_pl', 'unrealized_pl',
|
||||
// ]
|
||||
// },
|
||||
// ],
|
||||
// );
|
||||
// return (res as List).map((e) => Portfolio.fromOdoo(e as Map<String, dynamic>)).toList();
|
||||
// }
|
||||
|
||||
// Future<List<Portfolio>> listPortofolio() async {
|
||||
// final res = await client.executeKwdWithArgs(
|
||||
// 'saat.portofolio',
|
||||
// 'search_read',
|
||||
// fields: [
|
||||
// {
|
||||
// "fields": ["saham_id", "sisa_lembar", "avg_cost", "harga_sekarang",
|
||||
// "nilai_sekarang", "realized_pl", "unrealized_pl"],
|
||||
// "limit": 20,
|
||||
// "offset": 0
|
||||
// }
|
||||
// ],
|
||||
// );
|
||||
// return (res as List).map((e) => Portfolio.fromOdoo(e as Map<String, dynamic>)).toList();
|
||||
// }
|
||||
|
||||
Future<List<Portfolio>> listPortofolio() async {
|
||||
final fields = [
|
||||
'saham_id', 'sisa_lembar', 'avg_cost', 'harga_sekarang',
|
||||
@@ -84,22 +26,6 @@ class StockService {
|
||||
}
|
||||
|
||||
// ---- Transaksi ----
|
||||
// Future<List<Transaksi>> listTransaksi() async {
|
||||
// final res = await client.executeKwdWithArgs(
|
||||
// 'saat.transaksi',
|
||||
// 'search_read',
|
||||
// fields: [
|
||||
// {
|
||||
// 'fields': [
|
||||
// 'tanggal', 'tipe', 'saham_id', 'volume', 'harga', 'fee', 'total'
|
||||
// ],
|
||||
// 'order': 'tanggal desc, id desc',
|
||||
// },
|
||||
// ],
|
||||
// );
|
||||
// return (res as List).map((e) => Transaksi.fromOdoo(e as Map<String, dynamic>)).toList();
|
||||
// }
|
||||
|
||||
Future<List<Transaksi>> listTransaksi() async {
|
||||
final fields = ['tanggal', 'tipe', 'saham_id', 'volume', 'harga', 'fee', 'total'];
|
||||
final res = await client.executeSearchReadPayload("saat.transaksi", fields);
|
||||
|
||||
Reference in New Issue
Block a user