تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
13 الردود
13453 أدوات العرض

Hi,

Due to some reason I need to run sql insert query for creating order lines.
The challenge is I need to map taxes to each order line but, due to I'm not having each line reference "ID"  before,  I can't perform insert onto many2many relation.

Thanks!

الصورة الرمزية
إهمال

Sushma, you know the order id, after that your trying to insert order lines into the particular order.So you can get line ids using order id and already you know the tax id, then tell me what's your problem.

أفضل إجابة

Hi,

At least you need record id to map with many2many relation.

الصورة الرمزية
إهمال
أفضل إجابة

Hello ,

        The id will be automatically created , you dont have to give an id to the record.

        Other than Using Query , You Can Try

        sale_order_line_id = self.env['sale.order.line'].create({
            'order_id':order_id,
            'product_id':product_id,
            'product_uom_qty':quantity,
            'price_unit':unit_price
})

    in this manner give every detailes of the order line and you can create an order line by code

    the line will appear on the order which's id is given as the order_id

الصورة الرمزية
إهمال
الكاتب

Hi,

My question is about creating through sql queries not orm. So i would like to know, identical to mapping many2many using orm [(6,0, ids)], can we perform something with SQL queries.

Thanks.

أفضل إجابة

Hi Sushma,

This is how inserts in query

query = """ INSERT INTO {rel} ({id1}, {id2})

                        (SELECT a, b FROM unnest(%s) AS a, unnest(%s) AS b)

                        EXCEPT (SELECT {id1}, {id2} FROM {rel} WHERE {id1} IN %s)

                    """.format(**parts)


Regards,

الصورة الرمزية
إهمال
أفضل إجابة

Hello, 

Check below link i think it's help you 

https://stackoverflow.com/questions/34362637/sql-many2many-query
الصورة الرمزية
إهمال
أفضل إجابة

Yes we can insert using query.

many2many have a relational table. so insert into the relational table, it will work

الصورة الرمزية
إهمال
الكاتب

Thanks for reply.

Indeed there is different relation for many2many, but my question is while creating parent record how we run SQL query for many2many without ID.

you mean while creating order lines you have insert into many2many relation table

الكاتب

Yes something like while create order lines wanted to add taxes for each lines through sql query

do you have the tax_id while create the order line

الكاتب

Yes oblivious, I guess you're diverting something else, please read my posted question once.

Thanks

so your problem is order line id is not available to link it

المنشورات ذات الصلة الردود أدوات العرض النشاط
1
مارس 22
13445
1
يوليو 21
3647
1
أكتوبر 20
4208
1
يوليو 19
4795
1
فبراير 18
3902