Skip to Content
Menu
This question has been flagged
3 Replies
8738 Views

Hi All,

I've created a pop up form and wishes to enforce user to fill in the details without them to close it until it is completed.

An example use case is like a EULA agreement, they have to agree before continuing into the application.

Is there a way to do that?



Avatar
Discard
Author Best Answer

My solution to my problem is to create a menu "eula" with sequence 0, that would trigger a server action.  Whenever a user logins, it will go to the first item of the menu item.  Thus by doing this, it will alway trigger the eula form I intend to display

<menuitem id="main_eula_menu"
name="EULA"
sequence="0"
action="ir_actions_server_eula_trigger"
/>

the menu would then trigger the server action below upon login.

<record id="ir_actions_server_eula_trigger" model="ir.actions.server">
<field name="sequence" eval="5"/>
<field name="state">code</field>
<field name="type">ir.actions.server</field>
<field name="model_id" ref="model_eula_eula"/>
<field name="code">action = self.trigger(cr, uid, None, context)</field>
<field name="condition">True</field>
<field name="name">EULA Agreement</field>
</record>

the form below is used to allow user's to agree or disagree the eula.

<record id="view_form_eula" model="ir.ui.view">
<field name="name">view_form_eula</field>
<field name="model">eula.eula</field>
<field name="arch" type="xml">
<form>
<div>
<field name="content"/>
</div>
<footer>
<a href="/eula/agree" class="oe_button">I agree</a>
<a href="/web/session/logout?redirect=/web" class="oe_button oe_highlight">I disagree</a>
</footer>
</form>
</field>
</record>


the Eula model  which has a trigger method to be called by the server action

class Eula(models.Model):
_name = 'eula.eula'
name = fields.Char()
content = fields.Html(readonly=True)
agree = fields.Boolean(string="Agree", help="By checking this, you agree to the EULA.", default=False)
@api.multi
def trigger(self):
_logger.info("Enter Eula Trigger")
return {
'name': 'EULA Agreement',
'view_type': 'form',
'view_mode': 'form',
'res_model': 'eula.eula',
'res_id': 1,
'type': 'ir.actions.act_window',
'target': 'new'
}

Finally a special route and controller to remove the eula menu if accepted.

class Eula(http.Controller):
@http.route('/eula/agree/', auth='user')
def index(self, **kw):
_logger.info(self);
model_datas = http.request.env['ir.model.data'].search([('module', '=', 'eula'), ('model', '=', 'ir.ui.menu')])
for model_data in model_datas:
model_name = model_data.model
model_id = model_data.res_id
model = http.request.env[model_name].search([('id', '=', model_id)])
model.sudo().unlink()
model_data.sudo().unlink()
eula = http.request.env['eula.eula'].search([('id', '=', 1)])
eula.agree = True
return werkzeug.utils.redirect("/")




Avatar
Discard
Best Answer

Try to get this button using xpath expression from the fields_view_get of the wizard class.

Then via a loop set its invisible property to true 

check the code posted in the following two links, it would help expressing my idea

https://www.odoo.com/nl_NL/forum/help-1/question/i-unable-to-change-the-readonly-proprety-of-a-button-from-within-fields-view-get-method-89309 

https://www.odoo.com/nl_NL/forum/help-1/question/i-unable-to-change-the-properties-of-some-fields-from-within-fields-view-get-method-89215 

Avatar
Discard
Author

I investigate, it seems that the fields_view_get does not attribute to disable closing of the pop up form

Related Posts Replies Views Activity
0
Jan 21
986
5
Jul 19
3511
1
May 16
2708
2
Jun 15
7345
0
Mar 15
2584