Skip to Content
Menu
This question has been flagged
1 Reply
1130 Views
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 ??

Avatar
Discard
Best Answer

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.

Avatar
Discard
Related Posts Replies Views Activity
0
Aug 24
714
1
Jul 24
1225
0
Apr 24
914
1
Jul 24
1431
1
Mar 22
4156