I am creating an addon in odoo to get some data and communicate it through a controller. I get the data I need from the DB correctly but when I transform it with json.dumps()
I get the following error:
TypeError: Object of type product.template is not JSON serializable - - -
So I decided to directly build a dictionary like this:
def cargarDiccionario(self, productos):
productos_dict = {
'skus': []
}
for producto in productos:
d = {
"name": producto.name,
"categ_id": producto.categ_id.name,
"booking_rom_num": producto.booking_rom_num,
"booking_floor": producto.booking_floor,
"booking_area": producto.booking_area,
"booking_lookout_area": producto.booking_lookout_area,
"is_booking_type": producto.is_booking_type,
"website_url": producto.website_url,
"booking_plan_ids": [x.id for x in producto.booking_plan_ids],
"product_template_image_ids": [
x.id for x in producto.product_template_image_ids],
"image_1024": self.imagen_procesar(producto.image_1024),
"description": producto.description,
"cost_currency_id": [x for x in producto.cost_currency_id],
}
productos_dict['skus'].append(d)
return productos_dict
Now I find that it producto.cost_currenci_id
contains elements that I don't know how they are named and I need to extract them, for example:
//Cost prodia contener
{
id:producto.cost_currency_id.id,
currenci:producto.cost_currenci_id.name,
price:producto.cost_currency_id.price,
}
How can I know the values that I eat producto.cost_currency_id
, .id
, .name
from .price
the console? And if possible, see the value with which they come. Similar to what happens with console.log(miObjeto)
in javascript.
Edit
I don't know how to access the model since the query is done like this:
from odoo import http
class OdooController(http.Controller):
@http.route("/barriotec/skus", auth="public", )
def index(self, **kw):
self.auth()
productos = http.request.env['product.template'].search([
["is_booking_type", "=", True],
# ["categ_id", "=", categoriaId],
])
self.auth(login=False)
datos = json.dumps(self.cargarDiccionario(productos))
return http.Response(
datos,
status=200,
content_type="application/json"
)