I have written a constraint for a particular field and I want to refresh the view of calendar when the constraint fails.
Below is the code I had tried
def _check_date_drag(self, cr, uid, ids, context=None):
mom_obj = self.pool.get('mom.meeting')
res = {}
for item in self.browse(cr, uid, ids):
mom_ids = mom_obj.search(cr, uid,
[('meet_ref','=',item.number), ('mdt','<',item.start_datetime)],
context=context)
if mom_ids:
res = {
'view_type': 'form',
'view_mode': 'form',
'res_model': 'calendar.event',
'type': 'ir.actions.act_window',
'target': 'new',
}
return False and res
return True
_constraints = [
(_check_date_drag, 'MOM is already created for this calendar
event! Kindly refresh the page to discard the changes!',
['start_datetime']),
]
If the constraint fails(i.e at the return False), I want to refresh the calendar view.
Anyone with idea kindly please guide me with some idea. I want to drag that(Green Arrow) meeting event After Drag and Drop, Constraint message will display When I click on OK button of warning message, event does not move to its original place
I want calendar to reload when i click on OK button
You can try one of the following (untested):
1) Add some javascript to refresh the view on dialogue close.
2) Catch the constraint error, and return action to display the same view (essentially refreshing the page). Pass the error information in the context, and make the view display the errors in the context in the end. This way when the execution stops because of the error, the refreshed page will already be there.
Hope it works for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With