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?
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
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?
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.
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
Cree una cuenta para poder utilizar funciones exclusivas e interactuar con la comunidad.
Inscribirse