Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to refresh a model's view programmatically within a constraint function in Odoo 8?

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 I want to drag that(Green Arrow) meeting event After Drag and Drop, Constraint message will display 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 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

like image 285
Shravy Avatar asked Apr 27 '17 03:04

Shravy


1 Answers

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.

like image 62
dgeorgiev Avatar answered Nov 02 '22 23:11

dgeorgiev