Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
1835 Vistas

just wanna find out all products which got no sales, so that we could re -consider the strategy about them.

Avatar
Descartar

It looks like this module - https://apps.odoo.com/apps/modules/17.0/low_sales_report - serve exactly for the goal.

Mejor respuesta

Hi Sigma, 

without any customization, I propose to use a scheduled action with python code. The code will give you a nice error message listing all products which were not sold during a specific period, which you can adjust in the code. Below is an example for getting these values. Of course if you want to only see which products are not delivered in a period or not invoiced in a period, you could use the same strategy but different models in odoo.

This is the code:

def get_unsold_products_in_january(self):

    # Step 1: Find all products that were sold in the given period

    env.cr.execute("""

        SELECT DISTINCT(product_id)

        FROM sale_order_line

        WHERE order_id IN (

            SELECT id FROM sale_order

            WHERE date_order >= '2024-01-01' AND date_order

        )

    """)

    sold_product_ids = [row[0] for row in env.cr.fetchall()]


    # Step 2: Find all products that were not sold in January 2024

    unsold_products = self.env['product.product'].search([

        ('id', 'not in', sold_product_ids)

    ])


    # Step 3: Prepare the message with product internal reference and name

    if unsold_products:

        message = "\n".join([f"{prod.default_code} - {prod.name}" for prod in unsold_products])

        raise UserError(f"The following products were not sold:\n\n{message}")

    else:

        raise UserError("All products were sold.")


Can I help you with this? Contact me at hi (at) latus . ch / thanks! Cheers, Joep

Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
2
may 25
3815
0
nov 24
1096
1
ago 24
3341
2
may 23
2196
2
may 20
36