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

I have a boolean smart button that when clicked triggers a @constrains method in product.template. It works as intended only AFTER the product is created (I use this button as a toggle, when true it "publishes" the product, and false would be "unpublish.")

My problem starts as soon as I click save when creating a product, since it triggers the function 3 times in a row. Now I read that api.constrains triggers when CREATE, WRITE, UNLINK. What can I do to avoid triggering the constrains when creating? I'd like to only trigger when I press the boolean smart button.

Is there an alternative to api.constrains? I tried all other decorators and they don't trigger my method. @api.constrains is the closest and my current solution.


My method looks like this, more or less:

product_template_extension.py

product_publish = fields.Boolean(name='Publish', default= False)

@api.one

@api.constrains( 'product_publish' )

        def publish_product(self):

                # my working function, sends data to my e-commerce correctly.

XML wise it's just a simple boolean button. (Smart button works perfectly)

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

Hi Mark,

Indeed api.constrains triggers when CREATE, WRITE, UNLINK. If your case I can only suggest you to use either api.onchange or api.depends.

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
2
พ.ค. 22
10429
3
ม.ค. 23
6753
1
มี.ค. 22
4898
1
ก.พ. 22
5056
1
ก.ค. 20
8974