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

In Odoo 9:

am not finding a way to get the value of compute fields in the create method. However the same had achieved in other version by calling the function of compute-fields,


Say for instance in Sale Order:

'amount_total' is a compute field which calls the function "_amount_all" to calculate the amount.


Now in create method, the value for amount_total is yet  to be filled hence in order to access it, one can just call the function _amount_all which will evaluate and return the value of amount_total.

So same way I would like to do in Odoo 9  as well, but not sure whether it is due to this api decorator or so, am unable to achieve .

Any thoughts are welcomed.

Thanks

アバター
破棄
最善の回答

The compute method or the compute fields are activated or being calculated while rendering the related view. If you want this values on create method then you have to do the same function on create method also. or next change is to trigger the function explicitly from the create method. 

アバター
破棄
著作者

I agree, but don't you think it calls for redundancy of Code?, whats the point in rewriting the code again when we are seem to be using the latest coding.

最善の回答

Hi,

You may try like this:

class SaleOrder(models.Model):
     _inherit = "sale.order"
     
     @api.model
     def create(self, vals):
         res = super(SaleOrder, self).create(vals)
         total = res.amount_total //compute field value
         return res
アバター
破棄
著作者 最善の回答

I wonder who marked this answer as resolved, when it is apparently, the solution isn't nowhere what am looking for.

アバター
破棄
最善の回答

dear deep,

you need to do something like this,

 @api.multi
@api.depends('amount_currency','currency_id')
 def _amount_in_words(self):
"""
this Function uses to get the ratification amount in words.
"""
for rec in self:
self.amount_words_letters = amount_to_text((self.amount_currency or 0.00))
amount_text= fields.Char(compute='_amount_in_words', string='Amount In Words', store=True)

I hope I helped you.

アバター
破棄
著作者

Wish I could say it helped me, but sadly no, Thanks for the reply.

Ayman, onchange is default on @api.depends, so no need to use @api.onchange along with @api.depends.

Edited Answer, Someone added a phishing method or something like that inside the answer with a link points to there. Which is not acceptable.

関連投稿 返信 ビュー 活動
0
9月 23
1914
0
9月 23
1610
2
6月 25
11049
6
10月 23
21911
3
3月 24
9373