Portofolio auto-sync: otomatis update saat transaksi berubah + tombol Rekalkulasi
- saat.transaksi.create/write/unlink memicu rekalkulasi portofolio otomatis (buka menu Portofolio selalu data segar, tanpa klik manual) - Tambah tombol 'Rekalkulasi' di form portofolio sbg cadangan (action_recalc_click) - Perbaiki help teks portofolio yg sebelumnya menyesatkan
This commit is contained in:
@@ -42,7 +42,9 @@ Akses UI: http://localhost:18069 — login `admin` / `admin`
|
|||||||
- ✅ Odoo 17 container jalan (port 18069), DB PostgreSQL 16 healthy
|
- ✅ Odoo 17 container jalan (port 18069), DB PostgreSQL 16 healthy
|
||||||
- ✅ JSON-RPC aktif (uid `admin` verified) — endpoint yang akan dipakai Flutter
|
- ✅ JSON-RPC aktif (uid `admin` verified) — endpoint yang akan dipakai Flutter
|
||||||
- ✅ **Addon `saat_invest` terinstal** (model saham, transaksi, portofolio + seed 5 saham IDX)
|
- ✅ **Addon `saat_invest` terinstal** (model saham, transaksi, portofolio + seed 5 saham IDX)
|
||||||
- ✅ End-to-end teruji: buat beli/jual → recalculate → hitung avg cost & realized/unrealized P/L
|
- ✅ **Portofolio auto-sync**: otomatis diperbarui tiap transaksi ditambah/ubah/hapus
|
||||||
|
(tidak perlu tombol manual; buka menu Portofolio selalu datanya segar)
|
||||||
|
- ✅ End-to-end teruji: buat beli/jual → portofolio ter-update → hitung avg cost & realized/unrealized P/L
|
||||||
- ⏳ Aplikasi Flutter (login, catat jual/beli, portfolio, P/L)
|
- ⏳ Aplikasi Flutter (login, catat jual/beli, portfolio, P/L)
|
||||||
|
|
||||||
## Install / upgrade addon saat_invest
|
## Install / upgrade addon saat_invest
|
||||||
|
|||||||
@@ -75,6 +75,19 @@ class SaatPortofolio(models.Model):
|
|||||||
'count': len(portfolios),
|
'count': len(portfolios),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def action_recalc_click(self):
|
||||||
|
"""Tombol 'Rekalkulasi' untuk UI web: hitung ulang lalu muat ulang view list."""
|
||||||
|
result = self.env['saat.portofolio'].action_recalculate()
|
||||||
|
# kembalikan action window portofolio agar view ter-refresh
|
||||||
|
action = {
|
||||||
|
'type': 'ir.actions.act_window',
|
||||||
|
'name': 'Portofolio',
|
||||||
|
'res_model': 'saat.portofolio',
|
||||||
|
'view_mode': 'list,form',
|
||||||
|
'target': 'current',
|
||||||
|
}
|
||||||
|
return action
|
||||||
|
|
||||||
# --- computed store fields ---
|
# --- computed store fields ---
|
||||||
@api.depends('total_beli_lembar', 'total_jual_lembar')
|
@api.depends('total_beli_lembar', 'total_jual_lembar')
|
||||||
def _compute_sisa(self):
|
def _compute_sisa(self):
|
||||||
|
|||||||
@@ -49,3 +49,24 @@ class SaatTransaksi(models.Model):
|
|||||||
raise models.ValidationError("Volume harus lebih dari 0.")
|
raise models.ValidationError("Volume harus lebih dari 0.")
|
||||||
if r.harga < 0:
|
if r.harga < 0:
|
||||||
raise models.ValidationError("Harga tidak boleh negatif.")
|
raise models.ValidationError("Harga tidak boleh negatif.")
|
||||||
|
|
||||||
|
# --- auto-sync portofolio: setiap transaksi berubah, portofolio diperbarui ---
|
||||||
|
def _resync_portofolio(self):
|
||||||
|
"""Rekalkulasi portofolio dari seluruh transaksi (idempoten)."""
|
||||||
|
self.env['saat.portofolio'].action_recalculate()
|
||||||
|
|
||||||
|
@api.model_create_multi
|
||||||
|
def create(self, vals_list):
|
||||||
|
res = super().create(vals_list)
|
||||||
|
res._resync_portofolio()
|
||||||
|
return res
|
||||||
|
|
||||||
|
def write(self, vals):
|
||||||
|
res = super().write(vals)
|
||||||
|
self._resync_portofolio()
|
||||||
|
return res
|
||||||
|
|
||||||
|
def unlink(self):
|
||||||
|
res = super().unlink()
|
||||||
|
self._resync_portofolio()
|
||||||
|
return res
|
||||||
|
|||||||
@@ -21,6 +21,10 @@
|
|||||||
<field name="model">saat.portofolio</field>
|
<field name="model">saat.portofolio</field>
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<form string="Portofolio">
|
<form string="Portofolio">
|
||||||
|
<header>
|
||||||
|
<button name="action_recalc_click" string="Rekalkulasi"
|
||||||
|
type="object" class="oe_highlight"/>
|
||||||
|
</header>
|
||||||
<sheet>
|
<sheet>
|
||||||
<group>
|
<group>
|
||||||
<field name="saham_id" readonly="1"/>
|
<field name="saham_id" readonly="1"/>
|
||||||
@@ -51,9 +55,9 @@
|
|||||||
<field name="res_model">saat.portofolio</field>
|
<field name="res_model">saat.portofolio</field>
|
||||||
<field name="view_mode">list,form</field>
|
<field name="view_mode">list,form</field>
|
||||||
<field name="help" type="html">
|
<field name="help" type="html">
|
||||||
<p class="o_view_nocontent_smiling_face">
|
<p class="o_view_nocontent_smiling_face">Portofolio dihitung dari seluruh transaksi.
|
||||||
Klik <b>Rekalkulasi</b> (menu Form) untuk memperbarui posisi dari transaksi.
|
Untuk memperbarui: klik salah satu baris portofolio, lalu tekan tombol
|
||||||
</p>
|
<b>Rekalkulasi</b> di atas form. (Belum ada baris? Tambah transaksi dulu di menu Transaksi.)</p>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user