fix searchRead

This commit is contained in:
2026-09-04 17:59:58 +07:00
parent 1f69f922be
commit 47c8688884
3 changed files with 242 additions and 34 deletions

View File

@@ -9,51 +9,100 @@ 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 res = await client.executeKwd(
'saat.saham',
'search_read',
args: [
[],
{'fields': ['name', 'perusahaan', 'sector']},
],
);
final fields = ['name', 'perusahaan', 'sector'];
final res = await client.executeSearchReadPayload("saat.saham", fields);
return (res as List).map((e) => Saham.fromOdoo(e as Map<String, dynamic>)).toList();
}
// ---- 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 res = await client.executeKwd(
'saat.portofolio',
'search_read',
args: [
[],
{
'fields': [
'saham_id', 'sisa_lembar', 'avg_cost', 'harga_sekarang',
'nilai_sekarang', 'realized_pl', 'unrealized_pl',
]
},
],
);
final fields = [
'saham_id', 'sisa_lembar', 'avg_cost', 'harga_sekarang',
'nilai_sekarang', 'realized_pl', 'unrealized_pl',
];
final res = await client.executeSearchReadPayload("saat.portofolio", fields);
return (res as List).map((e) => Portfolio.fromOdoo(e as Map<String, dynamic>)).toList();
}
// ---- 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 res = await client.executeKwd(
'saat.transaksi',
'search_read',
args: [
[],
{
'fields': [
'tanggal', 'tipe', 'saham_id', 'volume', 'harga', 'fee', 'total'
],
'order': 'tanggal desc, id desc',
},
],
);
final fields = ['tanggal', 'tipe', 'saham_id', 'volume', 'harga', 'fee', 'total'];
final res = await client.executeSearchReadPayload("saat.transaksi", fields);
return (res as List).map((e) => Transaksi.fromOdoo(e as Map<String, dynamic>)).toList();
}