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

I get a studio automation on sale.order, which is below.


p6120 and p6121 are find but when trying to create the order line, Odoo can't do it because :

" (Enregistrement : product.product(6120,), Utilisateur : 2)"


What is the issue and the solution :-) ? 


Thanks in advance

if not env.context.get('skip_auto_add_6120'):

try:
    p6120 = env.ref('__custom__.6120')
except:
    p6120 = None
try:
    p6121 = env.ref('__custom__.6121')
except:
    p6121 = None

# Si le produit cible (6120) n'existe pas on ne fait rien
if p6120:
    
    ids_to_check = [p6120.id] + ([p6121.id] if p6121 else [])
   
       # S'il n'y a aucune ligne avec 6120 ni 6121, on ajoute 6120
    if not any(line.product_id.id in ids_to_check for line in record.order_line):
        #raise UserError("La valeur de la variable est : %s" % p6120.id)
        record.with_context(skip_auto_add_6120=True).order_line.create({
            'order_id': record.id,
            'product_id': p6120.id,
            'product_uom_qty': 1,
            'product_uom': p6120.uom_id.id,
            'price_unit': p6120.list_price,
        })
Avatar
Descartar
Mejor respuesta

Hi,


Use env['sale.order.line'].create() instead. This is the proper way to create records in Odoo ORM.


Try the following code:


if not env.context.get('skip_auto_add_6120'):

    try:

        p6120 = env.ref('__custom__.6120')

    except:

        p6120 = None

    try:

        p6121 = env.ref('__custom__.6121')

    except:

        p6121 = None


    if p6120:

        ids_to_check = [p6120.id] + ([p6121.id] if p6121 else [])

       

        if not any(line.product_id.id in ids_to_check for line in record.order_line):

            env['sale.order.line'].with_context(skip_auto_add_6120=True).create({

                'order_id': record.id,

                'product_id': p6120.id,

                'product_uom_qty': 1,

                'product_uom': p6120.uom_id.id,

                'price_unit': p6120.list_price,

            })


Hope it helps

Avatar
Descartar
Autor

Hi,

thanks for your reply. Unfortunately, the error is still the same "Oh mince !
Enregistrement inexistant ou supprimé.
(Enregistrement : product.product(6120,), Utilisateur : 2)"

By the way, This product is really existing.

The error comes here : 'product_id': p6120.id,

something like this (to give the p6120 record) does not work too : product = env['product.product'].browse(6120) for information.

Any other idea?

Mejor respuesta

The error "Record: product.product(6120,), User: 2" in your Odoo Studio automation indicates that the system can't find the product with ID 6120 when trying to create the sales order line.



  1. Verify Product Existence: Check if a product with ID 6120 actually exists in your Odoo database. Go to Inventory ‣ Products and search for it. If it doesn't exist, create the product with the correct details.

  2. Check `env.ref` Call: The `env.ref('__custom__.6120')` line attempts to retrieve the product using its XML ID. Ensure '__custom__' is the correct module name where product 6120 is defined. Double-check for typos in the XML ID or module name. Incorrect XML IDs are a common cause of this error.

  3. Debug the Automation: Add more logging or debugging statements within your automation to pinpoint the exact point of failure. For example, print the value of `p6120` before the `if p6120:` condition to confirm if the product reference is being correctly retrieved. Consider using Odoo's built-in debugging tools.

  4. Contextual Issues: The error might stem from the context in which the automation runs. Examine the context variables available within the automation to ensure they are correctly set and don't interfere with the product lookup. The `with_context` call might be masking a deeper issue.

  5. Access Rights: Verify that the user running the automation (User 2) has the necessary access rights to read and create sales order lines and access the specified product.


For personalized assistance:
https://www.pragtech.co.in/contact-us-mql.html

Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
2
sept 25
179
1
sept 25
546
2
ago 25
690
1
sept 25
612
1
sept 25
613