跳至內容
選單
此問題已被標幟
1 回覆
1336 瀏覽次數
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.

頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
0
8月 24
997
1
7月 24
1434
0
4月 24
1098
1
7月 24
1750
1
3月 22
4509