Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
1 Beantwoorden
1280 Weergaven
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
Annuleer
Beste antwoord

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
Annuleer
Gerelateerde posts Antwoorden Weergaven Activiteit
0
aug. 24
899
1
jul. 24
1384
0
apr. 24
1053
1
jul. 24
1686
1
mrt. 22
4426