I have a function that updates rows in a child table, and a script that calls the function every time a field on the parent doc is changed. However, every time I change the field it appends the rows instead of updating them, so I end up with a table full of duplicate rows.
How do I prevent this from happening? In the function I have the following that performs the update:
for g in gl_entries:
row = self.append('forex_accounts', {})
g.account_name = g.account
g.currency = g.account_currency
g.current_balance = fmt_money(g.current_balance, 2, g.account_currency)
g.current_gbp_balance = fmt_money(g.current_gbp_balance, 2, 'GBP')
g.revalued_gbp_balance = fmt_money(g.revalued_gbp_balance, 2, 'GBP')
g.difference = fmt_money(g.difference, 2, 'GBP')
row.update(g)
And the script is simply:
frappe.ui.form.on('Forex Journal Entry', {
posting_date: function(frm) {
return frappe.call({
method: "get_accounts",
doc: frm.doc,
callback: function(r, rt) {
frm.refresh();
}
})
}
});
Note that instead of frm.refresh()
I have also tried:
frm.refresh_field("forex_accounts");
frm.refresh_fields();
with the same effect.