Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
3744 Lượt xem

What i have understood so far is:

1. 'qty_available' is a computed field: which means it will not be called unless it is loaded from view

2. 'api.depends' can only be used on computed field

3. maybe "store=True" on qty_available will work but I feel a bit risky, its odoo base field so maybe it will break

4. override 'write' function is kinda overkill

My goal is really simple, I want to trigger a function when qty_available (Quantity on hand) of a product changes, what should I do? I dont know if 'stock.quant' has anything to do with it

Ảnh đại diện
Huỷ bỏ

supering the action_done of stock move will help you in this case ?

Câu trả lời hay nhất

Hi,

You can super the compute function for that qty_available field by inheriting the model and you can call a new function inside that compute function, and you can define the function inside that model so that whenever that compute function is called the new function will be automatically triggered.
Please refer to the following code:
from odoo import fields, models


class ProductTemplate(models.Model):
    _inherit = 'product.template'

    def _compute_quantities(self):
        super(ProductTemplate, self)._compute_quantities()
        self.my_function()
   
    def my_function(self):
        print("This function will calls when compute function works")


Hope it helps

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 8 22
2536
1
thg 5 22
2993
0
thg 8 17
5482
2
thg 3 15
6505
2
thg 1 24
3251