docker-odoo/16.0/extra-addons/openems/controllers/user.py
Arila Barnes 5594ca8d5d Added support for OpenEMS Odoo Add-ons
Signed-off-by: Arila Barnes <axmsoftware@Arilas-MacBook-Air-2.local>
2024-07-30 09:30:39 -07:00

33 lines
1.1 KiB
Python

from odoo import http
from odoo.http import request
class User(http.Controller):
@http.route("/openems_backend/sendRegistrationEmail", type="json", auth="user")
def index(self, userId, password=None, oem: str = ''):
user_model = request.env["res.users"]
user_record = user_model.search_read([("id", "=", userId)], ["partner_id"])
if len(user_record) != 1:
raise ValueError("User not found for id [" + userId + "]")
partner = user_record[0]
partner_id = partner.get("partner_id")
if partner_id is None:
raise ValueError("User has no partner")
if password is None:
password = "*****"
# load template
template = self.getTemplate(oem)
# set mail values
email_values = {
'password': password
}
# send mail
template.with_context(email_values).send_mail(
res_id=partner_id[0], force_send=True)
return {}
def getTemplate(self, oem: str):
template = request.env.ref("openems.registration_email")
return template