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

Odoo v16

How can I programmatically track the change in the quantity in product and output to the log.

I need to track any change in the number of products, and update it on the API of another system, how can I catch this event?

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

try this way:
from odoo import models, fields, api

import logging

_logger = logging.getLogger(__name__)



class ProductProduct(models.Model):

_inherit = 'product.product'


quantity = fields.Float(string='Quantity')


@api.onchange('quantity')

def _onchange_quantity(self):

for product in self:

_logger.info(f"Quantity changed for product {product.name}: {product.quantity}")


# Update the API of the other system here


Remember to adjust the field names ('product.product', 'quantity', etc.) according to your specific model and field names.

This will log a message every time the quantity field of a product is changed. You can also include the necessary logic to update the API of the other system inside the _onchange_quantity method.

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

HI,

You can trigger your api based on stock moves in the system. May be by supering the action_done function of stock move model.


Thanks

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