en_US may not be activated as it is possible to create a database in another language using the database manager. When trying to install a chart of account, the tax return entry tried to format a date at the installation of the module, with no lang in the context. The fallback was made on en_US but an error is raised if that language is not activated. As it is a very common scenario to retrieve a language from the context, add a generic tool method to do it. Replace and closes odoo/odoo#37629 closes odoo/odoo#37568 Signed-off-by: Martin Trigaux (mat) <mat@odoo.com>
44 lines
1.9 KiB
Python
44 lines
1.9 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
import werkzeug
|
|
|
|
from odoo import http
|
|
from odoo.http import request
|
|
from odoo.tools.translate import _
|
|
from odoo.tools.misc import get_lang
|
|
|
|
|
|
class Rating(http.Controller):
|
|
|
|
@http.route('/rating/<string:token>/<int:rate>', type='http', auth="public", website=True)
|
|
def open_rating(self, token, rate, **kwargs):
|
|
assert rate in (1, 5, 10), "Incorrect rating"
|
|
rating = request.env['rating.rating'].sudo().search([('access_token', '=', token)])
|
|
if not rating:
|
|
return request.not_found()
|
|
rate_names = {
|
|
5: _("not satisfied"),
|
|
1: _("highly dissatisfied"),
|
|
10: _("satisfied")
|
|
}
|
|
rating.write({'rating': rate, 'consumed': True})
|
|
lang = rating.partner_id.lang or get_lang(request.env).code
|
|
return request.env['ir.ui.view'].with_context(lang=lang).render_template('rating.rating_external_page_submit', {
|
|
'rating': rating, 'token': token,
|
|
'rate_name': rate_names[rate], 'rate': rate
|
|
})
|
|
|
|
@http.route(['/rating/<string:token>/<int:rate>/submit_feedback'], type="http", auth="public", methods=['post'], website=True)
|
|
def submit_rating(self, token, rate, **kwargs):
|
|
rating = request.env['rating.rating'].sudo().search([('access_token', '=', token)])
|
|
if not rating:
|
|
return request.not_found()
|
|
record_sudo = request.env[rating.res_model].sudo().browse(rating.res_id)
|
|
record_sudo.rating_apply(rate, token=token, feedback=kwargs.get('feedback'))
|
|
lang = rating.partner_id.lang or get_lang(request.env).code
|
|
return request.env['ir.ui.view'].with_context(lang=lang).render_template('rating.rating_external_page_view', {
|
|
'web_base_url': request.env['ir.config_parameter'].sudo().get_param('web.base.url'),
|
|
'rating': rating,
|
|
})
|