Ir al contenido
Menú
Se marcó esta pregunta
2 Respuestas
1657 Vistas

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?

Avatar
Descartar
Mejor respuesta

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.

Avatar
Descartar
Mejor respuesta

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

Avatar
Descartar