Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
1 Ответить
1240 Представления
Its My JS code

/** @odoo-module **/

import { ProductScreen } from "@point_of_sale/app/screens/product_screen/product_screen";
import { patch } from "@web/core/utils/patch";
import { useService } from "@web/core/utils/hooks";

patch(ProductScreen.prototype, {
setup() {
super.setup();
this.orm = useService("orm");
},
async onMounted() {
const value = await this.orm.call("product.pricelist", "get_mrp");
console.log(value);
console.log(value.name);
},
});


Is MY py file

from odoo import fields, models, api


class Pricelist(models.Model):
_inherit = "product.pricelist"

@api.model
def get_mrp(self):
return self.env['product.pricelist'].search([], limit=1)


I am tryong to get all field of single row from db

but when i execute the code the output is :

product.pricelist(2,)  point_of_sale.assets_prod.min.js
undefined point_of_sale.assets_prod.min.js

Can Anyone help  how to fit all data in to variable value ??

Аватар
Отменить
Лучший ответ

Hi,

The issue you're encountering is due to how the ORM call is returning the result and how you're trying to access the data in JavaScript. When you use the ORM call to fetch a record, it returns a recordset, which in this case is product.pricelist(2,), but you need to access the fields of that record separately.


Ensure that your method returns the data in a dictionary format which is easier to work with in JavaScript:

from odoo import fields, models, api


class Pricelist(models.Model):

    _inherit = "product.pricelist"


    @api.model

    def get_mrp(self):

        pricelist = self.env['product.pricelist'].search([], limit=1)

        if pricelist:

            return {

                'id': pricelist.id,

                'name': pricelist.name,

                'currency_id': pricelist.currency_id.id,

                # Add other fields you want to return

            }

        return {}


Hope it helps.

Аватар
Отменить
Related Posts Ответы Просмотры Активность
0
авг. 24
857
1
июл. 24
1355
0
апр. 24
1029
1
июл. 24
1622
1
мар. 22
4386