コンテンツへスキップ
メニュー
この質問にフラグが付けられました
1 返信
5158 ビュー

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.

関連投稿 返信 ビュー 活動
3
10月 23
4895
0
3月 25
898
1
10月 24
1285
1
12月 23
1560
0
12月 23
1618