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

Hi all,


I am triggering a stock move via the API in order to update the stock quantity of a batch.


Now, whenever the stock is updated, I want to trigger a function to sync this change to another website. However, with my current solution, the sync is triggered before the quantity of the lot is updated.


This is the code I am using right now. Since StockMove.write() is called multiple times, I am checking with the _last_id attribute, to make sure it syncs only once. However, as stated before, it is too early.

```

from odoo.addons.stock.models.stock_move import StockMove as OStockMove

class StockMove(models.Model):
_inherit = "stock.move"
_last_id = 0

def write(self, vals):
res = OStockMove.write(self, vals)
if self.lot_ids:
if self._last_id != self.id:
type(self)._last_id = self.id
batch_sync(self.lot_ids)
_logger.error(str(self.is_done) + " " + str(self.lot_ids))
return res
```

How can I trigger the sync *after* the stock has been moved?
Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
4
thg 4 25
7931
0
thg 10 24
1553
3
thg 11 21
3449
2
thg 5 25
5108
1
thg 1 25
4735