Skip to content
Extraits de code Groupes Projets

Api formations

6 files
+ 102
42
Comparer les modifications
  • Côte à côte
  • En ligne

Fichiers

+ 59
21
# © 2023 Le Filament (<http://www.le-filament.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import json
import hashlib
from odoo import fields, http
from odoo.http import request
@@ -21,29 +22,66 @@ class TrainingsController(http.Controller):
Main route
:param company_id: specific company_id;
"""
domain = [
("is_published", "=", True),
("type_event_cg", "=", "formation")
# ("date_end", ">", fields.Datetime.now()),
]
domain = []
# fields = [
# 'name',
# 'training_id',
# 'date_begin',
# 'date_end',
# 'description'
# ]
if company_id:
domain.append([("company_id", "=", int(company_id))])
training_ids = request.env["event.event"].sudo().search(domain)
event_json = training_ids.mapped(
lambda e: {
"name": e.name,
"date_begin": fields.Datetime.to_string(e.date_begin),
"date_end": fields.Datetime.to_string(e.date_end),
"type_event_cg": e.type_event_cg,
"event_privacy": e.event_privacy,
"tags": e.tag_ids.mapped("name"),
"city": e.address_id.city,
"website_url": e.get_base_url() + e.website_url,
trainings = request.env["event_training"].sudo().search(domain)
trainings_j = trainings.mapped(
lambda t: {
"title": t.name,
"theme": "To be defined",
"is_subscriber": t.is_subscriber,
"text_body": t.text,
"description": t.description,
"other_training": t.other_training,
"modalities": t.modalities,
"pre_requisite": t.pre_requisite,
"duration": "To be defined",
"other_infos": t.other_infos,
"price": t.price,
"certification": t.certification,
"attachment": t.attachment,
"formation_type": t.formation_type,
"events": t.event_ids.mapped(
lambda e: {
"title": e.name,
"category": "To be defined",
"date_begin": fields.Datetime.to_string(e.date_begin),
"date_end": fields.Datetime.to_string(e.date_end),
"description": e.description,
"attachment": "To be defined",
"horaire": fields.Datetime.to_string(e.date_begin),
"address": e.address_id.mapped("name"),
"fax": "To be defined",
"website_url": (e.get_base_url() + e.website_url)
if e.event_privacy == "public"
else False,
"theme": "To be defined",
"city": e.address_id.mapped("city"),
"region": "To be defined",
"state": e.stage_id.mapped("name"),
}
),
}
)
return http.Response(
response=json.dumps(event_json),
headers=[("Content-Type", "application/json")],
)
result = trainings_j
params = request.get_http_params()
if params and "checksum" in params:
h = hashlib.sha256()
h.update(",".join(map(str, trainings_j)).encode("utf-8"))
checksum_dict = {"checksum": h.hexdigest()}
result = checksum_dict
return request.make_json_response(result)
Chargement en cours