Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
5611 Vistas

I want to directly modify the website application in odoo 14. I am using web.rpc for this, in this way but I cannot find documentation to do a more refined search.


odoo.define("website.user_custom_code", function (require) {


;("use strict")
require("web.dom_ready")
rpc = require("web.rpc")

const model = "product.template"
const method = "search_read"

// Use an empty array to search for all the records
const domain = ["fields_get"]
// Use an empty array to read all the fields of the records
const fields = [] //accessoADatos.map(x => x.campo)

const options = {
model,
method,
args: [domain, fields],

}

rpc
.query(options)
.then(products => console.log(products))
.catch(err => console.error(err))
})





Avatar
Descartar
Mejor respuesta

Hello Rafael,
web.rpc is just the wrapped by odoo web client ajax.rpc() call :)
so to help you, please take a look at the source of this js module:

https://github.com/odoo/odoo/blob/14.0/addons/web/static/src/js/core/rpc.js

take a look at the line 18:

return ajax.rpc(query.route, query.params, options);

you see exactly what parameters to use and that it is using js ajax call..

For the one of the easiest example of use, just analyze this usage from website_sale_shop_mail.js:

https://github.com/odoo/odoo/blob/14.0/addons/website_sale/static/tests/tours/website_sale_shop_mail.js

Hope this helped something..
if it did please vote +1 👍
and if you find it Best answer - make it so 😎

Avatar
Descartar
Autor

It is useful, but I realize that my problem is that I do not know how to access the models by name. For example, I can access `product.template`, but I have a boocking module that adds extra media fields. (A downloaded plugin) How to obtain the model to consult ?.

Is this module introducing it's own model or just inheriting existing one.. you always should access the table in which you have the field.. if this module is inheritng product.template and adding field to it, to get it's value you need to access product.template, otherwise you need to access newly created model (table) let's call it custom.model

if you are asking, where to find the model name and all fields in it you can do it from the source code (look at lines since 12-22)
https://github.com/odoo/odoo/blob/14.0/addons/website_sale/models/product.py

or by going to Settings -> Technical -> Models -> find your model name and description -> click -> and there you have your fields

Autor

I am looking for this data in the product, but it seems to be in product.image? How do I get the url of the video?
https://imgur.com/a/6iMMo8O

be sure you have developer mode activated (Settings -> Developer tools -> bottom page)
or just add ?debug=1 in the url of you browser right after /web
then if you hover the bolded url, you will find the popup with details of this field

Publicaciones relacionadas Respuestas Vistas Actividad
2
abr 21
3855
1
feb 16
3553
2
jul 24
859
1
may 23
7290
1
sept 22
3228