Gabung app Android Flutter 'Saat Invest' ke repo saat-app (folder flutter/)
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).
This commit is contained in:
41
flutter/lib/models/portfolio.dart
Normal file
41
flutter/lib/models/portfolio.dart
Normal file
@@ -0,0 +1,41 @@
|
||||
/// Model Portofolio: ringkasan posisi per saham dari Odoo saat.portofolio.
|
||||
class Portfolio {
|
||||
final int id;
|
||||
final String sahamTicker;
|
||||
final int sisaLembar;
|
||||
final double avgCost;
|
||||
final double hargaSekarang;
|
||||
final double nilaiSekarang;
|
||||
final double realizedPl;
|
||||
final double unrealizedPl;
|
||||
|
||||
Portfolio({
|
||||
required this.id,
|
||||
required this.sahamTicker,
|
||||
required this.sisaLembar,
|
||||
required this.avgCost,
|
||||
required this.hargaSekarang,
|
||||
required this.nilaiSekarang,
|
||||
required this.realizedPl,
|
||||
required this.unrealizedPl,
|
||||
});
|
||||
|
||||
factory Portfolio.fromOdoo(Map<String, dynamic> m) {
|
||||
// saham_id adalah tuple/list [id, ticker] dalam search_read
|
||||
String ticker = '';
|
||||
final sahamId = m['saham_id'];
|
||||
if (sahamId is List && sahamId.isNotEmpty) {
|
||||
ticker = sahamId.length > 1 ? sahamId[1].toString() : '${sahamId[0]}';
|
||||
}
|
||||
return Portfolio(
|
||||
id: (m['id'] as num).toInt(),
|
||||
sahamTicker: ticker,
|
||||
sisaLembar: (m['sisa_lembar'] as num?)?.toInt() ?? 0,
|
||||
avgCost: (m['avg_cost'] as num?)?.toDouble() ?? 0,
|
||||
hargaSekarang: (m['harga_sekarang'] as num?)?.toDouble() ?? 0,
|
||||
nilaiSekarang: (m['nilai_sekarang'] as num?)?.toDouble() ?? 0,
|
||||
realizedPl: (m['realized_pl'] as num?)?.toDouble() ?? 0,
|
||||
unrealizedPl: (m['unrealized_pl'] as num?)?.toDouble() ?? 0,
|
||||
);
|
||||
}
|
||||
}
|
||||
63
flutter/lib/models/saham_transaksi.dart
Normal file
63
flutter/lib/models/saham_transaksi.dart
Normal file
@@ -0,0 +1,63 @@
|
||||
/// Model Saham master dari saat.saham.
|
||||
class Saham {
|
||||
final int id;
|
||||
final String kode;
|
||||
final String? perusahaan;
|
||||
final String? sektor;
|
||||
|
||||
Saham({required this.id, required this.kode, this.perusahaan, this.sektor});
|
||||
|
||||
factory Saham.fromOdoo(Map<String, dynamic> m) => Saham(
|
||||
id: (m['id'] as num).toInt(),
|
||||
kode: (m['name'] as String?) ?? '',
|
||||
perusahaan: m['perusahaan'] as String?,
|
||||
sektor: m['sector'] as String?,
|
||||
);
|
||||
}
|
||||
|
||||
/// Model Transaksi dari saat.transaksi.
|
||||
class Transaksi {
|
||||
final int id;
|
||||
final String tanggal;
|
||||
final String tipe; // buy | sell
|
||||
final int sahamId;
|
||||
final String sahamTicker;
|
||||
final int volume;
|
||||
final double harga;
|
||||
final double fee;
|
||||
final double total;
|
||||
|
||||
Transaksi({
|
||||
required this.id,
|
||||
required this.tanggal,
|
||||
required this.tipe,
|
||||
required this.sahamId,
|
||||
required this.sahamTicker,
|
||||
required this.volume,
|
||||
required this.harga,
|
||||
required this.fee,
|
||||
required this.total,
|
||||
});
|
||||
|
||||
bool get isBuy => tipe == 'buy';
|
||||
|
||||
factory Transaksi.fromOdoo(Map<String, dynamic> m) {
|
||||
String ticker = '';
|
||||
final s = m['saham_id'];
|
||||
if (s is List && s.isNotEmpty) {
|
||||
ticker = s.length > 1 ? s[1].toString() : '${s[0]}';
|
||||
}
|
||||
final sid = s is List ? (s.first as num).toInt() : (s as num?)?.toInt() ?? 0;
|
||||
return Transaksi(
|
||||
id: (m['id'] as num).toInt(),
|
||||
tanggal: (m['tanggal'] as String?) ?? '',
|
||||
tipe: (m['tipe'] as String?) ?? 'buy',
|
||||
sahamId: sid,
|
||||
sahamTicker: ticker,
|
||||
volume: (m['volume'] as num?)?.toInt() ?? 0,
|
||||
harga: (m['harga'] as num?)?.toDouble() ?? 0,
|
||||
fee: (m['fee'] as num?)?.toDouble() ?? 0,
|
||||
total: (m['total'] as num?)?.toDouble() ?? 0,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user