Satu repo untuk backend Odoo (addon saat_invest) + app Android. - flutter/ berisi project Flutter (lib/, android/, pubspec, test) - Login Odoo JSON-RPC, tab Portofolio+Equity, tab Transaksi, catat jual/beli otomatis sync - Build .gitignore nested dipakai sehingga artefak build/.dart_tool tak ter-track Sejarah: gabung flat (satu sejarah backend+app).
84 lines
2.2 KiB
Dart
84 lines
2.2 KiB
Dart
import '../api/odoo_client.dart';
|
|
import '../models/portfolio.dart';
|
|
import '../models/saham_transaksi.dart';
|
|
|
|
/// Layanan domain utk model Odoo saat_invest.
|
|
class StockService {
|
|
StockService(this.client);
|
|
|
|
final OdooClient client;
|
|
|
|
// ---- Saham ----
|
|
Future<List<Saham>> listSaham() async {
|
|
final res = await client.executeKwd(
|
|
'saat.saham',
|
|
'search_read',
|
|
args: [
|
|
[],
|
|
{'fields': ['name', 'perusahaan', 'sector']},
|
|
],
|
|
);
|
|
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();
|
|
}
|
|
|
|
// ---- Transaksi ----
|
|
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',
|
|
},
|
|
],
|
|
);
|
|
return (res as List).map((e) => Transaksi.fromOdoo(e as Map<String, dynamic>)).toList();
|
|
}
|
|
|
|
Future<int> addTransaksi({
|
|
required int sahamId,
|
|
required String tipe, // buy | sell
|
|
required int volume,
|
|
required double harga,
|
|
required double fee,
|
|
String? tanggal, // 'YYYY-MM-DD'
|
|
}) async {
|
|
final vals = <String, dynamic>{
|
|
'saham_id': sahamId,
|
|
'tipe': tipe,
|
|
'volume': volume,
|
|
'harga': harga,
|
|
'fee': fee,
|
|
if (tanggal != null) 'tanggal': tanggal,
|
|
};
|
|
final res = await client.executeKwd('saat.transaksi', 'create', args: [vals]);
|
|
return (res as num).toInt();
|
|
}
|
|
|
|
Future<void> hapusTransaksi(List<int> ids) async {
|
|
await client.executeKwd('saat.transaksi', 'unlink', args: [ids]);
|
|
}
|
|
}
|