Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odpovědět
1449 Zobrazení
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
Zrušit
Nejlepší odpověď

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
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
0
srp 24
1074
1
čvc 24
1546
0
dub 24
1196
1
čvc 24
1837
1
bře 22
4623