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

Hello, I am just want to ask how can I run a function on a Yes or No button of a transient model/wizard in odoo 10? Thank very much in advance.

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

Hi, you can follow following link for this:

https://youtu.be/oMnHpHH54QU

Hope it helps,

Thanks

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

Hi,

Let's consider that you have a wizard 'abc.abc' and you have two buttons 'Yes' and 'No'.
Define the form view for the wizard.

To return a wizard in odoo 10,use the following syntax.

view_id = self.env.ref('module_name.view')
return {
'name': _('Abc'),
'res_model': 'abc.abc',
'context': {
},
'type': 'ir.actions.act_window',
'view_id': False,
'views': [(view_id.id, 'form')],
'view_mode': 'form',
'target': 'new',
'view_type': 'form',
'res_id': self.id
}

To run a python function from a button in odoo 10,please use the following syntax.

<button string="Yes" name="action_yes" type="object" class="btn-primary"/>


<button string="No" class="btn-default" special="cancel"/>

Define the function

def action_yes:
print('code blocks')

special='cancel' attribute can be used to cancel and close the wizard

Regards

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

Hi,

Let's discuss by taking an example, suppose if you are looking to do a confirmation functionality, you can create a transient model

with the Yes or No buttons, then from your main buttons, lets say Confirm button in sales which by default calls action_confirm method, you can inherit the button and instead of calling the action_confirm button, you can return your wizard.


Then once the wizard is displayed on user clicking the Yes button, you can trigger the action_confirm on the sale.order record, you can get the sale order, by browsing using the active_id in the context or by keeping related sale order field in the wizard. In the other hand, you can just pass special="cancel" for the No button.


Thanks

อวตาร
ละทิ้ง
ผู้เขียน

Hi Niyas, I did something like what you've said but neither yes nor no button does not trigger a function I put on them. What could be the problem?

Related Posts ตอบกลับ มุมมอง กิจกรรม
2
ก.ค. 25
156
0
ธ.ค. 24
940
2
ต.ค. 24
1075
1
ส.ค. 24
2180
2
ก.ค. 24
1455