Skip to Content
Menu
This question has been flagged
1 Reply
4346 Views

I have a python method:

class ReceiptModel(models.Model):
​_name = 'receipt.model'

​amount = fields.Integer('Amount')

​def get_receipt_amount(self):
​for record in self:
​amount = record.amount + 100
​return amount

OWL JS class:

/** @odoo-module **/

const { Component, useState, onWillStart, onWillUnmount } = owl;
export class ReceiptAmount extends Component {
​setup() {
​this.receiptAmount = useState ({ value: "" }); ​super.setup();
​}

_getWalletAmount() {
​//get value from the python method 'get_wallet_amount()'
}
}

In the '_getWalletAmount()' method I want to execute the 'get_wallet_amount()' and get the result. How to do this?


Thanks

Avatar
Discard
Best Answer

Hi,

To call a python method in js you can use orm method

example:

Your Js file,


const { Component, useState, onWillStart, onWillUnmount } = owl;

import { useService } from "@web/core/utils/hooks";

export class ReceiptAmount extends Component {

setup() {              

this.receiptAmount = useState ({ value: "" });        

this.orm = useService("orm");

}


   _getWalletAmount() {        

              let data = orm.call("receipt.model", "get_wallet_amount", [ ]);

    }

}


Your Python file,

def get_wallet_amount(self):

    for record in self:

           amount = record.amount + 100

            return amount


Hope it helps

Avatar
Discard
Author

thank you, this is the solution I was looking for.

Related Posts Replies Views Activity
3
Oct 23
4111
0
Mar 25
524
1
Oct 24
798
1
Dec 23
1078
0
Dec 23
1264