Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
542 มุมมอง

If search the forum and internet. Every example given, gets me a "forbidden opcode(s)" error when I try to execute a script.

I made a sequence with sequence code product.auto.reference

The automation executes a code, the code looks like this:

if not record.default_code:

    seq = env['ir.sequence'].next_by_code('product.auto.reference')

    if seq:

        record.default_code = seq


What I try to achieve is that the product field "Reference" (default.code) is auto filled with a predefiend sequence.


I'm using Odoo Online.



อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hello Bart,


For Security reasons Odoo prevented some actions from being used one of witch is the Store attribute "=" , you can Not use "=" to assign a value to an object of the record, what you can do instead is use the update method

here is how your code will look like

if not record.default_code:

    seq = env['ir.sequence'].next_by_code('product.auto.reference')

    if seq:

        record.update({

            'default_code': seq

        })


I hope this helps you

อวตาร
ละทิ้ง
ผู้เขียน คำตอบที่ดีที่สุด

This does the trick. Thanks!

อวตาร
ละทิ้ง