Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
1 Відповісти
5425 Переглядів

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

Аватар
Відмінити
Найкраща відповідь

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

Аватар
Відмінити
Автор

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

Related Posts Відповіді Переглядів Дія
3
жовт. 23
5178
0
бер. 25
1043
1
жовт. 24
1460
1
груд. 23
1708
0
груд. 23
1751