是否可以在Odoo 8中的约束函数中以编程方式刷新模型的视图?

时间:2022-02-16 23:04:24

I have written a constraint for a particular field and I want to refresh the view of calendar when the constraint fails.

我已经为特定字段编写了一个约束,我想在约束失败时刷新calendar视图。

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.

如果约束失败(我。在返回False时,我想刷新一下日历视图。

Anyone with idea kindly please guide me with some idea.是否可以在Odoo 8中的约束函数中以编程方式刷新模型的视图? I want to drag that(Green Arrow) meeting event 是否可以在Odoo 8中的约束函数中以编程方式刷新模型的视图? After Drag and Drop, Constraint message will display 是否可以在Odoo 8中的约束函数中以编程方式刷新模型的视图? When I click on OK button of warning message, event does not move to its original place

任何有意见的人请给我点化一下。我想拖拽这个(绿箭头)会议事件后拖放,当我点击OK按钮的警告消息时,约束消息会显示,事件不会移动到它原来的位置。

I want calendar to reload when i click on OK button

当我点击OK按钮时,我想要重新载入日历。

1 个解决方案

#1


1  

You can try one of the following (untested):

你可以尝试以下其中之一(未经测试):

1) Add some javascript to refresh the view on dialogue close.

添加一些javascript来刷新对话框关闭时的视图。

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.

2)捕获约束错误,并返回动作以显示相同的视图(实质上是刷新页面)。传递上下文中的错误信息,并使视图最终显示上下文中的错误。这样,当执行因为错误而停止时,刷新的页面将已经存在。

Hope it works for you.

希望对你有用。

#1


1  

You can try one of the following (untested):

你可以尝试以下其中之一(未经测试):

1) Add some javascript to refresh the view on dialogue close.

添加一些javascript来刷新对话框关闭时的视图。

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.

2)捕获约束错误,并返回动作以显示相同的视图(实质上是刷新页面)。传递上下文中的错误信息,并使视图最终显示上下文中的错误。这样,当执行因为错误而停止时,刷新的页面将已经存在。

Hope it works for you.

希望对你有用。