I am a beginner Odoo developer, I have a little issue with my code which is I change a field called “state” in a One2many field appointment_ids (tree), it changes, but it looks the same and the change appears only after I reload the page or click any other button and return.
the codes I am using :
The wizard used to return the form view :
class choose_appointment_customer(models.TransientModel):
_name = "choose.appointment.customer"
@api.model
def action_finish_scheduling(self, args):
// some code here that call _return_action_appointments function but it's long and it's working fine
return self._return_action_appointments(appointment_ids, batch_id)
@api.model
def _return_action_appointments(self, appointment_ids, batch_id):
"""
Method to return proper actions for those appointment_ids
Args:
* appointment_ids - business_appointment recordset
Returns:
* ir.act.window dict
"""
res = False
if len(appointment_ids) >= 1:
res = self.sudo().env.ref("slnee_appointment_core.business_appointment_batch_action_only_form").read()[0]
res["res_id"] = appointment_ids[0].batch_id.id
return res
XML:
<record id="business_appointment_batch_action_only_form" model="ir.actions.act_window">
<field name="name">Appointment</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">business.appointment.batch</field>
<field name="view_mode">form</field>
</record>
the js function executed to return the form view:
/**
* Re-write to make chosen appointments + close parent dialog + open form view
*/
_save: function () {
var self = this;
self.form_view.saveRecord(self.form_view.handle, {
stayInEdit: true,
reload: false,
savePoint: self.shouldSaveLocally,
viewType: 'form',
}).then(function (changedFields) {
var record = self.form_view.model.get(self.form_view.handle, {raw: true})
var chosenAppointments = self.parentRenderer.chosenAppointments;
self._rpc({
model: "choose.appointment.customer",
method: "action_finish_scheduling",
args: [{"data": record.data, "chosen": chosenAppointments}],
context: record.context,
}).then(function (res) {
self.close();
self.topWindow.closeCalc(res);
});
});
},
});
The One2many field I am talking about (model : business.appointment ) :
<!-- Form View -->
<record id="business_appointment_batch_view_form" model="ir.ui.view">
<field name="name">business.appointment.batch.form</field>
<field name="model">business.appointment.batch</field>
<field name="arch" type="xml">
<form js_class="ba_batch_form">
<page string="Reservations">
<field name="appointment_ids" readonly="1"
options="{'no_create_edit': 1, 'no_quick_create': 1,'no_open':True,'no_create' :1}"
widget="one2many_selection">
<tree default_order="datetime_start"
decoration-success="state in ['done']"
decoration-muted="state in ['cancel']"
decoration-warning="state in ['missed']"
>
<field name="hide_delete_button" invisible="1"/>
<field name="is_pack" invisible="1"/>
<field name="resource_id"/>
<field name="service_id"/>
<field name="datetime_start"/>
<field name="datetime_end"/>
<field name="state"/>
<button name="open_this" type="object" icon="fa-list"/>
<button name="%(base_cancel_reason.base_cancel_reason_wizard_action)d" type="action"
icon="fa-trash"
attrs="{'invisible': ['|','|',('hide_delete_button', '=', True),('state', 'in', ['cancel', 'missed', 'done']),('parent.state', '!=', 'reserved')]}"
/>
</tree>
</field>
</page>
Please help me and thank you in advance.
I tried crnd_web_view_refresh_timed module in Odoo apps store but it did not reload the tree view “appointment_ids”