Skip to Content
Menu
This question has been flagged

I have a custom module on my odoo server that clients need to pay extra for use, but they can use it for free as a demo for a month. On install the module creates an entry in demo.installation model, where the module name and date of install are saved.

From the date I've got a "timer". I need to show the timer in the menu. I've badly extended the menu following this question https://www.odoo.com/forum/help-1/question/odoo10-how-to-inherit-templates-of-web-module-119140


I now need to show the remaining days in the menu.

I've override the web.Home controllers web_client method to check and add to the context.


@http.route('/web', type='http', auth="none")
def web_client(self, s_action=None, **kw):
	ensure_db()
	if not request.session.uid:
		return werkzeug.utils.redirect('/web/login', 303)
	if kw.get('redirect'):
		return werkzeug.utils.redirect(kw.get('redirect'), 303)

	request.uid = request.session.uid

	# DODELAVA ZA TIMER
	demo_install = request.env['demo.installation'].search([])
	try:
		context = request.env['ir.http'].webclient_rendering_context()
	except:
		return werkzeug.utils.redirect('/web/login?error=access')

	if len(demo_install) > 0:
		demo_install = demo_install[0]

		demos_obj = self.get_expiration_dict(demo_install)
		# NE DELUJEJO COMPUTED POLJA
		if demos_obj['expires'] < 0:
			msg = u'Your demo time is over! The module will be deleted in {} days!'.format(demos_obj['deletes'])
			context['message'] = msg
			return request.render('odoo13_demo_timer.expiry_message', qcontext=context)
		else:
			demos_obj['message'] = u'Your demo will end in {} days. The module will be deleted in {} days!'.format(demos_obj['expires'], demos_obj['deletes'])
			if demos_obj['expires'] <= 2:
				demos_obj['message_class'] = 'red'
			elif demos_obj['expires'] <= 7:
				demos_obj['message_class'] = 'yellow'
			elif demos_obj['expires'] > 7:
				demos_obj['message_class'] = 'green'

		context['demo_timer'] = demos_obj

	try:
		response = request.render('web.webclient_bootstrap', qcontext=context)
		response.headers['X-Frame-Options'] = 'DENY'
		return response
	except AccessError:
		return werkzeug.utils.redirect('/web/login?error=access')


The menu templet looks like

<?xml version="1.0" encoding="UTF-8"?>

<templates id="template" xml:space="preserve">


<t t-extend="Menu">

    <t t-jquery='.o_menu_sections' t-operation='after'>

        <t t-if="demo_timer">

            <ul class="nav navbar-nav navbar-right demo_time_placeholder">

                <li t-attf-class="{{ demo_timer['message_class'] }}"><t t-esc="demo_timer['message']" /></li>

            </ul>

        </t>

        <ul class="full">FOO BAR</ul>

    </t>

</t>


</templates>


The problem is that there is no section "demo_timer" in the context that is passed to the template. 

How can I pass values in context so I can use them in the menu?

Avatar
Discard
Related Posts Replies Views Activity
1
Jun 24
2598
1
Apr 20
5222
0
Jul 24
225
4
May 24
10073
1
Apr 24
1563